xref: /illumos-gate/usr/src/tools/smatch/src/cgcc (revision 1f5207b7)
1*1f5207b7SJohn Levon#!/usr/bin/perl -w
2*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
3*1f5207b7SJohn Levon
4*1f5207b7SJohn Levonmy $cc = $ENV{'REAL_CC'} || 'cc';
5*1f5207b7SJohn Levonmy $check = $ENV{'CHECK'} || 'sparse';
6*1f5207b7SJohn Levonmy $ccom = $cc;
7*1f5207b7SJohn Levon
8*1f5207b7SJohn Levonmy $m32 = 0;
9*1f5207b7SJohn Levonmy $m64 = 0;
10*1f5207b7SJohn Levonmy $has_specs = 0;
11*1f5207b7SJohn Levonmy $gendeps = 0;
12*1f5207b7SJohn Levonmy $do_check = 0;
13*1f5207b7SJohn Levonmy $do_compile = 1;
14*1f5207b7SJohn Levonmy $gcc_base_dir;
15*1f5207b7SJohn Levonmy $multiarch_dir;
16*1f5207b7SJohn Levonmy $verbose = 0;
17*1f5207b7SJohn Levon
18*1f5207b7SJohn Levonwhile (@ARGV) {
19*1f5207b7SJohn Levon    $_ = shift(@ARGV);
20*1f5207b7SJohn Levon    # Look for a .c file.  We don't want to run the checker on .o or .so files
21*1f5207b7SJohn Levon    # in the link run.  (This simplistic check knows nothing about options
22*1f5207b7SJohn Levon    # with arguments, but it seems to do the job.)
23*1f5207b7SJohn Levon    $do_check = 1 if /^[^-].*\.c$/;
24*1f5207b7SJohn Levon
25*1f5207b7SJohn Levon    # Ditto for stdin.
26*1f5207b7SJohn Levon    $do_check = 1 if $_ eq '-';
27*1f5207b7SJohn Levon
28*1f5207b7SJohn Levon    $m32 = 1 if /^-m32$/;
29*1f5207b7SJohn Levon    $m64 = 1 if /^-m64$/;
30*1f5207b7SJohn Levon    $gendeps = 1 if /^-M$/;
31*1f5207b7SJohn Levon
32*1f5207b7SJohn Levon    if (/^-target=(.*)$/) {
33*1f5207b7SJohn Levon	$check .= &add_specs ($1);
34*1f5207b7SJohn Levon	$has_specs = 1;
35*1f5207b7SJohn Levon	next;
36*1f5207b7SJohn Levon    }
37*1f5207b7SJohn Levon
38*1f5207b7SJohn Levon    if ($_ eq '-no-compile') {
39*1f5207b7SJohn Levon	$do_compile = 0;
40*1f5207b7SJohn Levon	next;
41*1f5207b7SJohn Levon    }
42*1f5207b7SJohn Levon
43*1f5207b7SJohn Levon    if (/^-gcc-base-dir$/) {
44*1f5207b7SJohn Levon        $gcc_base_dir = shift @ARGV;
45*1f5207b7SJohn Levon        die ("$0: missing argument for -gcc-base-dir option") if !$gcc_base_dir;
46*1f5207b7SJohn Levon        next;
47*1f5207b7SJohn Levon    }
48*1f5207b7SJohn Levon
49*1f5207b7SJohn Levon    if (/^-multiarch-dir$/) {
50*1f5207b7SJohn Levon        $multiarch_dir = shift @ARGV;
51*1f5207b7SJohn Levon        die ("$0: missing argument for -multiarch-dir option") if !$multiarch_dir;
52*1f5207b7SJohn Levon        next;
53*1f5207b7SJohn Levon    }
54*1f5207b7SJohn Levon
55*1f5207b7SJohn Levon    # If someone adds "-E", don't pre-process twice.
56*1f5207b7SJohn Levon    $do_compile = 0 if $_ eq '-E';
57*1f5207b7SJohn Levon
58*1f5207b7SJohn Levon    $verbose = 1 if $_ eq '-v';
59*1f5207b7SJohn Levon
60*1f5207b7SJohn Levon    my $this_arg = ' ' . &quote_arg ($_);
61*1f5207b7SJohn Levon    $cc .= $this_arg unless &check_only_option ($_);
62*1f5207b7SJohn Levon    $check .= $this_arg;
63*1f5207b7SJohn Levon}
64*1f5207b7SJohn Levon
65*1f5207b7SJohn Levonif ($gendeps) {
66*1f5207b7SJohn Levon    $do_compile = 1;
67*1f5207b7SJohn Levon    $do_check = 0;
68*1f5207b7SJohn Levon}
69*1f5207b7SJohn Levon
70*1f5207b7SJohn Levonif ($do_check) {
71*1f5207b7SJohn Levon    if (!$has_specs) {
72*1f5207b7SJohn Levon	$check .= &add_specs ('host_arch_specs');
73*1f5207b7SJohn Levon	$check .= &add_specs ('host_os_specs');
74*1f5207b7SJohn Levon    }
75*1f5207b7SJohn Levon
76*1f5207b7SJohn Levon    $gcc_base_dir = qx($ccom -print-file-name=) if !$gcc_base_dir;
77*1f5207b7SJohn Levon    chomp($gcc_base_dir);  # possibly remove '\n' from compiler
78*1f5207b7SJohn Levon    $check .= " -gcc-base-dir " . $gcc_base_dir if $gcc_base_dir;
79*1f5207b7SJohn Levon
80*1f5207b7SJohn Levon    $multiarch_dir = qx($ccom -print-multiarch) if ! defined $multiarch_dir;
81*1f5207b7SJohn Levon    chomp($multiarch_dir);  # possibly remove '\n' from compiler
82*1f5207b7SJohn Levon    $check .= " -multiarch-dir " . $multiarch_dir if $multiarch_dir;
83*1f5207b7SJohn Levon
84*1f5207b7SJohn Levon    print "$check\n" if $verbose;
85*1f5207b7SJohn Levon    if ($do_compile) {
86*1f5207b7SJohn Levon	system ($check);
87*1f5207b7SJohn Levon    } else {
88*1f5207b7SJohn Levon	exec ($check);
89*1f5207b7SJohn Levon    }
90*1f5207b7SJohn Levon}
91*1f5207b7SJohn Levon
92*1f5207b7SJohn Levonif ($do_compile) {
93*1f5207b7SJohn Levon    print "$cc\n" if $verbose;
94*1f5207b7SJohn Levon    exec ($cc);
95*1f5207b7SJohn Levon}
96*1f5207b7SJohn Levon
97*1f5207b7SJohn Levonexit 0;
98*1f5207b7SJohn Levon
99*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
100*1f5207b7SJohn Levon# Check if an option is for "check" only.
101*1f5207b7SJohn Levon
102*1f5207b7SJohn Levonsub check_only_option {
103*1f5207b7SJohn Levon    my ($arg) = @_;
104*1f5207b7SJohn Levon    return 1 if $arg =~ /^-W(no-?)?(address-space|bitwise|cast-to-as|cast-truncate|context|decl|default-bitfield-sign|designated-init|do-while|enum-mismatch|external-function-has-definition|init-cstring|memcpy-max-count|non-ansi-function-declaration|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)$/;
105*1f5207b7SJohn Levon    return 1 if $arg =~ /^-v(no-?)?(entry|dead)$/;
106*1f5207b7SJohn Levon    return 1 if $arg =~ /^-f(dump-linearize|memcpy-max-count)(=\S*)?$/;
107*1f5207b7SJohn Levon    return 0;
108*1f5207b7SJohn Levon}
109*1f5207b7SJohn Levon
110*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
111*1f5207b7SJohn Levon# Simple arg-quoting function.  Just adds backslashes when needed.
112*1f5207b7SJohn Levon
113*1f5207b7SJohn Levonsub quote_arg {
114*1f5207b7SJohn Levon    my ($arg) = @_;
115*1f5207b7SJohn Levon    return "''" if $arg eq '';
116*1f5207b7SJohn Levon    return join ('',
117*1f5207b7SJohn Levon		 map {
118*1f5207b7SJohn Levon		     m|^[-a-zA-Z0-9._/,=]+$| ? $_ : "\\" . $_;
119*1f5207b7SJohn Levon		 } (split (//, $arg)));
120*1f5207b7SJohn Levon}
121*1f5207b7SJohn Levon
122*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
123*1f5207b7SJohn Levon
124*1f5207b7SJohn Levonsub integer_types {
125*1f5207b7SJohn Levon    my ($char,@dummy) = @_;
126*1f5207b7SJohn Levon
127*1f5207b7SJohn Levon    my %pow2m1 =
128*1f5207b7SJohn Levon	(8 => '127',
129*1f5207b7SJohn Levon	 16 => '32767',
130*1f5207b7SJohn Levon	 32 => '2147483647',
131*1f5207b7SJohn Levon	 64 => '9223372036854775807',
132*1f5207b7SJohn Levon	 128 => '170141183460469231731687303715884105727',
133*1f5207b7SJohn Levon	 );
134*1f5207b7SJohn Levon    my @types = (['SCHAR',''], ['SHRT',''], ['INT',''], ['LONG','L'], ['LONG_LONG','LL'], ['LONG_LONG_LONG','LLL']);
135*1f5207b7SJohn Levon
136*1f5207b7SJohn Levon    my $result = " -D__CHAR_BIT__=$char";
137*1f5207b7SJohn Levon    while (@types && @_) {
138*1f5207b7SJohn Levon	my $bits = shift @_;
139*1f5207b7SJohn Levon	my ($name,$suffix) = @{ shift @types };
140*1f5207b7SJohn Levon	die "$0: weird number of bits." unless exists $pow2m1{$bits};
141*1f5207b7SJohn Levon	$result .= " -D__${name}_MAX__=" . $pow2m1{$bits} . $suffix;
142*1f5207b7SJohn Levon    }
143*1f5207b7SJohn Levon    return $result;
144*1f5207b7SJohn Levon}
145*1f5207b7SJohn Levon
146*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
147*1f5207b7SJohn Levon
148*1f5207b7SJohn Levonsub float_types {
149*1f5207b7SJohn Levon    my ($has_inf,$has_qnan,$dec_dig,@bitsizes) = @_;
150*1f5207b7SJohn Levon    my $result = " -D__FLT_RADIX__=2";
151*1f5207b7SJohn Levon    $result .= " -D__FINITE_MATH_ONLY__=" . ($has_inf || $has_qnan ? '0' : '1');
152*1f5207b7SJohn Levon    $result .= " -D__DECIMAL_DIG__=$dec_dig";
153*1f5207b7SJohn Levon
154*1f5207b7SJohn Levon    my %constants =
155*1f5207b7SJohn Levon	(24 =>
156*1f5207b7SJohn Levon	 {
157*1f5207b7SJohn Levon	     'MIN' => '1.17549435e-38',
158*1f5207b7SJohn Levon	     'MAX' => '3.40282347e+38',
159*1f5207b7SJohn Levon	     'EPSILON' => '1.19209290e-7',
160*1f5207b7SJohn Levon	     'DENORM_MIN' => '1.40129846e-45',
161*1f5207b7SJohn Levon	 },
162*1f5207b7SJohn Levon	 53 =>
163*1f5207b7SJohn Levon	 {
164*1f5207b7SJohn Levon	     'MIN' => '2.2250738585072014e-308',
165*1f5207b7SJohn Levon	     'MAX' => '1.7976931348623157e+308',
166*1f5207b7SJohn Levon	     'EPSILON' => '2.2204460492503131e-16',
167*1f5207b7SJohn Levon	     'DENORM_MIN' => '4.9406564584124654e-324',
168*1f5207b7SJohn Levon	 },
169*1f5207b7SJohn Levon	 64 =>
170*1f5207b7SJohn Levon	 {
171*1f5207b7SJohn Levon	     'MIN' => '3.36210314311209350626e-4932',
172*1f5207b7SJohn Levon	     'MAX' => '1.18973149535723176502e+4932',
173*1f5207b7SJohn Levon	     'EPSILON' => '1.08420217248550443401e-19',
174*1f5207b7SJohn Levon	     'DENORM_MIN' => '3.64519953188247460253e-4951',
175*1f5207b7SJohn Levon	 },
176*1f5207b7SJohn Levon	 113 =>
177*1f5207b7SJohn Levon	 {
178*1f5207b7SJohn Levon	     'MIN' => '3.36210314311209350626267781732175260e-4932',
179*1f5207b7SJohn Levon	     'MAX' => '1.18973149535723176508575932662800702e+4932',
180*1f5207b7SJohn Levon	     'EPSILON' => '1.92592994438723585305597794258492732e-34',
181*1f5207b7SJohn Levon	     'DENORM_MIN' => '6.47517511943802511092443895822764655e-4966',
182*1f5207b7SJohn Levon	 },
183*1f5207b7SJohn Levon	 );
184*1f5207b7SJohn Levon
185*1f5207b7SJohn Levon    my @types = (['FLT','F'], ['DBL',''], ['LDBL','L']);
186*1f5207b7SJohn Levon    while (@types) {
187*1f5207b7SJohn Levon	my ($mant_bits,$exp_bits) = @{ shift @bitsizes };
188*1f5207b7SJohn Levon	my ($name,$suffix) = @{ shift @types };
189*1f5207b7SJohn Levon
190*1f5207b7SJohn Levon	my $h = $constants{$mant_bits};
191*1f5207b7SJohn Levon	die "$0: weird number of mantissa bits." unless $h;
192*1f5207b7SJohn Levon
193*1f5207b7SJohn Levon	my $mant_dig = int (($mant_bits - 1) * log (2) / log (10));
194*1f5207b7SJohn Levon	my $max_exp = 1 << ($exp_bits - 1);
195*1f5207b7SJohn Levon	my $min_exp = 3 - $max_exp;
196*1f5207b7SJohn Levon	my $max_10_exp = int ($max_exp * log (2) / log (10));
197*1f5207b7SJohn Levon	my $min_10_exp = -int (-$min_exp * log (2) / log (10));
198*1f5207b7SJohn Levon
199*1f5207b7SJohn Levon	$result .= " -D__${name}_MANT_DIG__=$mant_bits";
200*1f5207b7SJohn Levon	$result .= " -D__${name}_DIG__=$mant_dig";
201*1f5207b7SJohn Levon	$result .= " -D__${name}_MIN_EXP__='($min_exp)'";
202*1f5207b7SJohn Levon	$result .= " -D__${name}_MAX_EXP__=$max_exp";
203*1f5207b7SJohn Levon	$result .= " -D__${name}_MIN_10_EXP__='($min_10_exp)'";
204*1f5207b7SJohn Levon	$result .= " -D__${name}_MAX_10_EXP__=$max_10_exp";
205*1f5207b7SJohn Levon	$result .= " -D__${name}_HAS_INFINITY__=" . ($has_inf ? '1' : '0');
206*1f5207b7SJohn Levon	$result .= " -D__${name}_HAS_QUIET_NAN__=" . ($has_qnan ? '1' : '0');;
207*1f5207b7SJohn Levon
208*1f5207b7SJohn Levon	foreach my $inf (sort keys %$h) {
209*1f5207b7SJohn Levon	    $result .= " -D__${name}_${inf}__=" . $h->{$inf} . $suffix;
210*1f5207b7SJohn Levon	}
211*1f5207b7SJohn Levon    }
212*1f5207b7SJohn Levon    return $result;
213*1f5207b7SJohn Levon}
214*1f5207b7SJohn Levon
215*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
216*1f5207b7SJohn Levon
217*1f5207b7SJohn Levonsub define_size_t {
218*1f5207b7SJohn Levon    my ($text) = @_;
219*1f5207b7SJohn Levon    # We have to undef in order to override check's internal definition.
220*1f5207b7SJohn Levon    return ' -U__SIZE_TYPE__ ' . &quote_arg ("-D__SIZE_TYPE__=$text");
221*1f5207b7SJohn Levon}
222*1f5207b7SJohn Levon
223*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
224*1f5207b7SJohn Levon
225*1f5207b7SJohn Levonsub add_specs {
226*1f5207b7SJohn Levon    my ($spec) = @_;
227*1f5207b7SJohn Levon    if ($spec eq 'sunos') {
228*1f5207b7SJohn Levon	return &add_specs ('unix') .
229*1f5207b7SJohn Levon	    ' -D__sun__=1 -D__sun=1 -Dsun=1' .
230*1f5207b7SJohn Levon	    ' -D__svr4__=1 -DSVR4=1' .
231*1f5207b7SJohn Levon	    ' -D__STDC__=0' .
232*1f5207b7SJohn Levon	    ' -D_REENTRANT' .
233*1f5207b7SJohn Levon	    ' -D_SOLARIS_THREADS' .
234*1f5207b7SJohn Levon	    ' -DNULL="((void *)0)"';
235*1f5207b7SJohn Levon    } elsif ($spec eq 'linux') {
236*1f5207b7SJohn Levon	return &add_specs ('unix') .
237*1f5207b7SJohn Levon	    ' -D__linux__=1 -D__linux=1 -Dlinux=linux';
238*1f5207b7SJohn Levon    } elsif ($spec eq 'gnu/kfreebsd') {
239*1f5207b7SJohn Levon	return &add_specs ('unix') .
240*1f5207b7SJohn Levon	    ' -D__FreeBSD_kernel__=1';
241*1f5207b7SJohn Levon    } elsif ($spec eq 'openbsd') {
242*1f5207b7SJohn Levon	return &add_specs ('unix') .
243*1f5207b7SJohn Levon	    ' -D__OpenBSD__=1';
244*1f5207b7SJohn Levon    } elsif ($spec eq 'darwin') {
245*1f5207b7SJohn Levon	return
246*1f5207b7SJohn Levon	    ' -D__APPLE__=1 -D__MACH__=1';
247*1f5207b7SJohn Levon    } elsif ($spec eq 'unix') {
248*1f5207b7SJohn Levon	return ' -Dunix=1 -D__unix=1 -D__unix__=1';
249*1f5207b7SJohn Levon    } elsif ( $spec =~ /^cygwin/) {
250*1f5207b7SJohn Levon	return &add_specs ('unix') .
251*1f5207b7SJohn Levon	    ' -D__CYGWIN__=1 -D__CYGWIN32__=1' .
252*1f5207b7SJohn Levon	    " -D'_cdecl=__attribute__((__cdecl__))'" .
253*1f5207b7SJohn Levon	    " -D'__cdecl=__attribute__((__cdecl__))'" .
254*1f5207b7SJohn Levon	    " -D'_stdcall=__attribute__((__stdcall__))'" .
255*1f5207b7SJohn Levon	    " -D'__stdcall=__attribute__((__stdcall__))'" .
256*1f5207b7SJohn Levon	    " -D'_fastcall=__attribute__((__fastcall__))'" .
257*1f5207b7SJohn Levon	    " -D'__fastcall=__attribute__((__fastcall__))'" .
258*1f5207b7SJohn Levon	    " -D'__declspec(x)=__attribute__((x))'";
259*1f5207b7SJohn Levon    } elsif ($spec eq 'i86') {
260*1f5207b7SJohn Levon	return (' -D__i386=1 -D__i386__=1' .
261*1f5207b7SJohn Levon		&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
262*1f5207b7SJohn Levon		&float_types (1, 1, 21, [24,8], [53,11], [64,15]) .
263*1f5207b7SJohn Levon		&define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
264*1f5207b7SJohn Levon		' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
265*1f5207b7SJohn Levon    } elsif ($spec eq 'sparc') {
266*1f5207b7SJohn Levon	return (' -D__sparc=1 -D__sparc__=1' .
267*1f5207b7SJohn Levon		&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
268*1f5207b7SJohn Levon		&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
269*1f5207b7SJohn Levon		&define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
270*1f5207b7SJohn Levon		' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
271*1f5207b7SJohn Levon    } elsif ($spec eq 'sparc64') {
272*1f5207b7SJohn Levon	return (' -D__sparc=1 -D__sparc__=1 -D__sparcv9__=1 -D__sparc64__=1 -D__arch64__=1 -D__LP64__=1' .
273*1f5207b7SJohn Levon		&integer_types (8, 16, 32, 64, 64, 128) .
274*1f5207b7SJohn Levon		&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
275*1f5207b7SJohn Levon		&define_size_t ("long unsigned int") .
276*1f5207b7SJohn Levon		' -D__SIZEOF_POINTER__=8');
277*1f5207b7SJohn Levon    } elsif ($spec eq 'x86_64') {
278*1f5207b7SJohn Levon	return (' -D__x86_64=1 -D__x86_64__=1' . ($m32 ? '' : ' -D__LP64__=1') .
279*1f5207b7SJohn Levon		&integer_types (8, 16, 32, $m32 ? 32 : 64, 64, 128) .
280*1f5207b7SJohn Levon		&float_types (1, 1, 33, [24,8], [53,11], [113,15]) .
281*1f5207b7SJohn Levon		&define_size_t ($m32 ? "unsigned int" : "long unsigned int") .
282*1f5207b7SJohn Levon		' -D__SIZEOF_POINTER__=' . ($m32 ? '4' : '8'));
283*1f5207b7SJohn Levon    } elsif ($spec eq 'ppc') {
284*1f5207b7SJohn Levon	return (' -D__powerpc__=1 -D_BIG_ENDIAN -D_STRING_ARCH_unaligned=1' .
285*1f5207b7SJohn Levon		&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
286*1f5207b7SJohn Levon		&float_types (1, 1, 21, [24,8], [53,11], [113,15]) .
287*1f5207b7SJohn Levon		&define_size_t ($m64 ? "long unsigned int" : "unsigned int") .
288*1f5207b7SJohn Levon		' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
289*1f5207b7SJohn Levon    } elsif ($spec eq 'ppc64') {
290*1f5207b7SJohn Levon	return (' -D__powerpc__=1 -D__PPC__=1 -D_STRING_ARCH_unaligned=1' .
291*1f5207b7SJohn Levon		' -D__powerpc64__=1 -D__PPC64__=1' .
292*1f5207b7SJohn Levon		' -m64' .
293*1f5207b7SJohn Levon		&float_types (1, 1, 21, [24,8], [53,11], [113,15]));
294*1f5207b7SJohn Levon    } elsif ($spec eq 's390x') {
295*1f5207b7SJohn Levon	return (' -D__s390x__ -D__s390__ -D_BIG_ENDIAN' .
296*1f5207b7SJohn Levon		&integer_types (8, 16, 32, $m64 ? 64 : 32, 64) .
297*1f5207b7SJohn Levon		&float_types (1, 1, 36, [24,8], [53,11], [113,15]) .
298*1f5207b7SJohn Levon		&define_size_t ("long unsigned int") .
299*1f5207b7SJohn Levon		' -D__SIZEOF_POINTER__=' . ($m64 ? '8' : '4'));
300*1f5207b7SJohn Levon    } elsif ($spec eq 'arm') {
301*1f5207b7SJohn Levon	chomp (my $gccmachine = `$cc -dumpmachine`);
302*1f5207b7SJohn Levon	my $cppsymbols = ' -D__arm__=1 -m32';
303*1f5207b7SJohn Levon
304*1f5207b7SJohn Levon	if ($gccmachine eq 'arm-linux-gnueabihf') {
305*1f5207b7SJohn Levon	    $cppsymbols .= ' -D__ARM_PCS_VFP=1';
306*1f5207b7SJohn Levon	}
307*1f5207b7SJohn Levon
308*1f5207b7SJohn Levon	return ($cppsymbols .
309*1f5207b7SJohn Levon		&float_types (1, 1, 36, [24,8], [53,11], [53, 11]));
310*1f5207b7SJohn Levon    } elsif ($spec eq 'aarch64') {
311*1f5207b7SJohn Levon	return (' -D__aarch64__=1 -m64' .
312*1f5207b7SJohn Levon		&float_types (1, 1, 36, [24,8], [53,11], [113,15]));
313*1f5207b7SJohn Levon    } elsif ($spec eq 'host_os_specs') {
314*1f5207b7SJohn Levon	my $os = `uname -s`;
315*1f5207b7SJohn Levon	chomp $os;
316*1f5207b7SJohn Levon	return &add_specs (lc $os);
317*1f5207b7SJohn Levon    } elsif ($spec eq 'host_arch_specs') {
318*1f5207b7SJohn Levon	my $arch = `uname -m`;
319*1f5207b7SJohn Levon	chomp $arch;
320*1f5207b7SJohn Levon	if ($arch =~ /^(i.?86|athlon)$/i) {
321*1f5207b7SJohn Levon	    return &add_specs ('i86');
322*1f5207b7SJohn Levon	} elsif ($arch =~ /^(sun4u)$/i) {
323*1f5207b7SJohn Levon	    return &add_specs ('sparc');
324*1f5207b7SJohn Levon	} elsif ($arch =~ /^(x86_64)$/i) {
325*1f5207b7SJohn Levon	    return &add_specs ('x86_64');
326*1f5207b7SJohn Levon	} elsif ($arch =~ /^(ppc)$/i) {
327*1f5207b7SJohn Levon	    return &add_specs ('ppc');
328*1f5207b7SJohn Levon	} elsif ($arch =~ /^(ppc64)$/i) {
329*1f5207b7SJohn Levon	    return &add_specs ('ppc64') . ' -mbig-endian -D_CALL_ELF=1';
330*1f5207b7SJohn Levon	} elsif ($arch =~ /^(ppc64le)$/i) {
331*1f5207b7SJohn Levon	    return &add_specs ('ppc64') . ' -mlittle-endian -D_CALL_ELF=2';
332*1f5207b7SJohn Levon	} elsif ($arch =~ /^(s390x)$/i) {
333*1f5207b7SJohn Levon	    return &add_specs ('s390x');
334*1f5207b7SJohn Levon	} elsif ($arch =~ /^(sparc64)$/i) {
335*1f5207b7SJohn Levon	    return &add_specs ('sparc64');
336*1f5207b7SJohn Levon	} elsif ($arch =~ /^arm(?:v[78]l)?$/i) {
337*1f5207b7SJohn Levon	    return &add_specs ('arm');
338*1f5207b7SJohn Levon	} elsif ($arch =~ /^(aarch64)$/i) {
339*1f5207b7SJohn Levon	    return &add_specs ('aarch64');
340*1f5207b7SJohn Levon	}
341*1f5207b7SJohn Levon    } else {
342*1f5207b7SJohn Levon	die "$0: invalid specs: $spec\n";
343*1f5207b7SJohn Levon    }
344*1f5207b7SJohn Levon}
345*1f5207b7SJohn Levon
346*1f5207b7SJohn Levon# -----------------------------------------------------------------------------
347