Compilation: prefer glib functions over goffice equivalents
[gnumeric.git] / plugins / perl-loader / perl-cc-wrapper
blob4d86b50663c939df0f42872cf7e6a90f9f8fb710
1 #!/usr/bin/perl -w
2 # -----------------------------------------------------------------------------
3 # This program changes "... -o foo.lo ..." into "... -o foo.o ...", runs the
4 # compiler proper and then renames foo.o onto foo.lo
6 my @cmd = ();
7 my $target;
8 my $tmptarget;
9 my $sanitize = 0;
11 while (@ARGV) {
12 my $arg = shift @ARGV;
13 if ($arg =~ /^--sanitize=(.*)/) {
14 $sanitize = $1;
15 next;
18 if ($sanitize && $arg =~ /^-/ && $arg !~ /^-(threads|-pthread|D|U|I|c|o)/) {
19 # Options that get here are not in the desiret set.
20 # Notably we drop "-fPIC" (some variant of which should probably
21 # also occur in an unsanitized section).
22 print STDERR "$0: warning dropping $arg\n";
23 next;
26 push @cmd, $arg;
27 if ($arg eq '-o') {
28 $target = shift @ARGV;
29 if ($target =~ /\.lo$/) {
30 $tmptarget = $target;
31 $tmptarget =~ s/\.lo$/-tmp.o/;
32 push @cmd, $tmptarget;
33 } else {
34 push @cmd, $target;
39 # Uncomment to force debug information
40 # push @cmd, '-g';
42 # print STDERR "# ", join (" ", @cmd), "\n";
43 system (@cmd);
45 my $code = $?;
46 if ($code != 0) {
47 unlink $tmptarget if defined $tmptarget;
48 unlink $target;
49 } elsif (defined $tmptarget) {
50 rename $tmptarget, $target;
52 exit $code >> 8;