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