@@ -51,63 +51,40 @@ sub silent_system {
51
51
# Compiler command setup.
52
52
# #===----------------------------------------------------------------------===##
53
53
54
- # Search in the PATH if the compiler exists
55
- sub SearchInPath {
56
- my $file = shift ;
57
- foreach my $dir (split (' :' , $ENV {PATH })) {
58
- if (-x " $dir /$file " ) {
59
- return 1;
60
- }
61
- }
62
- return 0;
63
- }
64
-
65
- my $Compiler ;
66
- my $Clang ;
67
- my $DefaultCCompiler ;
68
- my $DefaultCXXCompiler ;
69
- my $IsCXX ;
70
- my $AnalyzerTarget ;
71
-
72
- # If on OSX, use xcrun to determine the SDK root.
73
- my $UseXCRUN = 0;
74
-
75
- if (` uname -s` =~ m / Darwin/ ) {
76
- $DefaultCCompiler = ' clang' ;
77
- $DefaultCXXCompiler = ' clang++' ;
78
- # Older versions of OSX do not have xcrun to
79
- # query the SDK location.
80
- if (-x " /usr/bin/xcrun" ) {
81
- $UseXCRUN = 1;
82
- }
83
- } elsif (` uname -s` =~ m / (FreeBSD|OpenBSD)/ ) {
84
- $DefaultCCompiler = ' cc' ;
85
- $DefaultCXXCompiler = ' c++' ;
86
- } else {
87
- $DefaultCCompiler = ' gcc' ;
88
- $DefaultCXXCompiler = ' g++' ;
89
- }
90
-
91
- if ($FindBin::Script =~ / c\+\+ -analyzer/ ) {
92
- $Compiler = $ENV {' CCC_CXX' };
93
- if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler ))) { $Compiler = $DefaultCXXCompiler ; }
94
-
95
- $Clang = $ENV {' CLANG_CXX' };
96
- if (!defined $Clang || ! -x $Clang ) { $Clang = ' clang++' ; }
97
-
98
- $IsCXX = 1
54
+ {
55
+ my ($DefaultCCompiler , $DefaultCXXCompiler );
56
+
57
+ my $os = ` uname -s` ;
58
+ if ($os =~ m / Darwin/ ) {
59
+ $DefaultCCompiler = ' clang' ;
60
+ $DefaultCXXCompiler = ' clang++' ;
61
+ } elsif ($os =~ m / (FreeBSD|OpenBSD)/ ) {
62
+ $DefaultCCompiler = ' cc' ;
63
+ $DefaultCXXCompiler = ' c++' ;
64
+ } else {
65
+ $DefaultCCompiler = ' gcc' ;
66
+ $DefaultCXXCompiler = ' g++' ;
67
+ }
68
+
69
+ sub DetermineCompiler {
70
+ my ($is_cxx ) = @_ ;
71
+ my $default = $is_cxx ? $DefaultCXXCompiler : $DefaultCCompiler ;
72
+ my $opt = $ENV {$is_cxx ? ' CCC_CXX' : ' CCC_CC' };
73
+ return defined $opt ? shellwords($opt ) : $default ;
74
+ }
99
75
}
100
- else {
101
- $Compiler = $ENV {' CCC_CC' };
102
- if (!defined $Compiler || (! -x $Compiler && ! SearchInPath($Compiler ))) { $Compiler = $DefaultCCompiler ; }
103
-
104
- $Clang = $ENV {' CLANG' };
105
- if (!defined $Clang || ! -x $Clang ) { $Clang = ' clang' ; }
106
76
107
- $IsCXX = 0
77
+ sub DetermineClang {
78
+ my ($is_cxx ) = @_ ;
79
+ my $default = $is_cxx ? ' clang++' : ' clang' ;
80
+ my $opt = $ENV {$is_cxx ? ' CLANG_CXX' : ' CLANG' };
81
+ return defined $opt ? $opt : $default ;
108
82
}
109
83
110
- $AnalyzerTarget = $ENV {' CLANG_ANALYZER_TARGET' };
84
+ my $IsCXX = $FindBin::Script =~ / c\+\+ -analyzer/ ;
85
+ my ($Compiler , @CompilerArgs ) = DetermineCompiler($IsCXX );
86
+ my $Clang = DetermineClang($IsCXX );
87
+ my $AnalyzerTarget = $ENV {' CLANG_ANALYZER_TARGET' };
111
88
112
89
# #===----------------------------------------------------------------------===##
113
90
# Cleanup.
@@ -199,7 +176,7 @@ sub GetCCArgs {
199
176
die " could not find clang line\n " if (!defined $line );
200
177
# Strip leading and trailing whitespace characters.
201
178
$line =~ s / ^\s +|\s +$// g ;
202
- my @items = quotewords( ' \s+ ' , 0, $line );
179
+ my @items = shellwords( $line );
203
180
my $cmd = shift @items ;
204
181
die " cannot find 'clang' in 'clang' command\n " if (!($cmd =~ / clang/ || basename($cmd ) =~ / llvm/ ));
205
182
# If this is the llvm-driver the internal command will look like "llvm clang ...".
@@ -462,9 +439,9 @@ my $Output;
462
439
my %Uniqued ;
463
440
464
441
# Forward arguments to gcc.
465
- my $Status = system ($Compiler ,@ARGV );
442
+ my $Status = system ($Compiler ,@CompilerArgs , @ ARGV );
466
443
if (defined $ENV {' CCC_ANALYZER_LOG' }) {
467
- print STDERR " $Compiler @ARGV \n " ;
444
+ print STDERR " $Compiler @CompilerArgs @ ARGV\n " ;
468
445
}
469
446
if ($Status ) { exit ($Status >> 8); }
470
447
@@ -698,8 +675,9 @@ if ($ForceAnalyzeDebugCode) {
698
675
699
676
# If we are on OSX and have an installation where the
700
677
# default SDK is inferred by xcrun use xcrun to infer
701
- # the SDK.
702
- if (not $HasSDK and $UseXCRUN ) {
678
+ # the SDK. Older versions of OSX do not have xcrun to
679
+ # query the SDK location.
680
+ if (not $HasSDK and -x ' /usr/bin/xcrun' ) {
703
681
my $sdk = ` /usr/bin/xcrun --show-sdk-path -sdk macosx` ;
704
682
chomp $sdk ;
705
683
push @CompileOpts , " -isysroot" , $sdk ;
0 commit comments