source: mainline/tools/autotool.py@ 0c2d9bb

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

merge mainline changes

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