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