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