3 # +------------------------------------+
4 # | Inspire Internet Relay Chat Daemon |
5 # +------------------------------------+
7 # InspIRCd: (C) 2002-2009 InspIRCd Development Team
8 # See: http://wiki.inspircd.org/Credits
10 # This program is free but copyrighted software; see
11 # the file COPYING for details.
13 # ---------------------------------------------------
15 ### THIS IS DESIGNED TO BE RUN BY MAKE! DO NOT RUN FROM THE SHELL (because it MIGHT sigterm the shell)! ###
18 use warnings FATAL => qw(all);
22 # Runs the compiler, passing it the given arguments.
23 # Filters select output from the compiler's standard error channel and
24 # can take different actions as a result.
26 # 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)
27 # even though we use the => in it.
29 # The subs are passed the message, and anything the regex captured.
31 my $cc = shift(@ARGV);
35 # GCC's "location of error stuff", which accumulates the "In file included from" include stack
39 [ qr/^(.*) warning: cannot pass objects of non-POD type `(.*)' through `\.\.\.'; call will abort at runtime/ => sub {
40 my ($msg, $where, $type) = @_;
41 my $errstr = $location . "$where error: cannot pass objects of non-POD type `$type' through `...'\n";
43 if ($type =~ m/::(basic_)?string/) {
44 $errstr .= "$where (Did you forget to call c_str()?)\n";
49 # Start of an include stack.
50 [ qr/^In file included from .*[,:]$/ => sub {
56 # Continuation of an include stack.
57 [ qr/^ from .*[,:]$/ => sub {
59 $location .= "$msg\n";
63 # A function, method, constructor, or destructor is the site of a problem
64 [ qr/In ((con|de)structor|(member )?function)/ => sub {
66 # If a complete location string is waiting then probably we dropped an error, so drop the location for a new one.
67 if ($location =~ m/In ((con|de)structor|(member )?function)/) {
70 $location .= "$msg\n";
75 [ qr/^.* warning: / => sub {
77 my $str = $location . "\e[33;1m$msg\e[0m\n";
83 [ qr/^.* error: / => sub {
86 $str = "An error occured when executing:\e[37;1m $cc " . join(' ', @ARGV) . "\n" unless $showncmdline;
88 $str .= $location . "\e[31;1m$msg\e[0m\n";
95 $msg = $location . $msg;
97 $msg =~ s/std::basic_string\<char\, std\:\:char_traits\<char\>, std::allocator\<char\> \>(\s+|)/std::string/g;
98 $msg =~ s/std::basic_string\<char\, .*?irc_char_traits\<char\>, std::allocator\<char\> \>(\s+|)/irc::string/g;
99 for my $stl (qw(deque vector list)) {
100 $msg =~ s/std::$stl\<(\S+), std::allocator\<\1\> \>/std::$stl\<$1\>/g;
101 $msg =~ s/std::$stl\<(std::pair\<\S+, \S+\>), std::allocator\<\1 \> \>/std::$stl<$1 >/g;
103 $msg =~ s/std::map\<(\S+), (\S+), std::less\<\1\>, std::allocator\<std::pair\<const \1, \2\> \> \>/std::map<$1, $2>/g;
104 # Warning: These filters are GNU C++ specific!
105 $msg =~ s/__gnu_cxx::__normal_iterator\<(\S+)\*, std::vector\<\1\> \>/std::vector<$1>::iterator/g;
106 $msg =~ s/__gnu_cxx::__normal_iterator\<(std::pair\<\S+, \S+\>)\*, std::vector\<\1 \> \>/std::vector<$1 >::iterator/g;
107 $msg =~ s/__gnu_cxx::__normal_iterator\<char\*, std::string\>/std::string::iterator/g;
108 $msg =~ s/__gnu_cxx::__normal_iterator\<char\*, irc::string\>/irc::string::iterator/g;
115 my ($r_stderr, $w_stderr);
124 foreach my $n (@ARGV)
129 if (defined $ENV{SOURCEPATH}) {
130 $f =~ s#^$ENV{SOURCEPATH}/src/##;
132 if ($action eq "BUILD")
142 elsif ($action eq "BUILD") # .cpp has priority.
148 $action = $name = $n;
150 elsif ($name eq "-o")
158 if (!defined($cc) || $cc eq "") {
159 die "Compiler not specified!\n";
162 pipe($r_stderr, $w_stderr) or die "pipe stderr: $!\n";
166 die "Cannot fork to start $cc! $!\n" unless defined($pid);
170 printf "\t\e[1;32m%-20s\e[0m%s\n", $action . ":", $name unless $name eq "";
173 # Parent - Close child-side pipes.
175 # Close STDIN to ensure no conflicts with child.
177 # Now read each line of stderr
178 LINE: while (defined(my $line = <$r_stderr>)) {
181 for my $filter (@msgfilters) {
183 if (@caps = ($line =~ $filter->[0])) {
186 $filter->[1]->($line, @caps);
189 # Note that $line is undef now.
193 next LINE unless defined($line);
196 # Chomp off newlines again, in case the filters put some back in.
198 print STDERR "$line\n";
203 # Simulate the same exit, so make gets the right termination info.
204 if (POSIX::WIFSIGNALED($exit)) {
205 # 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!
206 print STDERR "$cc killed by signal " . POSIX::WTERMSIGN($exit) . "\n";
207 kill "TERM", getppid(); # Needed for bsd make.
211 if (POSIX::WEXITSTATUS($exit) == 0) {
213 kill "TERM", getppid(); # Needed for bsd make.
218 exit POSIX::WEXITSTATUS($exit);
222 # Child - Close parent-side pipes.
225 open STDERR, ">&", $w_stderr or die "Cannot divert STDERR: $!\n";
227 exec { $cc } $cc, @ARGV;
228 die "exec $cc: $!\n";