This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
darwin can have libfoo.0.dylib, as opposed to libfoo.dylib.0
[perl5.git] / cpan / ExtUtils-MakeMaker / lib / ExtUtils / Liblist / Kid.pm
CommitLineData
f6d6199c
MS
1package ExtUtils::Liblist::Kid;
2
3# XXX Splitting this out into its own .pm is a temporary solution.
4
5# This kid package is to be used by MakeMaker. It will not work if
6# $self is not a Makemaker.
7
a592ba15 8use 5.006;
4b5789fe 9
f6d6199c
MS
10# Broken out of MakeMaker from version 4.11
11
1df8d179 12use strict;
4b5789fe 13use warnings;
608fe6e2 14our $VERSION = '6.98';
f6d6199c 15
4b5789fe 16use ExtUtils::MakeMaker::Config;
f6d6199c
MS
17use Cwd 'cwd';
18use File::Basename;
19use File::Spec;
20
21sub ext {
4b5789fe
CBW
22 if ( $^O eq 'VMS' ) { return &_vms_ext; }
23 elsif ( $^O eq 'MSWin32' ) { return &_win32_ext; }
24 else { return &_unix_os2_ext; }
f6d6199c
MS
25}
26
27sub _unix_os2_ext {
4b5789fe 28 my ( $self, $potential_libs, $verbose, $give_libs ) = @_;
479d2113
MS
29 $verbose ||= 0;
30
33eef971 31 if ( $^O =~ /os2|android/ and $Config{perllibs} ) {
4b5789fe
CBW
32
33 # Dynamic libraries are not transitive, so we may need including
33eef971 34 # the libraries linked against perl.dll/libperl.so again.
f6d6199c 35
4b5789fe
CBW
36 $potential_libs .= " " if $potential_libs;
37 $potential_libs .= $Config{perllibs};
f6d6199c 38 }
4b5789fe 39 return ( "", "", "", "", ( $give_libs ? [] : () ) ) unless $potential_libs;
f6d6199c
MS
40 warn "Potential libraries are '$potential_libs':\n" if $verbose;
41
4b5789fe
CBW
42 my ( $so ) = $Config{so};
43 my ( $libs ) = defined $Config{perllibs} ? $Config{perllibs} : $Config{libs};
f6d6199c 44 my $Config_libext = $Config{lib_ext} || ".a";
9b47cdde 45 my $Config_dlext = $Config{dlext};
f6d6199c 46
f6d6199c
MS
47 # compute $extralibs, $bsloadlibs and $ldloadlibs from
48 # $potential_libs
49 # this is a rewrite of Andy Dougherty's extliblist in perl
50
4b5789fe
CBW
51 my ( @searchpath ); # from "-L/path" entries in $potential_libs
52 my ( @libpath ) = split " ", $Config{'libpth'};
53 my ( @ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen );
54 my ( @libs, %libs_seen );
55 my ( $fullname, @fullname );
56 my ( $pwd ) = cwd(); # from Cwd.pm
57 my ( $found ) = 0;
58
59 foreach my $thislib ( split ' ', $potential_libs ) {
60
61 # Handle possible linker path arguments.
127c4457 62 if ( $thislib =~ s/^(-[LR]|-Wl,-R|-Wl,-rpath,)// ) { # save path flag type
4b5789fe
CBW
63 my ( $ptype ) = $1;
64 unless ( -d $thislib ) {
65 warn "$ptype$thislib ignored, directory does not exist\n"
66 if $verbose;
67 next;
68 }
69 my ( $rtype ) = $ptype;
127c4457
CBW
70 if ( ( $ptype eq '-R' ) or ( $ptype =~ m!^-Wl,-[Rr]! ) ) {
71 if ( $Config{'lddlflags'} =~ /-Wl,-[Rr]/ ) {
4b5789fe
CBW
72 $rtype = '-Wl,-R';
73 }
74 elsif ( $Config{'lddlflags'} =~ /-R/ ) {
75 $rtype = '-R';
76 }
77 }
78 unless ( File::Spec->file_name_is_absolute( $thislib ) ) {
79 warn "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
80 $thislib = $self->catdir( $pwd, $thislib );
81 }
82 push( @searchpath, $thislib );
83 push( @extralibs, "$ptype$thislib" );
84 push( @ldloadlibs, "$rtype$thislib" );
85 next;
86 }
87
127c4457
CBW
88 if ( $thislib =~ m!^-Wl,! ) {
89 push( @extralibs, $thislib );
90 push( @ldloadlibs, $thislib );
91 next;
92 }
93
4b5789fe
CBW
94 # Handle possible library arguments.
95 unless ( $thislib =~ s/^-l// ) {
96 warn "Unrecognized argument in LIBS ignored: '$thislib'\n";
97 next;
98 }
99
100 my ( $found_lib ) = 0;
101 foreach my $thispth ( @searchpath, @libpath ) {
102
103 # Try to find the full name of the library. We need this to
104 # determine whether it's a dynamically-loadable library or not.
105 # This tends to be subject to various os-specific quirks.
106 # For gcc-2.6.2 on linux (March 1995), DLD can not load
107 # .sa libraries, with the exception of libm.sa, so we
108 # deliberately skip them.
991b13da
JH
109 if ((@fullname =
110 $self->lsdir($thispth, "^\Qlib$thislib.$so.\E[0-9]+")) ||
111 (@fullname =
112 $self->lsdir($thispth, "^\Qlib$thislib.\E[0-9]+\Q\.$so"))) {
4b5789fe
CBW
113 # Take care that libfoo.so.10 wins against libfoo.so.9.
114 # Compare two libraries to find the most recent version
115 # number. E.g. if you have libfoo.so.9.0.7 and
116 # libfoo.so.10.1, first convert all digits into two
117 # decimal places. Then we'll add ".00" to the shorter
118 # strings so that we're comparing strings of equal length
119 # Thus we'll compare libfoo.so.09.07.00 with
120 # libfoo.so.10.01.00. Some libraries might have letters
121 # in the version. We don't know what they mean, but will
122 # try to skip them gracefully -- we'll set any letter to
123 # '0'. Finally, sort in reverse so we can take the
124 # first element.
125
126 #TODO: iterate through the directory instead of sorting
127
128 $fullname = "$thispth/" . (
129 sort {
130 my ( $ma ) = $a;
131 my ( $mb ) = $b;
132 $ma =~ tr/A-Za-z/0/s;
133 $ma =~ s/\b(\d)\b/0$1/g;
134 $mb =~ tr/A-Za-z/0/s;
135 $mb =~ s/\b(\d)\b/0$1/g;
136 while ( length( $ma ) < length( $mb ) ) { $ma .= ".00"; }
137 while ( length( $mb ) < length( $ma ) ) { $mb .= ".00"; }
138
139 # Comparison deliberately backwards
140 $mb cmp $ma;
141 } @fullname
142 )[0];
143 }
144 elsif ( -f ( $fullname = "$thispth/lib$thislib.$so" )
145 && ( ( $Config{'dlsrc'} ne "dl_dld.xs" ) || ( $thislib eq "m" ) ) )
146 {
147 }
148 elsif (-f ( $fullname = "$thispth/lib${thislib}_s$Config_libext" )
149 && ( $Config{'archname'} !~ /RM\d\d\d-svr4/ )
150 && ( $thislib .= "_s" ) )
151 { # we must explicitly use _s version
152 }
153 elsif ( -f ( $fullname = "$thispth/lib$thislib$Config_libext" ) ) {
154 }
155 elsif ( defined( $Config_dlext )
156 && -f ( $fullname = "$thispth/lib$thislib.$Config_dlext" ) )
157 {
158 }
159 elsif ( -f ( $fullname = "$thispth/$thislib$Config_libext" ) ) {
160 }
161 elsif ( -f ( $fullname = "$thispth/lib$thislib.dll$Config_libext" ) ) {
162 }
eb7cfb31 163 elsif ( $^O eq 'cygwin' && -f ( $fullname = "$thispth/$thislib.dll" ) ) {
673553d0 164 }
4b5789fe
CBW
165 elsif ( -f ( $fullname = "$thispth/Slib$thislib$Config_libext" ) ) {
166 }
167 elsif ($^O eq 'dgux'
168 && -l ( $fullname = "$thispth/lib$thislib$Config_libext" )
169 && readlink( $fullname ) =~ /^elink:/s )
170 {
171
172 # Some of DG's libraries look like misconnected symbolic
173 # links, but development tools can follow them. (They
174 # look like this:
175 #
176 # libm.a -> elink:${SDE_PATH:-/usr}/sde/\
177 # ${TARGET_BINARY_INTERFACE:-m88kdgux}/usr/lib/libm.a
178 #
179 # , the compilation tools expand the environment variables.)
180 }
181 else {
182 warn "$thislib not found in $thispth\n" if $verbose;
183 next;
184 }
185 warn "'-l$thislib' found at $fullname\n" if $verbose;
186 push @libs, $fullname unless $libs_seen{$fullname}++;
187 $found++;
188 $found_lib++;
189
190 # Now update library lists
191
192 # what do we know about this library...
193 my $is_dyna = ( $fullname !~ /\Q$Config_libext\E\z/ );
194 my $in_perl = ( $libs =~ /\B-l\Q${thislib}\E\b/s );
f6d6199c 195
2530b651
MS
196 # include the path to the lib once in the dynamic linker path
197 # but only if it is a dynamic lib and not in Perl itself
4b5789fe 198 my ( $fullnamedir ) = dirname( $fullname );
2530b651 199 push @ld_run_path, $fullnamedir
4b5789fe
CBW
200 if $is_dyna
201 && !$in_perl
202 && !$ld_run_path_seen{$fullnamedir}++;
203
204 # Do not add it into the list if it is already linked in
205 # with the main perl executable.
206 # We have to special-case the NeXT, because math and ndbm
207 # are both in libsys_s
208 unless (
209 $in_perl
210 || ( $Config{'osname'} eq 'next'
211 && ( $thislib eq 'm' || $thislib eq 'ndbm' ) )
212 )
213 {
214 push( @extralibs, "-l$thislib" );
215 }
216
217 # We might be able to load this archive file dynamically
218 if ( ( $Config{'dlsrc'} =~ /dl_next/ && $Config{'osvers'} lt '4_0' )
219 || ( $Config{'dlsrc'} =~ /dl_dld/ ) )
220 {
221
222 # We push -l$thislib instead of $fullname because
223 # it avoids hardwiring a fixed path into the .bs file.
224 # Mkbootstrap will automatically add dl_findfile() to
225 # the .bs file if it sees a name in the -l format.
226 # USE THIS, when dl_findfile() is fixed:
227 # push(@bsloadlibs, "-l$thislib");
228 # OLD USE WAS while checking results against old_extliblist
229 push( @bsloadlibs, "$fullname" );
230 }
231 else {
232 if ( $is_dyna ) {
233
f6d6199c
MS
234 # For SunOS4, do not add in this shared library if
235 # it is already linked in the main perl executable
4b5789fe
CBW
236 push( @ldloadlibs, "-l$thislib" )
237 unless ( $in_perl and $^O eq 'sunos' );
238 }
239 else {
240 push( @ldloadlibs, "-l$thislib" );
241 }
242 }
243 last; # found one here so don't bother looking further
244 }
48000314 245 warn "Warning (mostly harmless): " . "No library found for -l$thislib\n"
4b5789fe 246 unless $found_lib > 0;
f6d6199c
MS
247 }
248
4b5789fe
CBW
249 unless ( $found ) {
250 return ( '', '', '', '', ( $give_libs ? \@libs : () ) );
f6d6199c
MS
251 }
252 else {
4b5789fe 253 return ( "@extralibs", "@bsloadlibs", "@ldloadlibs", join( ":", @ld_run_path ), ( $give_libs ? \@libs : () ) );
f6d6199c
MS
254 }
255}
256
257sub _win32_ext {
258
259 require Text::ParseWords;
260
4b5789fe 261 my ( $self, $potential_libs, $verbose, $give_libs ) = @_;
479d2113 262 $verbose ||= 0;
f6d6199c
MS
263
264 # If user did not supply a list, we punt.
265 # (caller should probably use the list in $Config{libs})
4b5789fe 266 return ( "", "", "", "", ( $give_libs ? [] : () ) ) unless $potential_libs;
f6d6199c 267
4b5789fe
CBW
268 # TODO: make this use MM_Win32.pm's compiler detection
269 my %libs_seen;
270 my @extralibs;
33cc85ac
GG
271 my $cc = $Config{cc} || '';
272 my $VC = $cc =~ /\bcl\b/i;
273 my $GC = $cc =~ /\bgcc\b/i;
274
4b5789fe 275 my $libext = _win32_lib_extensions();
33cc85ac
GG
276 my @searchpath = ( '' ); # from "-L/path" entries in $potential_libs
277 my @libpath = _win32_default_search_paths( $VC, $GC );
278 my $pwd = cwd(); # from Cwd.pm
4b5789fe 279 my $search = 1;
f6d6199c 280
4b5789fe
CBW
281 # compute @extralibs from $potential_libs
282 my @lib_search_list = _win32_make_lib_search_list( $potential_libs, $verbose );
283 for ( @lib_search_list ) {
f6d6199c 284
4b5789fe 285 my $thislib = $_;
f6d6199c 286
4b5789fe
CBW
287 # see if entry is a flag
288 if ( /^:\w+$/ ) {
289 $search = 0 if lc eq ':nosearch';
290 $search = 1 if lc eq ':search';
291 _debug( "Ignoring unknown flag '$thislib'\n", $verbose ) if !/^:(no)?(search|default)$/i;
292 next;
293 }
f6d6199c 294
4b5789fe
CBW
295 # if searching is disabled, do compiler-specific translations
296 unless ( $search ) {
297 s/^-l(.+)$/$1.lib/ unless $GC;
298 s/^-L/-libpath:/ if $VC;
299 push( @extralibs, $_ );
300 next;
301 }
f6d6199c 302
4b5789fe
CBW
303 # handle possible linker path arguments
304 if ( s/^-L// and not -d ) {
305 _debug( "$thislib ignored, directory does not exist\n", $verbose );
306 next;
307 }
308 elsif ( -d ) {
309 unless ( File::Spec->file_name_is_absolute( $_ ) ) {
310 warn "Warning: '$thislib' changed to '-L$pwd/$_'\n";
311 $_ = $self->catdir( $pwd, $_ );
312 }
313 push( @searchpath, $_ );
314 next;
315 }
f6d6199c 316
4b5789fe
CBW
317 my @paths = ( @searchpath, @libpath );
318 my ( $fullname, $path ) = _win32_search_file( $thislib, $libext, \@paths, $verbose, $GC );
f6d6199c 319
4b5789fe 320 if ( !$fullname ) {
48000314 321 warn "Warning (mostly harmless): No library found for $thislib\n";
4b5789fe
CBW
322 next;
323 }
f6d6199c 324
4b5789fe
CBW
325 _debug( "'$thislib' found as '$fullname'\n", $verbose );
326 push( @extralibs, $fullname );
327 $libs_seen{$fullname} = 1 if $path; # why is this a special case?
f6d6199c
MS
328 }
329
4b5789fe
CBW
330 my @libs = keys %libs_seen;
331
332 return ( '', '', '', '', ( $give_libs ? \@libs : () ) ) unless @extralibs;
f6d6199c
MS
333
334 # make sure paths with spaces are properly quoted
4b5789fe
CBW
335 @extralibs = map { /\s/ ? qq["$_"] : $_ } @extralibs;
336 @libs = map { /\s/ ? qq["$_"] : $_ } @libs;
337
338 my $lib = join( ' ', @extralibs );
f6d6199c
MS
339
340 # normalize back to backward slashes (to help braindead tools)
341 # XXX this may break equally braindead GNU tools that don't understand
342 # backslashes, either. Seems like one can't win here. Cursed be CP/M.
343 $lib =~ s,/,\\,g;
344
4b5789fe
CBW
345 _debug( "Result: $lib\n", $verbose );
346 wantarray ? ( $lib, '', $lib, '', ( $give_libs ? \@libs : () ) ) : $lib;
f6d6199c
MS
347}
348
4b5789fe
CBW
349sub _win32_make_lib_search_list {
350 my ( $potential_libs, $verbose ) = @_;
f6d6199c 351
4b5789fe
CBW
352 # If Config.pm defines a set of default libs, we always
353 # tack them on to the user-supplied list, unless the user
354 # specified :nodefault
355 my $libs = $Config{'perllibs'};
356 $potential_libs = join( ' ', $potential_libs, $libs ) if $libs and $potential_libs !~ /:nodefault/i;
357 _debug( "Potential libraries are '$potential_libs':\n", $verbose );
358
359 $potential_libs =~ s,\\,/,g; # normalize to forward slashes
360
361 my @list = Text::ParseWords::quotewords( '\s+', 0, $potential_libs );
362
363 return @list;
364}
365
366sub _win32_default_search_paths {
33cc85ac 367 my ( $VC, $GC ) = @_;
4b5789fe
CBW
368
369 my $libpth = $Config{'libpth'} || '';
370 $libpth =~ s,\\,/,g; # normalize to forward slashes
371
372 my @libpath = Text::ParseWords::quotewords( '\s+', 0, $libpth );
373 push @libpath, "$Config{installarchlib}/CORE"; # add "$Config{installarchlib}/CORE" to default search path
374
33cc85ac
GG
375 push @libpath, split /;/, $ENV{LIB} if $VC and $ENV{LIB};
376 push @libpath, split /;/, $ENV{LIBRARY_PATH} if $GC and $ENV{LIBRARY_PATH};
4b5789fe
CBW
377
378 return @libpath;
379}
380
381sub _win32_search_file {
382 my ( $thislib, $libext, $paths, $verbose, $GC ) = @_;
383
384 my @file_list = _win32_build_file_list( $thislib, $GC, $libext );
385
386 for my $lib_file ( @file_list ) {
387 for my $path ( @{$paths} ) {
388 my $fullname = $lib_file;
389 $fullname = "$path\\$fullname" if $path;
390
391 return ( $fullname, $path ) if -f $fullname;
392
393 _debug( "'$thislib' not found as '$fullname'\n", $verbose );
394 }
f6d6199c 395 }
4b5789fe
CBW
396
397 return;
398}
399
400sub _win32_build_file_list {
401 my ( $lib, $GC, $extensions ) = @_;
402
403 my @pre_fixed = _win32_build_prefixed_list( $lib, $GC );
404 return map _win32_attach_extensions( $_, $extensions ), @pre_fixed;
405}
406
407sub _win32_build_prefixed_list {
408 my ( $lib, $GC ) = @_;
409
410 return $lib if $lib !~ s/^-l//;
411 return $lib if $lib =~ /^lib/ and !$GC;
412
413 ( my $no_prefix = $lib ) =~ s/^lib//i;
414 $lib = "lib$lib" if $no_prefix eq $lib;
415
416 return ( $lib, $no_prefix ) if $GC;
417 return ( $no_prefix, $lib );
418}
419
420sub _win32_attach_extensions {
421 my ( $lib, $extensions ) = @_;
422 return map _win32_try_attach_extension( $lib, $_ ), @{$extensions};
423}
424
425sub _win32_try_attach_extension {
426 my ( $lib, $extension ) = @_;
427
428 return $lib if $lib =~ /\Q$extension\E$/i;
429 return "$lib$extension";
430}
431
432sub _win32_lib_extensions {
d67fe576
CBW
433 my @extensions;
434 push @extensions, $Config{'lib_ext'} if $Config{'lib_ext'};
435 push @extensions, '.dll.a' if grep { m!^\.a$! } @extensions;
436 push @extensions, '.lib' unless grep { m!^\.lib$! } @extensions;
437 return \@extensions;
4b5789fe
CBW
438}
439
440sub _debug {
441 my ( $message, $verbose ) = @_;
442 return if !$verbose;
443 warn $message;
444 return;
445}
446
447sub _vms_ext {
448 my ( $self, $potential_libs, $verbose, $give_libs ) = @_;
449 $verbose ||= 0;
450
451 my ( @crtls, $crtlstr );
452 @crtls = ( ( $Config{'ldflags'} =~ m-/Debug-i ? $Config{'dbgprefix'} : '' ) . 'PerlShr/Share' );
453 push( @crtls, grep { not /\(/ } split /\s+/, $Config{'perllibs'} );
454 push( @crtls, grep { not /\(/ } split /\s+/, $Config{'libc'} );
455
456 # In general, we pass through the basic libraries from %Config unchanged.
457 # The one exception is that if we're building in the Perl source tree, and
458 # a library spec could be resolved via a logical name, we go to some trouble
459 # to insure that the copy in the local tree is used, rather than one to
460 # which a system-wide logical may point.
461 if ( $self->{PERL_SRC} ) {
462 my ( $locspec, $type );
463 foreach my $lib ( @crtls ) {
464 if ( ( $locspec, $type ) = $lib =~ m{^([\w\$-]+)(/\w+)?} and $locspec =~ /perl/i ) {
465 if ( lc $type eq '/share' ) { $locspec .= $Config{'exe_ext'}; }
466 elsif ( lc $type eq '/library' ) { $locspec .= $Config{'lib_ext'}; }
467 else { $locspec .= $Config{'obj_ext'}; }
468 $locspec = $self->catfile( $self->{PERL_SRC}, $locspec );
469 $lib = "$locspec$type" if -e $locspec;
470 }
471 }
f6d6199c 472 }
4b5789fe 473 $crtlstr = @crtls ? join( ' ', @crtls ) : '';
f6d6199c 474
4b5789fe
CBW
475 unless ( $potential_libs ) {
476 warn "Result:\n\tEXTRALIBS: \n\tLDLOADLIBS: $crtlstr\n" if $verbose;
477 return ( '', '', $crtlstr, '', ( $give_libs ? [] : () ) );
478 }
f6d6199c 479
4b5789fe
CBW
480 my ( %found, @fndlibs, $ldlib );
481 my $cwd = cwd();
482 my ( $so, $lib_ext, $obj_ext ) = @Config{ 'so', 'lib_ext', 'obj_ext' };
483
484 # List of common Unix library names and their VMS equivalents
485 # (VMS equivalent of '' indicates that the library is automatically
486 # searched by the linker, and should be skipped here.)
487 my ( @flibs, %libs_seen );
488 my %libmap = (
489 'm' => '',
490 'f77' => '',
491 'F77' => '',
492 'V77' => '',
493 'c' => '',
494 'malloc' => '',
495 'crypt' => '',
496 'resolv' => '',
497 'c_s' => '',
498 'socket' => '',
499 'X11' => 'DECW$XLIBSHR',
500 'Xt' => 'DECW$XTSHR',
501 'Xm' => 'DECW$XMLIBSHR',
502 'Xmu' => 'DECW$XMULIBSHR'
503 );
504 if ( $Config{'vms_cc_type'} ne 'decc' ) { $libmap{'curses'} = 'VAXCCURSE'; }
505
506 warn "Potential libraries are '$potential_libs'\n" if $verbose;
507
508 # First, sort out directories and library names in the input
509 my ( @dirs, @libs );
510 foreach my $lib ( split ' ', $potential_libs ) {
511 push( @dirs, $1 ), next if $lib =~ /^-L(.*)/;
512 push( @dirs, $lib ), next if $lib =~ /[:>\]]$/;
513 push( @dirs, $lib ), next if -d $lib;
514 push( @libs, $1 ), next if $lib =~ /^-l(.*)/;
515 push( @libs, $lib );
f6d6199c 516 }
4b5789fe
CBW
517 push( @dirs, split( ' ', $Config{'libpth'} ) );
518
519 # Now make sure we've got VMS-syntax absolute directory specs
520 # (We don't, however, check whether someone's hidden a relative
521 # path in a logical name.)
522 foreach my $dir ( @dirs ) {
523 unless ( -d $dir ) {
524 warn "Skipping nonexistent Directory $dir\n" if $verbose > 1;
525 $dir = '';
526 next;
f6d6199c 527 }
4b5789fe
CBW
528 warn "Resolving directory $dir\n" if $verbose;
529 if ( File::Spec->file_name_is_absolute( $dir ) ) {
530 $dir = $self->fixpath( $dir, 1 );
f6d6199c 531 }
4b5789fe
CBW
532 else {
533 $dir = $self->catdir( $cwd, $dir );
f6d6199c 534 }
4b5789fe
CBW
535 }
536 @dirs = grep { length( $_ ) } @dirs;
537 unshift( @dirs, '' ); # Check each $lib without additions first
538
539 LIB: foreach my $lib ( @libs ) {
540 if ( exists $libmap{$lib} ) {
541 next unless length $libmap{$lib};
542 $lib = $libmap{$lib};
f6d6199c 543 }
4b5789fe
CBW
544
545 my ( @variants, $cand );
546 my ( $ctype ) = '';
547
548 # If we don't have a file type, consider it a possibly abbreviated name and
549 # check for common variants. We try these first to grab libraries before
550 # a like-named executable image (e.g. -lperl resolves to perlshr.exe
551 # before perl.exe).
552 if ( $lib !~ /\.[^:>\]]*$/ ) {
553 push( @variants, "${lib}shr", "${lib}rtl", "${lib}lib" );
554 push( @variants, "lib$lib" ) if $lib !~ /[:>\]]/;
555 }
556 push( @variants, $lib );
557 warn "Looking for $lib\n" if $verbose;
558 foreach my $variant ( @variants ) {
559 my ( $fullname, $name );
560
561 foreach my $dir ( @dirs ) {
562 my ( $type );
563
564 $name = "$dir$variant";
565 warn "\tChecking $name\n" if $verbose > 2;
566 $fullname = VMS::Filespec::rmsexpand( $name );
567 if ( defined $fullname and -f $fullname ) {
568
569 # It's got its own suffix, so we'll have to figure out the type
570 if ( $fullname =~ /(?:$so|exe)$/i ) { $type = 'SHR'; }
571 elsif ( $fullname =~ /(?:$lib_ext|olb)$/i ) { $type = 'OLB'; }
572 elsif ( $fullname =~ /(?:$obj_ext|obj)$/i ) {
48000314 573 warn "Warning (mostly harmless): " . "Plain object file $fullname found in library list\n";
4b5789fe
CBW
574 $type = 'OBJ';
575 }
576 else {
48000314 577 warn "Warning (mostly harmless): " . "Unknown library type for $fullname; assuming shared\n";
4b5789fe
CBW
578 $type = 'SHR';
579 }
580 }
581 elsif (-f ( $fullname = VMS::Filespec::rmsexpand( $name, $so ) )
582 or -f ( $fullname = VMS::Filespec::rmsexpand( $name, '.exe' ) ) )
583 {
584 $type = 'SHR';
585 $name = $fullname unless $fullname =~ /exe;?\d*$/i;
586 }
587 elsif (
588 not length( $ctype ) and # If we've got a lib already,
589 # don't bother
590 ( -f ( $fullname = VMS::Filespec::rmsexpand( $name, $lib_ext ) ) or -f ( $fullname = VMS::Filespec::rmsexpand( $name, '.olb' ) ) )
591 )
592 {
593 $type = 'OLB';
594 $name = $fullname unless $fullname =~ /olb;?\d*$/i;
595 }
596 elsif (
597 not length( $ctype ) and # If we've got a lib already,
598 # don't bother
599 ( -f ( $fullname = VMS::Filespec::rmsexpand( $name, $obj_ext ) ) or -f ( $fullname = VMS::Filespec::rmsexpand( $name, '.obj' ) ) )
600 )
601 {
48000314 602 warn "Warning (mostly harmless): " . "Plain object file $fullname found in library list\n";
4b5789fe
CBW
603 $type = 'OBJ';
604 $name = $fullname unless $fullname =~ /obj;?\d*$/i;
605 }
606 if ( defined $type ) {
607 $ctype = $type;
608 $cand = $name;
609 last if $ctype eq 'SHR';
610 }
611 }
612 if ( $ctype ) {
613
614 # This has to precede any other CRTLs, so just make it first
615 if ( $cand eq 'VAXCCURSE' ) { unshift @{ $found{$ctype} }, $cand; }
616 else { push @{ $found{$ctype} }, $cand; }
617 warn "\tFound as $cand (really $fullname), type $ctype\n"
618 if $verbose > 1;
619 push @flibs, $name unless $libs_seen{$fullname}++;
620 next LIB;
621 }
f6d6199c 622 }
48000314 623 warn "Warning (mostly harmless): " . "No library found for $lib\n";
f6d6199c 624 }
4b5789fe
CBW
625
626 push @fndlibs, @{ $found{OBJ} } if exists $found{OBJ};
627 push @fndlibs, map { "$_/Library" } @{ $found{OLB} } if exists $found{OLB};
628 push @fndlibs, map { "$_/Share" } @{ $found{SHR} } if exists $found{SHR};
629 my $lib = join( ' ', @fndlibs );
630
631 $ldlib = $crtlstr ? "$lib $crtlstr" : $lib;
632 warn "Result:\n\tEXTRALIBS: $lib\n\tLDLOADLIBS: $ldlib\n" if $verbose;
633 wantarray ? ( $lib, '', $ldlib, '', ( $give_libs ? \@flibs : () ) ) : $lib;
f6d6199c
MS
634}
635
6361;