#!/usr/local/bin/perl # # original published as part of SmallEiffel -0.81 under the GPL # slightly adapted for use with WipeOut # $gc = ""; #"-gc"; $HOME = $ENV{'HOME'}; #$ENV{'SmallEiffel'} = "$HOME/SmallEiffel/"; #$ENV{'PATH'} = "$HOME/SmallEiffel/bin:/usr/local/bin:/bin:/usr/bin:$HOME/bin/command"; $e_flags = "-require_check"; $dbg_flags = "-g"; if($gc) { $c_flags = "-I/usr/local/include"; $ld_flags = "-z /usr/local/lib/libgc.a"; } else { $ld_flags = "-z"; } mkdir("B",0755); #prepare orginal source dir mkdir("C",0755); #prepare converted source dir $debug = 1; $target = shift(@ARGV); $root = shift(@ARGV); if(!$target || !$root) { $help++; } else { if(@ARGV) { $e_flags = ""; while($fl = shift(@ARGV)) { if($fl =~ /^-?hel/) {$help++;} elsif($fl =~ /^-?deb/) {$e_flags = "-debug_check";} elsif($fl =~ /^-?all/) {$e_flags = "-all_check";} elsif($fl =~ /^-?loo/) {$e_flags = "-loop_check";} elsif($fl =~ /^-?inv/) {$e_flags = "-invariant_check";} elsif($fl =~ /^-?ens/) {$e_flags = "-ensure_check";} elsif($fl =~ /^-?req/) {$e_flags = "-require_check";} elsif($fl =~ /^-?no/) {$e_flags = "-no_check";} elsif($fl =~ /^-?boo/) {$e_flags = "-boost";} elsif($fl =~ /^-?opt/) {$e_flags = "-boost";$dbg_flags = "-g -O3";} elsif($fl =~ /^-?ver/) {$e_flags .= " -verbose";} elsif($fl =~ /^-c/) {$c = shift(@ARGV); $e_flags .= " -cecil $c.ce"; $extra .= " $c.c";} elsif($fl =~ /^[^\/].*.o$/) {$rest .= " ../$fl";} else {$rest .= " $fl";} } } } if($help) { print "Usage: sec target root [-daliernbO]\n"; exit; } if(-f $target) { $target_age = -M $target; } else { $target_age = 10000000; } chomp($cwd = `pwd`); opendir(DIR,$cwd); @sources = grep(/.e$/,readdir(DIR)); @new_sources = grep {(-M $_) < $target_age} @sources; closedir(DIR); if(@new_sources) { $ret0 = 0; $ret0 = do_command("compile_to_c $e_flags -o $target $root make"); if ($ret0 > 0) { print "exit code: $ret0\n"; exit 1; } opendir(DIR,$cwd); @cfiles = grep {(-M $_) < $target_age} grep(/^$root\d*.[ch]$/,readdir(DIR)); closedir(DIR); if(!@cfiles) { print "no cfiles\n"; exit; } if($e_flags ne "-boost") { do_command("add_line_directive $gc @cfiles"); } else { do_command("move-if-changed @cfiles C"); unlink @cfiles; } if($extra) { do_command("gcc -ansi -c $extra"); $extra =~ s?(\S+).c?../$1.o?; } chdir "C"; @new_cfiles = grep(/^$root\d+.c$/,@cfiles); @new = (); foreach $s (@new_cfiles) { $o = $s; $o =~ s/\.c$/.o/; if(!-f $o || (-M $o) > (-M $s)) { push(@new,$s); } } $ret = 0; if(@new) { $ret += do_command("gcc -ansi $dbg_flags $c_flags -c @new"); } if(!$ret) { @objects = grep{s/(.*)\.c$/$1.o/} @cfiles; do_command("gcc -o ../$target $dbg_flags @objects $extra $ld_flags $rest -lm"); } } sub do_command { my($com) = @_; print "$com\n" if $debug; system($com); }