1 package ExtUtils::Liblist::Kid;
3 # XXX Splitting this out into its own .pm is a temporary solution.
5 # This kid package is to be used by MakeMaker. It will not work if
6 # $self is not a Makemaker.
9 # Broken out of MakeMaker from version 4.11
11 use vars qw($VERSION);
20 if ($^O eq 'VMS') { return &_vms_ext; }
21 elsif($^O eq 'MSWin32') { return &_win32_ext; }
22 else { return &_unix_os2_ext; }
26 my($self,$potential_libs, $verbose, $give_libs) = @_;
27 if ($^O =~ 'os2' and $Config{perllibs}) {
28 # Dynamic libraries are not transitive, so we may need including
29 # the libraries linked against perl.dll again.
31 $potential_libs .= " " if $potential_libs;
32 $potential_libs .= $Config{perllibs};
34 return ("", "", "", "", ($give_libs ? [] : ())) unless $potential_libs;
35 warn "Potential libraries are '$potential_libs':\n" if $verbose;
37 my($so) = $Config{'so'};
38 my($libs) = $Config{'perllibs'};
39 my $Config_libext = $Config{lib_ext} || ".a";
42 # compute $extralibs, $bsloadlibs and $ldloadlibs from
44 # this is a rewrite of Andy Dougherty's extliblist in perl
46 my(@searchpath); # from "-L/path" entries in $potential_libs
47 my(@libpath) = split " ", $Config{'libpth'};
48 my(@ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen);
49 my(@libs, %libs_seen);
50 my($fullname, $thislib, $thispth, @fullname);
51 my($pwd) = cwd(); # from Cwd.pm
54 foreach $thislib (split ' ', $potential_libs){
56 # Handle possible linker path arguments.
57 if ($thislib =~ s/^(-[LR]|-Wl,-R)//){ # save path flag type
60 warn "$ptype$thislib ignored, directory does not exist\n"
65 if (($ptype eq '-R') or ($ptype eq '-Wl,-R')) {
66 if ($Config{'lddlflags'} =~ /-Wl,-R/) {
68 } elsif ($Config{'lddlflags'} =~ /-R/) {
72 unless (File::Spec->file_name_is_absolute($thislib)) {
73 warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
74 $thislib = $self->catdir($pwd,$thislib);
76 push(@searchpath, $thislib);
77 push(@extralibs, "$ptype$thislib");
78 push(@ldloadlibs, "$rtype$thislib");
82 # Handle possible library arguments.
83 unless ($thislib =~ s/^-l//){
84 warn "Unrecognized argument in LIBS ignored: '$thislib'\n";
89 foreach $thispth (@searchpath, @libpath){
91 # Try to find the full name of the library. We need this to
92 # determine whether it's a dynamically-loadable library or not.
93 # This tends to be subject to various os-specific quirks.
94 # For gcc-2.6.2 on linux (March 1995), DLD can not load
95 # .sa libraries, with the exception of libm.sa, so we
96 # deliberately skip them.
98 $self->lsdir($thispth,"^\Qlib$thislib.$so.\E[0-9]+")){
99 # Take care that libfoo.so.10 wins against libfoo.so.9.
100 # Compare two libraries to find the most recent version
101 # number. E.g. if you have libfoo.so.9.0.7 and
102 # libfoo.so.10.1, first convert all digits into two
103 # decimal places. Then we'll add ".00" to the shorter
104 # strings so that we're comparing strings of equal length
105 # Thus we'll compare libfoo.so.09.07.00 with
106 # libfoo.so.10.01.00. Some libraries might have letters
107 # in the version. We don't know what they mean, but will
108 # try to skip them gracefully -- we'll set any letter to
109 # '0'. Finally, sort in reverse so we can take the
112 #TODO: iterate through the directory instead of sorting
114 $fullname = "$thispth/" .
115 (sort { my($ma) = $a;
117 $ma =~ tr/A-Za-z/0/s;
118 $ma =~ s/\b(\d)\b/0$1/g;
119 $mb =~ tr/A-Za-z/0/s;
120 $mb =~ s/\b(\d)\b/0$1/g;
121 while (length($ma) < length($mb)) { $ma .= ".00"; }
122 while (length($mb) < length($ma)) { $mb .= ".00"; }
123 # Comparison deliberately backwards
124 $mb cmp $ma;} @fullname)[0];
125 } elsif (-f ($fullname="$thispth/lib$thislib.$so")
126 && (($Config{'dlsrc'} ne "dl_dld.xs") || ($thislib eq "m"))){
127 } elsif (-f ($fullname="$thispth/lib${thislib}_s$Config_libext")
128 && (! $Config{'archname'} =~ /RM\d\d\d-svr4/)
129 && ($thislib .= "_s") ){ # we must explicitly use _s version
130 } elsif (-f ($fullname="$thispth/lib$thislib$Config_libext")){
131 } elsif (-f ($fullname="$thispth/$thislib$Config_libext")){
132 } elsif (-f ($fullname="$thispth/Slib$thislib$Config_libext")){
133 } elsif ($^O eq 'dgux'
134 && -l ($fullname="$thispth/lib$thislib$Config_libext")
135 && readlink($fullname) =~ /^elink:/s) {
136 # Some of DG's libraries look like misconnected symbolic
137 # links, but development tools can follow them. (They
140 # libm.a -> elink:${SDE_PATH:-/usr}/sde/\
141 # ${TARGET_BINARY_INTERFACE:-m88kdgux}/usr/lib/libm.a
143 # , the compilation tools expand the environment variables.)
145 warn "$thislib not found in $thispth\n" if $verbose;
148 warn "'-l$thislib' found at $fullname\n" if $verbose;
149 my($fullnamedir) = dirname($fullname);
150 push @ld_run_path, $fullnamedir
151 unless $ld_run_path_seen{$fullnamedir}++;
152 push @libs, $fullname unless $libs_seen{$fullname}++;
156 # Now update library lists
158 # what do we know about this library...
159 my $is_dyna = ($fullname !~ /\Q$Config_libext\E\z/);
160 my $in_perl = ($libs =~ /\B-l\Q$ {thislib}\E\b/s);
162 # Do not add it into the list if it is already linked in
163 # with the main perl executable.
164 # We have to special-case the NeXT, because math and ndbm
165 # are both in libsys_s
167 ($Config{'osname'} eq 'next' &&
168 ($thislib eq 'm' || $thislib eq 'ndbm')) ){
169 push(@extralibs, "-l$thislib");
172 # We might be able to load this archive file dynamically
173 if ( ($Config{'dlsrc'} =~ /dl_next/ && $Config{'osvers'} lt '4_0')
174 || ($Config{'dlsrc'} =~ /dl_dld/) )
176 # We push -l$thislib instead of $fullname because
177 # it avoids hardwiring a fixed path into the .bs file.
178 # Mkbootstrap will automatically add dl_findfile() to
179 # the .bs file if it sees a name in the -l format.
180 # USE THIS, when dl_findfile() is fixed:
181 # push(@bsloadlibs, "-l$thislib");
182 # OLD USE WAS while checking results against old_extliblist
183 push(@bsloadlibs, "$fullname");
186 # For SunOS4, do not add in this shared library if
187 # it is already linked in the main perl executable
188 push(@ldloadlibs, "-l$thislib")
189 unless ($in_perl and $^O eq 'sunos');
191 push(@ldloadlibs, "-l$thislib");
194 last; # found one here so don't bother looking further
196 warn "Note (probably harmless): "
197 ."No library found for -l$thislib\n"
202 return ('','','','', ($give_libs ? \@libs : ()));
205 return ("@extralibs", "@bsloadlibs", "@ldloadlibs",
206 join(":",@ld_run_path), ($give_libs ? \@libs : ()));
212 require Text::ParseWords;
214 my($self, $potential_libs, $verbose, $give_libs) = @_;
216 # If user did not supply a list, we punt.
217 # (caller should probably use the list in $Config{libs})
218 return ("", "", "", "", ($give_libs ? [] : ())) unless $potential_libs;
220 my $cc = $Config{cc};
221 my $VC = 1 if $cc =~ /^cl/i;
222 my $BC = 1 if $cc =~ /^bcc/i;
223 my $GC = 1 if $cc =~ /^gcc/i;
224 my $so = $Config{'so'};
225 my $libs = $Config{'perllibs'};
226 my $libpth = $Config{'libpth'};
227 my $libext = $Config{'lib_ext'} || ".lib";
228 my(@libs, %libs_seen);
230 if ($libs and $potential_libs !~ /:nodefault/i) {
231 # If Config.pm defines a set of default libs, we always
232 # tack them on to the user-supplied list, unless the user
233 # specified :nodefault
235 $potential_libs .= " " if $potential_libs;
236 $potential_libs .= $libs;
238 warn "Potential libraries are '$potential_libs':\n" if $verbose;
240 # normalize to forward slashes
242 $potential_libs =~ s,\\,/,g;
244 # compute $extralibs from $potential_libs
246 my @searchpath; # from "-L/path" in $potential_libs
247 my @libpath = Text::ParseWords::quotewords('\s+', 0, $libpth);
249 my $pwd = cwd(); # from Cwd.pm
253 my($fullname, $thislib, $thispth);
255 # add "$Config{installarchlib}/CORE" to default search path
256 push @libpath, "$Config{installarchlib}/CORE";
258 if ($VC and exists $ENV{LIB} and $ENV{LIB}) {
259 push @libpath, split /;/, $ENV{LIB};
262 foreach (Text::ParseWords::quotewords('\s+', 0, $potential_libs)){
266 # see if entry is a flag
268 $search = 0 if lc eq ':nosearch';
269 $search = 1 if lc eq ':search';
270 warn "Ignoring unknown flag '$thislib'\n"
271 if $verbose and !/^:(no)?(search|default)$/i;
275 # if searching is disabled, do compiler-specific translations
277 s/^-l(.+)$/$1.lib/ unless $GC;
278 s/^-L/-libpath:/ if $VC;
279 push(@extralibs, $_);
284 # handle possible linker path arguments
285 if (s/^-L// and not -d) {
286 warn "$thislib ignored, directory does not exist\n"
291 unless (File::Spec->file_name_is_absolute($_)) {
292 warn "Warning: '$thislib' changed to '-L$pwd/$_'\n";
293 $_ = $self->catdir($pwd,$_);
295 push(@searchpath, $_);
299 # handle possible library arguments
300 if (s/^-l// and $GC and !/^lib/i) {
303 $_ .= $libext if !/\Q$libext\E$/i;
308 # look for the file itself
310 warn "'$thislib' found as '$_'\n" if $verbose;
312 push(@extralibs, $_);
317 foreach $thispth (@searchpath, @libpath){
318 unless (-f ($fullname="$thispth\\$_")) {
319 warn "'$thislib' not found as '$fullname'\n" if $verbose;
322 warn "'$thislib' found as '$fullname'\n" if $verbose;
325 push(@extralibs, $fullname);
326 push @libs, $fullname unless $libs_seen{$fullname}++;
330 # do another pass with (or without) leading 'lib' if they used -l
331 if (!$found_lib and $thislib =~ /^-l/ and !$secondpass++) {
333 goto LOOKAGAIN if s/^lib//i;
342 warn "Note (probably harmless): "
343 ."No library found for '$thislib'\n"
348 return ('','','','', ($give_libs ? \@libs : ())) unless $found;
350 # make sure paths with spaces are properly quoted
351 @extralibs = map { (/\s/ && !/^".*"$/) ? qq["$_"] : $_ } @extralibs;
352 @libs = map { (/\s/ && !/^".*"$/) ? qq["$_"] : $_ } @libs;
353 $lib = join(' ',@extralibs);
355 # normalize back to backward slashes (to help braindead tools)
356 # XXX this may break equally braindead GNU tools that don't understand
357 # backslashes, either. Seems like one can't win here. Cursed be CP/M.
360 warn "Result: $lib\n" if $verbose;
361 wantarray ? ($lib, '', $lib, '', ($give_libs ? \@libs : ())) : $lib;
366 my($self, $potential_libs,$verbose,$give_libs) = @_;
368 my($dbgqual) = $self->{OPTIMIZE} || $Config{'optimize'} ||
369 $self->{CCFLAS} || $Config{'ccflags'};
370 @crtls = ( ($dbgqual =~ m-/Debug-i ? $Config{'dbgprefix'} : '')
372 push(@crtls, grep { not /\(/ } split /\s+/, $Config{'perllibs'});
373 push(@crtls, grep { not /\(/ } split /\s+/, $Config{'libc'});
374 # In general, we pass through the basic libraries from %Config unchanged.
375 # The one exception is that if we're building in the Perl source tree, and
376 # a library spec could be resolved via a logical name, we go to some trouble
377 # to insure that the copy in the local tree is used, rather than one to
378 # which a system-wide logical may point.
379 if ($self->{PERL_SRC}) {
380 my($lib,$locspec,$type);
381 foreach $lib (@crtls) {
382 if (($locspec,$type) = $lib =~ m-^([\w$\-]+)(/\w+)?- and $locspec =~ /perl/i) {
383 if (lc $type eq '/share') { $locspec .= $Config{'exe_ext'}; }
384 elsif (lc $type eq '/library') { $locspec .= $Config{'lib_ext'}; }
385 else { $locspec .= $Config{'obj_ext'}; }
386 $locspec = $self->catfile($self->{PERL_SRC},$locspec);
387 $lib = "$locspec$type" if -e $locspec;
391 $crtlstr = @crtls ? join(' ',@crtls) : '';
393 unless ($potential_libs) {
394 warn "Result:\n\tEXTRALIBS: \n\tLDLOADLIBS: $crtlstr\n" if $verbose;
395 return ('', '', $crtlstr, '', ($give_libs ? [] : ()));
398 my(@dirs,@libs,$dir,$lib,%found,@fndlibs,$ldlib);
400 my($so,$lib_ext,$obj_ext) = @Config{'so','lib_ext','obj_ext'};
401 # List of common Unix library names and there VMS equivalents
402 # (VMS equivalent of '' indicates that the library is automatially
403 # searched by the linker, and should be skipped here.)
404 my(@flibs, %libs_seen);
405 my %libmap = ( 'm' => '', 'f77' => '', 'F77' => '', 'V77' => '', 'c' => '',
406 'malloc' => '', 'crypt' => '', 'resolv' => '', 'c_s' => '',
407 'socket' => '', 'X11' => 'DECW$XLIBSHR',
408 'Xt' => 'DECW$XTSHR', 'Xm' => 'DECW$XMLIBSHR',
409 'Xmu' => 'DECW$XMULIBSHR');
410 if ($Config{'vms_cc_type'} ne 'decc') { $libmap{'curses'} = 'VAXCCURSE'; }
412 warn "Potential libraries are '$potential_libs'\n" if $verbose;
414 # First, sort out directories and library names in the input
415 foreach $lib (split ' ',$potential_libs) {
416 push(@dirs,$1), next if $lib =~ /^-L(.*)/;
417 push(@dirs,$lib), next if $lib =~ /[:>\]]$/;
418 push(@dirs,$lib), next if -d $lib;
419 push(@libs,$1), next if $lib =~ /^-l(.*)/;
422 push(@dirs,split(' ',$Config{'libpth'}));
424 # Now make sure we've got VMS-syntax absolute directory specs
425 # (We don't, however, check whether someone's hidden a relative
426 # path in a logical name.)
427 foreach $dir (@dirs) {
429 warn "Skipping nonexistent Directory $dir\n" if $verbose > 1;
433 warn "Resolving directory $dir\n" if $verbose;
434 if (File::Spec->file_name_is_absolute($dir)) {
435 $dir = $self->fixpath($dir,1);
438 $dir = $self->catdir($cwd,$dir);
441 @dirs = grep { length($_) } @dirs;
442 unshift(@dirs,''); # Check each $lib without additions first
444 LIB: foreach $lib (@libs) {
445 if (exists $libmap{$lib}) {
446 next unless length $libmap{$lib};
447 $lib = $libmap{$lib};
450 my(@variants,$variant,$name,$test,$cand);
453 # If we don't have a file type, consider it a possibly abbreviated name and
454 # check for common variants. We try these first to grab libraries before
455 # a like-named executable image (e.g. -lperl resolves to perlshr.exe
457 if ($lib !~ /\.[^:>\]]*$/) {
458 push(@variants,"${lib}shr","${lib}rtl","${lib}lib");
459 push(@variants,"lib$lib") if $lib !~ /[:>\]]/;
461 push(@variants,$lib);
462 warn "Looking for $lib\n" if $verbose;
463 foreach $variant (@variants) {
464 foreach $dir (@dirs) {
467 $name = "$dir$variant";
468 warn "\tChecking $name\n" if $verbose > 2;
469 if (-f ($test = VMS::Filespec::rmsexpand($name))) {
470 # It's got its own suffix, so we'll have to figure out the type
471 if ($test =~ /(?:$so|exe)$/i) { $type = 'SHR'; }
472 elsif ($test =~ /(?:$lib_ext|olb)$/i) { $type = 'OLB'; }
473 elsif ($test =~ /(?:$obj_ext|obj)$/i) {
474 warn "Note (probably harmless): "
475 ."Plain object file $test found in library list\n";
479 warn "Note (probably harmless): "
480 ."Unknown library type for $test; assuming shared\n";
484 elsif (-f ($test = VMS::Filespec::rmsexpand($name,$so)) or
485 -f ($test = VMS::Filespec::rmsexpand($name,'.exe'))) {
487 $name = $test unless $test =~ /exe;?\d*$/i;
489 elsif (not length($ctype) and # If we've got a lib already, don't bother
490 ( -f ($test = VMS::Filespec::rmsexpand($name,$lib_ext)) or
491 -f ($test = VMS::Filespec::rmsexpand($name,'.olb')))) {
493 $name = $test unless $test =~ /olb;?\d*$/i;
495 elsif (not length($ctype) and # If we've got a lib already, don't bother
496 ( -f ($test = VMS::Filespec::rmsexpand($name,$obj_ext)) or
497 -f ($test = VMS::Filespec::rmsexpand($name,'.obj')))) {
498 warn "Note (probably harmless): "
499 ."Plain object file $test found in library list\n";
501 $name = $test unless $test =~ /obj;?\d*$/i;
504 $ctype = $type; $cand = $name;
505 last if $ctype eq 'SHR';
509 # This has to precede any other CRTLs, so just make it first
510 if ($cand eq 'VAXCCURSE') { unshift @{$found{$ctype}}, $cand; }
511 else { push @{$found{$ctype}}, $cand; }
512 warn "\tFound as $cand (really $test), type $ctype\n" if $verbose > 1;
513 push @flibs, $name unless $libs_seen{$fullname}++;
517 warn "Note (probably harmless): "
518 ."No library found for $lib\n";
521 push @fndlibs, @{$found{OBJ}} if exists $found{OBJ};
522 push @fndlibs, map { "$_/Library" } @{$found{OLB}} if exists $found{OLB};
523 push @fndlibs, map { "$_/Share" } @{$found{SHR}} if exists $found{SHR};
524 $lib = join(' ',@fndlibs);
526 $ldlib = $crtlstr ? "$lib $crtlstr" : $lib;
527 warn "Result:\n\tEXTRALIBS: $lib\n\tLDLOADLIBS: $ldlib\n" if $verbose;
528 wantarray ? ($lib, '', $ldlib, '', ($give_libs ? \@flibs : ())) : $lib;