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 {
44 # Continuation of an include stack.
45 [ qr/^ from .*[,:]$/ => sub {
47 $location .= "$msg\n";
50 # A function, method, constructor, or destructor is the site of a problem
51 [ qr/In ((con|de)structor|(member )?function)/ => sub {
53 # If a complete location string is waiting then probably we dropped an error, so drop the location for a new one.
54 if ($location =~ m/In ((con|de)structor|(member )?function)/) {
57 $location .= "$msg\n";
61 [ qr/^.* warning: / => sub {
65 print STDERR "\e[33;1m$msg\e[0m\n";
68 [ qr/^.* error: / => sub {
70 print STDERR "An error occured when executing:\e[37;1m $cc " . join(' ', @ARGV) . "\n" unless $showncmdline;
74 print STDERR "\e[31;1m$msg\e[0m\n";
80 my ($r_stderr, $w_stderr);
93 if ($action eq "BUILD")
103 elsif ($action eq "BUILD") # .cpp has priority.
109 $action = $name = $n;
111 elsif ($name eq "-o")
119 if (!defined($cc) || $cc eq "") {
120 die "Compiler not specified!\n";
123 pipe($r_stderr, $w_stderr) or die "pipe stderr: $!\n";
127 die "Cannot fork to start $cc! $!\n" unless defined($pid);
131 printf "\t\e[1;32m%-20s\e[0m%s\n", $action . ":", $name unless $name eq "";
134 # Parent - Close child-side pipes.
136 # Close STDIN to ensure no conflicts with child.
138 # Now read each line of stderr
139 LINE: while (defined(my $line = <$r_stderr>)) {
142 # someone come up with a better way of doing this, it cant go in message filters as message filters
143 # cant do straight-out replace.
145 # The order of these replacements is IMPORTANT. DO NOT REORDER THEM.
147 $line =~ s/std\:\:basic_string\<char\, std\:\:char_traits\<char\>, std::allocator\<char\> \>(\s+|)/std::string/g;
148 $line =~ s/std\:\:basic_string\<char\, .*?irc_char_traits\<char\>, std::allocator\<char\> \>(\s+|)/irc::string/g;
149 $line =~ s/std\:\:deque\<(\S+)\, std::allocator\<\S+\> \>/std::deque<$1>/g;
151 for my $filter (@msgfilters) {
153 if (@caps = ($line =~ $filter->[0])) {
156 $filter->[1]->($line, @caps);
165 print STDERR "$line\n";
170 # Simulate the same exit, so make gets the right termination info.
171 if (POSIX::WIFSIGNALED($exit)) {
172 # 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!
173 print STDERR "$cc killed by signal " . POSIX::WTERMSIGN($exit) . "\n";
174 kill "TERM", getppid(); # Needed for bsd make.
178 if (POSIX::WEXITSTATUS($exit) == 0) {
180 kill "TERM", getppid(); # Needed for bsd make.
185 exit POSIX::WEXITSTATUS($exit);
189 # Child - Close parent-side pipes.
192 open STDERR, ">&", $w_stderr or die "Cannot divert STDERR: $!\n";
194 exec { $cc } $cc, @ARGV;
195 die "exec $cc: $!\n";