1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
#!perl -w
use strict;
# prints libraries for static linking and exits
use Config;
my $out;
if (@ARGV > 1 && $ARGV[0] eq "-o") {
shift;
$out = shift;
}
my @statics = split /\s+/, $Config{static_ext};
my (@extralibs, %extralibs); # collect extralibs, preserving their order
for (@statics) {
my $file = "..\\lib\\auto\\$_\\extralibs.ld";
open my $fh, '<', $file or die "can't open $file for reading: $!";
push @extralibs, grep {!$extralibs{$_}++} grep {/\S/} split /\s+/, join '', <$fh>;
}
my @libnames = join " ",
map {s|/|\\|g;m|([^\\]+)$|;"..\\lib\\auto\\$_\\$1$Config{_a}"} @statics,
@extralibs;
my $result = join " ", @libnames;
if ($out) {
my $do_update = 0;
# only write if:
# - output doesn't exist
# - there's a change in the content of the file
# - one of the generated static libs is newer than the file
my $out_mtime;
if (open my $fh, "<", $out) {
$out_mtime = (stat $fh)[9];
my $current = do { local $/; <$fh> };
if ($current ne $result) {
++$do_update;
}
close $fh;
}
else {
++$do_update;
}
if (!$do_update && $out_mtime) {
for my $lib (@libnames) {
if ((stat $lib)[9] > $out_mtime) {
++$do_update;
last;
}
}
}
unless ($do_update) {
print "$0: No changes, no libraries changed, nothing to do\n";
exit;
}
open my $fh, ">", $out
or die "Cannot create $out: $!";
print $fh $result;
close $fh or die "Failed to close $out: $!\n";
}
else {
print $result;
}
|