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