+my $cpp;
+my $deputyasmexe;
+my $gcc;
+
+my $safe_home = $ENV{'TOSDIR'}."/lib/safe";
+push @new_args, "-fnesc-include=${safe_home}/include/annots_stage1";
+push @new_args, "-fnesc-genprefix=#include \"${safe_home}/include/annots_stage2.h\"";
+
+if ($safe) {
+
+ if (($target eq "mica2") or ($target eq "micaz")) {
+ $mcu = "avr";
+ } elsif ($target eq "telosb") {
+ $mcu = "msp430";
+ } else {
+ print STDERR "Safe TinyOS does not (yet) support the ${target} target.\n";
+ print STDERR "Supported targets: ";
+ print STDERR "mica2, micaz, telosb\n";
+ exit 2;
+ }
+
+ my $deputy_include = $ENV{'DEPUTY_HOME'}."/include";
+
+ push @new_args, "-DSAFE_TINYOS";
+ push @new_args, "-conly";
+ push @new_args, "-fnesc-deputy";
+
+ if (!defined $appfilename) {
+ $appfilename="build/${target}/app.c";
+ }
+ if (!defined $exefilename) {
+ $exefilename="build/${target}/main.exe";
+ }
+
+ $appfilename =~ m/^((.*\/)?)[^\/]+$/;
+ my $directory = $1;
+
+ # Might be useful to keep this app.c somewhere...
+ # This could probably be avoided by using the deputy script
+ # instead of the executable directly...
+ $cpp = "${mcu}-gcc -E -DSAFE_TINYOS $appfilename -o ${directory}deputy-in.c -I${safe_home}/include";
+
+ # Not worrying about racing protection, for now...
+ # --checksnescatomic racing.txt
+ $deputyasmexe = "deputy-${mcu} --FLIDs --out ${directory}deputy-out.c ${directory}deputy-in.c";
+
+ $failfile = "${TOSDIR}/lib/safe/${mcu}/fail.c";
+
+ my $gccflags;
+ if (($target eq "mica2") or ($target eq "micaz")) {
+ $gccflags = ("-mmcu=atmega128 -Os -fdollars-in-identifiers " .
+ "-finline-limit=1000000 -Winline " .
+ "--param inline-unit-growth=1000000 " .
+ "--param large-function-growth=1000000");
+ }
+ elsif($target eq "telosb"){
+ $gccflags = "-Os -mdisable-hwmul -mmcu=msp430x1611";
+ }
+
+ $gcc = ("${mcu}-gcc $gccflags -I${deputy_include} ${directory}deputy-out.c " .
+ "$failfile -o $exefilename $libs");
+
+}
+