Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

786 lines
27 KiB

  1. package ExtUtils::Liblist;
  2. @ISA = qw(ExtUtils::Liblist::Kid File::Spec);
  3. sub lsdir {
  4. shift;
  5. my $rex = qr/$_[1]/;
  6. opendir my $dir, $_[0];
  7. grep /$rex/, readdir $dir;
  8. }
  9. sub file_name_is_absolute {
  10. require File::Spec;
  11. shift;
  12. 'File::Spec'->file_name_is_absolute(@_);
  13. }
  14. package ExtUtils::Liblist::Kid;
  15. # This kid package is to be used by MakeMaker. It will not work if
  16. # $self is not a Makemaker.
  17. use 5.005_64;
  18. # Broken out of MakeMaker from version 4.11
  19. our $VERSION = substr q$Revision: 1.26 $, 10;
  20. use Config;
  21. use Cwd 'cwd';
  22. use File::Basename;
  23. sub ext {
  24. if ($^O eq 'VMS') { return &_vms_ext; }
  25. elsif($^O eq 'MSWin32') { return &_win32_ext; }
  26. else { return &_unix_os2_ext; }
  27. }
  28. sub _unix_os2_ext {
  29. my($self,$potential_libs, $verbose, $give_libs) = @_;
  30. if ($^O =~ 'os2' and $Config{perllibs}) {
  31. # Dynamic libraries are not transitive, so we may need including
  32. # the libraries linked against perl.dll again.
  33. $potential_libs .= " " if $potential_libs;
  34. $potential_libs .= $Config{perllibs};
  35. }
  36. return ("", "", "", "", ($give_libs ? [] : ())) unless $potential_libs;
  37. warn "Potential libraries are '$potential_libs':\n" if $verbose;
  38. my($so) = $Config{'so'};
  39. my($libs) = $Config{'perllibs'};
  40. my $Config_libext = $Config{lib_ext} || ".a";
  41. # compute $extralibs, $bsloadlibs and $ldloadlibs from
  42. # $potential_libs
  43. # this is a rewrite of Andy Dougherty's extliblist in perl
  44. my(@searchpath); # from "-L/path" entries in $potential_libs
  45. my(@libpath) = split " ", $Config{'libpth'};
  46. my(@ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen);
  47. my(@libs, %libs_seen);
  48. my($fullname, $thislib, $thispth, @fullname);
  49. my($pwd) = cwd(); # from Cwd.pm
  50. my($found) = 0;
  51. foreach $thislib (split ' ', $potential_libs){
  52. # Handle possible linker path arguments.
  53. if ($thislib =~ s/^(-[LR])//){ # save path flag type
  54. my($ptype) = $1;
  55. unless (-d $thislib){
  56. warn "$ptype$thislib ignored, directory does not exist\n"
  57. if $verbose;
  58. next;
  59. }
  60. unless ($self->file_name_is_absolute($thislib)) {
  61. warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
  62. $thislib = $self->catdir($pwd,$thislib);
  63. }
  64. push(@searchpath, $thislib);
  65. push(@extralibs, "$ptype$thislib");
  66. push(@ldloadlibs, "$ptype$thislib");
  67. next;
  68. }
  69. # Handle possible library arguments.
  70. unless ($thislib =~ s/^-l//){
  71. warn "Unrecognized argument in LIBS ignored: '$thislib'\n";
  72. next;
  73. }
  74. my($found_lib)=0;
  75. foreach $thispth (@searchpath, @libpath){
  76. # Try to find the full name of the library. We need this to
  77. # determine whether it's a dynamically-loadable library or not.
  78. # This tends to be subject to various os-specific quirks.
  79. # For gcc-2.6.2 on linux (March 1995), DLD can not load
  80. # .sa libraries, with the exception of libm.sa, so we
  81. # deliberately skip them.
  82. if (@fullname =
  83. $self->lsdir($thispth,"^\Qlib$thislib.$so.\E[0-9]+")){
  84. # Take care that libfoo.so.10 wins against libfoo.so.9.
  85. # Compare two libraries to find the most recent version
  86. # number. E.g. if you have libfoo.so.9.0.7 and
  87. # libfoo.so.10.1, first convert all digits into two
  88. # decimal places. Then we'll add ".00" to the shorter
  89. # strings so that we're comparing strings of equal length
  90. # Thus we'll compare libfoo.so.09.07.00 with
  91. # libfoo.so.10.01.00. Some libraries might have letters
  92. # in the version. We don't know what they mean, but will
  93. # try to skip them gracefully -- we'll set any letter to
  94. # '0'. Finally, sort in reverse so we can take the
  95. # first element.
  96. #TODO: iterate through the directory instead of sorting
  97. $fullname = "$thispth/" .
  98. (sort { my($ma) = $a;
  99. my($mb) = $b;
  100. $ma =~ tr/A-Za-z/0/s;
  101. $ma =~ s/\b(\d)\b/0$1/g;
  102. $mb =~ tr/A-Za-z/0/s;
  103. $mb =~ s/\b(\d)\b/0$1/g;
  104. while (length($ma) < length($mb)) { $ma .= ".00"; }
  105. while (length($mb) < length($ma)) { $mb .= ".00"; }
  106. # Comparison deliberately backwards
  107. $mb cmp $ma;} @fullname)[0];
  108. } elsif (-f ($fullname="$thispth/lib$thislib.$so")
  109. && (($Config{'dlsrc'} ne "dl_dld.xs") || ($thislib eq "m"))){
  110. } elsif (-f ($fullname="$thispth/lib${thislib}_s$Config_libext")
  111. && (! $Config{'archname'} =~ /RM\d\d\d-svr4/)
  112. && ($thislib .= "_s") ){ # we must explicitly use _s version
  113. } elsif (-f ($fullname="$thispth/lib$thislib$Config_libext")){
  114. } elsif (-f ($fullname="$thispth/$thislib$Config_libext")){
  115. } elsif (-f ($fullname="$thispth/Slib$thislib$Config_libext")){
  116. } elsif ($^O eq 'dgux'
  117. && -l ($fullname="$thispth/lib$thislib$Config_libext")
  118. && readlink($fullname) =~ /^elink:/s) {
  119. # Some of DG's libraries look like misconnected symbolic
  120. # links, but development tools can follow them. (They
  121. # look like this:
  122. #
  123. # libm.a -> elink:${SDE_PATH:-/usr}/sde/\
  124. # ${TARGET_BINARY_INTERFACE:-m88kdgux}/usr/lib/libm.a
  125. #
  126. # , the compilation tools expand the environment variables.)
  127. } else {
  128. warn "$thislib not found in $thispth\n" if $verbose;
  129. next;
  130. }
  131. warn "'-l$thislib' found at $fullname\n" if $verbose;
  132. my($fullnamedir) = dirname($fullname);
  133. push @ld_run_path, $fullnamedir unless $ld_run_path_seen{$fullnamedir}++;
  134. push @libs, $fullname unless $libs_seen{$fullname}++;
  135. $found++;
  136. $found_lib++;
  137. # Now update library lists
  138. # what do we know about this library...
  139. my $is_dyna = ($fullname !~ /\Q$Config_libext\E\z/);
  140. my $in_perl = ($libs =~ /\B-l\Q$ {thislib}\E\b/s);
  141. # Do not add it into the list if it is already linked in
  142. # with the main perl executable.
  143. # We have to special-case the NeXT, because math and ndbm
  144. # are both in libsys_s
  145. unless ($in_perl ||
  146. ($Config{'osname'} eq 'next' &&
  147. ($thislib eq 'm' || $thislib eq 'ndbm')) ){
  148. push(@extralibs, "-l$thislib");
  149. }
  150. # We might be able to load this archive file dynamically
  151. if ( ($Config{'dlsrc'} =~ /dl_next/ && $Config{'osvers'} lt '4_0')
  152. || ($Config{'dlsrc'} =~ /dl_dld/) )
  153. {
  154. # We push -l$thislib instead of $fullname because
  155. # it avoids hardwiring a fixed path into the .bs file.
  156. # Mkbootstrap will automatically add dl_findfile() to
  157. # the .bs file if it sees a name in the -l format.
  158. # USE THIS, when dl_findfile() is fixed:
  159. # push(@bsloadlibs, "-l$thislib");
  160. # OLD USE WAS while checking results against old_extliblist
  161. push(@bsloadlibs, "$fullname");
  162. } else {
  163. if ($is_dyna){
  164. # For SunOS4, do not add in this shared library if
  165. # it is already linked in the main perl executable
  166. push(@ldloadlibs, "-l$thislib")
  167. unless ($in_perl and $^O eq 'sunos');
  168. } else {
  169. push(@ldloadlibs, "-l$thislib");
  170. }
  171. }
  172. last; # found one here so don't bother looking further
  173. }
  174. warn "Note (probably harmless): "
  175. ."No library found for -l$thislib\n"
  176. unless $found_lib>0;
  177. }
  178. return ('','','','', ($give_libs ? \@libs : ())) unless $found;
  179. ("@extralibs", "@bsloadlibs", "@ldloadlibs",join(":",@ld_run_path), ($give_libs ? \@libs : ()));
  180. }
  181. sub _win32_ext {
  182. require Text::ParseWords;
  183. my($self, $potential_libs, $verbose, $give_libs) = @_;
  184. # If user did not supply a list, we punt.
  185. # (caller should probably use the list in $Config{libs})
  186. return ("", "", "", "", ($give_libs ? [] : ())) unless $potential_libs;
  187. my $cc = $Config{cc};
  188. my $VC = 1 if $cc =~ /^cl/i;
  189. my $BC = 1 if $cc =~ /^bcc/i;
  190. my $GC = 1 if $cc =~ /^gcc/i;
  191. my $so = $Config{'so'};
  192. my $libs = $Config{'perllibs'};
  193. my $libpth = $Config{'libpth'};
  194. my $libext = $Config{'lib_ext'} || ".lib";
  195. my(@libs, %libs_seen);
  196. if ($libs and $potential_libs !~ /:nodefault/i) {
  197. # If Config.pm defines a set of default libs, we always
  198. # tack them on to the user-supplied list, unless the user
  199. # specified :nodefault
  200. $potential_libs .= " " if $potential_libs;
  201. $potential_libs .= $libs;
  202. }
  203. warn "Potential libraries are '$potential_libs':\n" if $verbose;
  204. # normalize to forward slashes
  205. $libpth =~ s,\\,/,g;
  206. $potential_libs =~ s,\\,/,g;
  207. # compute $extralibs from $potential_libs
  208. my @searchpath; # from "-L/path" in $potential_libs
  209. my @libpath = Text::ParseWords::quotewords('\s+', 0, $libpth);
  210. my @extralibs;
  211. my $pwd = cwd(); # from Cwd.pm
  212. my $lib = '';
  213. my $found = 0;
  214. my $search = 1;
  215. my($fullname, $thislib, $thispth);
  216. # add "$Config{installarchlib}/CORE" to default search path
  217. push @libpath, "$Config{installarchlib}/CORE";
  218. if ($VC and exists $ENV{LIB} and $ENV{LIB}) {
  219. push @libpath, split /;/, $ENV{LIB};
  220. }
  221. foreach (Text::ParseWords::quotewords('\s+', 0, $potential_libs)){
  222. $thislib = $_;
  223. # see if entry is a flag
  224. if (/^:\w+$/) {
  225. $search = 0 if lc eq ':nosearch';
  226. $search = 1 if lc eq ':search';
  227. warn "Ignoring unknown flag '$thislib'\n"
  228. if $verbose and !/^:(no)?(search|default)$/i;
  229. next;
  230. }
  231. # if searching is disabled, do compiler-specific translations
  232. unless ($search) {
  233. s/^-l(.+)$/$1.lib/ unless $GC;
  234. s/^-L/-libpath:/ if $VC;
  235. push(@extralibs, $_);
  236. $found++;
  237. next;
  238. }
  239. # handle possible linker path arguments
  240. if (s/^-L// and not -d) {
  241. warn "$thislib ignored, directory does not exist\n"
  242. if $verbose;
  243. next;
  244. }
  245. elsif (-d) {
  246. unless ($self->file_name_is_absolute($_)) {
  247. warn "Warning: '$thislib' changed to '-L$pwd/$_'\n";
  248. $_ = $self->catdir($pwd,$_);
  249. }
  250. push(@searchpath, $_);
  251. next;
  252. }
  253. # handle possible library arguments
  254. if (s/^-l// and $GC and !/^lib/i) {
  255. $_ = "lib$_";
  256. }
  257. $_ .= $libext if !/\Q$libext\E$/i;
  258. my $secondpass = 0;
  259. LOOKAGAIN:
  260. # look for the file itself
  261. if (-f) {
  262. warn "'$thislib' found as '$_'\n" if $verbose;
  263. $found++;
  264. push(@extralibs, $_);
  265. next;
  266. }
  267. my $found_lib = 0;
  268. foreach $thispth (@searchpath, @libpath){
  269. unless (-f ($fullname="$thispth\\$_")) {
  270. warn "'$thislib' not found as '$fullname'\n" if $verbose;
  271. next;
  272. }
  273. warn "'$thislib' found as '$fullname'\n" if $verbose;
  274. $found++;
  275. $found_lib++;
  276. push(@extralibs, $fullname);
  277. push @libs, $fullname unless $libs_seen{$fullname}++;
  278. last;
  279. }
  280. # do another pass with (or without) leading 'lib' if they used -l
  281. if (!$found_lib and $thislib =~ /^-l/ and !$secondpass++) {
  282. if ($GC) {
  283. goto LOOKAGAIN if s/^lib//i;
  284. }
  285. elsif (!/^lib/i) {
  286. $_ = "lib$_";
  287. goto LOOKAGAIN;
  288. }
  289. }
  290. # give up
  291. warn "Note (probably harmless): "
  292. ."No library found for '$thislib'\n"
  293. unless $found_lib>0;
  294. }
  295. return ('','','','', ($give_libs ? \@libs : ())) unless $found;
  296. # make sure paths with spaces are properly quoted
  297. @extralibs = map { (/\s/ && !/^".*"$/) ? qq["$_"] : $_ } @extralibs;
  298. @libs = map { (/\s/ && !/^".*"$/) ? qq["$_"] : $_ } @libs;
  299. $lib = join(' ',@extralibs);
  300. # normalize back to backward slashes (to help braindead tools)
  301. # XXX this may break equally braindead GNU tools that don't understand
  302. # backslashes, either. Seems like one can't win here. Cursed be CP/M.
  303. $lib =~ s,/,\\,g;
  304. warn "Result: $lib\n" if $verbose;
  305. wantarray ? ($lib, '', $lib, '', ($give_libs ? \@libs : ())) : $lib;
  306. }
  307. sub _vms_ext {
  308. my($self, $potential_libs,$verbose,$give_libs) = @_;
  309. my(@crtls,$crtlstr);
  310. my($dbgqual) = $self->{OPTIMIZE} || $Config{'optimize'} ||
  311. $self->{CCFLAS} || $Config{'ccflags'};
  312. @crtls = ( ($dbgqual =~ m-/Debug-i ? $Config{'dbgprefix'} : '')
  313. . 'PerlShr/Share' );
  314. push(@crtls, grep { not /\(/ } split /\s+/, $Config{'perllibs'});
  315. push(@crtls, grep { not /\(/ } split /\s+/, $Config{'libc'});
  316. # In general, we pass through the basic libraries from %Config unchanged.
  317. # The one exception is that if we're building in the Perl source tree, and
  318. # a library spec could be resolved via a logical name, we go to some trouble
  319. # to insure that the copy in the local tree is used, rather than one to
  320. # which a system-wide logical may point.
  321. if ($self->{PERL_SRC}) {
  322. my($lib,$locspec,$type);
  323. foreach $lib (@crtls) {
  324. if (($locspec,$type) = $lib =~ m-^([\w$\-]+)(/\w+)?- and $locspec =~ /perl/i) {
  325. if (lc $type eq '/share') { $locspec .= $Config{'exe_ext'}; }
  326. elsif (lc $type eq '/library') { $locspec .= $Config{'lib_ext'}; }
  327. else { $locspec .= $Config{'obj_ext'}; }
  328. $locspec = $self->catfile($self->{PERL_SRC},$locspec);
  329. $lib = "$locspec$type" if -e $locspec;
  330. }
  331. }
  332. }
  333. $crtlstr = @crtls ? join(' ',@crtls) : '';
  334. unless ($potential_libs) {
  335. warn "Result:\n\tEXTRALIBS: \n\tLDLOADLIBS: $crtlstr\n" if $verbose;
  336. return ('', '', $crtlstr, '', ($give_libs ? [] : ()));
  337. }
  338. my(@dirs,@libs,$dir,$lib,%found,@fndlibs,$ldlib);
  339. my $cwd = cwd();
  340. my($so,$lib_ext,$obj_ext) = @Config{'so','lib_ext','obj_ext'};
  341. # List of common Unix library names and there VMS equivalents
  342. # (VMS equivalent of '' indicates that the library is automatially
  343. # searched by the linker, and should be skipped here.)
  344. my(@flibs, %libs_seen);
  345. my %libmap = ( 'm' => '', 'f77' => '', 'F77' => '', 'V77' => '', 'c' => '',
  346. 'malloc' => '', 'crypt' => '', 'resolv' => '', 'c_s' => '',
  347. 'socket' => '', 'X11' => 'DECW$XLIBSHR',
  348. 'Xt' => 'DECW$XTSHR', 'Xm' => 'DECW$XMLIBSHR',
  349. 'Xmu' => 'DECW$XMULIBSHR');
  350. if ($Config{'vms_cc_type'} ne 'decc') { $libmap{'curses'} = 'VAXCCURSE'; }
  351. warn "Potential libraries are '$potential_libs'\n" if $verbose;
  352. # First, sort out directories and library names in the input
  353. foreach $lib (split ' ',$potential_libs) {
  354. push(@dirs,$1), next if $lib =~ /^-L(.*)/;
  355. push(@dirs,$lib), next if $lib =~ /[:>\]]$/;
  356. push(@dirs,$lib), next if -d $lib;
  357. push(@libs,$1), next if $lib =~ /^-l(.*)/;
  358. push(@libs,$lib);
  359. }
  360. push(@dirs,split(' ',$Config{'libpth'}));
  361. # Now make sure we've got VMS-syntax absolute directory specs
  362. # (We don't, however, check whether someone's hidden a relative
  363. # path in a logical name.)
  364. foreach $dir (@dirs) {
  365. unless (-d $dir) {
  366. warn "Skipping nonexistent Directory $dir\n" if $verbose > 1;
  367. $dir = '';
  368. next;
  369. }
  370. warn "Resolving directory $dir\n" if $verbose;
  371. if ($self->file_name_is_absolute($dir)) { $dir = $self->fixpath($dir,1); }
  372. else { $dir = $self->catdir($cwd,$dir); }
  373. }
  374. @dirs = grep { length($_) } @dirs;
  375. unshift(@dirs,''); # Check each $lib without additions first
  376. LIB: foreach $lib (@libs) {
  377. if (exists $libmap{$lib}) {
  378. next unless length $libmap{$lib};
  379. $lib = $libmap{$lib};
  380. }
  381. my(@variants,$variant,$name,$test,$cand);
  382. my($ctype) = '';
  383. # If we don't have a file type, consider it a possibly abbreviated name and
  384. # check for common variants. We try these first to grab libraries before
  385. # a like-named executable image (e.g. -lperl resolves to perlshr.exe
  386. # before perl.exe).
  387. if ($lib !~ /\.[^:>\]]*$/) {
  388. push(@variants,"${lib}shr","${lib}rtl","${lib}lib");
  389. push(@variants,"lib$lib") if $lib !~ /[:>\]]/;
  390. }
  391. push(@variants,$lib);
  392. warn "Looking for $lib\n" if $verbose;
  393. foreach $variant (@variants) {
  394. foreach $dir (@dirs) {
  395. my($type);
  396. $name = "$dir$variant";
  397. warn "\tChecking $name\n" if $verbose > 2;
  398. if (-f ($test = VMS::Filespec::rmsexpand($name))) {
  399. # It's got its own suffix, so we'll have to figure out the type
  400. if ($test =~ /(?:$so|exe)$/i) { $type = 'SHR'; }
  401. elsif ($test =~ /(?:$lib_ext|olb)$/i) { $type = 'OLB'; }
  402. elsif ($test =~ /(?:$obj_ext|obj)$/i) {
  403. warn "Note (probably harmless): "
  404. ."Plain object file $test found in library list\n";
  405. $type = 'OBJ';
  406. }
  407. else {
  408. warn "Note (probably harmless): "
  409. ."Unknown library type for $test; assuming shared\n";
  410. $type = 'SHR';
  411. }
  412. }
  413. elsif (-f ($test = VMS::Filespec::rmsexpand($name,$so)) or
  414. -f ($test = VMS::Filespec::rmsexpand($name,'.exe'))) {
  415. $type = 'SHR';
  416. $name = $test unless $test =~ /exe;?\d*$/i;
  417. }
  418. elsif (not length($ctype) and # If we've got a lib already, don't bother
  419. ( -f ($test = VMS::Filespec::rmsexpand($name,$lib_ext)) or
  420. -f ($test = VMS::Filespec::rmsexpand($name,'.olb')))) {
  421. $type = 'OLB';
  422. $name = $test unless $test =~ /olb;?\d*$/i;
  423. }
  424. elsif (not length($ctype) and # If we've got a lib already, don't bother
  425. ( -f ($test = VMS::Filespec::rmsexpand($name,$obj_ext)) or
  426. -f ($test = VMS::Filespec::rmsexpand($name,'.obj')))) {
  427. warn "Note (probably harmless): "
  428. ."Plain object file $test found in library list\n";
  429. $type = 'OBJ';
  430. $name = $test unless $test =~ /obj;?\d*$/i;
  431. }
  432. if (defined $type) {
  433. $ctype = $type; $cand = $name;
  434. last if $ctype eq 'SHR';
  435. }
  436. }
  437. if ($ctype) {
  438. # This has to precede any other CRTLs, so just make it first
  439. if ($cand eq 'VAXCCURSE') { unshift @{$found{$ctype}}, $cand; }
  440. else { push @{$found{$ctype}}, $cand; }
  441. warn "\tFound as $cand (really $test), type $ctype\n" if $verbose > 1;
  442. push @flibs, $name unless $libs_seen{$fullname}++;
  443. next LIB;
  444. }
  445. }
  446. warn "Note (probably harmless): "
  447. ."No library found for $lib\n";
  448. }
  449. push @fndlibs, @{$found{OBJ}} if exists $found{OBJ};
  450. push @fndlibs, map { "$_/Library" } @{$found{OLB}} if exists $found{OLB};
  451. push @fndlibs, map { "$_/Share" } @{$found{SHR}} if exists $found{SHR};
  452. $lib = join(' ',@fndlibs);
  453. $ldlib = $crtlstr ? "$lib $crtlstr" : $lib;
  454. warn "Result:\n\tEXTRALIBS: $lib\n\tLDLOADLIBS: $ldlib\n" if $verbose;
  455. wantarray ? ($lib, '', $ldlib, '', ($give_libs ? \@flibs : ())) : $lib;
  456. }
  457. 1;
  458. __END__
  459. =head1 NAME
  460. ExtUtils::Liblist - determine libraries to use and how to use them
  461. =head1 SYNOPSIS
  462. C<require ExtUtils::Liblist;>
  463. C<ExtUtils::Liblist::ext($self, $potential_libs, $verbose, $need_names);>
  464. =head1 DESCRIPTION
  465. This utility takes a list of libraries in the form C<-llib1 -llib2
  466. -llib3> and returns lines suitable for inclusion in an extension
  467. Makefile. Extra library paths may be included with the form
  468. C<-L/another/path> this will affect the searches for all subsequent
  469. libraries.
  470. It returns an array of four or five scalar values: EXTRALIBS,
  471. BSLOADLIBS, LDLOADLIBS, LD_RUN_PATH, and, optionally, a reference to
  472. the array of the filenames of actual libraries. Some of these don't
  473. mean anything unless on Unix. See the details about those platform
  474. specifics below. The list of the filenames is returned only if
  475. $need_names argument is true.
  476. Dependent libraries can be linked in one of three ways:
  477. =over 2
  478. =item * For static extensions
  479. by the ld command when the perl binary is linked with the extension
  480. library. See EXTRALIBS below.
  481. =item * For dynamic extensions
  482. by the ld command when the shared object is built/linked. See
  483. LDLOADLIBS below.
  484. =item * For dynamic extensions
  485. by the DynaLoader when the shared object is loaded. See BSLOADLIBS
  486. below.
  487. =back
  488. =head2 EXTRALIBS
  489. List of libraries that need to be linked with when linking a perl
  490. binary which includes this extension. Only those libraries that
  491. actually exist are included. These are written to a file and used
  492. when linking perl.
  493. =head2 LDLOADLIBS and LD_RUN_PATH
  494. List of those libraries which can or must be linked into the shared
  495. library when created using ld. These may be static or dynamic
  496. libraries. LD_RUN_PATH is a colon separated list of the directories
  497. in LDLOADLIBS. It is passed as an environment variable to the process
  498. that links the shared library.
  499. =head2 BSLOADLIBS
  500. List of those libraries that are needed but can be linked in
  501. dynamically at run time on this platform. SunOS/Solaris does not need
  502. this because ld records the information (from LDLOADLIBS) into the
  503. object file. This list is used to create a .bs (bootstrap) file.
  504. =head1 PORTABILITY
  505. This module deals with a lot of system dependencies and has quite a
  506. few architecture specific C<if>s in the code.
  507. =head2 VMS implementation
  508. The version of ext() which is executed under VMS differs from the
  509. Unix-OS/2 version in several respects:
  510. =over 2
  511. =item *
  512. Input library and path specifications are accepted with or without the
  513. C<-l> and C<-L> prefixes used by Unix linkers. If neither prefix is
  514. present, a token is considered a directory to search if it is in fact
  515. a directory, and a library to search for otherwise. Authors who wish
  516. their extensions to be portable to Unix or OS/2 should use the Unix
  517. prefixes, since the Unix-OS/2 version of ext() requires them.
  518. =item *
  519. Wherever possible, shareable images are preferred to object libraries,
  520. and object libraries to plain object files. In accordance with VMS
  521. naming conventions, ext() looks for files named I<lib>shr and I<lib>rtl;
  522. it also looks for I<lib>lib and libI<lib> to accommodate Unix conventions
  523. used in some ported software.
  524. =item *
  525. For each library that is found, an appropriate directive for a linker options
  526. file is generated. The return values are space-separated strings of
  527. these directives, rather than elements used on the linker command line.
  528. =item *
  529. LDLOADLIBS contains both the libraries found based on C<$potential_libs> and
  530. the CRTLs, if any, specified in Config.pm. EXTRALIBS contains just those
  531. libraries found based on C<$potential_libs>. BSLOADLIBS and LD_RUN_PATH
  532. are always empty.
  533. =back
  534. In addition, an attempt is made to recognize several common Unix library
  535. names, and filter them out or convert them to their VMS equivalents, as
  536. appropriate.
  537. In general, the VMS version of ext() should properly handle input from
  538. extensions originally designed for a Unix or VMS environment. If you
  539. encounter problems, or discover cases where the search could be improved,
  540. please let us know.
  541. =head2 Win32 implementation
  542. The version of ext() which is executed under Win32 differs from the
  543. Unix-OS/2 version in several respects:
  544. =over 2
  545. =item *
  546. If C<$potential_libs> is empty, the return value will be empty.
  547. Otherwise, the libraries specified by C<$Config{perllibs}> (see Config.pm)
  548. will be appended to the list of C<$potential_libs>. The libraries
  549. will be searched for in the directories specified in C<$potential_libs>,
  550. C<$Config{libpth}>, and in C<$Config{installarchlib}/CORE>.
  551. For each library that is found, a space-separated list of fully qualified
  552. library pathnames is generated.
  553. =item *
  554. Input library and path specifications are accepted with or without the
  555. C<-l> and C<-L> prefixes used by Unix linkers.
  556. An entry of the form C<-La:\foo> specifies the C<a:\foo> directory to look
  557. for the libraries that follow.
  558. An entry of the form C<-lfoo> specifies the library C<foo>, which may be
  559. spelled differently depending on what kind of compiler you are using. If
  560. you are using GCC, it gets translated to C<libfoo.a>, but for other win32
  561. compilers, it becomes C<foo.lib>. If no files are found by those translated
  562. names, one more attempt is made to find them using either C<foo.a> or
  563. C<libfoo.lib>, depending on whether GCC or some other win32 compiler is
  564. being used, respectively.
  565. If neither the C<-L> or C<-l> prefix is present in an entry, the entry is
  566. considered a directory to search if it is in fact a directory, and a
  567. library to search for otherwise. The C<$Config{lib_ext}> suffix will
  568. be appended to any entries that are not directories and don't already have
  569. the suffix.
  570. Note that the C<-L> and C<-l> prefixes are B<not required>, but authors
  571. who wish their extensions to be portable to Unix or OS/2 should use the
  572. prefixes, since the Unix-OS/2 version of ext() requires them.
  573. =item *
  574. Entries cannot be plain object files, as many Win32 compilers will
  575. not handle object files in the place of libraries.
  576. =item *
  577. Entries in C<$potential_libs> beginning with a colon and followed by
  578. alphanumeric characters are treated as flags. Unknown flags will be ignored.
  579. An entry that matches C</:nodefault/i> disables the appending of default
  580. libraries found in C<$Config{perllibs}> (this should be only needed very rarely).
  581. An entry that matches C</:nosearch/i> disables all searching for
  582. the libraries specified after it. Translation of C<-Lfoo> and
  583. C<-lfoo> still happens as appropriate (depending on compiler being used,
  584. as reflected by C<$Config{cc}>), but the entries are not verified to be
  585. valid files or directories.
  586. An entry that matches C</:search/i> reenables searching for
  587. the libraries specified after it. You can put it at the end to
  588. enable searching for default libraries specified by C<$Config{perllibs}>.
  589. =item *
  590. The libraries specified may be a mixture of static libraries and
  591. import libraries (to link with DLLs). Since both kinds are used
  592. pretty transparently on the Win32 platform, we do not attempt to
  593. distinguish between them.
  594. =item *
  595. LDLOADLIBS and EXTRALIBS are always identical under Win32, and BSLOADLIBS
  596. and LD_RUN_PATH are always empty (this may change in future).
  597. =item *
  598. You must make sure that any paths and path components are properly
  599. surrounded with double-quotes if they contain spaces. For example,
  600. C<$potential_libs> could be (literally):
  601. "-Lc:\Program Files\vc\lib" msvcrt.lib "la test\foo bar.lib"
  602. Note how the first and last entries are protected by quotes in order
  603. to protect the spaces.
  604. =item *
  605. Since this module is most often used only indirectly from extension
  606. C<Makefile.PL> files, here is an example C<Makefile.PL> entry to add
  607. a library to the build process for an extension:
  608. LIBS => ['-lgl']
  609. When using GCC, that entry specifies that MakeMaker should first look
  610. for C<libgl.a> (followed by C<gl.a>) in all the locations specified by
  611. C<$Config{libpth}>.
  612. When using a compiler other than GCC, the above entry will search for
  613. C<gl.lib> (followed by C<libgl.lib>).
  614. If the library happens to be in a location not in C<$Config{libpth}>,
  615. you need:
  616. LIBS => ['-Lc:\gllibs -lgl']
  617. Here is a less often used example:
  618. LIBS => ['-lgl', ':nosearch -Ld:\mesalibs -lmesa -luser32']
  619. This specifies a search for library C<gl> as before. If that search
  620. fails to find the library, it looks at the next item in the list. The
  621. C<:nosearch> flag will prevent searching for the libraries that follow,
  622. so it simply returns the value as C<-Ld:\mesalibs -lmesa -luser32>,
  623. since GCC can use that value as is with its linker.
  624. When using the Visual C compiler, the second item is returned as
  625. C<-libpath:d:\mesalibs mesa.lib user32.lib>.
  626. When using the Borland compiler, the second item is returned as
  627. C<-Ld:\mesalibs mesa.lib user32.lib>, and MakeMaker takes care of
  628. moving the C<-Ld:\mesalibs> to the correct place in the linker
  629. command line.
  630. =back
  631. =head1 SEE ALSO
  632. L<ExtUtils::MakeMaker>
  633. =cut