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.
19 my $cc = shift(@ARGV);
23 # GCC's "location of error stuff", which accumulates the "In file included from" include stack
27 [ qr/^(.*) warning: cannot pass objects of non-POD type `(.*)' through `\.\.\.'; call will abort at runtime/ => sub {
28 my ($msg, $where, $type) = @_;
31 my $errstr = "$where error: cannot pass objects of non-POD type `$type' through `...'\n";
32 if ($type =~ m/::(basic_)?string/) {
33 $errstr .= "$where (Did you forget to call c_str()?)\n";
38 # Start of an include stack.
39 [ qr/^In file included from .*[,:]$/ => sub {
45 # Continuation of an include stack.
46 [ qr/^ from .*[,:]$/ => sub {
48 $location .= "$msg\n";
52 # A function, method, constructor, or destructor is the site of a problem
53 [ qr/In ((con|de)structor|(member )?function)/ => sub {
55 # If a complete location string is waiting then probably we dropped an error, so drop the location for a new one.
56 if ($location =~ m/In ((con|de)structor|(member )?function)/) {
59 $location .= "$msg\n";
64 [ qr/^.* warning: / => sub {
66 my $str = $location . "\e[33;1m$msg\e[0m\n";
71 [ qr/^.* error: / => sub {
74 $str = "An error occured when executing:\e[37;1m $cc " . join(' ', @ARGV) . "\n" unless $showncmdline;
76 $str .= $location . "\e[31;1m$msg\e[0m\n";
83 $msg = $location . $msg;
85 $msg =~ s/std::basic_string\<char\, std\:\:char_traits\<char\>, std::allocator\<char\> \>(\s+|)/std::string/g;
86 $msg =~ s/std::basic_string\<char\, .*?irc_char_traits\<char\>, std::allocator\<char\> \>(\s+|)/irc::string/g;
87 for my $stl (qw(deque vector list)) {
88 $msg =~ s/std::$stl\<(\S+), std::allocator\<(\1)\> \>/std::$stl\<$1\>/g;
90 $msg =~ s/std::map\<(\S+), (\S+), std::less\<\1\>, std::allocator\<std::pair\<const \1, \2\> \> \>/std::map\<$1, $2\>/g;
97 my ($r_stderr, $w_stderr);
106 foreach my $n (@ARGV)
110 if ($action eq "BUILD")
120 elsif ($action eq "BUILD") # .cpp has priority.
126 $action = $name = $n;
128 elsif ($name eq "-o")
136 if (!defined($cc) || $cc eq "") {
137 die "Compiler not specified!\n";
140 pipe($r_stderr, $w_stderr) or die "pipe stderr: $!\n";
144 die "Cannot fork to start $cc! $!\n" unless defined($pid);
148 printf "\t\e[1;32m%-20s\e[0m%s\n", $action . ":", $name unless $name eq "";
151 # Parent - Close child-side pipes.
153 # Close STDIN to ensure no conflicts with child.
155 # Now read each line of stderr
156 LINE: while (defined(my $line = <$r_stderr>)) {
159 # someone come up with a better way of doing this, it cant go in message filters as message filters
160 # cant do straight-out replace.
162 # The order of these replacements is IMPORTANT. DO NOT REORDER THEM.
165 for my $filter (@msgfilters) {
167 if (@caps = ($line =~ $filter->[0])) {
170 $filter->[1]->($line, @caps);
173 # Note that $line is undef now.
177 next LINE unless defined($line);
180 # Chomp off newlines again, in case the filters put some back in.
182 print STDERR "$line\n";
187 # Simulate the same exit, so make gets the right termination info.
188 if (POSIX::WIFSIGNALED($exit)) {
189 # 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!
190 print STDERR "$cc killed by signal " . POSIX::WTERMSIGN($exit) . "\n";
191 kill "TERM", getppid(); # Needed for bsd make.
195 if (POSIX::WEXITSTATUS($exit) == 0) {
197 kill "TERM", getppid(); # Needed for bsd make.
202 exit POSIX::WEXITSTATUS($exit);
206 # Child - Close parent-side pipes.
209 open STDERR, ">&", $w_stderr or die "Cannot divert STDERR: $!\n";
211 exec { $cc } $cc, @ARGV;
212 die "exec $cc: $!\n";