#!@pathperl@ # -*- perl -*- # This file is part of the nesC compiler. # # This file is derived from the RC Compiler. It is thus # Copyright (C) 2000-2001 The Regents of the University of California. # Changes for nesC are # Copyright (C) 2002 Intel Corporation # # The attached "nesC" software is provided to you under the terms and # conditions of the GNU General Public License Version 2 as published by the # Free Software Foundation. # # nesC is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with nesC; see the file COPYING. If not, write to # the Free Software Foundation, 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # Configuration $prefix = "@prefix@"; $exec_prefix = "@exec_prefix@"; $NCDIR = "@libdir@/ncc"; # Runtime configuration $ENV{"PATH"} = "$NCDIR:$ENV{PATH}"; $ENV{"NCDIR"} = $NCDIR; # Have fun with the arguments $gcc = "gcc"; for ($i = 0; $i <= $#ARGV; $i++) { $strip = 0; $_ = $ARGV[$i]; if (/^-/) { if (/^-docdir=(.*)/) { $docdir = $1; $strip = 1; } elsif (/^-topdir=(.*)/) { push @topdirs, $1; $strip = 1; } elsif (/^-graphviz=(.*)/) { if($1 =~ /^y/i) { $use_graphviz = 1; } else { $use_graphviz = 0; } $strip = 1; } elsif (/^--version$/) { $print_version = 1; $strip = 1; } elsif (/^-gcc=(.*)/) { $gcc = $1; $strip = 1; } 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 @new_args, $_ if !$strip; } if ($verbose || $print_version) { print "nescc: @PACKAGE_VERSION@\n"; } if ($print_version) { print "$gcc: "; system "$gcc --version"; exit 0; } # Compute numeric version, assumes PACKAGE_VERSION is of the form a.b.cXXX # where XXX is any alphanumeric suffix, b, c are optional and between 0 and 9 $_ = "@PACKAGE_VERSION@"; if (/^(\d*)([a-zA-Z]\w*)?$/) { $v_a = $1; $v_b = 0; $v_c = 0; } elsif (/^(\d*)\.(\d)([a-zA-Z]\w*)?$/) { $v_a = $1; $v_b = $2; $v_c = 0; } elsif (/^(\d*)\.(\d)\.(\d)([a-zA-Z]\w*)?$/) { $v_a = $1; $v_b = $2; $v_c = $3; } else { &fail("Internal error: invalid version $_"); } $numversion = $v_a * 100 + $v_b * 10 + $v_c; push @new_args, "-DNESC=$numversion"; # Base network type definitions unshift @new_args, "-I$NCDIR"; unshift @new_args, "-fnesc-include=nesc_nx"; # # documentation generation options # if( defined($docdir) ) { # add the doc output dir push @new_args, "-fnesc-docdir=$docdir"; # add top level dirs, to strip out of package names foreach my $dir (@topdirs) { push @new_args, "-fnesc-topdir=$dir"; } # add graphviz option if( defined($use_graphviz) ) { push @new_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*$/); } } 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"}); @ARGV = @new_args; @new_args = (); for ($i = 0; $i <= $#ARGV; $i++) { $_ = $ARGV[$i]; if (/^-/) { if (/^-[oIL]/) { # convert argument filename which may be in same arg $opt = substr $_, 1, 1; ($i, $file) = &extractarg($i); $file = &winpath($file); push @new_args, "-$opt$file"; } elsif (/^-[xubV]/) { # pass option and arg through unchanged $opt = substr $_, 1, 1; ($i, $arg) = &extractarg($i); push @new_args, "-$opt$arg"; } elsif ($i < $#ARGV && (/^-idirafter$/ || /^-include$/ || /^-imacros$/ || /^-iprefix$/ || /^-iwithprefix$/ || /^-iwithprefixbefore$/ || /^-isystem$/ || /^-Xlinker$/)) { # convert argument filename which is in next arg push @new_args, $_; push @new_args, &winpath($ARGV[++$i]); } elsif (/^-specs=(.*)$/) { # convert argument filename $path = &winpath($1); push @new_args, "-specs=$path"; } else { push @new_args, $_; } } else { push @new_args, &winpath($_); } } } # 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; print STDERR join(' ', @new_args), "\n" if $verbose; exec @new_args; print STDERR "Couldn't execute $gcc\n"; exit 2; sub extractarg { local ($i) = @_; if (length($ARGV[$i]) == 2) { $arg = $ARGV[++$i]; } else { $arg = substr($ARGV[$i], 2); } return ($i, $arg); } sub winpath { my ($path) = @_; $path = `cygpath -w $path`; chop $path; return $path; } sub fail { print STDERR "$_[0]\n"; exit 2; }