3 ### THIS IS DESIGNED TO BE RUN BY MAKE! DO NOT RUN FROM THE SHELL (because it MIGHT sigterm the shell)! ###
6 use warnings FATAL => qw(all);
10 # Runs the compiler, passing it the given arguments.
11 # Filters select output from the compiler's standard error channel and
12 # can take different actions as a result.
14 # NOTE: this is *NOT* a hash (sadly: a hash would stringize all the regexes and thus render them useless, plus you can't index a hash based on regexes anyway)
15 # even though we use the => in it.
17 # The subs are passed the message, and anything the regex captured.
20 [ qr/^(.*) warning: cannot pass objects of non-POD type `(.*)' through `\.\.\.'; call will abort at runtime/ => sub {
21 my ($msg, $where, $type) = @_;
22 my $errstr = "$where error: cannot pass objects of non-POD type `$type' through `...'\n";
23 if ($type =~ m/::string/) {
24 $errstr .= "$where (Did you forget to call c_str()?)\n";
29 [ qr/^.* warning: / => sub {
31 print STDERR "\e[33;1m$msg\e[0m\n";
34 [ qr/^.* error: / => sub {
36 print STDERR "\e[31;1m$msg\e[0m\n";
42 my ($r_stderr, $w_stderr);
44 my $cc = shift(@ARGV);
46 if (!defined($cc) || $cc eq "") {
47 die "Compiler not specified!\n";
50 pipe($r_stderr, $w_stderr) or die "pipe stderr: $!\n";
54 die "Cannot fork to start gcc! $!\n" unless defined($pid);
58 # Parent - Close child-side pipes.
60 # Close STDIN to ensure no conflicts with child.
62 # Now read each line of stderr
63 LINE: while (defined(my $line = <$r_stderr>)) {
65 for my $filter (@msgfilters) {
67 if (@caps = ($line =~ $filter->[0])) {
70 $filter->[1]->($line, @caps);
79 print STDERR "$line\n";
84 # Simulate the same exit, so make gets the right termination info.
85 if (POSIX::WIFSIGNALED($exit)) {
86 # Make won't get the right termination info (it gets ours, not the compiler's), so we must tell the user what really happened ourselves!
87 print STDERR "$cc killed by signal " . POSIX::WTERMSIGN($exit) . "\n";
88 kill "TERM", getppid(); # Needed for bsd make.
92 if (POSIX::WEXITSTATUS($exit) == 0) {
94 kill "TERM", getppid(); # Needed for bsd make.
99 exit POSIX::WEXITSTATUS($exit);
103 # Child - Close parent-side pipes.
106 open STDERR, ">&", $w_stderr or die "Cannot divert STDERR: $!\n";
108 exec { $cc } $cc, @ARGV;
109 die "exec $cc: $!\n";