#!/usr/bin/perl # FIX: Should use perl from path # genrecord: make a Mage genfile # { gcc prog.c -o prog.tmp; echo $?; } 2>&1 | genrecord prog 'gcc prog.c -o prog.tmp' sub mqas($) { my $s = $_[0]; $s =~ s/\$/\$\$/g; $s =~ s/\n/\$(nl)/g; return $s; } sub fmtMakeAssignment($$) { my ($n, $v) = @_; $v = mqas($v); return "$n:=\$(empty)$v"; } my ($target, $cmd) = @ARGV; my @errorLines = ; my $exitCode = 0; if ($errorLines[$#errorLines] =~ /^(\d+)$/) { chomp($exitCode = pop @errorLines); } my $errorText = join '', @errorLines; my $genfileText = fmtMakeAssignment("cmd-$target", $cmd) . "\n"; . fmtMakeAssignment("errors-$target", $errorText) . "\n" . fmtMakeAssignment("exitcode-$target", $exitCode) . "\n"; open GENFILE, '>', "$target.g.tmp" and print GENFILE $genfileText and close GENFILE or die;