diff --git a/bin/hipcc b/bin/hipcc index 1be33d55e1..2e7d62a1c5 100755 --- a/bin/hipcc +++ b/bin/hipcc @@ -381,15 +381,35 @@ foreach $arg (@ARGV) open my $out, ">", $new_file or die "$new_file: $!"; while (my $line = <$in>) { chomp $line; - if ($line =~ m/\.a$/) { + if ($line =~ m/\.a$/ || $line =~ m/\.lo$/) { + my $libFile = $line; my $path = abs_path($line); my @objs = split ('\n', `cd $tmpdir; ar xv $path`); + ## Check if all files in .a are object files. + my $allIsObj = 1; + my $realObjs = ""; foreach my $obj (@objs) { chomp $obj; $obj =~ s/^x - //; $obj = "$tmpdir/$obj"; - push (@inputs, $obj); - $new_arg = "$new_arg $obj"; + my $fileType = `file $obj`; + my $isObj = ($fileType =~ m/ELF/ or $fileType =~ m/COFF/); + $allIsObj = ($allIsObj and $isObj); + if ($isObj) { + $realObjs = ($realObjs . " " . $obj); + } else { + push (@inputs, $obj); + $new_arg = "$new_arg $obj"; + } + } + chomp $realObjs; + if ($allIsObj) { + print $out "$line\n"; + } elsif ($realObjs) { + my($libBaseName, $libDir, $libExt) = fileparse($libFile); + $libBaseName = mktemp($libBaseName . "XXXX") . $libExt; + system("cd $tmpdir; ar c $libBaseName $realObjs"); + print $out "$tmpdir/$libBaseName\n"; } } else { print $out "$line\n";