source: mainline/tools/autotool.py@ 491f773

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 491f773 was a4a0f1d, checked in by Martin Decky <martin@…>, 13 years ago

detect sizes and signness of types

  • Property mode set to 100755
File size: 26.4 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (c) 2010 Martin Decky
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30"""
31Detect important prerequisites and parameters for building HelenOS
32"""
33
34import sys
35import os
36import shutil
37import re
38import time
39import subprocess
40
41SANDBOX = 'autotool'
42CONFIG = 'Makefile.config'
43MAKEFILE = 'Makefile.common'
44HEADER = 'common.h'
45GUARD = 'AUTOTOOL_COMMON_H_'
46
47PROBE_SOURCE = 'probe.c'
48PROBE_OUTPUT = 'probe.s'
49
50PACKAGE_BINUTILS = "usually part of binutils"
51PACKAGE_GCC = "preferably version 4.7.0 or newer"
52PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
53
54COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
55COMPILER_WARNING = "The compilation of HelenOS might fail."
56
57PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
58 asm volatile ( \\
59 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
60 : \\
61 : [val] "n" (value) \\
62 )
63
64#define STRING(arg) STRING_ARG(arg)
65#define STRING_ARG(arg) #arg
66
67#define DECLARE_BUILTIN_TYPE(tag, type) \\
68 AUTOTOOL_DECLARE("builtin_size", "", tag, STRING(type), "", "", sizeof(type)); \\
69 AUTOTOOL_DECLARE("builtin_sign", "unsigned long long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long long int)); \\
70 AUTOTOOL_DECLARE("builtin_sign", "unsigned long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long int)); \\
71 AUTOTOOL_DECLARE("builtin_sign", "unsigned int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned int)); \\
72 AUTOTOOL_DECLARE("builtin_sign", "unsigned short int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned short int)); \\
73 AUTOTOOL_DECLARE("builtin_sign", "unsigned char", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned char)); \\
74 AUTOTOOL_DECLARE("builtin_sign", "signed long long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long long int)); \\
75 AUTOTOOL_DECLARE("builtin_sign", "signed long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long int)); \\
76 AUTOTOOL_DECLARE("builtin_sign", "signed int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed int)); \\
77 AUTOTOOL_DECLARE("builtin_sign", "signed short int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed short int)); \\
78 AUTOTOOL_DECLARE("builtin_sign", "signed char", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed char));
79
80#define DECLARE_INTSIZE(tag, type, strc, conc) \\
81 AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\
82 AUTOTOOL_DECLARE("intsize", "signed", tag, #type, strc, conc, sizeof(signed type));
83
84#define DECLARE_FLOATSIZE(tag, type) \\
85 AUTOTOOL_DECLARE("floatsize", "", tag, #type, "", "", sizeof(type));
86
87int main(int argc, char *argv[])
88{
89#ifdef __SIZE_TYPE__
90 DECLARE_BUILTIN_TYPE("size", __SIZE_TYPE__);
91#endif
92#ifdef __WCHAR_TYPE__
93 DECLARE_BUILTIN_TYPE("wchar", __WCHAR_TYPE__);
94#endif
95#ifdef __WINT_TYPE__
96 DECLARE_BUILTIN_TYPE("wint", __WINT_TYPE__);
97#endif
98"""
99
100PROBE_TAIL = """}
101"""
102
103def read_config(fname, config):
104 "Read HelenOS build configuration"
105
106 inf = open(fname, 'r')
107
108 for line in inf:
109 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
110 if (res):
111 config[res.group(1)] = res.group(2)
112
113 inf.close()
114
115def print_error(msg):
116 "Print a bold error message"
117
118 sys.stderr.write("\n")
119 sys.stderr.write("######################################################################\n")
120 sys.stderr.write("HelenOS build sanity check error:\n")
121 sys.stderr.write("\n")
122 sys.stderr.write("%s\n" % "\n".join(msg))
123 sys.stderr.write("######################################################################\n")
124 sys.stderr.write("\n")
125
126 sys.exit(1)
127
128def print_warning(msg):
129 "Print a bold error message"
130
131 sys.stderr.write("\n")
132 sys.stderr.write("######################################################################\n")
133 sys.stderr.write("HelenOS build sanity check warning:\n")
134 sys.stderr.write("\n")
135 sys.stderr.write("%s\n" % "\n".join(msg))
136 sys.stderr.write("######################################################################\n")
137 sys.stderr.write("\n")
138
139 time.sleep(5)
140
141def sandbox_enter():
142 "Create a temporal sandbox directory for running tests"
143
144 if (os.path.exists(SANDBOX)):
145 if (os.path.isdir(SANDBOX)):
146 try:
147 shutil.rmtree(SANDBOX)
148 except:
149 print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
150 else:
151 print_error(["Please inspect and remove unexpected directory,",
152 "entry \"%s\"." % SANDBOX])
153
154 try:
155 os.mkdir(SANDBOX)
156 except:
157 print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
158
159 owd = os.getcwd()
160 os.chdir(SANDBOX)
161
162 return owd
163
164def sandbox_leave(owd):
165 "Leave the temporal sandbox directory"
166
167 os.chdir(owd)
168
169def check_config(config, key):
170 "Check whether the configuration key exists"
171
172 if (not key in config):
173 print_error(["Build configuration of HelenOS does not contain %s." % key,
174 "Try running \"make config\" again.",
175 "If the problem persists, please contact the developers of HelenOS."])
176
177def check_common(common, key):
178 "Check whether the common key exists"
179
180 if (not key in common):
181 print_error(["Failed to determine the value %s." % key,
182 "Please contact the developers of HelenOS."])
183
184def check_app(args, name, details):
185 "Check whether an application can be executed"
186
187 try:
188 sys.stderr.write("Checking for %s ... " % args[0])
189 subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
190 except:
191 sys.stderr.write("failed\n")
192 print_error(["%s is missing." % name,
193 "",
194 "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
195 "is installed in your system (%s)." % details])
196
197 sys.stderr.write("ok\n")
198
199def check_app_alternatives(alts, args, name, details):
200 "Check whether an application can be executed (use several alternatives)"
201
202 tried = []
203 found = None
204
205 for alt in alts:
206 working = True
207 cmdline = [alt] + args
208 tried.append(" ".join(cmdline))
209
210 try:
211 sys.stderr.write("Checking for %s ... " % alt)
212 subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
213 except:
214 sys.stderr.write("failed\n")
215 working = False
216
217 if (working):
218 sys.stderr.write("ok\n")
219 found = alt
220 break
221
222 if (found is None):
223 print_error(["%s is missing." % name,
224 "",
225 "Please make sure that it is installed in your",
226 "system (%s)." % details,
227 "",
228 "The following alternatives were tried:"] + tried)
229
230 return found
231
232def check_gcc(path, prefix, common, details):
233 "Check for GCC"
234
235 common['GCC'] = "%sgcc" % prefix
236
237 if (not path is None):
238 common['GCC'] = "%s/%s" % (path, common['GCC'])
239
240 check_app([common['GCC'], "--version"], "GNU GCC", details)
241
242def check_binutils(path, prefix, common, details):
243 "Check for binutils toolchain"
244
245 common['AS'] = "%sas" % prefix
246 common['LD'] = "%sld" % prefix
247 common['AR'] = "%sar" % prefix
248 common['OBJCOPY'] = "%sobjcopy" % prefix
249 common['OBJDUMP'] = "%sobjdump" % prefix
250 common['STRIP'] = "%sstrip" % prefix
251
252 if (not path is None):
253 for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
254 common[key] = "%s/%s" % (path, common[key])
255
256 check_app([common['AS'], "--version"], "GNU Assembler", details)
257 check_app([common['LD'], "--version"], "GNU Linker", details)
258 check_app([common['AR'], "--version"], "GNU Archiver", details)
259 check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
260 check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
261 check_app([common['STRIP'], "--version"], "GNU strip", details)
262
263def decode_value(value):
264 "Decode integer value"
265
266 base = 10
267
268 if ((value.startswith('$')) or (value.startswith('#'))):
269 value = value[1:]
270
271 if (value.startswith('0x')):
272 value = value[2:]
273 base = 16
274
275 return int(value, base)
276
277def probe_compiler(common, intsizes, floatsizes):
278 "Generate, compile and parse probing source"
279
280 check_common(common, "CC")
281
282 outf = open(PROBE_SOURCE, 'w')
283 outf.write(PROBE_HEAD)
284
285 for typedef in intsizes:
286 outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
287
288 for typedef in floatsizes:
289 outf.write("\nDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
290
291 outf.write(PROBE_TAIL)
292 outf.close()
293
294 args = [common['CC']]
295 args.extend(common['CC_ARGS'])
296 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
297
298 try:
299 sys.stderr.write("Checking compiler properties ... ")
300 output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
301 except:
302 sys.stderr.write("failed\n")
303 print_error(["Error executing \"%s\"." % " ".join(args),
304 "Make sure that the compiler works properly."])
305
306 if (not os.path.isfile(PROBE_OUTPUT)):
307 sys.stderr.write("failed\n")
308 print(output[1])
309 print_error(["Error executing \"%s\"." % " ".join(args),
310 "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
311 "",
312 output[0],
313 output[1]])
314
315 sys.stderr.write("ok\n")
316
317 inf = open(PROBE_OUTPUT, 'r')
318 lines = inf.readlines()
319 inf.close()
320
321 unsigned_sizes = {}
322 signed_sizes = {}
323
324 unsigned_tags = {}
325 signed_tags = {}
326
327 unsigned_strcs = {}
328 signed_strcs = {}
329
330 unsigned_concs = {}
331 signed_concs = {}
332
333 float_tags = {}
334
335 builtin_sizes = {}
336 builtin_signs = {}
337
338 for j in range(len(lines)):
339 tokens = lines[j].strip().split("\t")
340
341 if (len(tokens) > 0):
342 if (tokens[0] == "AUTOTOOL_DECLARE"):
343 if (len(tokens) < 7):
344 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
345
346 category = tokens[1]
347 subcategory = tokens[2]
348 tag = tokens[3]
349 name = tokens[4]
350 strc = tokens[5]
351 conc = tokens[6]
352 value = tokens[7]
353
354 if (category == "intsize"):
355 try:
356 value_int = decode_value(value)
357 except:
358 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
359
360 if (subcategory == "unsigned"):
361 unsigned_sizes[value_int] = name
362 unsigned_tags[tag] = value_int
363 unsigned_strcs[value_int] = strc
364 unsigned_concs[value_int] = conc
365 elif (subcategory == "signed"):
366 signed_sizes[value_int] = name
367 signed_tags[tag] = value_int
368 signed_strcs[value_int] = strc
369 signed_concs[value_int] = conc
370 else:
371 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
372
373 if (category == "floatsize"):
374 try:
375 value_int = decode_value(value)
376 except:
377 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
378
379 float_tags[tag] = value_int
380
381 if (category == "builtin_size"):
382 try:
383 value_int = decode_value(value)
384 except:
385 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
386
387 builtin_sizes[tag] = {'name': name, 'value': value_int}
388
389 if (category == "builtin_sign"):
390 try:
391 value_int = decode_value(value)
392 except:
393 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
394
395 if (value_int == 1):
396 if (not tag in builtin_signs):
397 builtin_signs[tag] = strc;
398 elif (builtin_signs[tag] != strc):
399 print_error(["Inconsistent builtin type detection in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
400
401 return {'unsigned_sizes': unsigned_sizes, 'signed_sizes': signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags, 'unsigned_strcs': unsigned_strcs, 'signed_strcs': signed_strcs, 'unsigned_concs': unsigned_concs, 'signed_concs': signed_concs, 'float_tags': float_tags, 'builtin_sizes': builtin_sizes, 'builtin_signs': builtin_signs}
402
403def detect_sizes(probe, bytes, inttags, floattags):
404 "Detect correct types for fixed-size types"
405
406 macros = []
407 typedefs = []
408
409 for b in bytes:
410 if (not b in probe['unsigned_sizes']):
411 print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b,
412 COMPILER_FAIL])
413
414 if (not b in probe['signed_sizes']):
415 print_error(['Unable to find appropriate signed integer type for %u bytes.' % b,
416 COMPILER_FAIL])
417
418 if (not b in probe['unsigned_strcs']):
419 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b,
420 COMPILER_FAIL])
421
422 if (not b in probe['signed_strcs']):
423 print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b,
424 COMPILER_FAIL])
425
426 if (not b in probe['unsigned_concs']):
427 print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b,
428 COMPILER_FAIL])
429
430 if (not b in probe['signed_concs']):
431 print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b,
432 COMPILER_FAIL])
433
434 typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
435 typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
436
437 macros.append({'oldmacro': "unsigned %s" % probe['unsigned_sizes'][b], 'newmacro': "UINT%u_T" % (b * 8)})
438 macros.append({'oldmacro': "signed %s" % probe['signed_sizes'][b], 'newmacro': "INT%u_T" % (b * 8)})
439
440 macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
441 macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
442 macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
443 macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
444 macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
445
446 name = probe['unsigned_concs'][b]
447 if ((name.startswith('@')) or (name == "")):
448 macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
449 else:
450 macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
451
452 name = probe['unsigned_concs'][b]
453 if ((name.startswith('@')) or (name == "")):
454 macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
455 else:
456 macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
457
458 for tag in inttags:
459 newmacro = "U%s" % tag
460 if (not tag in probe['unsigned_tags']):
461 print_error(['Unable to find appropriate size macro for %s.' % newmacro,
462 COMPILER_FAIL])
463
464 oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
465 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
466 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
467 macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)})
468
469 newmacro = tag
470 if (not tag in probe['signed_tags']):
471 print_error(['Unable to find appropriate size macro for %s' % newmacro,
472 COMPILER_FAIL])
473
474 oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
475 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
476 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
477 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['signed_tags'][tag] * 8)})
478
479 for tag in floattags:
480 if (not tag in probe['float_tags']):
481 print_error(['Unable to find appropriate size macro for %s' % tag,
482 COMPILER_FAIL])
483
484 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['float_tags'][tag] * 8)})
485
486 if (not 'size' in probe['builtin_signs']):
487 print_error(['Unable to determine whether size_t is signed or unsigned.',
488 COMPILER_FAIL])
489
490 if (probe['builtin_signs']['size'] != 'unsigned'):
491 print_error(['The type size_t is not unsigned.',
492 COMPILER_FAIL])
493
494 fnd = True
495
496 if (not 'wchar' in probe['builtin_sizes']):
497 print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
498 'for defining the compiler-native type wchar_t. We are',
499 'forced to define wchar_t as a hardwired type int32_t.',
500 COMPILER_WARNING])
501 fnd = False
502
503 if (probe['builtin_sizes']['wchar']['value'] != 4):
504 print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
505 'the compiler-native type wchar_t is not compliant with',
506 'HelenOS. We are forced to define wchar_t as a hardwired',
507 'type int32_t.',
508 COMPILER_WARNING])
509 fnd = False
510
511 if (not fnd):
512 macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
513 else:
514 macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
515
516 if (not 'wchar' in probe['builtin_signs']):
517 print_error(['Unable to determine whether wchar_t is signed or unsigned.',
518 COMPILER_FAIL])
519
520 if (probe['builtin_signs']['wchar'] == 'unsigned'):
521 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_UNSIGNED'})
522 if (probe['builtin_signs']['wchar'] == 'signed'):
523 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_SIGNED'})
524
525 fnd = True
526
527 if (not 'wint' in probe['builtin_sizes']):
528 print_warning(['The compiler does not provide the macro __WINT_TYPE__',
529 'for defining the compiler-native type wint_t. We are',
530 'forced to define wint_t as a hardwired type int32_t.',
531 COMPILER_WARNING])
532 fnd = False
533
534 if (probe['builtin_sizes']['wint']['value'] != 4):
535 print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
536 'the compiler-native type wint_t is not compliant with',
537 'HelenOS. We are forced to define wint_t as a hardwired',
538 'type int32_t.',
539 COMPILER_WARNING])
540 fnd = False
541
542 if (not fnd):
543 macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
544 else:
545 macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
546
547 if (not 'wint' in probe['builtin_signs']):
548 print_error(['Unable to determine whether wint_t is signed or unsigned.',
549 COMPILER_FAIL])
550
551 if (probe['builtin_signs']['wint'] == 'unsigned'):
552 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_UNSIGNED'})
553 if (probe['builtin_signs']['wint'] == 'signed'):
554 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_SIGNED'})
555
556 return {'macros': macros, 'typedefs': typedefs}
557
558def create_makefile(mkname, common):
559 "Create makefile output"
560
561 outmk = open(mkname, 'w')
562
563 outmk.write('#########################################\n')
564 outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
565 outmk.write('#########################################\n\n')
566
567 for key, value in common.items():
568 if (type(value) is list):
569 outmk.write('%s = %s\n' % (key, " ".join(value)))
570 else:
571 outmk.write('%s = %s\n' % (key, value))
572
573 outmk.close()
574
575def create_header(hdname, maps):
576 "Create header output"
577
578 outhd = open(hdname, 'w')
579
580 outhd.write('/***************************************\n')
581 outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
582 outhd.write(' ***************************************/\n\n')
583
584 outhd.write('#ifndef %s\n' % GUARD)
585 outhd.write('#define %s\n\n' % GUARD)
586
587 for macro in maps['macros']:
588 outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
589
590 outhd.write('\n')
591
592 for typedef in maps['typedefs']:
593 outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
594
595 outhd.write('\n#endif\n')
596 outhd.close()
597
598def main():
599 config = {}
600 common = {}
601
602 # Read and check configuration
603 if os.path.exists(CONFIG):
604 read_config(CONFIG, config)
605 else:
606 print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
607 "configuration phase of HelenOS build went OK. Try running",
608 "\"make config\" again."])
609
610 check_config(config, "PLATFORM")
611 check_config(config, "COMPILER")
612 check_config(config, "BARCH")
613
614 # Cross-compiler prefix
615 if ('CROSS_PREFIX' in os.environ):
616 cross_prefix = os.environ['CROSS_PREFIX']
617 else:
618 cross_prefix = "/usr/local/cross"
619
620 # Prefix binutils tools on Solaris
621 if (os.uname()[0] == "SunOS"):
622 binutils_prefix = "g"
623 else:
624 binutils_prefix = ""
625
626 owd = sandbox_enter()
627
628 try:
629 # Common utilities
630 check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
631 check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
632 check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
633 check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
634 check_app(["find", "--version"], "Find utility", "usually part of findutils")
635 check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
636 check_app(["make", "--version"], "Make utility", "preferably GNU Make")
637 check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
638
639 # Compiler
640 common['CC_ARGS'] = []
641 if (config['COMPILER'] == "gcc_cross"):
642 if (config['PLATFORM'] == "abs32le"):
643 check_config(config, "CROSS_TARGET")
644 target = config['CROSS_TARGET']
645
646 if (config['CROSS_TARGET'] == "arm32"):
647 gnu_target = "arm-linux-gnueabi"
648
649 if (config['CROSS_TARGET'] == "ia32"):
650 gnu_target = "i686-pc-linux-gnu"
651
652 if (config['CROSS_TARGET'] == "mips32"):
653 gnu_target = "mipsel-linux-gnu"
654 common['CC_ARGS'].append("-mabi=32")
655
656 if (config['PLATFORM'] == "amd64"):
657 target = config['PLATFORM']
658 gnu_target = "amd64-linux-gnu"
659
660 if (config['PLATFORM'] == "arm32"):
661 target = config['PLATFORM']
662 gnu_target = "arm-linux-gnueabi"
663
664 if (config['PLATFORM'] == "ia32"):
665 target = config['PLATFORM']
666 gnu_target = "i686-pc-linux-gnu"
667
668 if (config['PLATFORM'] == "ia64"):
669 target = config['PLATFORM']
670 gnu_target = "ia64-pc-linux-gnu"
671
672 if (config['PLATFORM'] == "mips32"):
673 check_config(config, "MACHINE")
674 common['CC_ARGS'].append("-mabi=32")
675
676 if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
677 target = config['PLATFORM']
678 gnu_target = "mipsel-linux-gnu"
679
680 if (config['MACHINE'] == "bgxemul"):
681 target = "mips32eb"
682 gnu_target = "mips-linux-gnu"
683
684 if (config['PLATFORM'] == "mips64"):
685 check_config(config, "MACHINE")
686 common['CC_ARGS'].append("-mabi=64")
687
688 if (config['MACHINE'] == "msim"):
689 target = config['PLATFORM']
690 gnu_target = "mips64el-linux-gnu"
691
692 if (config['PLATFORM'] == "ppc32"):
693 target = config['PLATFORM']
694 gnu_target = "ppc-linux-gnu"
695
696 if (config['PLATFORM'] == "sparc64"):
697 target = config['PLATFORM']
698 gnu_target = "sparc64-linux-gnu"
699
700 path = "%s/%s/bin" % (cross_prefix, target)
701 prefix = "%s-" % gnu_target
702
703 check_gcc(path, prefix, common, PACKAGE_CROSS)
704 check_binutils(path, prefix, common, PACKAGE_CROSS)
705
706 check_common(common, "GCC")
707 common['CC'] = common['GCC']
708
709 if (config['COMPILER'] == "gcc_native"):
710 check_gcc(None, "", common, PACKAGE_GCC)
711 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
712
713 check_common(common, "GCC")
714 common['CC'] = common['GCC']
715
716 if (config['COMPILER'] == "icc"):
717 common['CC'] = "icc"
718 check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
719 check_gcc(None, "", common, PACKAGE_GCC)
720 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
721
722 if (config['COMPILER'] == "suncc"):
723 common['CC'] = "suncc"
724 check_app([common['CC'], "-V"], "Sun Studio Compiler", "support is experimental")
725 check_gcc(None, "", common, PACKAGE_GCC)
726 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
727
728 if (config['COMPILER'] == "clang"):
729 common['CC'] = "clang"
730 check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
731 check_gcc(None, "", common, PACKAGE_GCC)
732 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
733
734 # Platform-specific utilities
735 if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
736 common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
737
738 probe = probe_compiler(common,
739 [
740 {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
741 {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
742 {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
743 {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
744 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
745 ],
746 [
747 {'type': 'long double', 'tag': 'LONG_DOUBLE'},
748 {'type': 'double', 'tag': 'DOUBLE'},
749 {'type': 'float', 'tag': 'FLOAT'}
750 ]
751 )
752
753 maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT'])
754
755 finally:
756 sandbox_leave(owd)
757
758 create_makefile(MAKEFILE, common)
759 create_header(HEADER, maps)
760
761 return 0
762
763if __name__ == '__main__':
764 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.