Commit | Line | Data |
005c1a0e |
1 | package ExtUtils::Mkbootstrap; |
2 | use Config; |
3 | use Exporter; |
4 | @ISA=('Exporter'); |
5 | @EXPORT='&Mkbootstrap'; |
6 | $Version=2.0; # just to start somewhere |
7 | |
8 | sub Mkbootstrap { |
9 | |
10 | =head1 USEFUL SUBROUTINES |
11 | |
12 | =head2 Mkbootstrap() |
13 | |
14 | Make a bootstrap file for use by this system's DynaLoader. It |
15 | typically gets called from an extension Makefile. |
16 | |
17 | There is no C<*.bs> file supplied with the extension. Instead a |
18 | C<*_BS> file which has code for the special cases, like posix for |
19 | berkeley db on the NeXT. |
20 | |
21 | This file will get parsed, and produce a maybe empty |
22 | C<@DynaLoader::dl_resolve_using> array for the current architecture. |
23 | That will be extended by $BSLOADLIBS, which was computed by Andy's |
24 | extliblist script. If this array still is empty, we do nothing, else |
25 | we write a .bs file with an C<@DynaLoader::dl_resolve_using> array, but |
26 | without any C<if>s, because there is no longer a need to deal with |
27 | special cases. |
28 | |
29 | The C<*_BS> file can put some code into the generated C<*.bs> file by placing |
30 | it in C<$bscode>. This is a handy 'escape' mechanism that may prove |
31 | useful in complex situations. |
32 | |
33 | If @DynaLoader::dl_resolve_using contains C<-L*> or C<-l*> entries then |
34 | Mkbootstrap will automatically add a dl_findfile() call to the |
35 | generated C<*.bs> file. |
36 | |
37 | =cut |
38 | |
39 | my($baseext, @bsloadlibs)=@_; |
40 | |
41 | @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs |
42 | |
43 | print STDOUT " bsloadlibs=@bsloadlibs\n" if $Verbose; |
44 | |
45 | # We need DynaLoader here because we and/or the *_BS file may |
46 | # call dl_findfile(). We don't say `use' here because when |
47 | # first building perl extensions the DynaLoader will not have |
48 | # been built when MakeMaker gets first used. |
49 | require DynaLoader; |
50 | |
51 | rename "$baseext.bs", "$baseext.bso" |
52 | if -s "$baseext.bs"; |
53 | |
54 | if (-f "${baseext}_BS"){ |
55 | $_ = "${baseext}_BS"; |
56 | package DynaLoader; # execute code as if in DynaLoader |
57 | local($osname, $dlsrc) = (); # avoid warnings |
58 | ($osname, $dlsrc) = @Config::Config{qw(osname dlsrc)}; |
59 | $bscode = ""; |
60 | unshift @INC, "."; |
61 | require $_; |
62 | shift @INC; |
63 | } |
64 | |
65 | if ($Config{'dlsrc'} =~ /^dl_dld/){ |
66 | package DynaLoader; |
67 | push(@dl_resolve_using, dl_findfile('-lc')); |
68 | } |
69 | |
70 | my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using); |
71 | my($method) = ''; |
72 | if (@all){ |
73 | open BS, ">$baseext.bs" |
74 | or die "Unable to open $baseext.bs: $!"; |
75 | print STDOUT "Writing $baseext.bs\n"; |
76 | print STDOUT " containing: @all" if $Verbose; |
77 | print BS "# $baseext DynaLoader bootstrap file for $Config{'osname'} architecture.\n"; |
78 | print BS "# Do not edit this file, changes will be lost.\n"; |
79 | print BS "# This file was automatically generated by the\n"; |
80 | print BS "# Mkbootstrap routine in ExtUtils::Mkbootstrap (v$Version).\n"; |
81 | print BS "\@DynaLoader::dl_resolve_using = "; |
82 | # If @all contains names in the form -lxxx or -Lxxx then it's asking for |
83 | # runtime library location so we automatically add a call to dl_findfile() |
84 | if (" @all" =~ m/ -[lLR]/){ |
85 | print BS " dl_findfile(qw(\n @all\n ));\n"; |
86 | }else{ |
87 | print BS " qw(@all);\n"; |
88 | } |
89 | # write extra code if *_BS says so |
90 | print BS $DynaLoader::bscode if $DynaLoader::bscode; |
91 | print BS "\n1;\n"; |
92 | close BS; |
93 | } |
94 | } |
95 | |