Commit | Line | Data |
---|---|---|
00804b7c MM |
1 | #!/usr/bin/perl |
2 | # FIX: Should use perl from path | |
099638eb | 3 | # genrecord: make an mgear genfile |
00804b7c MM |
4 | # { gcc prog.c -o prog.tmp; echo $?; } 2>&1 | genrecord prog 'gcc prog.c -o prog.tmp' |
5 | ||
6 | sub mqas($) { | |
7 | my $s = $_[0]; | |
8 | $s =~ s/\$/\$\$/g; | |
9 | $s =~ s/\n/\$(nl)/g; | |
10 | return $s; | |
11 | } | |
12 | sub fmtMakeAssignment($$) { | |
13 | my ($n, $v) = @_; | |
14 | $v = mqas($v); | |
15 | return "$n:=\$(empty)$v"; | |
16 | } | |
17 | ||
18 | my ($target, $cmd) = @ARGV; | |
19 | ||
20 | my @errorLines = <STDIN>; | |
21 | my $exitCode = 0; | |
22 | if ($errorLines[$#errorLines] =~ /^(\d+)$/) { | |
23 | chomp($exitCode = pop @errorLines); | |
24 | } | |
25 | my $errorText = join '', @errorLines; | |
26 | ||
27 | my $genfileText = fmtMakeAssignment("cmd-$target", $cmd) . "\n"; | |
28 | . fmtMakeAssignment("errors-$target", $errorText) . "\n" | |
29 | . fmtMakeAssignment("exitcode-$target", $exitCode) . "\n"; | |
30 | ||
31 | open GENFILE, '>', "$target.g.tmp" and print GENFILE $genfileText and close GENFILE or die; |