1 package ExtUtils::Mkbootstrap;
5 @EXPORT='&Mkbootstrap';
6 $Version=2.0; # just to start somewhere
12 ExtUtils::Mkbootstrap - make a bootstrap file for use by DynaLoader
20 Mkbootstrap typically gets called from an extension Makefile.
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.
26 This file will get parsed, and produce a maybe empty
27 C<@DynaLoader::dl_resolve_using> array for the current architecture.
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>
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.
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.
43 my($baseext, @bsloadlibs)=@_;
45 @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
47 print STDOUT " bsloadlibs=@bsloadlibs\n" if $Verbose;
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.
55 rename "$baseext.bs", "$baseext.bso"
58 if (-f "${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)};
69 if ($Config{'dlsrc'} =~ /^dl_dld/){
71 push(@dl_resolve_using, dl_findfile('-lc'));
74 my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
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";
91 print BS " qw(@all);\n";
93 # write extra code if *_BS says so
94 print BS $DynaLoader::bscode if $DynaLoader::bscode;