source: mainline/tools/autotool.py@ 860a7bb

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

Add support for *-helenos-* toolchain

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