]> git.imager.perl.org - imager.git/commitdiff
handle multiple library tests correctly in probe
authorTony Cook <tony@develop=help.com>
Mon, 9 Aug 2010 11:44:19 +0000 (11:44 +0000)
committerTony Cook <tony@develop=help.com>
Mon, 9 Aug 2010 11:44:19 +0000 (11:44 +0000)
Adjusted the bundled Devel::CheckLib to handle multiple libraries at a
time (more) correctly, and Probe to call that appropriately

inc/Devel/CheckLib.pm
lib/Imager/Probe.pm

index 6e7f0af4768fb8c9247f74b56549f8da8959c379..ead38afbf81d0b85e3778538bd40796c7053b218 100644 (file)
@@ -185,6 +185,11 @@ sub assert_lib {
     @incpaths = (ref($args{incpath}) ? @{$args{incpath}} : $args{incpath}) 
         if $args{incpath};
 
+    # each entry is an arrayref containing:
+    # 0: arrayref of library search paths
+    # 1: arrayref of library names
+    my @link_cfgs = map [ \@libpaths, [ $_ ] ], @libs;
+
     # work-a-like for Makefile.PL's LIBS and INC arguments
     # if given as command-line argument, append to %args
     for my $arg (@ARGV) {
@@ -197,12 +202,14 @@ sub assert_lib {
             }
         }
     }
-
     # using special form of split to trim whitespace
     if(defined($args{LIBS})) {
-        foreach my $arg (split(' ', $args{LIBS})) {
-            die("LIBS argument badly-formed: $arg\n") unless($arg =~ /^-l/i);
-            push @{$arg =~ /^-l/ ? \@libs : \@libpaths}, substr($arg, 2);
+       my @LIBS = ref $args{LIBS} ? @{$args{LIBS}} : split ' ', $args{LIBS};
+        foreach my $arg (@LIBS) {
+           my @sep = split ' ', $arg;
+           my @libs = map { /^-l(.+)$/ ? $1 : () } @sep;
+           my @paths = map { /^-L(.+)$/ ? $1 : () } @sep;
+           push @link_cfgs, [ \@paths, \@libs ];
         }
     }
     if(defined($args{INC})) {
@@ -263,7 +270,8 @@ sub assert_lib {
     print $ch qq{#include <$_>\n} foreach (@headers);
     print $ch "int main(void) { ".($args{function} || 'return 0;')." }\n";
     close($ch);
-    for my $lib ( @libs ) {
+    for my $link_cfg ( @link_cfgs ) {
+       my ($paths, $libs) = @$link_cfg;
         my $exefile = File::Temp::mktemp( 'assertlibXXXXXXXX' ) . $Config{_exe};
         my @sys_cmd;
         if ( $Config{cc} eq 'cl' ) {                 # Microsoft compiler
@@ -275,20 +283,20 @@ sub assert_lib {
             @sys_cmd = (
                 @cc,
                 $cfile,
-                "${lib}.lib",
+                ( map { "$_.lib" } @$libs ),
                 "/Fe$exefile", 
                 (map { '/I'.Win32::GetShortPathName($_) } @incpaths),
                 "/link",
-                (map {'/libpath:'.Win32::GetShortPathName($_)} @libpaths),
+                (map {'/libpath:'.Win32::GetShortPathName($_)} @$paths),
             );
         } elsif($Config{cc} eq 'CC/DECC') {          # VMS
         } elsif($Config{cc} =~ /bcc32(\.exe)?/) {    # Borland
             @sys_cmd = (
                 @cc,
                 "-o$exefile",
-                "-l$lib",
+                (map { "-l$_" } @$libs ),
                 (map { "-I$_" } @incpaths),
-                (map { "-L$_" } @libpaths),
+                (map { "-L$_" } @$paths),
                 $cfile);
         } else {                                     # Unix-ish
                                                      # gcc, Sun, AIX (gcc, cc)
@@ -296,15 +304,15 @@ sub assert_lib {
                 @cc,
                 $cfile,
                 "-o", "$exefile",
-                "-l$lib",
+                (map { "-l$_" } @$libs ),
                 (map { "-I$_" } @incpaths),
-                (map { "-L$_" } @libpaths)
+                (map { "-L$_" } @$paths)
             );
         }
         warn "# @sys_cmd\n" if $args{debug};
         my $rv = $args{debug} ? system(@sys_cmd) : _quiet_system(@sys_cmd);
-        push @missing, $lib if $rv != 0 || ! -x $exefile;
-        push @wrongresult, $lib if $rv == 0 && -x $exefile && system(File::Spec->rel2abs($exefile)) != 0; 
+        push @missing, @$libs if $rv != 0 || ! -x $exefile;
+        push @wrongresult, @$libs if $rv == 0 && -x $exefile && system(File::Spec->rel2abs($exefile)) != 0; 
         _cleanup_exe($exefile);
     } 
     unlink $cfile;
index d882b5b761aa065573fa6c5403679f14623819cf..38b4bee7d5b10df2175ff4b328325ea6a2ebabaa 100644 (file)
@@ -214,7 +214,7 @@ sub _probe_test {
     Devel::CheckLib::check_lib
        (
         debug => $req->{verbose},
-        LIBS => $result->{LIBS},
+        LIBS => [ $result->{LIBS} ],
         INC => $result->{INC},
         header => $req->{testcodeheaders},
         function => $req->{testcode},