home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / D12 / PERL1.TGZ / perl1.tar / usr / lib / perl5 / ExtUtils / Mkbootstrap.pm < prev    next >
Text File  |  1996-06-28  |  3KB  |  98 lines

  1. package ExtUtils::Mkbootstrap;
  2. use Config;
  3. use Exporter;
  4. @ISA=('Exporter');
  5. @EXPORT='&Mkbootstrap';
  6. $Version=2.0; # just to start somewhere
  7.  
  8. sub Mkbootstrap {
  9.  
  10. =head1 NAME
  11.  
  12. ExtUtils::Mkbootstrap - make a bootstrap file for use by DynaLoader
  13.  
  14. =head1 SYNOPSIS
  15.  
  16. C<mkbootstrap>
  17.  
  18. =head1 DESCRIPTION
  19.  
  20. Mkbootstrap typically gets called from an extension Makefile.
  21.  
  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.
  25.  
  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>
  31. array.
  32.  
  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.
  36.  
  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.
  40.  
  41. =cut
  42.  
  43.     my($baseext, @bsloadlibs)=@_;
  44.  
  45.     @bsloadlibs = grep($_, @bsloadlibs); # strip empty libs
  46.  
  47.     print STDOUT "    bsloadlibs=@bsloadlibs\n" if $Verbose;
  48.  
  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.
  53.     require DynaLoader;
  54.  
  55.     rename "$baseext.bs", "$baseext.bso"
  56.       if -s "$baseext.bs";
  57.  
  58.     if (-f "${baseext}_BS"){
  59.     $_ = "${baseext}_BS";
  60.     package DynaLoader; # execute code as if in DynaLoader
  61.     $bscode = "";
  62.     unshift @INC, ".";
  63.     require $_;
  64.     shift @INC;
  65.     }
  66.  
  67.     if ($Config{'dlsrc'} =~ /^dl_dld/){
  68.     package DynaLoader;
  69.     push(@dl_resolve_using, dl_findfile('-lc'));
  70.     }
  71.  
  72.     my(@all) = (@bsloadlibs, @DynaLoader::dl_resolve_using);
  73.     my($method) = '';
  74.     if (@all){
  75.     open BS, ">$baseext.bs"
  76.         or die "Unable to open $baseext.bs: $!";
  77.     print STDOUT "Writing $baseext.bs\n";
  78.     print STDOUT "    containing: @all" if $Verbose;
  79.     print BS "# $baseext DynaLoader bootstrap file for $^O architecture.\n";
  80.     print BS "# Do not edit this file, changes will be lost.\n";
  81.     print BS "# This file was automatically generated by the\n";
  82.     print BS "# Mkbootstrap routine in ExtUtils::Mkbootstrap (v$Version).\n";
  83.     print BS "\@DynaLoader::dl_resolve_using = ";
  84.     # If @all contains names in the form -lxxx or -Lxxx then it's asking for
  85.     # runtime library location so we automatically add a call to dl_findfile()
  86.     if (" @all" =~ m/ -[lLR]/){
  87.         print BS "  dl_findfile(qw(\n  @all\n  ));\n";
  88.     }else{
  89.         print BS "  qw(@all);\n";
  90.     }
  91.     # write extra code if *_BS says so
  92.     print BS $DynaLoader::bscode if $DynaLoader::bscode;
  93.     print BS "\n1;\n";
  94.     close BS;
  95.     }
  96. }
  97.  
  98.