source: mainline/tools/autotool.py@ 26bcc658

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 26bcc658 was 26bcc658, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Run clang with -target in autotool

This ensures that sizes of long/int/short are determined correctly
(based on target architecture, not a host one).

  • Property mode set to 100755
File size: 26.9 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 get_target(config, needs_clang = False):
185 target = None
186 gnu_target = None
187 clang_target = None
188
189 if (config['PLATFORM'] == "abs32le"):
190 check_config(config, "CROSS_TARGET")
191 target = config['CROSS_TARGET']
192
193 if (config['CROSS_TARGET'] == "arm32"):
194 gnu_target = "arm-linux-gnueabi"
195
196 if (config['CROSS_TARGET'] == "ia32"):
197 gnu_target = "i686-pc-linux-gnu"
198
199 if (config['CROSS_TARGET'] == "mips32"):
200 gnu_target = "mipsel-linux-gnu"
201 common['CC_ARGS'].append("-mabi=32")
202
203 if (config['PLATFORM'] == "amd64"):
204 target = config['PLATFORM']
205 gnu_target = "amd64-linux-gnu"
206 clang_target = "x86_64-uknown-linux"
207
208 if (config['PLATFORM'] == "arm32"):
209 target = config['PLATFORM']
210 gnu_target = "arm-linux-gnueabi"
211
212 if (config['PLATFORM'] == "ia32"):
213 target = config['PLATFORM']
214 gnu_target = "i686-pc-linux-gnu"
215 clang_target = "i386-uknown-linux"
216
217 if (config['PLATFORM'] == "ia64"):
218 target = config['PLATFORM']
219 gnu_target = "ia64-pc-linux-gnu"
220
221 if (config['PLATFORM'] == "mips32"):
222 check_config(config, "MACHINE")
223 common['CC_ARGS'].append("-mabi=32")
224
225 if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
226 target = config['PLATFORM']
227 gnu_target = "mipsel-linux-gnu"
228
229 if (config['MACHINE'] == "bgxemul"):
230 target = "mips32eb"
231 gnu_target = "mips-linux-gnu"
232
233 if (config['PLATFORM'] == "mips64"):
234 check_config(config, "MACHINE")
235 common['CC_ARGS'].append("-mabi=64")
236
237 if (config['MACHINE'] == "msim"):
238 target = config['PLATFORM']
239 gnu_target = "mips64el-linux-gnu"
240
241 if (config['PLATFORM'] == "ppc32"):
242 target = config['PLATFORM']
243 gnu_target = "ppc-linux-gnu"
244
245 if (config['PLATFORM'] == "sparc64"):
246 target = config['PLATFORM']
247 gnu_target = "sparc64-linux-gnu"
248
249 if (target is None) or (gnu_target is None) or (clang_target is None and needs_clang):
250 print_error(["Failed to determine target for compiler.",
251 "Please contact the developers of HelenOS."])
252
253 return (target, gnu_target, clang_target)
254
255def check_app(args, name, details):
256 "Check whether an application can be executed"
257
258 try:
259 sys.stderr.write("Checking for %s ... " % args[0])
260 subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
261 except:
262 sys.stderr.write("failed\n")
263 print_error(["%s is missing." % name,
264 "",
265 "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
266 "is installed in your system (%s)." % details])
267
268 sys.stderr.write("ok\n")
269
270def check_app_alternatives(alts, args, name, details):
271 "Check whether an application can be executed (use several alternatives)"
272
273 tried = []
274 found = None
275
276 for alt in alts:
277 working = True
278 cmdline = [alt] + args
279 tried.append(" ".join(cmdline))
280
281 try:
282 sys.stderr.write("Checking for %s ... " % alt)
283 subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
284 except:
285 sys.stderr.write("failed\n")
286 working = False
287
288 if (working):
289 sys.stderr.write("ok\n")
290 found = alt
291 break
292
293 if (found is None):
294 print_error(["%s is missing." % name,
295 "",
296 "Please make sure that it is installed in your",
297 "system (%s)." % details,
298 "",
299 "The following alternatives were tried:"] + tried)
300
301 return found
302
303def check_gcc(path, prefix, common, details):
304 "Check for GCC"
305
306 common['GCC'] = "%sgcc" % prefix
307
308 if (not path is None):
309 common['GCC'] = "%s/%s" % (path, common['GCC'])
310
311 check_app([common['GCC'], "--version"], "GNU GCC", details)
312
313def check_binutils(path, prefix, common, details):
314 "Check for binutils toolchain"
315
316 common['AS'] = "%sas" % prefix
317 common['LD'] = "%sld" % prefix
318 common['AR'] = "%sar" % prefix
319 common['OBJCOPY'] = "%sobjcopy" % prefix
320 common['OBJDUMP'] = "%sobjdump" % prefix
321 common['STRIP'] = "%sstrip" % prefix
322
323 if (not path is None):
324 for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
325 common[key] = "%s/%s" % (path, common[key])
326
327 check_app([common['AS'], "--version"], "GNU Assembler", details)
328 check_app([common['LD'], "--version"], "GNU Linker", details)
329 check_app([common['AR'], "--version"], "GNU Archiver", details)
330 check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
331 check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
332 check_app([common['STRIP'], "--version"], "GNU strip", details)
333
334def decode_value(value):
335 "Decode integer value"
336
337 base = 10
338
339 if ((value.startswith('$')) or (value.startswith('#'))):
340 value = value[1:]
341
342 if (value.startswith('0x')):
343 value = value[2:]
344 base = 16
345
346 return int(value, base)
347
348def probe_compiler(common, intsizes, floatsizes):
349 "Generate, compile and parse probing source"
350
351 check_common(common, "CC")
352
353 outf = open(PROBE_SOURCE, 'w')
354 outf.write(PROBE_HEAD)
355
356 for typedef in intsizes:
357 outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
358
359 for typedef in floatsizes:
360 outf.write("\nDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
361
362 outf.write(PROBE_TAIL)
363 outf.close()
364
365 args = [common['CC']]
366 args.extend(common['CC_ARGS'])
367 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
368
369 try:
370 sys.stderr.write("Checking compiler properties ... ")
371 output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
372 except:
373 sys.stderr.write("failed\n")
374 print_error(["Error executing \"%s\"." % " ".join(args),
375 "Make sure that the compiler works properly."])
376
377 if (not os.path.isfile(PROBE_OUTPUT)):
378 sys.stderr.write("failed\n")
379 print(output[1])
380 print_error(["Error executing \"%s\"." % " ".join(args),
381 "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
382 "",
383 output[0],
384 output[1]])
385
386 sys.stderr.write("ok\n")
387
388 inf = open(PROBE_OUTPUT, 'r')
389 lines = inf.readlines()
390 inf.close()
391
392 unsigned_sizes = {}
393 signed_sizes = {}
394
395 unsigned_tags = {}
396 signed_tags = {}
397
398 unsigned_strcs = {}
399 signed_strcs = {}
400
401 unsigned_concs = {}
402 signed_concs = {}
403
404 float_tags = {}
405
406 builtin_sizes = {}
407 builtin_signs = {}
408
409 for j in range(len(lines)):
410 tokens = lines[j].strip().split("\t")
411
412 if (len(tokens) > 0):
413 if (tokens[0] == "AUTOTOOL_DECLARE"):
414 if (len(tokens) < 7):
415 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
416
417 category = tokens[1]
418 subcategory = tokens[2]
419 tag = tokens[3]
420 name = tokens[4]
421 strc = tokens[5]
422 conc = tokens[6]
423 value = tokens[7]
424
425 if (category == "intsize"):
426 try:
427 value_int = decode_value(value)
428 except:
429 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
430
431 if (subcategory == "unsigned"):
432 unsigned_sizes[value_int] = name
433 unsigned_tags[tag] = value_int
434 unsigned_strcs[value_int] = strc
435 unsigned_concs[value_int] = conc
436 elif (subcategory == "signed"):
437 signed_sizes[value_int] = name
438 signed_tags[tag] = value_int
439 signed_strcs[value_int] = strc
440 signed_concs[value_int] = conc
441 else:
442 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
443
444 if (category == "floatsize"):
445 try:
446 value_int = decode_value(value)
447 except:
448 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
449
450 float_tags[tag] = value_int
451
452 if (category == "builtin_size"):
453 try:
454 value_int = decode_value(value)
455 except:
456 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
457
458 builtin_sizes[tag] = {'name': name, 'value': value_int}
459
460 if (category == "builtin_sign"):
461 try:
462 value_int = decode_value(value)
463 except:
464 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
465
466 if (value_int == 1):
467 if (not tag in builtin_signs):
468 builtin_signs[tag] = strc;
469 elif (builtin_signs[tag] != strc):
470 print_error(["Inconsistent builtin type detection in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
471
472 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}
473
474def detect_sizes(probe, bytes, inttags, floattags):
475 "Detect correct types for fixed-size types"
476
477 macros = []
478 typedefs = []
479
480 for b in bytes:
481 if (not b in probe['unsigned_sizes']):
482 print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b,
483 COMPILER_FAIL])
484
485 if (not b in probe['signed_sizes']):
486 print_error(['Unable to find appropriate signed integer type for %u bytes.' % b,
487 COMPILER_FAIL])
488
489 if (not b in probe['unsigned_strcs']):
490 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b,
491 COMPILER_FAIL])
492
493 if (not b in probe['signed_strcs']):
494 print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b,
495 COMPILER_FAIL])
496
497 if (not b in probe['unsigned_concs']):
498 print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b,
499 COMPILER_FAIL])
500
501 if (not b in probe['signed_concs']):
502 print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b,
503 COMPILER_FAIL])
504
505 typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
506 typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
507
508 macros.append({'oldmacro': "unsigned %s" % probe['unsigned_sizes'][b], 'newmacro': "UINT%u_T" % (b * 8)})
509 macros.append({'oldmacro': "signed %s" % probe['signed_sizes'][b], 'newmacro': "INT%u_T" % (b * 8)})
510
511 macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
512 macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
513 macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
514 macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
515 macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
516
517 name = probe['unsigned_concs'][b]
518 if ((name.startswith('@')) or (name == "")):
519 macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
520 else:
521 macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
522
523 name = probe['unsigned_concs'][b]
524 if ((name.startswith('@')) or (name == "")):
525 macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
526 else:
527 macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
528
529 for tag in inttags:
530 newmacro = "U%s" % tag
531 if (not tag in probe['unsigned_tags']):
532 print_error(['Unable to find appropriate size macro for %s.' % newmacro,
533 COMPILER_FAIL])
534
535 oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
536 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
537 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
538 macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)})
539
540 newmacro = tag
541 if (not tag in probe['signed_tags']):
542 print_error(['Unable to find appropriate size macro for %s' % newmacro,
543 COMPILER_FAIL])
544
545 oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
546 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
547 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
548 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['signed_tags'][tag] * 8)})
549
550 for tag in floattags:
551 if (not tag in probe['float_tags']):
552 print_error(['Unable to find appropriate size macro for %s' % tag,
553 COMPILER_FAIL])
554
555 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['float_tags'][tag] * 8)})
556
557 if (not 'size' in probe['builtin_signs']):
558 print_error(['Unable to determine whether size_t is signed or unsigned.',
559 COMPILER_FAIL])
560
561 if (probe['builtin_signs']['size'] != 'unsigned'):
562 print_error(['The type size_t is not unsigned.',
563 COMPILER_FAIL])
564
565 fnd = True
566
567 if (not 'wchar' in probe['builtin_sizes']):
568 print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
569 'for defining the compiler-native type wchar_t. We are',
570 'forced to define wchar_t as a hardwired type int32_t.',
571 COMPILER_WARNING])
572 fnd = False
573
574 if (probe['builtin_sizes']['wchar']['value'] != 4):
575 print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
576 'the compiler-native type wchar_t is not compliant with',
577 'HelenOS. We are forced to define wchar_t as a hardwired',
578 'type int32_t.',
579 COMPILER_WARNING])
580 fnd = False
581
582 if (not fnd):
583 macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
584 else:
585 macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
586
587 if (not 'wchar' in probe['builtin_signs']):
588 print_error(['Unable to determine whether wchar_t is signed or unsigned.',
589 COMPILER_FAIL])
590
591 if (probe['builtin_signs']['wchar'] == 'unsigned'):
592 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_UNSIGNED'})
593 if (probe['builtin_signs']['wchar'] == 'signed'):
594 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_SIGNED'})
595
596 fnd = True
597
598 if (not 'wint' in probe['builtin_sizes']):
599 print_warning(['The compiler does not provide the macro __WINT_TYPE__',
600 'for defining the compiler-native type wint_t. We are',
601 'forced to define wint_t as a hardwired type int32_t.',
602 COMPILER_WARNING])
603 fnd = False
604
605 if (probe['builtin_sizes']['wint']['value'] != 4):
606 print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
607 'the compiler-native type wint_t is not compliant with',
608 'HelenOS. We are forced to define wint_t as a hardwired',
609 'type int32_t.',
610 COMPILER_WARNING])
611 fnd = False
612
613 if (not fnd):
614 macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
615 else:
616 macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
617
618 if (not 'wint' in probe['builtin_signs']):
619 print_error(['Unable to determine whether wint_t is signed or unsigned.',
620 COMPILER_FAIL])
621
622 if (probe['builtin_signs']['wint'] == 'unsigned'):
623 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_UNSIGNED'})
624 if (probe['builtin_signs']['wint'] == 'signed'):
625 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_SIGNED'})
626
627 return {'macros': macros, 'typedefs': typedefs}
628
629def create_makefile(mkname, common):
630 "Create makefile output"
631
632 outmk = open(mkname, 'w')
633
634 outmk.write('#########################################\n')
635 outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
636 outmk.write('## Generated by: tools/autotool.py ##\n')
637 outmk.write('#########################################\n\n')
638
639 for key, value in common.items():
640 if (type(value) is list):
641 outmk.write('%s = %s\n' % (key, " ".join(value)))
642 else:
643 outmk.write('%s = %s\n' % (key, value))
644
645 outmk.close()
646
647def create_header(hdname, maps):
648 "Create header output"
649
650 outhd = open(hdname, 'w')
651
652 outhd.write('/***************************************\n')
653 outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
654 outhd.write(' * Generated by: tools/autotool.py *\n')
655 outhd.write(' ***************************************/\n\n')
656
657 outhd.write('#ifndef %s\n' % GUARD)
658 outhd.write('#define %s\n\n' % GUARD)
659
660 for macro in maps['macros']:
661 outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
662
663 outhd.write('\n')
664
665 for typedef in maps['typedefs']:
666 outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
667
668 outhd.write('\n#endif\n')
669 outhd.close()
670
671def main():
672 config = {}
673 common = {}
674
675 # Read and check configuration
676 if os.path.exists(CONFIG):
677 read_config(CONFIG, config)
678 else:
679 print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
680 "configuration phase of HelenOS build went OK. Try running",
681 "\"make config\" again."])
682
683 check_config(config, "PLATFORM")
684 check_config(config, "COMPILER")
685 check_config(config, "BARCH")
686
687 # Cross-compiler prefix
688 if ('CROSS_PREFIX' in os.environ):
689 cross_prefix = os.environ['CROSS_PREFIX']
690 else:
691 cross_prefix = "/usr/local/cross"
692
693 # Prefix binutils tools on Solaris
694 if (os.uname()[0] == "SunOS"):
695 binutils_prefix = "g"
696 else:
697 binutils_prefix = ""
698
699 owd = sandbox_enter()
700
701 try:
702 # Common utilities
703 check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
704 check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
705 check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
706 check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
707 check_app(["find", "--version"], "Find utility", "usually part of findutils")
708 check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
709 check_app(["make", "--version"], "Make utility", "preferably GNU Make")
710 check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
711
712 # Compiler
713 common['CC_ARGS'] = []
714 if (config['COMPILER'] == "gcc_cross"):
715 target, gnu_target, clang_target_unused = get_target(config)
716
717 path = "%s/%s/bin" % (cross_prefix, target)
718 prefix = "%s-" % gnu_target
719
720 check_gcc(path, prefix, common, PACKAGE_CROSS)
721 check_binutils(path, prefix, common, PACKAGE_CROSS)
722
723 check_common(common, "GCC")
724 common['CC'] = common['GCC']
725
726 if (config['COMPILER'] == "gcc_native"):
727 check_gcc(None, "", common, PACKAGE_GCC)
728 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
729
730 check_common(common, "GCC")
731 common['CC'] = common['GCC']
732
733 if (config['COMPILER'] == "icc"):
734 common['CC'] = "icc"
735 check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
736 check_gcc(None, "", common, PACKAGE_GCC)
737 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
738
739 if (config['COMPILER'] == "clang"):
740 target, gnu_target, clang_target = get_target(config, True)
741 path = "%s/%s/bin" % (cross_prefix, target)
742 prefix = "%s-" % gnu_target
743
744 common['CC'] = "clang"
745 common['CC_ARGS'].append("-target")
746 common['CC_ARGS'].append(clang_target)
747 check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
748 check_gcc(path, prefix, common, PACKAGE_GCC)
749 check_binutils(path, prefix, common, PACKAGE_BINUTILS)
750
751 # Platform-specific utilities
752 if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
753 common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
754
755 probe = probe_compiler(common,
756 [
757 {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
758 {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
759 {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
760 {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
761 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
762 ],
763 [
764 {'type': 'long double', 'tag': 'LONG_DOUBLE'},
765 {'type': 'double', 'tag': 'DOUBLE'},
766 {'type': 'float', 'tag': 'FLOAT'}
767 ]
768 )
769
770 maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT'])
771
772 finally:
773 sandbox_leave(owd)
774
775 create_makefile(MAKEFILE, common)
776 create_header(HEADER, maps)
777
778 return 0
779
780if __name__ == '__main__':
781 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.