summaryrefslogtreecommitdiffstats
path: root/winsup/cygwin/mkstatic
diff options
context:
space:
mode:
Diffstat (limited to 'winsup/cygwin/mkstatic')
-rwxr-xr-xwinsup/cygwin/mkstatic59
1 files changed, 59 insertions, 0 deletions
diff --git a/winsup/cygwin/mkstatic b/winsup/cygwin/mkstatic
new file mode 100755
index 000000000..b7a81b0ad
--- /dev/null
+++ b/winsup/cygwin/mkstatic
@@ -0,0 +1,59 @@
+#!/usr/bin/perl
+use strict;
+use Cwd;
+use Getopt::Long;
+use File::Temp qw/tempdir/;
+use File::Basename;
+
+sub xsystem(@);
+
+my @exclude = ();
+my @library = ();
+my $ar;
+our $x;
+GetOptions('exclude=s'=>\@exclude, 'library=s'=>\@library, 'ar=s'=>\$ar, 'x!'=>\$x);
+
+die "$0: must specify --ar\n" unless defined $ar;
+my $lib = shift or die "$0: missing lib argument\nusage: $0 lib [map-file]\n";
+$lib = Cwd::abs_path($lib);
+
+my %excludes = map {($_, 1)} @exclude;
+my $libraries = join('|', map {quotemeta} @library);
+
+my %sources = ();
+while (<>) {
+ my ($source, $file, $absfile);
+ if (m%^($libraries)\(([^)]*)\)%o) {
+ $source = $1;
+ $absfile = $file = $2;
+ } elsif (/^LOAD\s+(.*\.o)$/o) {
+ $source = '.';
+ $file = $1;
+ $absfile = Cwd::abs_path($file);
+ } else {
+ next;
+ }
+ push @{$sources{$source}}, $absfile unless $excludes{$file} || $excludes{$source};
+}
+
+my $here = getcwd();
+my $dir = tempdir(CLEANUP=>1);
+chdir $dir;
+my @files = ();
+for (sort keys %sources) {
+ if ($_ eq '.') {
+ xsystem '/bin/cp', '-a', @{$sources{$_}}, '.';
+ } else {
+ xsystem $ar, 'x', $_, @{$sources{$_}}, '.';
+ }
+ push @files, map {basename($_)} @{$sources{$_}};
+}
+
+unlink $lib;
+xsystem $ar, 'crs', $lib, sort @files;
+exit 0;
+
+sub xsystem(@) {
+ print join(' ', 'x', @_), "\n" if $x;
+ system(@_) == 0 or die "$0: @_[0] $_[1] $_[2]... exited with non-zero status\n";
+}