2012-11-23 21:22:47 +08:00
|
|
|
#!/usr/bin/perl
|
|
|
|
use Cwd;
|
|
|
|
use strict;
|
|
|
|
my $cxx;
|
|
|
|
my $ccorcxx;
|
|
|
|
if ($ARGV[0] ne '++') {
|
|
|
|
$ccorcxx = 'CC';
|
|
|
|
$cxx = 0;
|
|
|
|
} else {
|
|
|
|
shift @ARGV;
|
|
|
|
$ccorcxx = 'CXX';
|
|
|
|
$cxx = 1;
|
|
|
|
}
|
|
|
|
die "$0: $ccorcxx environment variable does not exist\n" unless exists $ENV{$ccorcxx};
|
2016-02-29 21:34:09 +08:00
|
|
|
$ENV{'LANG'} = 'C';
|
2012-11-23 21:22:47 +08:00
|
|
|
my @compiler = split ' ', $ENV{$ccorcxx};
|
|
|
|
if ("@ARGV" !~ / -nostdinc/o) {
|
|
|
|
my $fd;
|
|
|
|
push @compiler, ($cxx ? '-xc++' : '-xc');
|
|
|
|
if (!open $fd, '-|') {
|
|
|
|
open STDERR, '>&', \*STDOUT;
|
|
|
|
exec @compiler, '/dev/null', '-v', '-E', '-o', '/dev/null' or die "*** error execing $compiler[0] - $!\n";
|
|
|
|
}
|
|
|
|
$compiler[1] =~ s/xc/nostdinc/o;
|
|
|
|
push @compiler, '-nostdinc' if $cxx;
|
|
|
|
push @compiler, '-I' . $_ for split ' ', $ENV{CCWRAP_HEADERS};
|
|
|
|
push @compiler, '-isystem', $_ for split ' ', $ENV{CCWRAP_SYSTEM_HEADERS};
|
|
|
|
my $finding_paths = 0;
|
2012-11-27 03:00:35 +08:00
|
|
|
my $mingw_compiler = $compiler[0] =~ /mingw/o;
|
|
|
|
my @dirafters;
|
|
|
|
for my $d (split ' ', $ENV{CCWRAP_DIRAFTER_HEADERS}) {
|
|
|
|
push @dirafters, '-isystem', $d if !$mingw_compiler || $d !~ /w32api/o;
|
|
|
|
}
|
2012-11-23 21:22:47 +08:00
|
|
|
while (<$fd>) {
|
|
|
|
if (/^\*\*\*/o) {
|
|
|
|
print;
|
|
|
|
} elsif ($_ eq "#include <...> search starts here:\n") {
|
|
|
|
$finding_paths = 1;
|
|
|
|
} elsif (!$finding_paths) {
|
|
|
|
next;
|
|
|
|
} elsif ($_ eq "End of search list.\n") {
|
|
|
|
last;
|
2012-11-27 03:00:35 +08:00
|
|
|
} elsif (!@dirafters || !m%w32api|mingw.*/include%o) {
|
2012-11-23 21:22:47 +08:00
|
|
|
chomp;
|
|
|
|
s/^\s+//;
|
|
|
|
push @compiler, '-isystem', Cwd::abs_path($_);
|
|
|
|
}
|
|
|
|
}
|
2012-11-27 03:00:35 +08:00
|
|
|
push @compiler, @dirafters;
|
2012-11-23 21:22:47 +08:00
|
|
|
close $fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
push @compiler, @ARGV;
|
|
|
|
|
|
|
|
print join(' ', '+', @compiler), "\n" if $ENV{CCWRAP_VERBOSE};
|
|
|
|
exec @compiler or die "$0: $compiler[0] failed to execute\n";
|