11f5207b7SJohn Levon#!/usr/bin/perl -w 21f5207b7SJohn Levon# ----------------------------------------------------------------------------- 31f5207b7SJohn Levon 4*c85f09ccSJohn Levonuse strict; 5*c85f09ccSJohn Levonuse warnings; 6*c85f09ccSJohn Levon 71f5207b7SJohn Levonmy $cc = $ENV{'REAL_CC'} || 'cc'; 81f5207b7SJohn Levonmy $check = $ENV{'CHECK'} || 'sparse'; 91f5207b7SJohn Levonmy $ccom = $cc; 101f5207b7SJohn Levon 111f5207b7SJohn Levonmy $m32 = 0; 121f5207b7SJohn Levonmy $m64 = 0; 131f5207b7SJohn Levonmy $has_specs = 0; 141f5207b7SJohn Levonmy $gendeps = 0; 151f5207b7SJohn Levonmy $do_check = 0; 161f5207b7SJohn Levonmy $do_compile = 1; 171f5207b7SJohn Levonmy $gcc_base_dir; 181f5207b7SJohn Levonmy $multiarch_dir; 191f5207b7SJohn Levonmy $verbose = 0; 20*c85f09ccSJohn Levonmy $nargs = 0; 211f5207b7SJohn Levon 221f5207b7SJohn Levonwhile (@ARGV) { 231f5207b7SJohn Levon $_ = shift(@ARGV); 24*c85f09ccSJohn Levon 25*c85f09ccSJohn Levon if ($nargs) { 26*c85f09ccSJohn Levon $nargs--; 27*c85f09ccSJohn Levon goto add_option; 28*c85f09ccSJohn Levon } 29*c85f09ccSJohn Levon 301f5207b7SJohn Levon # Look for a .c file. We don't want to run the checker on .o or .so files 31*c85f09ccSJohn Levon # in the link run. 321f5207b7SJohn Levon $do_check = 1 if /^[^-].*\.c$/; 331f5207b7SJohn Levon 341f5207b7SJohn Levon # Ditto for stdin. 351f5207b7SJohn Levon $do_check = 1 if $_ eq '-'; 361f5207b7SJohn Levon 37*c85f09ccSJohn Levon if (/^-(o|MF|MT|MQ)$/) { 38*c85f09ccSJohn Levon # Need to be checked explicitly since otherwise 39*c85f09ccSJohn Levon # the argument would be processed as a 40*c85f09ccSJohn Levon # (non-existant) source file or as an option. 41*c85f09ccSJohn Levon die ("$0: missing argument for $_") if !@ARGV; 42*c85f09ccSJohn Levon $nargs = 1; 43*c85f09ccSJohn Levon } 44*c85f09ccSJohn Levon 45*c85f09ccSJohn Levon # Ignore the extension if '-x c' is given. 46*c85f09ccSJohn Levon if ($_ eq '-x') { 47*c85f09ccSJohn Levon die ("$0: missing argument for $_") if !@ARGV; 48*c85f09ccSJohn Levon die ("$0: invalid argument for $_") if $ARGV[0] ne 'c'; 49*c85f09ccSJohn Levon $do_check = 1; 50*c85f09ccSJohn Levon $nargs = 1; 51*c85f09ccSJohn Levon } 52*c85f09ccSJohn Levon 531f5207b7SJohn Levon $m32 = 1 if /^-m32$/; 541f5207b7SJohn Levon $m64 = 1 if /^-m64$/; 55*c85f09ccSJohn Levon $gendeps = 1 if /^-(M|MM|MD|MMD)$/; 561f5207b7SJohn Levon 571f5207b7SJohn Levon if (/^-target=(.*)$/) { 581f5207b7SJohn Levon $check .= &add_specs ($1); 591f5207b7SJohn Levon $has_specs = 1; 601f5207b7SJohn Levon next; 611f5207b7SJohn Levon } 621f5207b7SJohn Levon 631f5207b7SJohn Levon if ($_ eq '-no-compile') { 641f5207b7SJohn Levon $do_compile = 0; 651f5207b7SJohn Levon next; 661f5207b7SJohn Levon } 671f5207b7SJohn Levon 681f5207b7SJohn Levon if (/^-gcc-base-dir$/) { 691f5207b7SJohn Levon $gcc_base_dir = shift @ARGV; 701f5207b7SJohn Levon die ("$0: missing argument for -gcc-base-dir option") if !$gcc_base_dir; 711f5207b7SJohn Levon next; 721f5207b7SJohn Levon } 731f5207b7SJohn Levon 741f5207b7SJohn Levon if (/^-multiarch-dir$/) { 751f5207b7SJohn Levon $multiarch_dir = shift @ARGV; 761f5207b7SJohn Levon die ("$0: missing argument for -multiarch-dir option") if !$multiarch_dir; 771f5207b7SJohn Levon next; 781f5207b7SJohn Levon } 791f5207b7SJohn Levon 801f5207b7SJohn Levon # If someone adds "-E", don't pre-process twice. 811f5207b7SJohn Levon $do_compile = 0 if $_ eq '-E'; 821f5207b7SJohn Levon 831f5207b7SJohn Levon $verbose = 1 if $_ eq '-v'; 841f5207b7SJohn Levon 85*c85f09ccSJohn Levonadd_option: 861f5207b7SJohn Levon my $this_arg = ' ' . "e_arg ($_); 871f5207b7SJohn Levon $cc .= $this_arg unless &check_only_option ($_); 881f5207b7SJohn Levon $check .= $this_arg; 891f5207b7SJohn Levon} 901f5207b7SJohn Levon 911f5207b7SJohn Levonif ($gendeps) { 921f5207b7SJohn Levon $do_compile = 1; 931f5207b7SJohn Levon $do_check = 0; 941f5207b7SJohn Levon} 951f5207b7SJohn Levon 961f5207b7SJohn Levonif ($do_check) { 971f5207b7SJohn Levon if (!$has_specs) { 981f5207b7SJohn Levon $check .= &add_specs ('host_arch_specs'); 991f5207b7SJohn Levon $check .= &add_specs ('host_os_specs'); 1001f5207b7SJohn Levon } 1011f5207b7SJohn Levon 1021f5207b7SJohn Levon $gcc_base_dir = qx($ccom -print-file-name=) if !$gcc_base_dir; 1031f5207b7SJohn Levon chomp($gcc_base_dir); # possibly remove '\n' from compiler 1041f5207b7SJohn Levon $check .= " -gcc-base-dir " . $gcc_base_dir if $gcc_base_dir; 1051f5207b7SJohn Levon 1061f5207b7SJohn Levon $multiarch_dir = qx($ccom -print-multiarch) if ! defined $multiarch_dir; 1071f5207b7SJohn Levon chomp($multiarch_dir); # possibly remove '\n' from compiler 1081f5207b7SJohn Levon $check .= " -multiarch-dir " . $multiarch_dir if $multiarch_dir; 1091f5207b7SJohn Levon 1101f5207b7SJohn Levon print "$check\n" if $verbose; 1111f5207b7SJohn Levon if ($do_compile) { 1121f5207b7SJohn Levon system ($check); 1131f5207b7SJohn Levon } else { 1141f5207b7SJohn Levon exec ($check); 1151f5207b7SJohn Levon } 1161f5207b7SJohn Levon} 1171f5207b7SJohn Levon 1181f5207b7SJohn Levonif ($do_compile) { 1191f5207b7SJohn Levon print "$cc\n" if $verbose; 1201f5207b7SJohn Levon exec ($cc); 1211f5207b7SJohn Levon} 1221f5207b7SJohn Levon 1231f5207b7SJohn Levonexit 0; 1241f5207b7SJohn Levon 1251f5207b7SJohn Levon# ----------------------------------------------------------------------------- 1261f5207b7SJohn Levon# Check if an option is for "check" only. 1271f5207b7SJohn Levon 1281f5207b7SJohn Levonsub check_only_option { 1291f5207b7SJohn Levon my ($arg) = @_; 130*c85f09ccSJohn Levon return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|constant-suffix|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|external-function-has-definition|init-cstring|memcpy-max-count|non-pointer-null|old-initializer|one-bit-signed-bitfield|override-init-all|paren-string|ptr-subtraction-blows|return-void|sizeof-bool|sparse-all|sparse-error|transparent-union|typesign|undef|unknown-attribute)$/; 1311f5207b7SJohn Levon return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/; 132*c85f09ccSJohn Levon return 1 if $arg =~ /^-f(dump-ir|memcpy-max-count|diagnostic-prefix)(=\S*)?$/; 133*c85f09ccSJohn Levon return 1 if $arg =~ /^-f(mem2reg|optim)(-enable|-disable|=last)?$/; 1341f5207b7SJohn Levon return 0; 1351f5207b7SJohn Levon} 1361f5207b7SJohn Levon 1371f5207b7SJohn Levon# ----------------------------------------------------------------------------- 1381f5207b7SJohn Levon# Simple arg-quoting function. Just adds backslashes when needed. 1391f5207b7SJohn Levon 1401f5207b7SJohn Levonsub quote_arg { 1411f5207b7SJohn Levon my ($arg) = @_; 1421f5207b7SJohn Levon return "''" if $arg eq ''; 1431f5207b7SJohn Levon return join ('', 1441f5207b7SJohn Levon map { 1451f5207b7SJohn Levon m|^[-a-zA-Z0-9._/,=]+$| ? $_ : "\\" . $_; 1461f5207b7SJohn Levon } (split (//, $arg))); 1471f5207b7SJohn Levon} 1481f5207b7SJohn Levon 1491f5207b7SJohn Levon# ----------------------------------------------------------------------------- 1501f5207b7SJohn Levon 1511f5207b7SJohn Levonsub integer_types { 1521f5207b7SJohn Levon my ($char,@dummy) = @_; 1531f5207b7SJohn Levon 1541f5207b7SJohn Levon my %pow2m1 = 1551f5207b7SJohn Levon (8 => '127', 1561f5207b7SJohn Levon 16 => '32767', 1571f5207b7SJohn Levon 32 => '2147483647', 1581f5207b7SJohn Levon 64 => '9223372036854775807', 1591f5207b7SJohn Levon 128 => '170141183460469231731687303715884105727', 1601f5207b7SJohn Levon ); 1611f5207b7SJohn Levon my @types = (['SCHAR',''], ['SHRT',''], ['INT',''], ['LONG','L'], ['LONG_LONG','LL'], ['LONG_LONG_LONG','LLL']); 1621f5207b7SJohn Levon 1631f5207b7SJohn Levon my $result = " -D__CHAR_BIT__=$char"; 1641f5207b7SJohn Levon while (@types && @_) { 1651f5207b7SJohn Levon my $bits = shift @_; 1661f5207b7SJohn Levon my ($name,$suffix) = @{ shift @types }; 1671f5207b7SJohn Levon die "$0: weird number of bits." unless exists $pow2m1{$bits}; 1681f5207b7SJohn Levon $result .= " -D__${name}_MAX__=" . $pow2m1{$bits} . $suffix; 1691f5207b7SJohn Levon } 1701f5207b7SJohn Levon return $result; 1711f5207b7SJohn Levon} 1721f5207b7SJohn Levon 1731f5207b7SJohn Levon# ----------------------------------------------------------------------------- 1741f5207b7SJohn Levon 1751f5207b7SJohn Levonsub float_types { 1761f5207b7SJohn Levon my ($has_inf,$has_qnan,$dec_dig,@bitsizes) = @_; 1771f5207b7SJohn Levon my $result = " -D__FLT_RADIX__=2"; 1781f5207b7SJohn Levon $result .= " -D__FINITE_MATH_ONLY__=" . ($has_inf || $has_qnan ? '0' : '1'); 1791f5207b7SJohn Levon $result .= " -D__DECIMAL_DIG__=$dec_dig"; 1801f5207b7SJohn Levon 1811f5207b7SJohn Levon my %constants = 1821f5207b7SJohn Levon (24 => 1831f5207b7SJohn Levon { 1841f5207b7SJohn Levon 'MIN' => '1.17549435e-38', 1851f5207b7SJohn Levon 'MAX' => '3.40282347e+38', 1861f5207b7SJohn Levon 'EPSILON' => '1.19209290e-7', 1871f5207b7SJohn Levon 'DENORM_MIN' => '1.40129846e-45', 1881f5207b7SJohn Levon }, 1891f5207b7SJohn Levon 53 => 1901f5207b7SJohn Levon { 1911f5207b7SJohn Levon 'MIN' => '2.2250738585072014e-308', 1921f5207b7SJohn Levon 'MAX' => '1.7976931348623157e+308', 1931f5207b7SJohn Levon 'EPSILON' => '2.2204460492503131e-16', 1941f5207b7SJohn Levon 'DENORM_MIN' => '4.9406564584124654e-324', 1951f5207b7SJohn Levon }, 1961f5207b7SJohn Levon 64 => 1971f5207b7SJohn Levon { 1981f5207b7SJohn Levon 'MIN' => '3.36210314311209350626e-4932', 1991f5207b7SJohn Levon 'MAX' => '1.18973149535723176502e+4932', 2001f5207b7SJohn Levon 'EPSILON' => '1.08420217248550443401e-19', 2011f5207b7SJohn Levon 'DENORM_MIN' => '3.64519953188247460253e-4951', 2021f5207b7SJohn Levon }, 2031f5207b7SJohn Levon 113 => 2041f5207b7SJohn Levon { 2051f5207b7SJohn Levon 'MIN' => '3.36210314311209350626267781732175260e-4932', 2061f5207b7SJohn Levon 'MAX' => '1.18973149535723176508575932662800702e+4932', 2071f5207b7SJohn Levon 'EPSILON' => '1.92592994438723585305597794258492732e-34', 2081f5207b7SJohn Levon 'DENORM_MIN' => '6.47517511943802511092443895822764655e-4966', 2091f5207b7SJohn Levon }, 2101f5207b7SJohn Levon ); 2111f5207b7SJohn Levon 2121f5207b7SJohn Levon my @types = (['FLT','F'], ['DBL',''], ['LDBL','L']); 2131f5207b7SJohn Levon while (@types) { 2141f5207b7SJohn Levon my ($mant_bits,$exp_bits) = @{ shift @bitsizes }; 2151f5207b7SJohn Levon my ($name,$suffix) = @{ shift @types }; 2161f5207b7SJohn Levon 2171f5207b7SJohn Levon my $h = $constants{$mant_bits}; 2181f5207b7SJohn Levon die "$0: weird number of mantissa bits." unless $h; 2191f5207b7SJohn Levon 2201f5207b7SJohn Levon my $mant_dig = int (($mant_bits - 1) * log (2) / log (10)); 2211f5207b7SJohn Levon my $max_exp = 1 << ($exp_bits - 1); 2221f5207b7SJohn Levon my $min_exp = 3 - $max_exp; 2231f5207b7SJohn Levon my $max_10_exp = int ($max_exp * log (2) / log (10)); 2241f5207b7SJohn Levon my $min_10_exp = -int (-$min_exp * log (2) / log (10)); 2251f5207b7SJohn Levon 2261f5207b7SJohn Levon $result .= " -D__${name}_MANT_DIG__=$mant_bits"; 2271f5207b7SJohn Levon $result .= " -D__${name}_DIG__=$mant_dig"; 2281f5207b7SJohn Levon $result .= " -D__${name}_MIN_EXP__='($min_exp)'"; 2291f5207b7SJohn Levon $result .= " -D__${name}_MAX_EXP__=$max_exp"; 2301f5207b7SJohn Levon $result .= " -D__${name}_MIN_10_EXP__='($min_10_exp)'"; 2311f5207b7SJohn Levon $result .= " -D__${name}_MAX_10_EXP__=$max_10_exp"; 2321f5207b7SJohn Levon $result .= " -D__${name}_HAS_INFINITY__=" . ($has_inf ? '1' : '0'); 2331f5207b7SJohn Levon $result .= " -D__${name}_HAS_QUIET_NAN__=" . ($has_qnan ? '1' : '0');; 2341f5207b7SJohn Levon 2351f5207b7SJohn Levon foreach my $inf (sort keys %$h) { 2361f5207b7SJohn Levon $result .= " -D__${name}_${inf}__=" . $h->{$inf} . $suffix; 2371f5207b7SJohn Levon } 2381f5207b7SJohn Levon } 2391f5207b7SJohn Levon return $result; 2401f5207b7SJohn Levon} 2411f5207b7SJohn Levon 2421f5207b7SJohn Levon# ----------------------------------------------------------------------------- 2431f5207b7SJohn Levon 2441f5207b7SJohn Levonsub define_size_t { 2451f5207b7SJohn Levon my ($text) = @_; 2461f5207b7SJohn Levon # We have to undef in order to override check's internal definition. 2471f5207b7SJohn Levon return ' -U__SIZE_TYPE__ ' . "e_arg ("-D__SIZE_TYPE__=$text"); 2481f5207b7SJohn Levon} 2491f5207b7SJohn Levon 2501f5207b7SJohn Levon# ----------------------------------------------------------------------------- 2511f5207b7SJohn Levon 2521f5207b7SJohn Levonsub add_specs { 2531f5207b7SJohn Levon my ($spec) = @_; 2541f5207b7SJohn Levon if ($spec eq 'sunos') { 2551f5207b7SJohn Levon return &add_specs ('unix') . 2561f5207b7SJohn Levon ' -D__sun__=1 -D__sun=1 -Dsun=1' . 2571f5207b7SJohn Levon ' -D__svr4__=1 -DSVR4=1' . 2581f5207b7SJohn Levon ' -D__STDC__=0' . 2591f5207b7SJohn Levon ' -D_REENTRANT' . 2601f5207b7SJohn Levon ' -D_SOLARIS_THREADS' . 2611f5207b7SJohn Levon ' -DNULL="((void *)0)"'; 2621f5207b7SJohn Levon } elsif ($spec eq 'linux') { 2631f5207b7SJohn Levon return &add_specs ('unix') . 2641f5207b7SJohn Levon ' -D__linux__=1 -D__linux=1 -Dlinux=linux'; 2651f5207b7SJohn Levon } elsif ($spec eq 'gnu/kfreebsd') { 2661f5207b7SJohn Levon return &add_specs ('unix') . 2671f5207b7SJohn Levon ' -D__FreeBSD_kernel__=1'; 2681f5207b7SJohn Levon } elsif ($spec eq 'openbsd') { 2691f5207b7SJohn Levon return &add_specs ('unix') . 2701f5207b7SJohn Levon ' -D__OpenBSD__=1'; 271*c85f09ccSJohn Levon } elsif ($spec eq 'freebsd') { 272*c85f09ccSJohn Levon return &add_specs ('unix') . 273*c85f09ccSJohn Levon ' -D__FreeBSD__=1'; 274*c85f09ccSJohn Levon } elsif ($spec eq 'netbsd') { 275*c85f09ccSJohn Levon return &add_specs ('unix') . 276*c85f09ccSJohn Levon ' -D__NetBSD__=1'; 2771f5207b7SJohn Levon } elsif ($spec eq 'darwin') { 2781f5207b7SJohn Levon return 279*c85f09ccSJohn Levon ' -D__APPLE__=1 -D__APPLE_CC__=1 -D__MACH__=1'; 280*c85f09ccSJohn Levon } elsif ($spec eq 'gnu') { # Hurd 281*c85f09ccSJohn Levon return &add_specs ('unix') . # So, GNU is Unix, uh? 282*c85f09ccSJohn Levon ' -D__GNU__=1 -D__gnu_hurd__=1 -D__MACH__=1'; 2831f5207b7SJohn Levon } elsif ($spec eq 'unix') { 2841f5207b7SJohn Levon return ' -Dunix=1 -D__unix=1 -D__unix__=1'; 2851f5207b7SJohn Levon } elsif ( $spec =~ /^cygwin/) { 2861f5207b7SJohn Levon return &add_specs ('unix') . 2871f5207b7SJohn Levon ' -D__CYGWIN__=1 -D__CYGWIN32__=1' . 2881f5207b7SJohn Levon " -D'_cdecl=__attribute__((__cdecl__))'" . 2891f5207b7SJohn Levon " -D'__cdecl=__attribute__((__cdecl__))'" . 2901f5207b7SJohn Levon " -D'_stdcall=__attribute__((__stdcall__))'" . 2911f5207b7SJohn Levon " -D'__stdcall=__attribute__((__stdcall__))'" . 2921f5207b7SJohn Levon " -D'_fastcall=__attribute__((__fastcall__))'" . 2931f5207b7SJohn Levon " -D'__fastcall=__attribute__((__fastcall__))'" . 2941f5207b7SJohn Levon " -D'__declspec(x)=__attribute__((x))'"; 295*c85f09ccSJohn Levon } elsif ($spec eq 'i386') { 296*c85f09ccSJohn Levon return ( 297*c85f09ccSJohn Levon &float_types (1, 1, 21, [24,8], [53,11], [64,15])); 2981f5207b7SJohn Levon } elsif ($spec eq 'sparc') { 299*c85f09ccSJohn Levon return ( 3001f5207b7SJohn Levon &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) . 3011f5207b7SJohn Levon &float_types (1, 1, 33, [24,8], [53,11], [113,15]) . 3021f5207b7SJohn Levon &define_size_t ($m64 ? "long unsigned int" : "unsigned int") . 3031f5207b7SJohn Levon ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4')); 3041f5207b7SJohn Levon } elsif ($spec eq 'sparc64') { 305*c85f09ccSJohn Levon return ( 3061f5207b7SJohn Levon &integer_types (8, 16, 32, 64, 64, 128) . 3071f5207b7SJohn Levon &float_types (1, 1, 33, [24,8], [53,11], [113,15]) . 3081f5207b7SJohn Levon &define_size_t ("long unsigned int") . 3091f5207b7SJohn Levon ' -D__SIZEOF_POINTER__=8'); 3101f5207b7SJohn Levon } elsif ($spec eq 'x86_64') { 311*c85f09ccSJohn Levon return &float_types (1, 1, 33, [24,8], [53,11], [113,15]); 3121f5207b7SJohn Levon } elsif ($spec eq 'ppc') { 313*c85f09ccSJohn Levon return (' -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' . 3141f5207b7SJohn Levon &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) . 3151f5207b7SJohn Levon &float_types (1, 1, 21, [24,8], [53,11], [113,15]) . 3161f5207b7SJohn Levon &define_size_t ($m64 ? "long unsigned int" : "unsigned int") . 3171f5207b7SJohn Levon ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4')); 3181f5207b7SJohn Levon } elsif ($spec eq 'ppc64') { 319*c85f09ccSJohn Levon return (' -D_STRING_ARCH_unaligned=1 -m64' . 3201f5207b7SJohn Levon &float_types (1, 1, 21, [24,8], [53,11], [113,15])); 321*c85f09ccSJohn Levon } elsif ($spec eq 'ppc64+be') { 322*c85f09ccSJohn Levon return &add_specs ('ppc64') . ' -mbig-endian -D_CALL_ELF=1'; 323*c85f09ccSJohn Levon } elsif ($spec eq 'ppc64+le') { 324*c85f09ccSJohn Levon return &add_specs ('ppc64') . ' -mlittle-endian -D_CALL_ELF=2'; 3251f5207b7SJohn Levon } elsif ($spec eq 's390x') { 326*c85f09ccSJohn Levon return (' -D_BIG_ENDIAN' . 3271f5207b7SJohn Levon &integer_types (8, 16, 32, $m64 ? 64 : 32, 64) . 3281f5207b7SJohn Levon &float_types (1, 1, 36, [24,8], [53,11], [113,15]) . 3291f5207b7SJohn Levon &define_size_t ("long unsigned int") . 3301f5207b7SJohn Levon ' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4')); 3311f5207b7SJohn Levon } elsif ($spec eq 'arm') { 332*c85f09ccSJohn Levon return (' -m32' . 3331f5207b7SJohn Levon &float_types (1, 1, 36, [24,8], [53,11], [53, 11])); 334*c85f09ccSJohn Levon } elsif ($spec eq 'arm+hf') { 335*c85f09ccSJohn Levon return &add_specs ('arm') . ' -D__ARM_PCS_VFP=1'; 3361f5207b7SJohn Levon } elsif ($spec eq 'aarch64') { 337*c85f09ccSJohn Levon return (' -m64' . 3381f5207b7SJohn Levon &float_types (1, 1, 36, [24,8], [53,11], [113,15])); 3391f5207b7SJohn Levon } elsif ($spec eq 'host_os_specs') { 3401f5207b7SJohn Levon my $os = `uname -s`; 3411f5207b7SJohn Levon chomp $os; 3421f5207b7SJohn Levon return &add_specs (lc $os); 3431f5207b7SJohn Levon } elsif ($spec eq 'host_arch_specs') { 344*c85f09ccSJohn Levon my $gccmachine; 345*c85f09ccSJohn Levon my $arch; 346*c85f09ccSJohn Levon 347*c85f09ccSJohn Levon $gccmachine = `$ccom -dumpmachine`; 348*c85f09ccSJohn Levon chomp $gccmachine; 349*c85f09ccSJohn Levon 350*c85f09ccSJohn Levon if ($gccmachine =~ '^aarch64-') { 351*c85f09ccSJohn Levon return &add_specs ('aarch64'); 352*c85f09ccSJohn Levon } elsif ($gccmachine =~ '^arm-.*eabihf$') { 353*c85f09ccSJohn Levon return &add_specs ('arm+hf'); 354*c85f09ccSJohn Levon } elsif ($gccmachine =~ '^arm-') { 355*c85f09ccSJohn Levon return &add_specs ('arm'); 356*c85f09ccSJohn Levon } elsif ($gccmachine =~ '^i[23456]86-') { 357*c85f09ccSJohn Levon return &add_specs ('i386'); 358*c85f09ccSJohn Levon } elsif ($gccmachine =~ '^(powerpc|ppc)64le-') { 359*c85f09ccSJohn Levon return &add_specs ('ppc64+le'); 360*c85f09ccSJohn Levon } elsif ($gccmachine =~ '^s390x-') { 361*c85f09ccSJohn Levon return &add_specs ('s390x'); 362*c85f09ccSJohn Levon } elsif ($gccmachine eq 'x86_64-linux-gnux32') { 363*c85f09ccSJohn Levon return &add_specs ('x86_64') . ' -mx32'; 364*c85f09ccSJohn Levon } elsif ($gccmachine =~ '^x86_64-') { 365*c85f09ccSJohn Levon return &add_specs ('x86_64'); 366*c85f09ccSJohn Levon } 367*c85f09ccSJohn Levon 368*c85f09ccSJohn Levon # fall back to uname -m to determine the specifics. 369*c85f09ccSJohn Levon # Note: this is only meaningful when using natively 370*c85f09ccSJohn Levon # since information about the host is used to 371*c85f09ccSJohn Levon # guess characteristics of the target. 372*c85f09ccSJohn Levon 373*c85f09ccSJohn Levon $arch = `uname -m`; 3741f5207b7SJohn Levon chomp $arch; 3751f5207b7SJohn Levon if ($arch =~ /^(i.?86|athlon)$/i) { 376*c85f09ccSJohn Levon return &add_specs ('i386'); 3771f5207b7SJohn Levon } elsif ($arch =~ /^(sun4u)$/i) { 3781f5207b7SJohn Levon return &add_specs ('sparc'); 3791f5207b7SJohn Levon } elsif ($arch =~ /^(x86_64)$/i) { 3801f5207b7SJohn Levon return &add_specs ('x86_64'); 3811f5207b7SJohn Levon } elsif ($arch =~ /^(ppc)$/i) { 3821f5207b7SJohn Levon return &add_specs ('ppc'); 3831f5207b7SJohn Levon } elsif ($arch =~ /^(ppc64)$/i) { 384*c85f09ccSJohn Levon return &add_specs ('ppc64+be'); 3851f5207b7SJohn Levon } elsif ($arch =~ /^(ppc64le)$/i) { 386*c85f09ccSJohn Levon return &add_specs ('ppc64+le'); 3871f5207b7SJohn Levon } elsif ($arch =~ /^(s390x)$/i) { 3881f5207b7SJohn Levon return &add_specs ('s390x'); 3891f5207b7SJohn Levon } elsif ($arch =~ /^(sparc64)$/i) { 3901f5207b7SJohn Levon return &add_specs ('sparc64'); 3911f5207b7SJohn Levon } elsif ($arch =~ /^arm(?:v[78]l)?$/i) { 3921f5207b7SJohn Levon return &add_specs ('arm'); 3931f5207b7SJohn Levon } elsif ($arch =~ /^(aarch64)$/i) { 3941f5207b7SJohn Levon return &add_specs ('aarch64'); 3951f5207b7SJohn Levon } 3961f5207b7SJohn Levon } else { 3971f5207b7SJohn Levon die "$0: invalid specs: $spec\n"; 3981f5207b7SJohn Levon } 3991f5207b7SJohn Levon} 4001f5207b7SJohn Levon 4011f5207b7SJohn Levon# ----------------------------------------------------------------------------- 402