source: mainline/tools/autotool.py@ 270bf4f

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

use intrinsic 128-bit integer type if available

  • Property mode set to 100755
File size: 32.0 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
103PROBE_INT128_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
104 asm volatile ( \\
105 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
106 : \\
107 : [val] "n" (value) \\
108 )
109
110#define DECLARE_INTSIZE(tag, type) \\
111 AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, "", "", sizeof(unsigned type)); \\
112 AUTOTOOL_DECLARE("intsize", "signed", tag, #type, "", "", sizeof(signed type));
113
114int main(int argc, char *argv[])
115{
116"""
117
118PROBE_INT128_TAIL = """}
119"""
120
121def read_config(fname, config):
122 "Read HelenOS build configuration"
123
124 inf = open(fname, 'r')
125
126 for line in inf:
127 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
128 if (res):
129 config[res.group(1)] = res.group(2)
130
131 inf.close()
132
133def print_error(msg):
134 "Print a bold error message"
135
136 sys.stderr.write("\n")
137 sys.stderr.write("######################################################################\n")
138 sys.stderr.write("HelenOS build sanity check error:\n")
139 sys.stderr.write("\n")
140 sys.stderr.write("%s\n" % "\n".join(msg))
141 sys.stderr.write("######################################################################\n")
142 sys.stderr.write("\n")
143
144 sys.exit(1)
145
146def print_warning(msg):
147 "Print a bold error message"
148
149 sys.stderr.write("\n")
150 sys.stderr.write("######################################################################\n")
151 sys.stderr.write("HelenOS build sanity check warning:\n")
152 sys.stderr.write("\n")
153 sys.stderr.write("%s\n" % "\n".join(msg))
154 sys.stderr.write("######################################################################\n")
155 sys.stderr.write("\n")
156
157 time.sleep(5)
158
159def sandbox_enter():
160 "Create a temporal sandbox directory for running tests"
161
162 if (os.path.exists(SANDBOX)):
163 if (os.path.isdir(SANDBOX)):
164 try:
165 shutil.rmtree(SANDBOX)
166 except:
167 print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
168 else:
169 print_error(["Please inspect and remove unexpected directory,",
170 "entry \"%s\"." % SANDBOX])
171
172 try:
173 os.mkdir(SANDBOX)
174 except:
175 print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
176
177 owd = os.getcwd()
178 os.chdir(SANDBOX)
179
180 return owd
181
182def sandbox_leave(owd):
183 "Leave the temporal sandbox directory"
184
185 os.chdir(owd)
186
187def check_config(config, key):
188 "Check whether the configuration key exists"
189
190 if (not key in config):
191 print_error(["Build configuration of HelenOS does not contain %s." % key,
192 "Try running \"make config\" again.",
193 "If the problem persists, please contact the developers of HelenOS."])
194
195def check_common(common, key):
196 "Check whether the common key exists"
197
198 if (not key in common):
199 print_error(["Failed to determine the value %s." % key,
200 "Please contact the developers of HelenOS."])
201
202def get_target(config):
203 target = None
204 gnu_target = None
205 clang_target = None
206 helenos_target = None
207 cc_args = []
208
209 if (config['PLATFORM'] == "abs32le"):
210 check_config(config, "CROSS_TARGET")
211 target = config['CROSS_TARGET']
212
213 if (config['CROSS_TARGET'] == "arm32"):
214 gnu_target = "arm-linux-gnueabi"
215 clang_target = "arm-unknown-linux"
216 helenos_target = "arm-helenos-gnueabi"
217
218 if (config['CROSS_TARGET'] == "ia32"):
219 gnu_target = "i686-pc-linux-gnu"
220 clang_target = "i386-unknown-linux"
221 helenos_target = "i686-pc-helenos"
222
223 if (config['CROSS_TARGET'] == "mips32"):
224 gnu_target = "mipsel-linux-gnu"
225 clang_target = "mipsel-unknown-linux"
226 helenos_target = "mipsel-helenos"
227 common['CC_ARGS'].append("-mabi=32")
228
229 if (config['PLATFORM'] == "amd64"):
230 target = config['PLATFORM']
231 gnu_target = "amd64-linux-gnu"
232 clang_target = "x86_64-unknown-linux"
233 helenos_target = "amd64-helenos"
234
235 if (config['PLATFORM'] == "arm32"):
236 target = config['PLATFORM']
237 gnu_target = "arm-linux-gnueabi"
238 clang_target = "arm-unknown-linux"
239 helenos_target = "arm-helenos-gnueabi"
240
241 if (config['PLATFORM'] == "ia32"):
242 target = config['PLATFORM']
243 gnu_target = "i686-pc-linux-gnu"
244 clang_target = "i386-unknown-linux"
245 helenos_target = "i686-pc-helenos"
246
247 if (config['PLATFORM'] == "ia64"):
248 target = config['PLATFORM']
249 gnu_target = "ia64-pc-linux-gnu"
250 helenos_target = "ia64-pc-helenos"
251
252 if (config['PLATFORM'] == "mips32"):
253 check_config(config, "MACHINE")
254 cc_args.append("-mabi=32")
255
256 if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
257 target = config['PLATFORM']
258 gnu_target = "mipsel-linux-gnu"
259 clang_target = "mipsel-unknown-linux"
260 helenos_target = "mipsel-helenos"
261
262 if ((config['MACHINE'] == "bmalta")):
263 target = "mips32eb"
264 gnu_target = "mips-linux-gnu"
265 clang_target = "mips-unknown-linux"
266 helenos_target = "mips-helenos"
267
268 if (config['PLATFORM'] == "mips64"):
269 check_config(config, "MACHINE")
270 cc_args.append("-mabi=64")
271
272 if (config['MACHINE'] == "msim"):
273 target = config['PLATFORM']
274 gnu_target = "mips64el-linux-gnu"
275 clang_target = "mips64el-unknown-linux"
276 helenos_target = "mips64el-helenos"
277
278 if (config['PLATFORM'] == "ppc32"):
279 target = config['PLATFORM']
280 gnu_target = "ppc-linux-gnu"
281 clang_target = "powerpc-unknown-linux"
282 helenos_target = "ppc-helenos"
283
284 if (config['PLATFORM'] == "sparc32"):
285 target = config['PLATFORM'];
286 gnu_target = "sparc-leon3-linux-gnu"
287 helenos_target = "sparc-leon3-helenos"
288
289 if (config['PLATFORM'] == "sparc64"):
290 target = config['PLATFORM']
291 gnu_target = "sparc64-linux-gnu"
292 clang_target = "sparc-unknown-linux"
293 helenos_target = "sparc64-helenos"
294
295 return (target, cc_args, gnu_target, clang_target, helenos_target)
296
297def check_app(args, name, details):
298 "Check whether an application can be executed"
299
300 try:
301 sys.stderr.write("Checking for %s ... " % args[0])
302 subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
303 except:
304 sys.stderr.write("failed\n")
305 print_error(["%s is missing." % name,
306 "",
307 "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
308 "is installed in your system (%s)." % details])
309
310 sys.stderr.write("ok\n")
311
312def check_app_alternatives(alts, args, name, details):
313 "Check whether an application can be executed (use several alternatives)"
314
315 tried = []
316 found = None
317
318 for alt in alts:
319 working = True
320 cmdline = [alt] + args
321 tried.append(" ".join(cmdline))
322
323 try:
324 sys.stderr.write("Checking for %s ... " % alt)
325 subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
326 except:
327 sys.stderr.write("failed\n")
328 working = False
329
330 if (working):
331 sys.stderr.write("ok\n")
332 found = alt
333 break
334
335 if (found is None):
336 print_error(["%s is missing." % name,
337 "",
338 "Please make sure that it is installed in your",
339 "system (%s)." % details,
340 "",
341 "The following alternatives were tried:"] + tried)
342
343 return found
344
345def check_gcc(path, prefix, common, details):
346 "Check for GCC"
347
348 common['GCC'] = "%sgcc" % prefix
349
350 if (not path is None):
351 common['GCC'] = "%s/%s" % (path, common['GCC'])
352
353 check_app([common['GCC'], "--version"], "GNU GCC", details)
354
355def check_binutils(path, prefix, common, details):
356 "Check for binutils toolchain"
357
358 common['AS'] = "%sas" % prefix
359 common['LD'] = "%sld" % prefix
360 common['AR'] = "%sar" % prefix
361 common['OBJCOPY'] = "%sobjcopy" % prefix
362 common['OBJDUMP'] = "%sobjdump" % prefix
363 common['STRIP'] = "%sstrip" % prefix
364
365 if (not path is None):
366 for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
367 common[key] = "%s/%s" % (path, common[key])
368
369 check_app([common['AS'], "--version"], "GNU Assembler", details)
370 check_app([common['LD'], "--version"], "GNU Linker", details)
371 check_app([common['AR'], "--version"], "GNU Archiver", details)
372 check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
373 check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
374 check_app([common['STRIP'], "--version"], "GNU strip", details)
375
376def check_python():
377 "Check for Python dependencies"
378
379 try:
380 sys.stderr.write("Checking for PyYAML ... ")
381 import yaml
382 except ImportError:
383 print_error(["PyYAML is missing.",
384 "",
385 "Please make sure that it is installed in your",
386 "system (usually part of PyYAML package)."])
387
388 sys.stderr.write("ok\n")
389
390def decode_value(value):
391 "Decode integer value"
392
393 base = 10
394
395 if ((value.startswith('$')) or (value.startswith('#'))):
396 value = value[1:]
397
398 if (value.startswith('0x')):
399 value = value[2:]
400 base = 16
401
402 return int(value, base)
403
404def probe_compiler(common, intsizes, floatsizes):
405 "Generate, compile and parse probing source"
406
407 check_common(common, "CC")
408
409 outf = open(PROBE_SOURCE, 'w')
410 outf.write(PROBE_HEAD)
411
412 for typedef in intsizes:
413 outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
414
415 for typedef in floatsizes:
416 outf.write("\nDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
417
418 outf.write(PROBE_TAIL)
419 outf.close()
420
421 args = [common['CC']]
422 args.extend(common['CC_ARGS'])
423 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
424
425 try:
426 sys.stderr.write("Checking compiler properties ... ")
427 output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
428 except:
429 sys.stderr.write("failed\n")
430 print_error(["Error executing \"%s\"." % " ".join(args),
431 "Make sure that the compiler works properly."])
432
433 if (not os.path.isfile(PROBE_OUTPUT)):
434 sys.stderr.write("failed\n")
435 print(output[1])
436 print_error(["Error executing \"%s\"." % " ".join(args),
437 "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
438 "",
439 output[0],
440 output[1]])
441
442 sys.stderr.write("ok\n")
443
444 inf = open(PROBE_OUTPUT, 'r')
445 lines = inf.readlines()
446 inf.close()
447
448 unsigned_sizes = {}
449 signed_sizes = {}
450
451 unsigned_tags = {}
452 signed_tags = {}
453
454 unsigned_strcs = {}
455 signed_strcs = {}
456
457 unsigned_concs = {}
458 signed_concs = {}
459
460 float_tags = {}
461
462 builtin_sizes = {}
463 builtin_signs = {}
464
465 for j in range(len(lines)):
466 tokens = lines[j].strip().split("\t")
467
468 if (len(tokens) > 0):
469 if (tokens[0] == "AUTOTOOL_DECLARE"):
470 if (len(tokens) < 7):
471 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
472
473 category = tokens[1]
474 subcategory = tokens[2]
475 tag = tokens[3]
476 name = tokens[4]
477 strc = tokens[5]
478 conc = tokens[6]
479 value = tokens[7]
480
481 if (category == "intsize"):
482 try:
483 value_int = decode_value(value)
484 except:
485 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
486
487 if (subcategory == "unsigned"):
488 unsigned_sizes[value_int] = name
489 unsigned_tags[tag] = value_int
490 unsigned_strcs[value_int] = strc
491 unsigned_concs[value_int] = conc
492 elif (subcategory == "signed"):
493 signed_sizes[value_int] = name
494 signed_tags[tag] = value_int
495 signed_strcs[value_int] = strc
496 signed_concs[value_int] = conc
497 else:
498 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
499
500 if (category == "floatsize"):
501 try:
502 value_int = decode_value(value)
503 except:
504 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
505
506 float_tags[tag] = value_int
507
508 if (category == "builtin_size"):
509 try:
510 value_int = decode_value(value)
511 except:
512 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
513
514 builtin_sizes[tag] = {'name': name, 'value': value_int}
515
516 if (category == "builtin_sign"):
517 try:
518 value_int = decode_value(value)
519 except:
520 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
521
522 if (value_int == 1):
523 if (not tag in builtin_signs):
524 builtin_signs[tag] = strc;
525 elif (builtin_signs[tag] != strc):
526 print_error(["Inconsistent builtin type detection in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
527
528 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}
529
530def probe_int128(common):
531 "Generate, compile and parse probing source for 128-bit integers"
532
533 check_common(common, "CC")
534
535 outf = open(PROBE_SOURCE, 'w')
536 outf.write(PROBE_INT128_HEAD)
537 outf.write("\tDECLARE_INTSIZE(\"INT128\", int __attribute((mode(TI))));\n")
538 outf.write(PROBE_INT128_TAIL)
539 outf.close()
540
541 args = [common['CC']]
542 args.extend(common['CC_ARGS'])
543 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
544
545 try:
546 sys.stderr.write("Checking whether the compiler has intrinsic support for 128-bit integers ... ")
547 output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
548 except:
549 sys.stderr.write("no\n")
550 return False
551
552 if (not os.path.isfile(PROBE_OUTPUT)):
553 sys.stderr.write("no\n")
554 return False
555
556 inf = open(PROBE_OUTPUT, 'r')
557 lines = inf.readlines()
558 inf.close()
559
560 for j in range(len(lines)):
561 tokens = lines[j].strip().split("\t")
562
563 if (len(tokens) > 0):
564 if (tokens[0] == "AUTOTOOL_DECLARE"):
565 if (len(tokens) < 7):
566 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
567
568 category = tokens[1]
569 subcategory = tokens[2]
570 tag = tokens[3]
571 name = tokens[4]
572 strc = tokens[5]
573 conc = tokens[6]
574 value = tokens[7]
575
576 if (category == "intsize"):
577 try:
578 value_int = decode_value(value)
579 except:
580 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
581
582 if (subcategory == "unsigned"):
583 if (value_int != 16):
584 sys.stderr.write("no\n")
585 return False
586 elif (subcategory == "signed"):
587 if (value_int != 16):
588 sys.stderr.write("no\n")
589 return False
590 else:
591 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
592
593 sys.stderr.write("yes\n")
594 return True
595
596def detect_sizes(probe, bytes, inttags, floattags):
597 "Detect correct types for fixed-size types"
598
599 macros = []
600 typedefs = []
601
602 for b in bytes:
603 if (not b in probe['unsigned_sizes']):
604 print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b,
605 COMPILER_FAIL])
606
607 if (not b in probe['signed_sizes']):
608 print_error(['Unable to find appropriate signed integer type for %u bytes.' % b,
609 COMPILER_FAIL])
610
611 if (not b in probe['unsigned_strcs']):
612 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b,
613 COMPILER_FAIL])
614
615 if (not b in probe['signed_strcs']):
616 print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b,
617 COMPILER_FAIL])
618
619 if (not b in probe['unsigned_concs']):
620 print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b,
621 COMPILER_FAIL])
622
623 if (not b in probe['signed_concs']):
624 print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b,
625 COMPILER_FAIL])
626
627 typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
628 typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
629
630 macros.append({'oldmacro': "unsigned %s" % probe['unsigned_sizes'][b], 'newmacro': "UINT%u_T" % (b * 8)})
631 macros.append({'oldmacro': "signed %s" % probe['signed_sizes'][b], 'newmacro': "INT%u_T" % (b * 8)})
632
633 macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
634 macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
635 macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
636 macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
637 macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
638
639 name = probe['unsigned_concs'][b]
640 if ((name.startswith('@')) or (name == "")):
641 macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
642 else:
643 macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
644
645 name = probe['unsigned_concs'][b]
646 if ((name.startswith('@')) or (name == "")):
647 macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
648 else:
649 macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
650
651 for tag in inttags:
652 newmacro = "U%s" % tag
653 if (not tag in probe['unsigned_tags']):
654 print_error(['Unable to find appropriate size macro for %s.' % newmacro,
655 COMPILER_FAIL])
656
657 oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
658 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
659 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
660 macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)})
661
662 newmacro = tag
663 if (not tag in probe['signed_tags']):
664 print_error(['Unable to find appropriate size macro for %s' % newmacro,
665 COMPILER_FAIL])
666
667 oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
668 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
669 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
670 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['signed_tags'][tag] * 8)})
671
672 for tag in floattags:
673 if (not tag in probe['float_tags']):
674 print_error(['Unable to find appropriate size macro for %s' % tag,
675 COMPILER_FAIL])
676
677 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['float_tags'][tag] * 8)})
678
679 if (not 'size' in probe['builtin_signs']):
680 print_error(['Unable to determine whether size_t is signed or unsigned.',
681 COMPILER_FAIL])
682
683 if (probe['builtin_signs']['size'] != 'unsigned'):
684 print_error(['The type size_t is not unsigned.',
685 COMPILER_FAIL])
686
687 fnd = True
688
689 if (not 'wchar' in probe['builtin_sizes']):
690 print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
691 'for defining the compiler-native type wchar_t. We are',
692 'forced to define wchar_t as a hardwired type int32_t.',
693 COMPILER_WARNING])
694 fnd = False
695
696 if (probe['builtin_sizes']['wchar']['value'] != 4):
697 print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
698 'the compiler-native type wchar_t is not compliant with',
699 'HelenOS. We are forced to define wchar_t as a hardwired',
700 'type int32_t.',
701 COMPILER_WARNING])
702 fnd = False
703
704 if (not fnd):
705 macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
706 else:
707 macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
708
709 if (not 'wchar' in probe['builtin_signs']):
710 print_error(['Unable to determine whether wchar_t is signed or unsigned.',
711 COMPILER_FAIL])
712
713 if (probe['builtin_signs']['wchar'] == 'unsigned'):
714 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_UNSIGNED'})
715 if (probe['builtin_signs']['wchar'] == 'signed'):
716 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_SIGNED'})
717
718 fnd = True
719
720 if (not 'wint' in probe['builtin_sizes']):
721 print_warning(['The compiler does not provide the macro __WINT_TYPE__',
722 'for defining the compiler-native type wint_t. We are',
723 'forced to define wint_t as a hardwired type int32_t.',
724 COMPILER_WARNING])
725 fnd = False
726
727 if (probe['builtin_sizes']['wint']['value'] != 4):
728 print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
729 'the compiler-native type wint_t is not compliant with',
730 'HelenOS. We are forced to define wint_t as a hardwired',
731 'type int32_t.',
732 COMPILER_WARNING])
733 fnd = False
734
735 if (not fnd):
736 macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
737 else:
738 macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
739
740 if (not 'wint' in probe['builtin_signs']):
741 print_error(['Unable to determine whether wint_t is signed or unsigned.',
742 COMPILER_FAIL])
743
744 if (probe['builtin_signs']['wint'] == 'unsigned'):
745 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_UNSIGNED'})
746 if (probe['builtin_signs']['wint'] == 'signed'):
747 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_SIGNED'})
748
749 return {'macros': macros, 'typedefs': typedefs}
750
751def create_makefile(mkname, common):
752 "Create makefile output"
753
754 outmk = open(mkname, 'w')
755
756 outmk.write('#########################################\n')
757 outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
758 outmk.write('## Generated by: tools/autotool.py ##\n')
759 outmk.write('#########################################\n\n')
760
761 for key, value in common.items():
762 if (type(value) is list):
763 outmk.write('%s = %s\n' % (key, " ".join(value)))
764 else:
765 outmk.write('%s = %s\n' % (key, value))
766
767 outmk.close()
768
769def create_header(hdname, maps, int128):
770 "Create header output"
771
772 outhd = open(hdname, 'w')
773
774 outhd.write('/***************************************\n')
775 outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
776 outhd.write(' * Generated by: tools/autotool.py *\n')
777 outhd.write(' ***************************************/\n\n')
778
779 outhd.write('#ifndef %s\n' % GUARD)
780 outhd.write('#define %s\n\n' % GUARD)
781
782 for macro in maps['macros']:
783 outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
784
785 outhd.write('\n')
786
787 for typedef in maps['typedefs']:
788 outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
789
790 if (int128):
791 outhd.write('typedef unsigned int __attribute((mode(TI))) uint128_t;\n')
792 outhd.write('typedef signed int __attribute((mode(TI))) int128_t;\n')
793
794 outhd.write('\n#endif\n')
795 outhd.close()
796
797def main():
798 config = {}
799 common = {}
800
801 # Read and check configuration
802 if os.path.exists(CONFIG):
803 read_config(CONFIG, config)
804 else:
805 print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
806 "configuration phase of HelenOS build went OK. Try running",
807 "\"make config\" again."])
808
809 check_config(config, "PLATFORM")
810 check_config(config, "COMPILER")
811 check_config(config, "BARCH")
812
813 # Cross-compiler prefix
814 if ('CROSS_PREFIX' in os.environ):
815 cross_prefix = os.environ['CROSS_PREFIX']
816 else:
817 cross_prefix = "/usr/local/cross"
818
819 # HelenOS cross-compiler prefix
820 if ('CROSS_HELENOS_PREFIX' in os.environ):
821 cross_helenos_prefix = os.environ['CROSS_HELENOS_PREFIX']
822 else:
823 cross_helenos_prefix = "/usr/local/cross-helenos"
824
825 # Prefix binutils tools on Solaris
826 if (os.uname()[0] == "SunOS"):
827 binutils_prefix = "g"
828 else:
829 binutils_prefix = ""
830
831 owd = sandbox_enter()
832
833 try:
834 # Common utilities
835 check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
836 check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
837 check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
838 check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
839 check_app(["find", "--version"], "Find utility", "usually part of findutils")
840 check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
841 check_app(["make", "--version"], "Make utility", "preferably GNU Make")
842 check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
843
844 # Compiler
845 common['CC_ARGS'] = []
846 if (config['COMPILER'] == "gcc_cross"):
847 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
848
849 if (target is None) or (gnu_target is None):
850 print_error(["Unsupported compiler target for GNU GCC.",
851 "Please contact the developers of HelenOS."])
852
853 path = "%s/%s/bin" % (cross_prefix, target)
854 prefix = "%s-" % gnu_target
855
856 check_gcc(path, prefix, common, PACKAGE_CROSS)
857 check_binutils(path, prefix, common, PACKAGE_CROSS)
858
859 check_common(common, "GCC")
860 common['CC'] = common['GCC']
861 common['CC_ARGS'].extend(cc_args)
862
863 if (config['COMPILER'] == "gcc_helenos"):
864 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
865
866 if (target is None) or (helenos_target is None):
867 print_error(["Unsupported compiler target for GNU GCC.",
868 "Please contact the developers of HelenOS."])
869
870 path = "%s/%s/bin" % (cross_helenos_prefix, target)
871 prefix = "%s-" % helenos_target
872
873 check_gcc(path, prefix, common, PACKAGE_CROSS)
874 check_binutils(path, prefix, common, PACKAGE_CROSS)
875
876 check_common(common, "GCC")
877 common['CC'] = common['GCC']
878 common['CC_ARGS'].extend(cc_args)
879
880 if (config['COMPILER'] == "gcc_native"):
881 check_gcc(None, "", common, PACKAGE_GCC)
882 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
883
884 check_common(common, "GCC")
885 common['CC'] = common['GCC']
886
887 if (config['COMPILER'] == "icc"):
888 common['CC'] = "icc"
889 check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
890 check_gcc(None, "", common, PACKAGE_GCC)
891 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
892
893 if (config['COMPILER'] == "clang"):
894 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
895
896 if (target is None) or (gnu_target is None) or (clang_target is None):
897 print_error(["Unsupported compiler target for clang.",
898 "Please contact the developers of HelenOS."])
899
900 path = "%s/%s/bin" % (cross_prefix, target)
901 prefix = "%s-" % gnu_target
902
903 check_app(["clang", "--version"], "clang compiler", "preferably version 1.0 or newer")
904 check_gcc(path, prefix, common, PACKAGE_GCC)
905 check_binutils(path, prefix, common, PACKAGE_BINUTILS)
906
907 check_common(common, "GCC")
908 common['CC'] = "clang"
909 common['CC_ARGS'].extend(cc_args)
910 common['CC_ARGS'].append("-target")
911 common['CC_ARGS'].append(clang_target)
912 common['CLANG_TARGET'] = clang_target
913
914 check_python()
915
916 # Platform-specific utilities
917 if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
918 common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
919
920 probe = probe_compiler(common,
921 [
922 {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
923 {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
924 {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
925 {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
926 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
927 ],
928 [
929 {'type': 'long double', 'tag': 'LONG_DOUBLE'},
930 {'type': 'double', 'tag': 'DOUBLE'},
931 {'type': 'float', 'tag': 'FLOAT'}
932 ]
933 )
934
935 int128 = probe_int128(common)
936
937 maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT'])
938
939 finally:
940 sandbox_leave(owd)
941
942 common['AUTOGEN'] = "%s/autogen.py" % os.path.dirname(os.path.abspath(sys.argv[0]))
943
944 create_makefile(MAKEFILE, common)
945 create_header(HEADER, maps, int128)
946
947 return 0
948
949if __name__ == '__main__':
950 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.