Re: Debugger in beta3
[p5sagit/p5-mst-13.2.git] / lib / ExtUtils / Liblist.pm
index da98d20..ebc5018 100644 (file)
@@ -1,16 +1,24 @@
 package ExtUtils::Liblist;
-require ExtUtils::MakeMaker; # currently for MM_Unix::lsdir
 
 # Broken out of MakeMaker from version 4.11
 
 use Config;
 use Cwd;
-# --- Determine libraries to use and how to use them ---
+use File::Basename;
+
+my $Config_libext = $Config{lib_ext} || ".a";
 
 sub ext {
-    my($potential_libs, $Verbose) = @_;
-    return ("", "", "") unless $potential_libs;
-    print STDOUT "Potential libraries are '$potential_libs':" if $Verbose;
+    my($self,$potential_libs, $Verbose) = @_;
+    if ($Config{osname} =~ m|^os/?2$|i and $Config{libs}) { 
+       # Dynamic libraries are not transitive, so we may need including
+       # the libraries linked against perl.dll again.
+
+       $potential_libs .= " " if $potential_libs;
+       $potential_libs .= $Config{libs};
+    }
+    return ("", "", "", "") unless $potential_libs;
+    print STDOUT "Potential libraries are '$potential_libs':\n" if $Verbose;
 
     my($so)   = $Config{'so'};
     my($libs) = $Config{'libs'};
@@ -22,7 +30,7 @@ sub ext {
 
     my(@searchpath); # from "-L/path" entries in $potential_libs
     my(@libpath) = split " ", $Config{'libpth'};
-    my(@ldloadlibs, @bsloadlibs, @extralibs);
+    my(@ldloadlibs, @bsloadlibs, @extralibs, @ld_run_path, %ld_run_path_seen);
     my($fullname, $thislib, $thispth, @fullname);
     my($pwd) = fastcwd(); # from Cwd.pm
     my($found) = 0;
@@ -62,7 +70,7 @@ sub ext {
                # For gcc-2.6.2 on linux (March 1995), DLD can not load
                # .sa libraries, with the exception of libm.sa, so we
                # deliberately skip them.
-           if (@fullname = MM_Unix::lsdir($thispth,"^lib$thislib\.$so\.[0-9]+")){
+           if (@fullname = $self->lsdir($thispth,"^lib$thislib\.$so\.[0-9]+")){
                # Take care that libfoo.so.10 wins against libfoo.so.9.
                # Compare two libraries to find the most recent version
                # number.  E.g.  if you have libfoo.so.9.0.7 and
@@ -91,23 +99,37 @@ sub ext {
                        $mb cmp $ma;} @fullname)[0];
            } elsif (-f ($fullname="$thispth/lib$thislib.$so")
                 && (($Config{'dlsrc'} ne "dl_dld.xs") || ($thislib eq "m"))){
-           } elsif (-f ($fullname="$thispth/lib${thislib}_s.a")
+           } elsif (-f ($fullname="$thispth/lib${thislib}_s$Config_libext")
                 && ($thislib .= "_s") ){ # we must explicitly use _s version
-           } elsif (-f ($fullname="$thispth/lib$thislib.a")){
-           } elsif (-f ($fullname="$thispth/Slib$thislib.a")){
+           } elsif (-f ($fullname="$thispth/lib$thislib$Config_libext")){
+           } elsif (-f ($fullname="$thispth/$thislib$Config_libext")){
+           } elsif (-f ($fullname="$thispth/Slib$thislib$Config_libext")){
+           } elsif ($Config{'osname'} eq 'dgux'
+                && -l ($fullname="$thispth/lib$thislib$Config_libext")
+                && readlink($fullname) =~ /^elink:/) {
+                # Some of DG's libraries look like misconnected symbolic
+                # links, but development tools can follow them.  (They
+                # look like this:
+                #
+                #    libm.a -> elink:${SDE_PATH:-/usr}/sde/\
+                #    ${TARGET_BINARY_INTERFACE:-m88kdgux}/usr/lib/libm.a
+                #
+                # , the compilation tools expand the environment variables.)
            } else {
-               print STDOUT "$thislib not found in $thispth" if $Verbose;
+               print STDOUT "$thislib not found in $thispth\n" if $Verbose;
                next;
            }
-           print STDOUT "'-l$thislib' found at $fullname" if $Verbose;
+           print STDOUT "'-l$thislib' found at $fullname\n" if $Verbose;
+           my($fullnamedir) = dirname($fullname);
+           push @ld_run_path, $fullnamedir unless $ld_run_path_seen{$fullnamedir}++;
            $found++;
            $found_lib++;
 
            # Now update library lists
 
            # what do we know about this library...
-           my $is_dyna = ($fullname !~ /\.a$/);
-           my $in_perl = ($libs =~ /\B-l${thislib}\b/s);
+           my $is_dyna = ($fullname !~ /\Q$Config_libext\E$/);
+           my $in_perl = ($libs =~ /\B-l\Q$ {thislib}\E\b/s);
 
            # Do not add it into the list if it is already linked in
            # with the main perl executable.
@@ -140,12 +162,91 @@ sub ext {
            }
            last;       # found one here so don't bother looking further
        }
-       print STDOUT "Warning (non-fatal): No library found for -l$thislib" 
+       print STDOUT "Warning (will try anyway): No library found for -l$thislib\n"
            unless $found_lib>0;
     }
-    return ('','','') unless $found;
-    ("@extralibs", "@bsloadlibs", "@ldloadlibs");
+    return ('','','','') unless $found;
+    ("@extralibs", "@bsloadlibs", "@ldloadlibs",join(":",@ld_run_path));
 }
 
-
 1;
+
+__END__
+
+=head1 NAME
+
+ExtUtils::Liblist - determine libraries to use and how to use them
+
+=head1 SYNOPSIS
+
+C<require ExtUtils::Liblist;>
+
+C<ExtUtils::Liblist::ext($potential_libs, $Verbose);>
+
+=head1 DESCRIPTION
+
+This utility takes a list of libraries in the form C<-llib1 -llib2
+-llib3> and prints out lines suitable for inclusion in an extension
+Makefile.  Extra library paths may be included with the form
+C<-L/another/path> this will affect the searches for all subsequent
+libraries.
+
+It returns an array of four scalar values: EXTRALIBS, BSLOADLIBS,
+LDLOADLIBS, and LD_RUN_PATH.
+
+Dependent libraries can be linked in one of three ways:
+
+=over 2
+
+=item * For static extensions
+
+by the ld command when the perl binary is linked with the extension
+library. See EXTRALIBS below.
+
+=item * For dynamic extensions
+
+by the ld command when the shared object is built/linked. See
+LDLOADLIBS below.
+
+=item * For dynamic extensions
+
+by the DynaLoader when the shared object is loaded. See BSLOADLIBS
+below.
+
+=back
+
+=head2 EXTRALIBS
+
+List of libraries that need to be linked with when linking a perl
+binary which includes this extension Only those libraries that
+actually exist are included.  These are written to a file and used
+when linking perl.
+
+=head2 LDLOADLIBS and LD_RUN_PATH
+
+List of those libraries which can or must be linked into the shared
+library when created using ld. These may be static or dynamic
+libraries.  LD_RUN_PATH is a colon separated list of the directories
+in LDLOADLIBS. It is passed as an environment variable to the process
+that links the shared library.
+
+=head2 BSLOADLIBS
+
+List of those libraries that are needed but can be linked in
+dynamically at run time on this platform.  SunOS/Solaris does not need
+this because ld records the information (from LDLOADLIBS) into the
+object file.  This list is used to create a .bs (bootstrap) file.
+
+=head1 PORTABILITY
+
+This module deals with a lot of system dependencies and has quite a
+few architecture specific B<if>s in the code.
+
+=head1 SEE ALSO
+
+L<ExtUtils::MakeMaker>
+
+=cut
+
+
+