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