2 # -----------------------------------------------------------------------------
4 my $cc = $ENV{'REAL_CC'} || 'cc';
5 my $check = $ENV{'CHECK'} || 'check';
14 # Look for a .c file. We don't want to run the checker on .o or .so files
15 # in the link run. (This simplistic check knows nothing about options
16 # with arguments, but it seems to do the job.)
17 $do_check = 1 if /^[^-].*\.c$/;
21 if (/^-specs=(.*)$/) {
22 $check .= &add_specs
($1);
27 if ($_ eq '-no-compile') {
32 # If someone adds "-E", don't pre-process twice.
33 $do_compile = 0 if $_ eq '-E';
35 $verbose = 1 if $_ eq '-v';
37 my $this_arg = ' ' . "e_arg
($_);
38 $cc .= $this_arg unless &check_only_option
($_);
44 $check .= &add_specs
('host_arch_specs');
45 $check .= &add_specs
('host_os_specs');
47 print "$check\n" if $verbose;
53 print "$cc\n" if $verbose;
59 # -----------------------------------------------------------------------------
60 # Check if an option is for "check" only.
62 sub check_only_option
{
64 return 1 if $arg =~ /^-W(no-?)?(default-bitfield-sig|bitwise|typesign)$/;
68 # -----------------------------------------------------------------------------
69 # Simple arg-quoting function. Just adds backslashes when needed.
73 return "''" if $arg eq '';
76 m
|^[-a
-zA
-Z0
-9._
/,=]+$| ?
$_ : "\\" . $_;
77 } (split (//, $arg)));
80 # -----------------------------------------------------------------------------
83 my ($char,@dummy) = @_;
89 64 => '9223372036854775807',
91 my @types = (['SCHAR',''], ['SHRT',''], ['INT',''], ['LONG','L'], ['LONG_LONG','LL']);
93 my $result = " -D__CHAR_BIT__=$char";
96 my ($name,$suffix) = @
{ shift @types };
97 die "$0: wierd number of bits." unless exists $pow2m1{$bits};
98 $result .= " -D__${name}_MAX__=" . $pow2m1{$bits} . $suffix;
103 # -----------------------------------------------------------------------------
106 my ($has_inf,$has_qnan,$dec_dig,@bitsizes) = @_;
107 my $result = " -D__FLT_RADIX__=2";
108 $result .= " -D__FINITE_MATH_ONLY__=" . ($has_inf || $has_qnan ?
'0' : '1');
109 $result .= " -D__DECIMAL_DIG__=$dec_dig";
114 'MIN' => '1.17549435e-38',
115 'MAX' => '3.40282347e+38',
116 'EPSILON' => '1.19209290e-7',
117 'DENORM_MIN' => '1.40129846e-45',
121 'MIN' => '2.2250738585072014e-308',
122 'MAX' => '1.7976931348623157e+308',
123 'EPSILON' => '2.2204460492503131e-16',
124 'DENORM_MIN' => '4.9406564584124654e-324',
128 'MIN' => '3.36210314311209350626e-4932',
129 'MAX' => '1.18973149535723176502e+4932',
130 'EPSILON' => '1.08420217248550443401e-19',
131 'DENORM_MIN' => '3.64519953188247460253e-4951',
135 'MIN' => '3.36210314311209350626267781732175260e-4932',
136 'MAX' => '1.18973149535723176508575932662800702e+4932',
137 'EPSILON' => '1.92592994438723585305597794258492732e-34',
138 'DENORM_MIN' => '6.47517511943802511092443895822764655e-4966',
142 my @types = (['FLT','F'], ['DBL',''], ['LDBL','L']);
144 my ($mant_bits,$exp_bits) = @
{ shift @bitsizes };
145 my ($name,$suffix) = @
{ shift @types };
147 my $h = $constants{$mant_bits};
148 die "$0: wierd number of mantissa bits." unless $h;
150 my $mant_dig = int (($mant_bits - 1) * log (2) / log (10));
151 my $max_exp = 1 << ($exp_bits - 1);
152 my $min_exp = 3 - $max_exp;
153 my $max_10_exp = int ($max_exp * log (2) / log (10));
154 my $min_10_exp = -int (-$min_exp * log (2) / log (10));
156 $result .= " -D__${name}_MANT_DIG__=$mant_bits";
157 $result .= " -D__${name}_DIG__=$mant_dig";
158 $result .= " -D__${name}_MIN_EXP__='($min_exp)'";
159 $result .= " -D__${name}_MAX_EXP__=$max_exp";
160 $result .= " -D__${name}_MIN_10_EXP__='($min_10_exp)'";
161 $result .= " -D__${name}_MAX_10_EXP__=$max_10_exp";
162 $result .= " -D__${name}_HAS_INFINITY__=" . ($has_inf ?
'1' : '0');
163 $result .= " -D__${name}_HAS_QUIET_NAN__=" . ($has_qnan ?
'1' : '0');;
165 foreach my $inf (sort keys %$h) {
166 $result .= " -D__${name}_${inf}__=" . $h->{$inf} . $suffix;
172 # -----------------------------------------------------------------------------
176 # We have to undef in order to override check's internal definition.
177 return ' -U__SIZE_TYPE__ ' . "e_arg
("-D__SIZE_TYPE__=$text");
180 # -----------------------------------------------------------------------------
184 if ($spec eq 'sunos') {
185 return &add_specs
('unix') .
186 ' -D__sun__=1 -D__sun=1 -Dsun=1' .
187 ' -D__svr4__=1 -DSVR4=1' .
190 ' -D_SOLARIS_THREADS' .
191 ' -DNULL="((void *)0)"';
192 } elsif ($spec eq 'linux') {
193 return &add_specs
('unix') .
194 ' -D__linux__=1 -D__linux=1 -Dlinux=linux' .
196 } elsif ($spec eq 'unix') {
197 return ' -Dunix=1 -D__unix=1 -D__unix__=1';
198 } elsif ($spec eq 'i86') {
199 return (' -Di386=1 -D__i386=1 -D__i386__=1' .
200 &integer_types
(8, 16, 32, $m64 ?
64 : 32, 64) .
201 &float_types
(1, 1, 21, [24,8], [53,11], [64,15]) .
202 &define_size_t
($m64 ?
"long unsigned int" : "unsigned int"));
203 } elsif ($spec eq 'sparc') {
204 return (' -Dsparc=1 -D__sparc=1 -D__sparc__=1' .
205 &integer_types
(8, 16, 32, $m64 ?
64 : 32, 64) .
206 &float_types
(1, 1, 33, [24,8], [53,11], [113,15]) .
207 &define_size_t
($m64 ?
"long unsigned int" : "unsigned int"));
208 } elsif ($spec eq 'host_os_specs') {
211 return &add_specs
(lc $os);
212 } elsif ($spec eq 'host_arch_specs') {
213 my $arch = `uname -m`;
215 if ($arch =~ /^(i.?86|athlon)$/i) {
216 return &add_specs
('i86');
217 } elsif ($arch =~ /^(sun4u)$/i) {
218 return &add_specs
('sparc');
221 die "$0: invalid specs: $spec\n";
225 # -----------------------------------------------------------------------------