home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / ExtUtils / Mksymlists.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  8.6 KB  |  262 lines

  1. package ExtUtils::Mksymlists;
  2. use strict qw[ subs refs ];
  3.  
  4. use Carp;
  5. use Exporter;
  6. use vars qw( @ISA @EXPORT $VERSION );
  7. @ISA = 'Exporter';
  8. @EXPORT = '&Mksymlists';
  9. $VERSION = substr q$Revision: 1.16 $, 10;
  10.  
  11. sub Mksymlists {
  12.     my(%spec) = @_;
  13.     my($osname) = $^O;
  14.  
  15.     croak("Insufficient information specified to Mksymlists")
  16.         unless ( $spec{NAME} or
  17.                  ($spec{FILE} and ($spec{DL_FUNCS} or $spec{FUNCLIST})) );
  18.  
  19.     $spec{DL_VARS} = [] unless $spec{DL_VARS};
  20.     ($spec{FILE} = $spec{NAME}) =~ s/.*::// unless $spec{FILE};
  21.     $spec{DL_FUNCS} = { $spec{NAME} => [] }
  22.         unless ( ($spec{DL_FUNCS} and keys %{$spec{DL_FUNCS}}) or
  23.                  $spec{FUNCLIST});
  24.     $spec{FUNCLIST} = [] unless $spec{FUNCLIST};
  25.     if (defined $spec{DL_FUNCS}) {
  26.         my($package);
  27.         foreach $package (keys %{$spec{DL_FUNCS}}) {
  28.             my($packprefix,$sym,$bootseen);
  29.             ($packprefix = $package) =~ s/\W/_/g;
  30.             foreach $sym (@{$spec{DL_FUNCS}->{$package}}) {
  31.                 if ($sym =~ /^boot_/) {
  32.                     push(@{$spec{FUNCLIST}},$sym);
  33.                     $bootseen++;
  34.                 }
  35.                 else { push(@{$spec{FUNCLIST}},"XS_${packprefix}_$sym"); }
  36.             }
  37.             push(@{$spec{FUNCLIST}},"boot_$packprefix") unless $bootseen;
  38.         }
  39.     }
  40.  
  41.     if (defined &DynaLoader::mod2fname and not $spec{DLBASE}) {
  42.         $spec{DLBASE} = DynaLoader::mod2fname([ split(/::/,$spec{NAME}) ]);
  43.     }
  44.  
  45.     if    ($osname eq 'aix') { _write_aix(\%spec); }
  46.     elsif ($osname eq 'VMS') { _write_vms(\%spec) }
  47.     elsif ($osname eq 'os2') { _write_os2(\%spec) }
  48.     elsif ($osname eq 'MSWin32') { _write_win32(\%spec) }
  49.     else { croak("Don't know how to create linker option file for $osname\n"); }
  50. }
  51.  
  52.  
  53. sub _write_aix {
  54.     my($data) = @_;
  55.  
  56.     rename "$data->{FILE}.exp", "$data->{FILE}.exp_old";
  57.  
  58.     open(EXP,">$data->{FILE}.exp")
  59.         or croak("Can't create $data->{FILE}.exp: $!\n");
  60.     print EXP join("\n",@{$data->{DL_VARS}}, "\n") if @{$data->{DL_VARS}};
  61.     print EXP join("\n",@{$data->{FUNCLIST}}, "\n") if @{$data->{FUNCLIST}};
  62.     close EXP;
  63. }
  64.  
  65.  
  66. sub _write_os2 {
  67.     my($data) = @_;
  68.  
  69.     if (not $data->{DLBASE}) {
  70.         ($data->{DLBASE} = $data->{NAME}) =~ s/.*:://;
  71.         $data->{DLBASE} = substr($data->{DLBASE},0,7) . '_';
  72.     }
  73.     rename "$data->{FILE}.def", "$data->{FILE}_def.old";
  74.  
  75.     open(DEF,">$data->{FILE}.def")
  76.         or croak("Can't create $data->{FILE}.def: $!\n");
  77.     print DEF "LIBRARY '$data->{DLBASE}' INITINSTANCE TERMINSTANCE\n";
  78.     print DEF "CODE LOADONCALL\n";
  79.     print DEF "DATA LOADONCALL NONSHARED MULTIPLE\n";
  80.     print DEF "EXPORTS\n  ";
  81.     print DEF join("\n  ",@{$data->{DL_VARS}}, "\n") if @{$data->{DL_VARS}};
  82.     print DEF join("\n  ",@{$data->{FUNCLIST}}, "\n") if @{$data->{FUNCLIST}};
  83.     if (%{$data->{IMPORTS}}) {
  84.         print DEF "IMPORTS\n";
  85. my ($name, $exp);
  86. while (($name, $exp)= each %{$data->{IMPORTS}}) {
  87.   print DEF "  $name=$exp\n";
  88. }
  89.     }
  90.     close DEF;
  91. }
  92.  
  93. sub _write_win32 {
  94.     my($data) = @_;
  95.  
  96.     require Config;
  97.     if (not $data->{DLBASE}) {
  98.         ($data->{DLBASE} = $data->{NAME}) =~ s/.*:://;
  99.         $data->{DLBASE} = substr($data->{DLBASE},0,7) . '_';
  100.     }
  101.     rename "$data->{FILE}.def", "$data->{FILE}_def.old";
  102.  
  103.     open(DEF,">$data->{FILE}.def")
  104.         or croak("Can't create $data->{FILE}.def: $!\n");
  105.     print DEF "LIBRARY \"$data->{DLBASE}\"\n";
  106.     print DEF "CODE LOADONCALL\n";
  107.     print DEF "DATA LOADONCALL NONSHARED MULTIPLE\n";
  108.     print DEF "EXPORTS\n  ";
  109.     my @syms;
  110.     if ($Config::Config{'cc'} =~ /^bcc/i) {
  111.     for (@{$data->{DL_VARS}}, @{$data->{FUNCLIST}}) {
  112.         push @syms, "_$_", "$_ = _$_";
  113.     }
  114.     }
  115.     else {
  116.     for (@{$data->{DL_VARS}}, @{$data->{FUNCLIST}}) {
  117.         push @syms, "$_", "_$_ = $_";
  118.     }
  119.     }
  120.     print DEF join("\n  ",@syms, "\n") if @syms;
  121.     if (%{$data->{IMPORTS}}) {
  122.         print DEF "IMPORTS\n";
  123.         my ($name, $exp);
  124.         while (($name, $exp)= each %{$data->{IMPORTS}}) {
  125.             print DEF "  $name=$exp\n";
  126.         }
  127.     }
  128.     close DEF;
  129. }
  130.  
  131.  
  132. sub _write_vms {
  133.     my($data) = @_;
  134.  
  135.     require Config; # a reminder for once we do $^O
  136.     require ExtUtils::XSSymSet;
  137.  
  138.     my($isvax) = $Config::Config{'arch'} =~ /VAX/i;
  139.     my($set) = new ExtUtils::XSSymSet;
  140.     my($sym);
  141.  
  142.     rename "$data->{FILE}.opt", "$data->{FILE}.opt_old";
  143.  
  144.     open(OPT,">$data->{FILE}.opt")
  145.         or croak("Can't create $data->{FILE}.opt: $!\n");
  146.  
  147.  
  148.     foreach $sym (@{$data->{FUNCLIST}}) {
  149.         my $safe = $set->addsym($sym);
  150.         if ($isvax) { print OPT "UNIVERSAL=$safe\n" }
  151.         else        { print OPT "SYMBOL_VECTOR=($safe=PROCEDURE)\n"; }
  152.     }
  153.     foreach $sym (@{$data->{DL_VARS}}) {
  154.         my $safe = $set->addsym($sym);
  155.         print OPT "PSECT_ATTR=${sym},PIC,OVR,RD,NOEXE,WRT,NOSHR\n";
  156.         if ($isvax) { print OPT "UNIVERSAL=$safe\n" }
  157.         else        { print OPT "SYMBOL_VECTOR=($safe=DATA)\n"; }
  158.     }
  159.     close OPT;
  160.  
  161.     open OPT,'>rtls.opt';
  162.     print OPT "PerlShr/Share\n";
  163.     foreach $rtl (split(/\s+/,$Config::Config{'libs'})) { print OPT "$rtl\n"; }
  164.     close OPT;
  165. }
  166.  
  167. 1;
  168.  
  169. __END__
  170.  
  171. =head1 NAME
  172.  
  173. ExtUtils::Mksymlists - write linker options files for dynamic extension
  174.  
  175. =head1 SYNOPSIS
  176.  
  177.     use ExtUtils::Mksymlists;
  178.     Mksymlists({ NAME     => $name ,
  179.                  DL_VARS  => [ $var1, $var2, $var3 ],
  180.                  DL_FUNCS => { $pkg1 => [ $func1, $func2 ],
  181.                                $pkg2 => [ $func3 ] });
  182.  
  183. =head1 DESCRIPTION
  184.  
  185. C<ExtUtils::Mksymlists> produces files used by the linker under some OSs
  186. during the creation of shared libraries for dynamic extensions.  It is
  187. normally called from a MakeMaker-generated Makefile when the extension
  188. is built.  The linker option file is generated by calling the function
  189. C<Mksymlists>, which is exported by default from C<ExtUtils::Mksymlists>.
  190. It takes one argument, a list of key-value pairs, in which the following
  191. keys are recognized:
  192.  
  193. =over
  194.  
  195. =item NAME
  196.  
  197. This gives the name of the extension (I<e.g.> Tk::Canvas) for which
  198. the linker option file will be produced.
  199.  
  200. =item DL_FUNCS
  201.  
  202. This is identical to the DL_FUNCS attribute available via MakeMaker,
  203. from which it is usually taken.  Its value is a reference to an
  204. associative array, in which each key is the name of a package, and
  205. each value is an a reference to an array of function names which
  206. should be exported by the extension.  For instance, one might say
  207. C<DL_FUNCS =E<gt> { Homer::Iliad   =E<gt> [ qw(trojans greeks) ],
  208. Homer::Odyssey =E<gt> [ qw(travellers family suitors) ] }>.  The
  209. function names should be identical to those in the XSUB code;
  210. C<Mksymlists> will alter the names written to the linker option
  211. file to match the changes made by F<xsubpp>.  In addition, if
  212. none of the functions in a list begin with the string B<boot_>,
  213. C<Mksymlists> will add a bootstrap function for that package,
  214. just as xsubpp does.  (If a B<boot_E<lt>pkgE<gt>> function is
  215. present in the list, it is passed through unchanged.)  If
  216. DL_FUNCS is not specified, it defaults to the bootstrap
  217. function for the extension specified in NAME.
  218.  
  219. =item DL_VARS
  220.  
  221. This is identical to the DL_VARS attribute available via MakeMaker,
  222. and, like DL_FUNCS, it is usually specified via MakeMaker.  Its
  223. value is a reference to an array of variable names which should
  224. be exported by the extension.
  225.  
  226. =item FILE
  227.  
  228. This key can be used to specify the name of the linker option file
  229. (minus the OS-specific extension), if for some reason you do not
  230. want to use the default value, which is the last word of the NAME
  231. attribute (I<e.g.> for Tk::Canvas, FILE defaults to 'Canvas').
  232.  
  233. =item FUNCLIST
  234.  
  235. This provides an alternate means to specify function names to be
  236. exported from the extension.  Its value is a reference to an
  237. array of function names to be exported by the extension.  These
  238. names are passed through unaltered to the linker options file.
  239.  
  240. =item DLBASE
  241.  
  242. This item specifies the name by which the linker knows the
  243. extension, which may be different from the name of the
  244. extension itself (for instance, some linkers add an '_' to the
  245. name of the extension).  If it is not specified, it is derived
  246. from the NAME attribute.  It is presently used only by OS2.
  247.  
  248. =back
  249.  
  250. When calling C<Mksymlists>, one should always specify the NAME
  251. attribute.  In most cases, this is all that's necessary.  In
  252. the case of unusual extensions, however, the other attributes
  253. can be used to provide additional information to the linker.
  254.  
  255. =head1 AUTHOR
  256.  
  257. Charles Bailey I<E<lt>bailey@genetics.upenn.eduE<gt>>
  258.  
  259. =head1 REVISION
  260.  
  261. Last revised 14-Feb-1996, for Perl 5.002.
  262.