]> oss.titaniummirror.com Git - nesc.git/blobdiff - src/nesc-compile
Pristine nesc-1.3.4
[nesc.git] / src / nesc-compile
index b02b5ba325fe64ffaf49a85aab56dc153327436a..cdda7760ab1fa42ccdf3e92fa3b1ee9cd0374380 100755 (executable)
 
 use File::Basename;
 
+# Extract information from enviroment variables set by nescc
+$ctarget = $ENV{NESCC_CFILE};
+$conly = $ENV{NESCC_CONLY} eq "yes";
+$deputy = $ENV{NESCC_DEPUTY} eq "yes";
+@deputy_args = split(" ", $ENV{NESCC_DEPUTY_ARGS});
+$gcc = $ENV{NESCC_GCC};
+
+push @nesc_args, "-fnesc-gcc=$gcc";
+
 for ($i = 0; $i <= $#ARGV; $i++) {
     $_ = $ARGV[$i];
 
@@ -33,18 +42,15 @@ for ($i = 0; $i <= $#ARGV; $i++) {
            $nocompile = 1;
        }
 
-       if (/^-_?fnesc-conly$/) {
-           $conly = 1;
-       }
-
-       if (/^-[_WwvpfmD]/ || /^-pedantic$/ || /^-ansi$/) {
-           push @nesc_args, $_ unless /^-_?fnesc-.*cfile=/;
+       if (/^-[_WwvpfmH]/ || /^-pedantic$/ || /^-ansi$/) {
+           push @nesc_args, $_;
            $verbose = 1 if /^-v/;
        }
 
-       if (/^-I/) {
-           ($i, $idir) = &extractarg($i);
-           push @nesc_args, "-I$idir";
+       if (/^-([IDUA])/) {
+           $opt = $1;
+           ($i, $val) = &extractarg($i);
+           push @nesc_args, "-$opt$val";
        }
        elsif (/^-o/) {
            ($i, $objtarget) = &extractarg($i);
@@ -54,31 +60,21 @@ for ($i = 0; $i <= $#ARGV; $i++) {
            push @gcc_args, "--param";
            push @gcc_args, $param;
        }
+       elsif (/^-include$/) {
+           ($i, $file) = &nextarg($i);
+           push @nesc_args, "-include", $file;
+       }
        elsif (/^-S$/) {
            $asmonly = 1;
        }
-       elsif (/^-_?fnesc-/) {
-           if (/^-_?fnesc-cfile=(.*)$/) {
-               $ctarget = $1;
-           }
-           if (/^-_?fnesc-tmpcfile=(.*)$/) {
-               $ctarget = $1;
-               $delcfile = 1;
-           }
-           if (/^-_?fnesc-gcc=(.*)$/) {
-               $gcc = $1;
-           }
-            if (/^-_?fnesc-deputy$/) {
-                $deputy = 1;
-            }
-            if (/^-_?fnesc-deputy-args=(.*)$/) {
-                @deputy_args = split(" ", $1);
-            }
+       elsif (/^-fnesc-tmpcfile=(.*)$/) {
+         if ($ctarget eq "") {
+           $ctarget = $1;
+           $delcfile = 1;
+         }
        }
-       elsif (!(/^-D/)) {
-           if (!(/^-_?W(no-)?nesc/)) {
-               push @gcc_args, $_;
-           }
+       else {
+           push @gcc_args, $_;
        }
     }
     else {
@@ -90,6 +86,12 @@ for ($i = 0; $i <= $#ARGV; $i++) {
     }
 }
 
+# Split on spaces not preceded by \, then unquote.
+push @nesc_args, split(/(?<!\\) /, $ENV{NESCC_ARGS});
+foreach (@nesc_args) {
+  s/\\(.)/\1/g;
+}
+
 if ($source eq "") {
     printf STDERR "no source file specified\n";
     exit 2;
@@ -117,7 +119,7 @@ if ($objtarget eq "") {
 }
 
 # Deputy annotations
-if($deputy) {
+if ($deputy) {
     unshift @nesc_args, "-fnesc-include=deputy_stage1";
     unshift @nesc_args, "-fnesc-genprefix=#include \"$ENV{NCDIR}/deputy_stage2.h\"";
 }
@@ -136,6 +138,10 @@ if ($nocompile && !$conly) {
 # Check for gcc 4.0.x, which don't tell us about the __STDC__ #define
 unshift @nesc_args, "-D__STDC__" if isgcc40($gcc);
 
+# Get rid of __BLOCKS__ define, if any (prevent use of Apple C extension that
+# nesC doesn't understand)
+unshift @nesc_args, "-U__BLOCKS__";
+
 unshift @nesc_args, "nesc1";
 
 &vsystem(@nesc_args);
@@ -145,7 +151,7 @@ if ($? != 0) {
 }
 exit 0 if $nocompile || $conly;
 
-if($deputy) {
+if ($deputy) {
     push @deputy_args, "--gcc=$gcc";
     push @gcc_args, @deputy_args;
     $gcc = "deputy";