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