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