1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
#!/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};
$ENV{'LANG'} = 'C';
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;
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;
}
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;
} elsif (!@dirafters || !m%w32api|mingw.*/include%o) {
chomp;
s/^\s+//;
push @compiler, '-isystem', Cwd::abs_path($_);
}
}
push @compiler, @dirafters;
close $fd;
}
push @compiler, @ARGV;
print join(' ', '+', @compiler), "\n" if $ENV{CCWRAP_VERBOSE};
exec @compiler or die "$0: $compiler[0] failed to execute\n";
|