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) = @_;
29 if ($^O =~ 'os2' and $Config{perllibs}) {
30 # Dynamic libraries are not transitive, so we may need including
31 # the libraries linked against perl.dll again.
33 $potential_libs .= " " if $potential_libs;
34 $potential_libs .= $Config{perllibs};
36 return ("", "", "", "", ($give_libs ? [] : ())) unless $potential_libs;
37 warn "Potential libraries are '$potential_libs':\n" if $verbose;
39 my($so) = $Config{so};
40 my($libs) = defined $Config{perllibs} ? $Config{perllibs} : $Config{libs};
41 my $Config_libext = $Config{lib_ext} || ".a";
44 # compute $extralibs, $bsloadlibs and $ldloadlibs from
46 # this is a rewrite of Andy Dougherty's extliblist in perl
48 my(@searchpath); # from "-L/path" entries in $potential_libs
49 my(@libpath) = split " ", $Config{'libpth'};
50 my(@ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen);
51 my(@libs, %libs_seen);
52 my($fullname, $thislib, $thispth, @fullname);
53 my($pwd) = cwd(); # from Cwd.pm
56 foreach $thislib (split ' ', $potential_libs){
58 # Handle possible linker path arguments.
59 if ($thislib =~ s/^(-[LR]|-Wl,-R)//){ # save path flag type
62 warn "$ptype$thislib ignored, directory does not exist\n"
67 if (($ptype eq '-R') or ($ptype eq '-Wl,-R')) {
68 if ($Config{'lddlflags'} =~ /-Wl,-R/) {
70 } elsif ($Config{'lddlflags'} =~ /-R/) {
74 unless (File::Spec->file_name_is_absolute($thislib)) {
75 warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
76 $thislib = $self->catdir($pwd,$thislib);
78 push(@searchpath, $thislib);
79 push(@extralibs, "$ptype$thislib");
80 push(@ldloadlibs, "$rtype$thislib");
84 # Handle possible library arguments.
85 unless ($thislib =~ s/^-l//){
86 warn "Unrecognized argument in LIBS ignored: '$thislib'\n";
91 foreach $thispth (@searchpath, @libpath){
93 # Try to find the full name of the library. We need this to
94 # determine whether it's a dynamically-loadable library or not.
95 # This tends to be subject to various os-specific quirks.
96 # For gcc-2.6.2 on linux (March 1995), DLD can not load
97 # .sa libraries, with the exception of libm.sa, so we
98 # deliberately skip them.
100 $self->lsdir($thispth,"^\Qlib$thislib.$so.\E[0-9]+")){
101 # Take care that libfoo.so.10 wins against libfoo.so.9.
102 # Compare two libraries to find the most recent version
103 # number. E.g. if you have libfoo.so.9.0.7 and
104 # libfoo.so.10.1, first convert all digits into two
105 # decimal places. Then we'll add ".00" to the shorter
106 # strings so that we're comparing strings of equal length
107 # Thus we'll compare libfoo.so.09.07.00 with
108 # libfoo.so.10.01.00. Some libraries might have letters
109 # in the version. We don't know what they mean, but will
110 # try to skip them gracefully -- we'll set any letter to
111 # '0'. Finally, sort in reverse so we can take the
114 #TODO: iterate through the directory instead of sorting
116 $fullname = "$thispth/" .
117 (sort { my($ma) = $a;
119 $ma =~ tr/A-Za-z/0/s;
120 $ma =~ s/\b(\d)\b/0$1/g;
121 $mb =~ tr/A-Za-z/0/s;
122 $mb =~ s/\b(\d)\b/0$1/g;
123 while (length($ma) < length($mb)) { $ma .= ".00"; }
124 while (length($mb) < length($ma)) { $mb .= ".00"; }
125 # Comparison deliberately backwards
126 $mb cmp $ma;} @fullname)[0];
127 } elsif (-f ($fullname="$thispth/lib$thislib.$so")
128 && (($Config{'dlsrc'} ne "dl_dld.xs") || ($thislib eq "m"))){
129 } elsif (-f ($fullname="$thispth/lib${thislib}_s$Config_libext")
130 && (! $Config{'archname'} =~ /RM\d\d\d-svr4/)
131 && ($thislib .= "_s") ){ # we must explicitly use _s version
132 } elsif (-f ($fullname="$thispth/lib$thislib$Config_libext")){
133 } elsif (-f ($fullname="$thispth/$thislib$Config_libext")){
134 } elsif (-f ($fullname="$thispth/Slib$thislib$Config_libext")){
135 } elsif ($^O eq 'dgux'
136 && -l ($fullname="$thispth/lib$thislib$Config_libext")
137 && readlink($fullname) =~ /^elink:/s) {
138 # Some of DG's libraries look like misconnected symbolic
139 # links, but development tools can follow them. (They
142 # libm.a -> elink:${SDE_PATH:-/usr}/sde/\
143 # ${TARGET_BINARY_INTERFACE:-m88kdgux}/usr/lib/libm.a
145 # , the compilation tools expand the environment variables.)
147 warn "$thislib not found in $thispth\n" if $verbose;
150 warn "'-l$thislib' found at $fullname\n" if $verbose;
151 push @libs, $fullname unless $libs_seen{$fullname}++;
155 # Now update library lists
157 # what do we know about this library...
158 my $is_dyna = ($fullname !~ /\Q$Config_libext\E\z/);
159 my $in_perl = ($libs =~ /\B-l\Q${thislib}\E\b/s);
161 # include the path to the lib once in the dynamic linker path
162 # but only if it is a dynamic lib and not in Perl itself
163 my($fullnamedir) = dirname($fullname);
164 push @ld_run_path, $fullnamedir
165 if $is_dyna && !$in_perl &&
166 !$ld_run_path_seen{$fullnamedir}++;
168 # Do not add it into the list if it is already linked in
169 # with the main perl executable.
170 # We have to special-case the NeXT, because math and ndbm
171 # are both in libsys_s
173 ($Config{'osname'} eq 'next' &&
174 ($thislib eq 'm' || $thislib eq 'ndbm')) ){
175 push(@extralibs, "-l$thislib");
178 # We might be able to load this archive file dynamically
179 if ( ($Config{'dlsrc'} =~ /dl_next/ && $Config{'osvers'} lt '4_0')
180 || ($Config{'dlsrc'} =~ /dl_dld/) )
182 # We push -l$thislib instead of $fullname because
183 # it avoids hardwiring a fixed path into the .bs file.
184 # Mkbootstrap will automatically add dl_findfile() to
185 # the .bs file if it sees a name in the -l format.
186 # USE THIS, when dl_findfile() is fixed:
187 # push(@bsloadlibs, "-l$thislib");
188 # OLD USE WAS while checking results against old_extliblist
189 push(@bsloadlibs, "$fullname");
192 # For SunOS4, do not add in this shared library if
193 # it is already linked in the main perl executable
194 push(@ldloadlibs, "-l$thislib")
195 unless ($in_perl and $^O eq 'sunos');
197 push(@ldloadlibs, "-l$thislib");
200 last; # found one here so don't bother looking further
202 warn "Note (probably harmless): "
203 ."No library found for -l$thislib\n"
208 return ('','','','', ($give_libs ? \@libs : ()));
211 return ("@extralibs", "@bsloadlibs", "@ldloadlibs",
212 join(":",@ld_run_path), ($give_libs ? \@libs : ()));
218 require Text::ParseWords;
220 my($self, $potential_libs, $verbose, $give_libs) = @_;
223 # If user did not supply a list, we punt.
224 # (caller should probably use the list in $Config{libs})
225 return ("", "", "", "", ($give_libs ? [] : ())) unless $potential_libs;
227 my $cc = $Config{cc};
228 my $VC = 1 if $cc =~ /^cl/i;
229 my $BC = 1 if $cc =~ /^bcc/i;
230 my $GC = 1 if $cc =~ /^gcc/i;
231 my $so = $Config{'so'};
232 my $libs = $Config{'perllibs'};
233 my $libpth = $Config{'libpth'};
234 my $libext = $Config{'lib_ext'} || ".lib";
235 my(@libs, %libs_seen);
237 if ($libs and $potential_libs !~ /:nodefault/i) {
238 # If Config.pm defines a set of default libs, we always
239 # tack them on to the user-supplied list, unless the user
240 # specified :nodefault
242 $potential_libs .= " " if $potential_libs;
243 $potential_libs .= $libs;
245 warn "Potential libraries are '$potential_libs':\n" if $verbose;
247 # normalize to forward slashes
249 $potential_libs =~ s,\\,/,g;
251 # compute $extralibs from $potential_libs
253 my @searchpath; # from "-L/path" in $potential_libs
254 my @libpath = Text::ParseWords::quotewords('\s+', 0, $libpth);
256 my $pwd = cwd(); # from Cwd.pm
260 my($fullname, $thislib, $thispth);
262 # add "$Config{installarchlib}/CORE" to default search path
263 push @libpath, "$Config{installarchlib}/CORE";
265 if ($VC and exists $ENV{LIB} and $ENV{LIB}) {
266 push @libpath, split /;/, $ENV{LIB};
269 foreach (Text::ParseWords::quotewords('\s+', 0, $potential_libs)){
273 # see if entry is a flag
275 $search = 0 if lc eq ':nosearch';
276 $search = 1 if lc eq ':search';
277 warn "Ignoring unknown flag '$thislib'\n"
278 if $verbose and !/^:(no)?(search|default)$/i;
282 # if searching is disabled, do compiler-specific translations
284 s/^-l(.+)$/$1.lib/ unless $GC;
285 s/^-L/-libpath:/ if $VC;
286 push(@extralibs, $_);
291 # handle possible linker path arguments
292 if (s/^-L// and not -d) {
293 warn "$thislib ignored, directory does not exist\n"
298 unless (File::Spec->file_name_is_absolute($_)) {
299 warn "Warning: '$thislib' changed to '-L$pwd/$_'\n";
300 $_ = $self->catdir($pwd,$_);
302 push(@searchpath, $_);
306 # handle possible library arguments
307 if (s/^-l// and $GC and !/^lib/i) {
310 $_ .= $libext if !/\Q$libext\E$/i;
315 # look for the file itself
317 warn "'$thislib' found as '$_'\n" if $verbose;
319 push(@extralibs, $_);
324 foreach $thispth (@searchpath, @libpath){
325 unless (-f ($fullname="$thispth\\$_")) {
326 warn "'$thislib' not found as '$fullname'\n" if $verbose;
329 warn "'$thislib' found as '$fullname'\n" if $verbose;
332 push(@extralibs, $fullname);
333 push @libs, $fullname unless $libs_seen{$fullname}++;
337 # do another pass with (or without) leading 'lib' if they used -l
338 if (!$found_lib and $thislib =~ /^-l/ and !$secondpass++) {
340 goto LOOKAGAIN if s/^lib//i;
349 warn "Note (probably harmless): "
350 ."No library found for $thislib\n"
355 return ('','','','', ($give_libs ? \@libs : ())) unless $found;
357 # make sure paths with spaces are properly quoted
358 @extralibs = map { (/\s/ && !/^".*"$/) ? qq["$_"] : $_ } @extralibs;
359 @libs = map { (/\s/ && !/^".*"$/) ? qq["$_"] : $_ } @libs;
360 $lib = join(' ',@extralibs);
362 # normalize back to backward slashes (to help braindead tools)
363 # XXX this may break equally braindead GNU tools that don't understand
364 # backslashes, either. Seems like one can't win here. Cursed be CP/M.
367 warn "Result: $lib\n" if $verbose;
368 wantarray ? ($lib, '', $lib, '', ($give_libs ? \@libs : ())) : $lib;
373 my($self, $potential_libs,$verbose,$give_libs) = @_;
377 my($dbgqual) = $self->{OPTIMIZE} || $Config{'optimize'} ||
378 $self->{CCFLAGS} || $Config{'ccflags'};
379 @crtls = ( ($dbgqual =~ m-/Debug-i ? $Config{'dbgprefix'} : '')
381 push(@crtls, grep { not /\(/ } split /\s+/, $Config{'perllibs'});
382 push(@crtls, grep { not /\(/ } split /\s+/, $Config{'libc'});
383 # In general, we pass through the basic libraries from %Config unchanged.
384 # The one exception is that if we're building in the Perl source tree, and
385 # a library spec could be resolved via a logical name, we go to some trouble
386 # to insure that the copy in the local tree is used, rather than one to
387 # which a system-wide logical may point.
388 if ($self->{PERL_SRC}) {
389 my($lib,$locspec,$type);
390 foreach $lib (@crtls) {
391 if (($locspec,$type) = $lib =~ m-^([\w$\-]+)(/\w+)?- and $locspec =~ /perl/i) {
392 if (lc $type eq '/share') { $locspec .= $Config{'exe_ext'}; }
393 elsif (lc $type eq '/library') { $locspec .= $Config{'lib_ext'}; }
394 else { $locspec .= $Config{'obj_ext'}; }
395 $locspec = $self->catfile($self->{PERL_SRC},$locspec);
396 $lib = "$locspec$type" if -e $locspec;
400 $crtlstr = @crtls ? join(' ',@crtls) : '';
402 unless ($potential_libs) {
403 warn "Result:\n\tEXTRALIBS: \n\tLDLOADLIBS: $crtlstr\n" if $verbose;
404 return ('', '', $crtlstr, '', ($give_libs ? [] : ()));
407 my(@dirs,@libs,$dir,$lib,%found,@fndlibs,$ldlib);
409 my($so,$lib_ext,$obj_ext) = @Config{'so','lib_ext','obj_ext'};
410 # List of common Unix library names and their VMS equivalents
411 # (VMS equivalent of '' indicates that the library is automatically
412 # searched by the linker, and should be skipped here.)
413 my(@flibs, %libs_seen);
414 my %libmap = ( 'm' => '', 'f77' => '', 'F77' => '', 'V77' => '', 'c' => '',
415 'malloc' => '', 'crypt' => '', 'resolv' => '', 'c_s' => '',
416 'socket' => '', 'X11' => 'DECW$XLIBSHR',
417 'Xt' => 'DECW$XTSHR', 'Xm' => 'DECW$XMLIBSHR',
418 'Xmu' => 'DECW$XMULIBSHR');
419 if ($Config{'vms_cc_type'} ne 'decc') { $libmap{'curses'} = 'VAXCCURSE'; }
421 warn "Potential libraries are '$potential_libs'\n" if $verbose;
423 # First, sort out directories and library names in the input
424 foreach $lib (split ' ',$potential_libs) {
425 push(@dirs,$1), next if $lib =~ /^-L(.*)/;
426 push(@dirs,$lib), next if $lib =~ /[:>\]]$/;
427 push(@dirs,$lib), next if -d $lib;
428 push(@libs,$1), next if $lib =~ /^-l(.*)/;
431 push(@dirs,split(' ',$Config{'libpth'}));
433 # Now make sure we've got VMS-syntax absolute directory specs
434 # (We don't, however, check whether someone's hidden a relative
435 # path in a logical name.)
436 foreach $dir (@dirs) {
438 warn "Skipping nonexistent Directory $dir\n" if $verbose > 1;
442 warn "Resolving directory $dir\n" if $verbose;
443 if (File::Spec->file_name_is_absolute($dir)) {
444 $dir = $self->fixpath($dir,1);
447 $dir = $self->catdir($cwd,$dir);
450 @dirs = grep { length($_) } @dirs;
451 unshift(@dirs,''); # Check each $lib without additions first
453 LIB: foreach $lib (@libs) {
454 if (exists $libmap{$lib}) {
455 next unless length $libmap{$lib};
456 $lib = $libmap{$lib};
459 my(@variants,$variant,$name,$test,$cand);
462 # If we don't have a file type, consider it a possibly abbreviated name and
463 # check for common variants. We try these first to grab libraries before
464 # a like-named executable image (e.g. -lperl resolves to perlshr.exe
466 if ($lib !~ /\.[^:>\]]*$/) {
467 push(@variants,"${lib}shr","${lib}rtl","${lib}lib");
468 push(@variants,"lib$lib") if $lib !~ /[:>\]]/;
470 push(@variants,$lib);
471 warn "Looking for $lib\n" if $verbose;
472 foreach $variant (@variants) {
473 foreach $dir (@dirs) {
476 $name = "$dir$variant";
477 warn "\tChecking $name\n" if $verbose > 2;
478 if (-f ($test = VMS::Filespec::rmsexpand($name))) {
479 # It's got its own suffix, so we'll have to figure out the type
480 if ($test =~ /(?:$so|exe)$/i) { $type = 'SHR'; }
481 elsif ($test =~ /(?:$lib_ext|olb)$/i) { $type = 'OLB'; }
482 elsif ($test =~ /(?:$obj_ext|obj)$/i) {
483 warn "Note (probably harmless): "
484 ."Plain object file $test found in library list\n";
488 warn "Note (probably harmless): "
489 ."Unknown library type for $test; assuming shared\n";
493 elsif (-f ($test = VMS::Filespec::rmsexpand($name,$so)) or
494 -f ($test = VMS::Filespec::rmsexpand($name,'.exe'))) {
496 $name = $test unless $test =~ /exe;?\d*$/i;
498 elsif (not length($ctype) and # If we've got a lib already, don't bother
499 ( -f ($test = VMS::Filespec::rmsexpand($name,$lib_ext)) or
500 -f ($test = VMS::Filespec::rmsexpand($name,'.olb')))) {
502 $name = $test unless $test =~ /olb;?\d*$/i;
504 elsif (not length($ctype) and # If we've got a lib already, don't bother
505 ( -f ($test = VMS::Filespec::rmsexpand($name,$obj_ext)) or
506 -f ($test = VMS::Filespec::rmsexpand($name,'.obj')))) {
507 warn "Note (probably harmless): "
508 ."Plain object file $test found in library list\n";
510 $name = $test unless $test =~ /obj;?\d*$/i;
513 $ctype = $type; $cand = $name;
514 last if $ctype eq 'SHR';
518 # This has to precede any other CRTLs, so just make it first
519 if ($cand eq 'VAXCCURSE') { unshift @{$found{$ctype}}, $cand; }
520 else { push @{$found{$ctype}}, $cand; }
521 warn "\tFound as $cand (really $test), type $ctype\n" if $verbose > 1;
522 push @flibs, $name unless $libs_seen{$fullname}++;
526 warn "Note (probably harmless): "
527 ."No library found for $lib\n";
530 push @fndlibs, @{$found{OBJ}} if exists $found{OBJ};
531 push @fndlibs, map { "$_/Library" } @{$found{OLB}} if exists $found{OLB};
532 push @fndlibs, map { "$_/Share" } @{$found{SHR}} if exists $found{SHR};
533 $lib = join(' ',@fndlibs);
535 $ldlib = $crtlstr ? "$lib $crtlstr" : $lib;
536 warn "Result:\n\tEXTRALIBS: $lib\n\tLDLOADLIBS: $ldlib\n" if $verbose;
537 wantarray ? ($lib, '', $ldlib, '', ($give_libs ? \@flibs : ())) : $lib;