home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_mlb.zip / ExtUtils / Mkbootstrap.pm < prev    next >
Text File  |  1997-11-25  |  3KB  |  104 lines

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