1 package ExtUtils::Liblist;
3 # Broken out of MakeMaker from version 4.11
5 $VERSION = substr q$Revision: 1.20 $, 10;
11 my $Config_libext = $Config{lib_ext} || ".a";
14 my($self,$potential_libs, $Verbose) = @_;
15 if ($^O =~ 'os2' and $Config{libs}) {
16 # Dynamic libraries are not transitive, so we may need including
17 # the libraries linked against perl.dll again.
19 $potential_libs .= " " if $potential_libs;
20 $potential_libs .= $Config{libs};
22 return ("", "", "", "") unless $potential_libs;
23 print STDOUT "Potential libraries are '$potential_libs':\n" if $Verbose;
25 my($so) = $Config{'so'};
26 my($libs) = $Config{'libs'};
28 # compute $extralibs, $bsloadlibs and $ldloadlibs from
30 # this is a rewrite of Andy Dougherty's extliblist in perl
31 # its home is in <distribution>/ext/util
33 my(@searchpath); # from "-L/path" entries in $potential_libs
34 my(@libpath) = split " ", $Config{'libpth'};
35 my(@ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen);
36 my($fullname, $thislib, $thispth, @fullname);
37 my($pwd) = cwd(); # from Cwd.pm
40 foreach $thislib (split ' ', $potential_libs){
42 # Handle possible linker path arguments.
43 if ($thislib =~ s/^(-[LR])//){ # save path flag type
46 print STDOUT "$ptype$thislib ignored, directory does not exist\n"
50 unless ($self->file_name_is_absolute($thislib)) {
51 print STDOUT "Warning: $ptype$thislib changed to $ptype$pwd/$thislib\n";
52 $thislib = $self->catdir($pwd,$thislib);
54 push(@searchpath, $thislib);
55 push(@extralibs, "$ptype$thislib");
56 push(@ldloadlibs, "$ptype$thislib");
60 # Handle possible library arguments.
61 unless ($thislib =~ s/^-l//){
62 print STDOUT "Unrecognized argument in LIBS ignored: '$thislib'\n";
67 foreach $thispth (@searchpath, @libpath){
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.
75 if (@fullname = $self->lsdir($thispth,"^lib$thislib\.$so\.[0-9]+")){
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
89 #TODO: iterate through the directory instead of sorting
91 $fullname = "$thispth/" .
95 $ma =~ s/\b(\d)\b/0$1/g;
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"))){
104 } elsif (-f ($fullname="$thispth/lib${thislib}_s$Config_libext")
105 && ($thislib .= "_s") ){ # we must explicitly use _s version
106 } elsif (-f ($fullname="$thispth/lib$thislib$Config_libext")){
107 } elsif (-f ($fullname="$thispth/$thislib$Config_libext")){
108 } elsif (-f ($fullname="$thispth/Slib$thislib$Config_libext")){
109 } elsif ($^O eq 'dgux'
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
116 # libm.a -> elink:${SDE_PATH:-/usr}/sde/\
117 # ${TARGET_BINARY_INTERFACE:-m88kdgux}/usr/lib/libm.a
119 # , the compilation tools expand the environment variables.)
121 print STDOUT "$thislib not found in $thispth\n" if $Verbose;
124 print STDOUT "'-l$thislib' found at $fullname\n" if $Verbose;
125 my($fullnamedir) = dirname($fullname);
126 push @ld_run_path, $fullnamedir unless $ld_run_path_seen{$fullnamedir}++;
130 # Now update library lists
132 # what do we know about this library...
133 my $is_dyna = ($fullname !~ /\Q$Config_libext\E$/);
134 my $in_perl = ($libs =~ /\B-l\Q$ {thislib}\E\b/s);
136 # Do not add it into the list if it is already linked in
137 # with the main perl executable.
138 # We have to special-case the NeXT, because math and ndbm
139 # are both in libsys_s
141 ($Config{'osname'} eq 'next' &&
142 ($thislib eq 'm' || $thislib eq 'ndbm')) ){
143 push(@extralibs, "-l$thislib");
146 # We might be able to load this archive file dynamically
147 if ( ($Config{'dlsrc'} =~ /dl_next/ && $Config{'osvers'} lt '4_0')
148 || ($Config{'dlsrc'} =~ /dl_dld/) )
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");
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")
163 unless ($in_perl and $^O eq 'sunos');
165 push(@ldloadlibs, "-l$thislib");
168 last; # found one here so don't bother looking further
170 print STDOUT "Warning (will try anyway): No library found for -l$thislib\n"
173 return ('','','','') unless $found;
174 ("@extralibs", "@bsloadlibs", "@ldloadlibs",join(":",@ld_run_path));
183 ExtUtils::Liblist - determine libraries to use and how to use them
187 C<require ExtUtils::Liblist;>
189 C<ExtUtils::Liblist::ext($potential_libs, $Verbose);>
193 This utility takes a list of libraries in the form C<-llib1 -llib2
194 -llib3> and prints out lines suitable for inclusion in an extension
195 Makefile. Extra library paths may be included with the form
196 C<-L/another/path> this will affect the searches for all subsequent
199 It returns an array of four scalar values: EXTRALIBS, BSLOADLIBS,
200 LDLOADLIBS, and LD_RUN_PATH.
202 Dependent libraries can be linked in one of three ways:
206 =item * For static extensions
208 by the ld command when the perl binary is linked with the extension
209 library. See EXTRALIBS below.
211 =item * For dynamic extensions
213 by the ld command when the shared object is built/linked. See
216 =item * For dynamic extensions
218 by the DynaLoader when the shared object is loaded. See BSLOADLIBS
225 List of libraries that need to be linked with when linking a perl
226 binary which includes this extension Only those libraries that
227 actually exist are included. These are written to a file and used
230 =head2 LDLOADLIBS and LD_RUN_PATH
232 List of those libraries which can or must be linked into the shared
233 library when created using ld. These may be static or dynamic
234 libraries. LD_RUN_PATH is a colon separated list of the directories
235 in LDLOADLIBS. It is passed as an environment variable to the process
236 that links the shared library.
240 List of those libraries that are needed but can be linked in
241 dynamically at run time on this platform. SunOS/Solaris does not need
242 this because ld records the information (from LDLOADLIBS) into the
243 object file. This list is used to create a .bs (bootstrap) file.
247 This module deals with a lot of system dependencies and has quite a
248 few architecture specific B<if>s in the code.
252 L<ExtUtils::MakeMaker>