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