1 package ExtUtils::Liblist;
3 # Broken out of MakeMaker from version 4.11
5 $ExtUtils::Liblist::VERSION = substr q$Revision: 1.19 $, 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 all the math
139 # is also in libsys_s
141 ($^O eq 'next' && $thislib eq 'm') ){
142 push(@extralibs, "-l$thislib");
145 # We might be able to load this archive file dynamically
146 if ( $Config{'dlsrc'} =~ /dl_next|dl_dld/){
147 # We push -l$thislib instead of $fullname because
148 # it avoids hardwiring a fixed path into the .bs file.
149 # Mkbootstrap will automatically add dl_findfile() to
150 # the .bs file if it sees a name in the -l format.
151 # USE THIS, when dl_findfile() is fixed:
152 # push(@bsloadlibs, "-l$thislib");
153 # OLD USE WAS while checking results against old_extliblist
154 push(@bsloadlibs, "$fullname");
157 # For SunOS4, do not add in this shared library if
158 # it is already linked in the main perl executable
159 push(@ldloadlibs, "-l$thislib")
160 unless ($in_perl and $^O eq 'sunos');
162 push(@ldloadlibs, "-l$thislib");
165 last; # found one here so don't bother looking further
167 print STDOUT "Warning (will try anyway): No library found for -l$thislib\n"
170 return ('','','','') unless $found;
171 ("@extralibs", "@bsloadlibs", "@ldloadlibs",join(":",@ld_run_path));
180 ExtUtils::Liblist - determine libraries to use and how to use them
184 C<require ExtUtils::Liblist;>
186 C<ExtUtils::Liblist::ext($potential_libs, $Verbose);>
190 This utility takes a list of libraries in the form C<-llib1 -llib2
191 -llib3> and prints out lines suitable for inclusion in an extension
192 Makefile. Extra library paths may be included with the form
193 C<-L/another/path> this will affect the searches for all subsequent
196 It returns an array of four scalar values: EXTRALIBS, BSLOADLIBS,
197 LDLOADLIBS, and LD_RUN_PATH.
199 Dependent libraries can be linked in one of three ways:
203 =item * For static extensions
205 by the ld command when the perl binary is linked with the extension
206 library. See EXTRALIBS below.
208 =item * For dynamic extensions
210 by the ld command when the shared object is built/linked. See
213 =item * For dynamic extensions
215 by the DynaLoader when the shared object is loaded. See BSLOADLIBS
222 List of libraries that need to be linked with when linking a perl
223 binary which includes this extension Only those libraries that
224 actually exist are included. These are written to a file and used
227 =head2 LDLOADLIBS and LD_RUN_PATH
229 List of those libraries which can or must be linked into the shared
230 library when created using ld. These may be static or dynamic
231 libraries. LD_RUN_PATH is a colon separated list of the directories
232 in LDLOADLIBS. It is passed as an environment variable to the process
233 that links the shared library.
237 List of those libraries that are needed but can be linked in
238 dynamically at run time on this platform. SunOS/Solaris does not need
239 this because ld records the information (from LDLOADLIBS) into the
240 object file. This list is used to create a .bs (bootstrap) file.
244 This module deals with a lot of system dependencies and has quite a
245 few architecture specific B<if>s in the code.
249 L<ExtUtils::MakeMaker>