source: mainline/tools/autotool.py@ cc92076

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since cc92076 was cc92076, checked in by jzr <zarevucky.jiri@…>, 8 years ago

Clean up minor issues with the Makefiles.

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