source: mainline/tools/autotool.py@ b886b60

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

add highly experimental support for further clang targets

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