Fix a2p translation of '{print "a" "b" "c"}'
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / Liblist.pm
CommitLineData
005c1a0e 1package ExtUtils::Liblist;
8a1da95f 2use vars qw($VERSION);
005c1a0e 3# Broken out of MakeMaker from version 4.11
4
8a1da95f 5$VERSION = substr q$Revision: 1.20 $, 10;
f1387719 6
005c1a0e 7use Config;
8f1aa56b 8use Cwd 'cwd';
4633a7c4 9use File::Basename;
10
11my $Config_libext = $Config{lib_ext} || ".a";
12
005c1a0e 13sub ext {
c2e89b3d 14 my($self,$potential_libs, $Verbose) = @_;
f1387719 15 if ($^O =~ 'os2' and $Config{libs}) {
4e68a208 16 # Dynamic libraries are not transitive, so we may need including
17 # the libraries linked against perl.dll again.
18
19 $potential_libs .= " " if $potential_libs;
20 $potential_libs .= $Config{libs};
21 }
4633a7c4 22 return ("", "", "", "") unless $potential_libs;
8e07c86e 23 print STDOUT "Potential libraries are '$potential_libs':\n" if $Verbose;
005c1a0e 24
25 my($so) = $Config{'so'};
26 my($libs) = $Config{'libs'};
27
28 # compute $extralibs, $bsloadlibs and $ldloadlibs from
29 # $potential_libs
30 # this is a rewrite of Andy Dougherty's extliblist in perl
31 # its home is in <distribution>/ext/util
32
33 my(@searchpath); # from "-L/path" entries in $potential_libs
34 my(@libpath) = split " ", $Config{'libpth'};
4633a7c4 35 my(@ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen);
005c1a0e 36 my($fullname, $thislib, $thispth, @fullname);
8f1aa56b 37 my($pwd) = cwd(); # from Cwd.pm
005c1a0e 38 my($found) = 0;
39
40 foreach $thislib (split ' ', $potential_libs){
41
42 # Handle possible linker path arguments.
43 if ($thislib =~ s/^(-[LR])//){ # save path flag type
44 my($ptype) = $1;
45 unless (-d $thislib){
46 print STDOUT "$ptype$thislib ignored, directory does not exist\n"
47 if $Verbose;
48 next;
49 }
f1387719 50 unless ($self->file_name_is_absolute($thislib)) {
005c1a0e 51 print STDOUT "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
f1387719 52 $thislib = $self->catdir($pwd,$thislib);
005c1a0e 53 }
54 push(@searchpath, $thislib);
55 push(@extralibs, "$ptype$thislib");
56 push(@ldloadlibs, "$ptype$thislib");
57 next;
58 }
59
60 # Handle possible library arguments.
61 unless ($thislib =~ s/^-l//){
62 print STDOUT "Unrecognized argument in LIBS ignored: '$thislib'\n";
63 next;
64 }
65
66 my($found_lib)=0;
67 foreach $thispth (@searchpath, @libpath){
68
69 # Try to find the full name of the library. We need this to
70 # determine whether it's a dynamically-loadable library or not.
71 # This tends to be subject to various os-specific quirks.
72 # For gcc-2.6.2 on linux (March 1995), DLD can not load
73 # .sa libraries, with the exception of libm.sa, so we
74 # deliberately skip them.
c2e89b3d 75 if (@fullname = $self->lsdir($thispth,"^lib$thislib\.$so\.[0-9]+")){
005c1a0e 76 # Take care that libfoo.so.10 wins against libfoo.so.9.
77 # Compare two libraries to find the most recent version
78 # number. E.g. if you have libfoo.so.9.0.7 and
79 # libfoo.so.10.1, first convert all digits into two
80 # decimal places. Then we'll add ".00" to the shorter
81 # strings so that we're comparing strings of equal length
82 # Thus we'll compare libfoo.so.09.07.00 with
83 # libfoo.so.10.01.00. Some libraries might have letters
84 # in the version. We don't know what they mean, but will
85 # try to skip them gracefully -- we'll set any letter to
86 # '0'. Finally, sort in reverse so we can take the
87 # first element.
88
89 #TODO: iterate through the directory instead of sorting
90
91 $fullname = "$thispth/" .
92 (sort { my($ma) = $a;
93 my($mb) = $b;
94 $ma =~ tr/A-Za-z/0/s;
95 $ma =~ s/\b(\d)\b/0$1/g;
96 $mb =~ tr/A-Za-z/0/s;
97 $mb =~ s/\b(\d)\b/0$1/g;
98 while (length($ma) < length($mb)) { $ma .= ".00"; }
99 while (length($mb) < length($ma)) { $mb .= ".00"; }
100 # Comparison deliberately backwards
101 $mb cmp $ma;} @fullname)[0];
102 } elsif (-f ($fullname="$thispth/lib$thislib.$so")
103 && (($Config{'dlsrc'} ne "dl_dld.xs") || ($thislib eq "m"))){
4633a7c4 104 } elsif (-f ($fullname="$thispth/lib${thislib}_s$Config_libext")
005c1a0e 105 && ($thislib .= "_s") ){ # we must explicitly use _s version
4633a7c4 106 } elsif (-f ($fullname="$thispth/lib$thislib$Config_libext")){
864a5fa8 107 } elsif (-f ($fullname="$thispth/$thislib$Config_libext")){
4633a7c4 108 } elsif (-f ($fullname="$thispth/Slib$thislib$Config_libext")){
8f1aa56b 109 } elsif ($^O eq 'dgux'
c07a80fd 110 && -l ($fullname="$thispth/lib$thislib$Config_libext")
111 && readlink($fullname) =~ /^elink:/) {
112 # Some of DG's libraries look like misconnected symbolic
113 # links, but development tools can follow them. (They
114 # look like this:
115 #
116 # libm.a -> elink:${SDE_PATH:-/usr}/sde/\
117 # ${TARGET_BINARY_INTERFACE:-m88kdgux}/usr/lib/libm.a
118 #
119 # , the compilation tools expand the environment variables.)
005c1a0e 120 } else {
8e07c86e 121 print STDOUT "$thislib not found in $thispth\n" if $Verbose;
005c1a0e 122 next;
123 }
8e07c86e 124 print STDOUT "'-l$thislib' found at $fullname\n" if $Verbose;
4633a7c4 125 my($fullnamedir) = dirname($fullname);
126 push @ld_run_path, $fullnamedir unless $ld_run_path_seen{$fullnamedir}++;
005c1a0e 127 $found++;
128 $found_lib++;
129
130 # Now update library lists
131
132 # what do we know about this library...
4633a7c4 133 my $is_dyna = ($fullname !~ /\Q$Config_libext\E$/);
4e68a208 134 my $in_perl = ($libs =~ /\B-l\Q$ {thislib}\E\b/s);
005c1a0e 135
136 # Do not add it into the list if it is already linked in
137 # with the main perl executable.
974f612f 138 # We have to special-case the NeXT, because math and ndbm
139 # are both in libsys_s
005c1a0e 140 unless ($in_perl ||
974f612f 141 ($Config{'osname'} eq 'next' &&
142 ($thislib eq 'm' || $thislib eq 'ndbm')) ){
005c1a0e 143 push(@extralibs, "-l$thislib");
144 }
145
146 # We might be able to load this archive file dynamically
974f612f 147 if ( ($Config{'dlsrc'} =~ /dl_next/ && $Config{'osvers'} lt '4_0')
148 || ($Config{'dlsrc'} =~ /dl_dld/) )
149 {
005c1a0e 150 # We push -l$thislib instead of $fullname because
151 # it avoids hardwiring a fixed path into the .bs file.
152 # Mkbootstrap will automatically add dl_findfile() to
153 # the .bs file if it sees a name in the -l format.
154 # USE THIS, when dl_findfile() is fixed:
155 # push(@bsloadlibs, "-l$thislib");
156 # OLD USE WAS while checking results against old_extliblist
157 push(@bsloadlibs, "$fullname");
158 } else {
159 if ($is_dyna){
160 # For SunOS4, do not add in this shared library if
161 # it is already linked in the main perl executable
162 push(@ldloadlibs, "-l$thislib")
8f1aa56b 163 unless ($in_perl and $^O eq 'sunos');
005c1a0e 164 } else {
165 push(@ldloadlibs, "-l$thislib");
166 }
167 }
168 last; # found one here so don't bother looking further
169 }
864a5fa8 170 print STDOUT "Warning (will try anyway): No library found for -l$thislib\n"
005c1a0e 171 unless $found_lib>0;
172 }
4633a7c4 173 return ('','','','') unless $found;
174 ("@extralibs", "@bsloadlibs", "@ldloadlibs",join(":",@ld_run_path));
005c1a0e 175}
176
005c1a0e 1771;
c2e89b3d 178
864a5fa8 179__END__
cb1a09d0 180
864a5fa8 181=head1 NAME
182
183ExtUtils::Liblist - determine libraries to use and how to use them
184
185=head1 SYNOPSIS
186
187C<require ExtUtils::Liblist;>
188
189C<ExtUtils::Liblist::ext($potential_libs, $Verbose);>
190
191=head1 DESCRIPTION
192
193This utility takes a list of libraries in the form C<-llib1 -llib2
194-llib3> and prints out lines suitable for inclusion in an extension
195Makefile. Extra library paths may be included with the form
196C<-L/another/path> this will affect the searches for all subsequent
197libraries.
198
199It returns an array of four scalar values: EXTRALIBS, BSLOADLIBS,
200LDLOADLIBS, and LD_RUN_PATH.
201
202Dependent libraries can be linked in one of three ways:
203
204=over 2
205
206=item * For static extensions
207
208by the ld command when the perl binary is linked with the extension
209library. See EXTRALIBS below.
210
211=item * For dynamic extensions
212
213by the ld command when the shared object is built/linked. See
214LDLOADLIBS below.
215
216=item * For dynamic extensions
217
218by the DynaLoader when the shared object is loaded. See BSLOADLIBS
219below.
220
221=back
222
223=head2 EXTRALIBS
224
225List of libraries that need to be linked with when linking a perl
226binary which includes this extension Only those libraries that
227actually exist are included. These are written to a file and used
228when linking perl.
229
230=head2 LDLOADLIBS and LD_RUN_PATH
231
232List of those libraries which can or must be linked into the shared
233library when created using ld. These may be static or dynamic
234libraries. LD_RUN_PATH is a colon separated list of the directories
235in LDLOADLIBS. It is passed as an environment variable to the process
236that links the shared library.
237
238=head2 BSLOADLIBS
239
240List of those libraries that are needed but can be linked in
241dynamically at run time on this platform. SunOS/Solaris does not need
242this because ld records the information (from LDLOADLIBS) into the
243object file. This list is used to create a .bs (bootstrap) file.
244
245=head1 PORTABILITY
246
247This module deals with a lot of system dependencies and has quite a
248few architecture specific B<if>s in the code.
249
250=head1 SEE ALSO
251
252L<ExtUtils::MakeMaker>
253
254=cut
255
256
257