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