aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cgcc
diff options
authorwelinder@troll.com <welinder@troll.com>2004-08-19 17:13:42 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:02:51 -0700
commit34686eac3ebc040e0cc6703bc132081c3be9616e (patch)
treef337a57c6d33e6840cb85493031ceb961a23fb45 /cgcc
parentcf874564fd4c2bc89f6359826fac7ae0b60962a1 (diff)
downloadsparse-dev-34686eac3ebc040e0cc6703bc132081c3be9616e.tar.gz
Teach cgcc about flags that are for sparse only.
Diffstat (limited to 'cgcc')
-rw-r--r--cgcc41
1 files changed, 31 insertions, 10 deletions
diff --git a/cgcc b/cgcc
index ec9e7ce7..9cfdf7b7 100644
--- a/cgcc
+++ b/cgcc
@@ -4,19 +4,40 @@
my $cc = $ENV{'REAL_CC'} || 'cc';
my $check = $ENV{'CHECK'} || 'check';
-# Look for a .c file. We don't want to run the checker on .o or .so files
-# in the link run. (This simplistic check knows nothing about options
-# with arguments, but it seems to do the job.)
my $seen_a_c_file = 0;
foreach (@ARGV) {
- if (/^[^-].*\.c/) {
- $seen_a_c_file = 1;
- last;
- }
+ # Look for a .c file. We don't want to run the checker on .o or .so files
+ # in the link run. (This simplistic check knows nothing about options
+ # with arguments, but it seems to do the job.)
+ $seen_a_c_file = 1 if /^[^-].*\.c/;
+
+ my $this_arg = ' ' . &quote_arg ($_);
+ $cc .= $this_arg unless &check_only_option ($_);
+ $check .= $this_arg;
}
-if ($seen_a_c_file) {
- system ($check, @ARGV);
+system ($check) if $seen_a_c_file;
+exec ($cc);
+
+# -----------------------------------------------------------------------------
+# Check if an option is for "check" only.
+
+sub check_only_option {
+ my ($arg) = @_;
+ return 1 if $arg =~ /^-W(no-?)?default-bitfield-sign$/;
+ return 0;
}
-exec ($cc, @ARGV);
+# -----------------------------------------------------------------------------
+# Simple arg-quoting function. Just adds backslashes when needed.
+
+sub quote_arg {
+ my ($arg) = @_;
+ return "''" if $arg eq '';
+ return join ('',
+ map {
+ m|^[-a-zA-Z0-9._/,=]+$| ? $_ : "\\" . $_;
+ } (split (//, $arg)));
+}
+
+# -----------------------------------------------------------------------------