Skip to content

Commit af6e225

Browse files
authored
Merge pull request #2000 from martin-frbg/issue1989
Make c_check robust against old or incomplete perl installations
2 parents f10408a + d70ae3a commit af6e225

File tree

1 file changed

+56
-29
lines changed

1 file changed

+56
-29
lines changed

c_check

Lines changed: 56 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/perl
22

3-
use File::Basename;
4-
use File::Temp qw(tempfile);
3+
#use File::Basename;
4+
# use File::Temp qw(tempfile);
55

66
# Checking cross compile
77
$hostos = `uname -s | sed -e s/\-.*//`; chop($hostos);
@@ -12,7 +12,7 @@ $hostarch = "arm64" if ($hostarch eq "aarch64");
1212
$hostarch = "power" if ($hostarch =~ /^(powerpc|ppc).*/);
1313
$hostarch = "zarch" if ($hostarch eq "s390x");
1414

15-
$tmpf = new File::Temp( UNLINK => 1 );
15+
#$tmpf = new File::Temp( UNLINK => 1 );
1616
$binary = $ENV{"BINARY"};
1717

1818
$makefile = shift(@ARGV);
@@ -31,12 +31,25 @@ if ($?) {
3131

3232
$cross_suffix = "";
3333

34-
if (dirname($compiler_name) ne ".") {
35-
$cross_suffix .= dirname($compiler_name) . "/";
36-
}
34+
eval "use File::Basename";
35+
if ($@){
36+
warn "could not load PERL module File::Basename, emulating its functionality";
37+
my $dirnam = substr($compiler_name, 0, rindex($compiler_name, "/")-1 );
38+
if ($dirnam ne ".") {
39+
$cross_suffix .= $dirnam . "/";
40+
}
41+
my $basnam = substr($compiler_name, rindex($compiler_name,"/")+1, length($compiler_name)-rindex($compiler_name,"/")-1);
42+
if ($basnam =~ /([^\s]*-)(.*)/) {
43+
$cross_suffix .= $1;
44+
}
45+
} else {
46+
if (dirname($compiler_name) ne ".") {
47+
$cross_suffix .= dirname($compiler_name) . "/";
48+
}
3749

38-
if (basename($compiler_name) =~ /([^\s]*-)(.*)/) {
39-
$cross_suffix .= $1;
50+
if (basename($compiler_name) =~ /([^\s]*-)(.*)/) {
51+
$cross_suffix .= $1;
52+
}
4053
}
4154

4255
$compiler = "";
@@ -171,20 +184,26 @@ if ($?) {
171184

172185
$have_msa = 0;
173186
if (($architecture eq "mips") || ($architecture eq "mips64")) {
174-
$code = '"addvi.b $w0, $w1, 1"';
175-
$msa_flags = "-mmsa -mfp64 -msched-weight -mload-store-pairs";
176-
print $tmpf "#include <msa.h>\n\n";
177-
print $tmpf "void main(void){ __asm__ volatile($code); }\n";
178-
179-
$args = "$msa_flags -o $tmpf.o -x c $tmpf";
180-
my @cmd = ("$compiler_name $args");
181-
system(@cmd) == 0;
182-
if ($? != 0) {
183-
$have_msa = 0;
187+
eval "use File::Temp qw(tempfile)";
188+
if ($@){
189+
warn "could not load PERL module File::Temp, so could not check MSA capatibility";
184190
} else {
185-
$have_msa = 1;
191+
$tmpf = new File::Temp( UNLINK => 1 );
192+
$code = '"addvi.b $w0, $w1, 1"';
193+
$msa_flags = "-mmsa -mfp64 -msched-weight -mload-store-pairs";
194+
print $tmpf "#include <msa.h>\n\n";
195+
print $tmpf "void main(void){ __asm__ volatile($code); }\n";
196+
197+
$args = "$msa_flags -o $tmpf.o -x c $tmpf";
198+
my @cmd = ("$compiler_name $args");
199+
system(@cmd) == 0;
200+
if ($? != 0) {
201+
$have_msa = 0;
202+
} else {
203+
$have_msa = 1;
204+
}
205+
unlink("$tmpf.o");
186206
}
187-
unlink("$tmpf.o");
188207
}
189208

190209
$architecture = x86 if ($data =~ /ARCH_X86/);
@@ -204,17 +223,25 @@ $binformat = bin64 if ($data =~ /BINARY_64/);
204223

205224
$no_avx512= 0;
206225
if (($architecture eq "x86") || ($architecture eq "x86_64")) {
207-
$code = '"vbroadcastss -4 * 4(%rsi), %zmm2"';
208-
print $tmpf "#include <immintrin.h>\n\nint main(void){ __asm__ volatile($code); }\n";
209-
$args = " -march=skylake-avx512 -o $tmpf.o -x c $tmpf";
210-
my @cmd = ("$compiler_name $args >/dev/null 2>/dev/null");
211-
system(@cmd) == 0;
212-
if ($? != 0) {
213-
$no_avx512 = 1;
214-
} else {
226+
eval "use File::Temp qw(tempfile)";
227+
if ($@){
228+
warn "could not load PERL module File::Temp, so could not check compiler compatibility with AVX512";
215229
$no_avx512 = 0;
230+
} else {
231+
# $tmpf = new File::Temp( UNLINK => 1 );
232+
($fh,$tmpf) = tempfile( UNLINK => 1 );
233+
$code = '"vbroadcastss -4 * 4(%rsi), %zmm2"';
234+
print $tmpf "#include <immintrin.h>\n\nint main(void){ __asm__ volatile($code); }\n";
235+
$args = " -march=skylake-avx512 -o $tmpf.o -x c $tmpf";
236+
my @cmd = ("$compiler_name $args >/dev/null 2>/dev/null");
237+
system(@cmd) == 0;
238+
if ($? != 0) {
239+
$no_avx512 = 1;
240+
} else {
241+
$no_avx512 = 0;
242+
}
243+
unlink("tmpf.o");
216244
}
217-
unlink("tmpf.o");
218245
}
219246

220247
$data = `$compiler_name -S ctest1.c && grep globl ctest1.s | head -n 1 && rm -f ctest1.s`;

0 commit comments

Comments
 (0)