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