$ENV{"NCDIR"} = $NCDIR;
# Have fun with the arguments
+
$gcc = "gcc";
+undef $ENV{NESCC_ARGS};
+undef $ENV{NESCC_CFILE};
+undef $ENV{NESCC_CONLY};
+undef $ENV{NESCC_DEPUTY};
+undef $ENV{NESCC_DEPUTY_ARGS};
+undef $ENV{NESCC_GCC};
+
for ($i = 0; $i <= $#ARGV; $i++) {
- $strip = 0;
$_ = $ARGV[$i];
if (/^-/) {
+ if (/^-v$/) {
+ $verbose = 1;
+ }
+
if (/^-docdir=(.*)/) {
$docdir = $1;
- $strip = 1;
- }
- elsif (/^-topdir=(.*)/) {
+ } elsif (/^-topdir=(.*)/) {
push @topdirs, $1;
- $strip = 1;
- }
- elsif (/^-graphviz=(.*)/) {
+ } elsif (/^-graphviz=(.*)/) {
if($1 =~ /^y/i) {
$use_graphviz = 1;
} else {
$use_graphviz = 0;
}
- $strip = 1;
- }
- elsif (/^--version$/) {
+ } elsif (/^--version$/) {
$print_version = 1;
- $strip = 1;
- }
- elsif (/^-gcc=(.*)/) {
- $gcc = $1;
- $strip = 1;
- }
- elsif (/^-mingw-gcc$/) {
+ } elsif (/^-(fnesc-)?gcc=(.*)/) {
+ $gcc = $2;
+ } elsif (/^-mingw-gcc$/) {
$mingw_gcc = 1;
- $strip = 1;
- push @new_args, "-fnesc-mingw-gcc";
- }
- elsif (/^-v$/) {
- $verbose = 1;
- }
- elsif (/^-conly$/) {
- $strip = 1;
- push @new_args, "-fnesc-conly";
- push @new_args, "-fsyntax-only";
+ push @nescc_args, "-fnesc-mingw-gcc";
+ } elsif (/^-conly$/) {
+ $ENV{NESCC_CONLY} = "yes";
+ push @nescc_args, "-fsyntax-only";
+ } elsif (/^-fnesc-cfile=(.*)$/) {
+ $ENV{NESCC_CFILE} = $1;
+ } elsif (/^-_?fnesc-deputy$/) {
+ $ENV{NESCC_DEPUTY} = "yes";
+ } elsif (/^-_?fnesc-deputy-args=(.*)$/) {
+ $ENV{NESCC_DEPUTY_ARGS} = $1;
+ } elsif (/^(-(f|W|Wno-)nesc.*)$/) {
+ # Don't confuse the non-nesC frontends with our -f and -W
+ # flags (these were ignored in earlier C/etc frontends,
+ # but current ones give error messages, preventing nescc
+ # from compiling C files)
+ push @nescc_args, $1;
+ } elsif (/^-([IDUAo])/) {
+ $opt = $1;
+ ($i, $val) = &extractarg($i);
+ push @new_args, "-$opt", $val;
+ } elsif (/^(-include|-idirafter|-imacro|-iprefix|-iwithprefix|-iwithprefixbefore|-isystem|-isysroot|-X[a-zA-Z]*|--param)$/) {
+ $opt = $1;
+ ($i, $arg) = &nextarg($i);
+ push @new_args, $opt, $arg;
+ } else {
+ push @new_args, $_;
}
- }
-
- push @new_args, $_ if !$strip;
+ } else {
+ push @new_args, $_;
+ }
}
-
if ($verbose || $print_version) {
print "nescc: @PACKAGE_VERSION@\n";
}
# Base network type definitions
unshift @new_args, "-I$NCDIR";
-unshift @new_args, "-fnesc-include=nesc_nx";
+unshift @nescc_args, "-fnesc-include=nesc_nx";
#
# documentation generation options
#
-if( defined($docdir) ) {
+if (defined($docdir)) {
# add the doc output dir
- push @new_args, "-fnesc-docdir=$docdir";
+ push @nescc_args, "-fnesc-docdir=$docdir";
# add top level dirs, to strip out of package names
foreach my $dir (@topdirs) {
- push @new_args, "-fnesc-topdir=$dir";
+ push @nescc_args, "-fnesc-topdir=$dir";
}
# add graphviz option
- if( defined($use_graphviz) ) {
- push @new_args, "-fnesc-docs-use-graphviz" if($use_graphviz);
+ if (defined($use_graphviz)) {
+ push @nescc_args, "-fnesc-docs-use-graphviz" if $use_graphviz;
} else {
- my $dot = `which dot 2>&1`;
- push @new_args, "-fnesc-docs-use-graphviz" if($dot !~ /^\s*$/);
+ local $dot = `which dot 2>&1`;
+ push @nescc_args, "-fnesc-docs-use-graphviz" if $dot !~ /^\s*$/;
}
}
-
unshift @new_args, "-specs=$NCDIR/tdspecs";
-unshift @new_args, "-fnesc-gcc=$gcc";
unshift @new_args, $gcc;
if ($mingw_gcc) {
# Yuck. Convert unix paths to windows paths
- $ENV{"NCDIR"} = &winpath($ENV{"NCDIR"});
+ $ENV{NCDIR} = &winpath($ENV{NCDIR});
+ $ENV{NESCC_CFILE} = &winpath($ENV{NESCC_CFILE});
@ARGV = @new_args;
@new_args = ();
for ($i = 0; $i <= $#ARGV; $i++) {
$_ = $ARGV[$i];
if (/^-/) {
- if (/^-[oIL]/) {
+ if (/^-([oIL])/) {
# convert argument filename which may be in same arg
- $opt = substr $_, 1, 1;
+ $opt = $1;
($i, $file) = &extractarg($i);
$file = &winpath($file);
push @new_args, "-$opt$file";
}
- elsif (/^-[xubV]/) {
+ elsif (/^-([xubV])/) {
# pass option and arg through unchanged
- $opt = substr $_, 1, 1;
+ $opt = $1;
($i, $arg) = &extractarg($i);
push @new_args, "-$opt$arg";
}
- elsif ($i < $#ARGV &&
- (/^-idirafter$/ || /^-include$/ || /^-imacros$/ ||
- /^-iprefix$/ || /^-iwithprefix$/ || /^-iwithprefixbefore$/ ||
- /^-isystem$/ || /^-Xlinker$/)) {
+ elsif (/^(-include|-idirafter|-imacro|-iprefix|-iwithprefix|-iwithprefixbefore|-isystem|-isysroot|-Xlinker)/) {
# convert argument filename which is in next arg
- push @new_args, $_;
- push @new_args, &winpath($ARGV[++$i]);
+ $opt = $1;
+ ($i, $arg) = &nextarg($i);
+ push @new_args, $opt, &winpath($arg);
}
elsif (/^-specs=(.*)$/) {
# convert argument filename
}
}
-# Don't confuse the non-nesC frontends with our -f and -W flags
-# (these were ignored in earlier C/etc frontends, but current ones give
-# error messages, preventing nescc from compiling C files)
-map { s/-((f|W|Wno-)nesc)/-_\1/; $_; } @new_args;
+foreach (@nescc_args) {
+ $_ = quotemeta $_;
+ s/\\([-=,\.\/])/\1/g;
+}
+
+$ENV{NESCC_ARGS} = join(' ', @nescc_args);
+$ENV{NESCC_GCC} = $gcc;
+
+printenv("NCDIR");
+printenv("NESCC_ARGS");
+printenv("NESCC_CFILE");
+printenv("NESCC_CONLY");
+printenv("NESCC_DEPUTY");
+printenv("NESCC_DEPUTY_ARGS");
+printenv("NESCC_GCC");
print STDERR join(' ', @new_args), "\n" if $verbose;
exec @new_args;
print STDERR "Couldn't execute $gcc\n";
exit 2;
+sub printenv {
+ local ($s) = @_;
+
+ print STDERR "$s=\"$ENV{$s}\"\n" if $verbose && defined($ENV{$s});
+}
+
sub extractarg {
local ($i) = @_;
if (length($ARGV[$i]) == 2) {
- $arg = $ARGV[++$i];
+ return &nextarg($i);
}
else {
$arg = substr($ARGV[$i], 2);
+ return ($i, $arg);
+ }
+}
+
+sub nextarg {
+ local ($i) = @_;
+
+ if ($i < $#ARGV) {
+ $arg = $ARGV[++$i];
+ }
+ else {
+ printf STDERR "missing argument to $ARGV[$i]\n";
+ exit 2;
}
return ($i, $arg);
}
sub winpath {
- my ($path) = @_;
+ local ($path) = @_;
$path = `cygpath -w $path`;
chop $path;