source: mainline/tools/autotool.py@ d8bb821

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

human-friendly check for PyYAML

  • Property mode set to 100755
File size: 29.4 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 check_python():
359 "Check for Python dependencies"
360
361 try:
362 sys.stderr.write("Checking for PyYAML ... ")
363 import yaml
364 except ImportError:
365 print_error(["PyYAML is missing.",
366 "",
367 "Please make sure that it is installed in your",
368 "system (usually part of PyYAML package)."])
369
370 sys.stderr.write("ok\n")
371
372def decode_value(value):
373 "Decode integer value"
374
375 base = 10
376
377 if ((value.startswith('$')) or (value.startswith('#'))):
378 value = value[1:]
379
380 if (value.startswith('0x')):
381 value = value[2:]
382 base = 16
383
384 return int(value, base)
385
386def probe_compiler(common, intsizes, floatsizes):
387 "Generate, compile and parse probing source"
388
389 check_common(common, "CC")
390
391 outf = open(PROBE_SOURCE, 'w')
392 outf.write(PROBE_HEAD)
393
394 for typedef in intsizes:
395 outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
396
397 for typedef in floatsizes:
398 outf.write("\nDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
399
400 outf.write(PROBE_TAIL)
401 outf.close()
402
403 args = [common['CC']]
404 args.extend(common['CC_ARGS'])
405 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
406
407 try:
408 sys.stderr.write("Checking compiler properties ... ")
409 output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
410 except:
411 sys.stderr.write("failed\n")
412 print_error(["Error executing \"%s\"." % " ".join(args),
413 "Make sure that the compiler works properly."])
414
415 if (not os.path.isfile(PROBE_OUTPUT)):
416 sys.stderr.write("failed\n")
417 print(output[1])
418 print_error(["Error executing \"%s\"." % " ".join(args),
419 "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
420 "",
421 output[0],
422 output[1]])
423
424 sys.stderr.write("ok\n")
425
426 inf = open(PROBE_OUTPUT, 'r')
427 lines = inf.readlines()
428 inf.close()
429
430 unsigned_sizes = {}
431 signed_sizes = {}
432
433 unsigned_tags = {}
434 signed_tags = {}
435
436 unsigned_strcs = {}
437 signed_strcs = {}
438
439 unsigned_concs = {}
440 signed_concs = {}
441
442 float_tags = {}
443
444 builtin_sizes = {}
445 builtin_signs = {}
446
447 for j in range(len(lines)):
448 tokens = lines[j].strip().split("\t")
449
450 if (len(tokens) > 0):
451 if (tokens[0] == "AUTOTOOL_DECLARE"):
452 if (len(tokens) < 7):
453 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
454
455 category = tokens[1]
456 subcategory = tokens[2]
457 tag = tokens[3]
458 name = tokens[4]
459 strc = tokens[5]
460 conc = tokens[6]
461 value = tokens[7]
462
463 if (category == "intsize"):
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 if (subcategory == "unsigned"):
470 unsigned_sizes[value_int] = name
471 unsigned_tags[tag] = value_int
472 unsigned_strcs[value_int] = strc
473 unsigned_concs[value_int] = conc
474 elif (subcategory == "signed"):
475 signed_sizes[value_int] = name
476 signed_tags[tag] = value_int
477 signed_strcs[value_int] = strc
478 signed_concs[value_int] = conc
479 else:
480 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
481
482 if (category == "floatsize"):
483 try:
484 value_int = decode_value(value)
485 except:
486 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
487
488 float_tags[tag] = value_int
489
490 if (category == "builtin_size"):
491 try:
492 value_int = decode_value(value)
493 except:
494 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
495
496 builtin_sizes[tag] = {'name': name, 'value': value_int}
497
498 if (category == "builtin_sign"):
499 try:
500 value_int = decode_value(value)
501 except:
502 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
503
504 if (value_int == 1):
505 if (not tag in builtin_signs):
506 builtin_signs[tag] = strc;
507 elif (builtin_signs[tag] != strc):
508 print_error(["Inconsistent builtin type detection in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
509
510 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}
511
512def detect_sizes(probe, bytes, inttags, floattags):
513 "Detect correct types for fixed-size types"
514
515 macros = []
516 typedefs = []
517
518 for b in bytes:
519 if (not b in probe['unsigned_sizes']):
520 print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b,
521 COMPILER_FAIL])
522
523 if (not b in probe['signed_sizes']):
524 print_error(['Unable to find appropriate signed integer type for %u bytes.' % b,
525 COMPILER_FAIL])
526
527 if (not b in probe['unsigned_strcs']):
528 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b,
529 COMPILER_FAIL])
530
531 if (not b in probe['signed_strcs']):
532 print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b,
533 COMPILER_FAIL])
534
535 if (not b in probe['unsigned_concs']):
536 print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b,
537 COMPILER_FAIL])
538
539 if (not b in probe['signed_concs']):
540 print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b,
541 COMPILER_FAIL])
542
543 typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
544 typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
545
546 macros.append({'oldmacro': "unsigned %s" % probe['unsigned_sizes'][b], 'newmacro': "UINT%u_T" % (b * 8)})
547 macros.append({'oldmacro': "signed %s" % probe['signed_sizes'][b], 'newmacro': "INT%u_T" % (b * 8)})
548
549 macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
550 macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
551 macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
552 macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
553 macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
554
555 name = probe['unsigned_concs'][b]
556 if ((name.startswith('@')) or (name == "")):
557 macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
558 else:
559 macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
560
561 name = probe['unsigned_concs'][b]
562 if ((name.startswith('@')) or (name == "")):
563 macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
564 else:
565 macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
566
567 for tag in inttags:
568 newmacro = "U%s" % tag
569 if (not tag in probe['unsigned_tags']):
570 print_error(['Unable to find appropriate size macro for %s.' % newmacro,
571 COMPILER_FAIL])
572
573 oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
574 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
575 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
576 macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)})
577
578 newmacro = tag
579 if (not tag in probe['signed_tags']):
580 print_error(['Unable to find appropriate size macro for %s' % newmacro,
581 COMPILER_FAIL])
582
583 oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
584 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
585 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
586 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['signed_tags'][tag] * 8)})
587
588 for tag in floattags:
589 if (not tag in probe['float_tags']):
590 print_error(['Unable to find appropriate size macro for %s' % tag,
591 COMPILER_FAIL])
592
593 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['float_tags'][tag] * 8)})
594
595 if (not 'size' in probe['builtin_signs']):
596 print_error(['Unable to determine whether size_t is signed or unsigned.',
597 COMPILER_FAIL])
598
599 if (probe['builtin_signs']['size'] != 'unsigned'):
600 print_error(['The type size_t is not unsigned.',
601 COMPILER_FAIL])
602
603 fnd = True
604
605 if (not 'wchar' in probe['builtin_sizes']):
606 print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
607 'for defining the compiler-native type wchar_t. We are',
608 'forced to define wchar_t as a hardwired type int32_t.',
609 COMPILER_WARNING])
610 fnd = False
611
612 if (probe['builtin_sizes']['wchar']['value'] != 4):
613 print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
614 'the compiler-native type wchar_t is not compliant with',
615 'HelenOS. We are forced to define wchar_t as a hardwired',
616 'type int32_t.',
617 COMPILER_WARNING])
618 fnd = False
619
620 if (not fnd):
621 macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
622 else:
623 macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
624
625 if (not 'wchar' in probe['builtin_signs']):
626 print_error(['Unable to determine whether wchar_t is signed or unsigned.',
627 COMPILER_FAIL])
628
629 if (probe['builtin_signs']['wchar'] == 'unsigned'):
630 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_UNSIGNED'})
631 if (probe['builtin_signs']['wchar'] == 'signed'):
632 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_SIGNED'})
633
634 fnd = True
635
636 if (not 'wint' in probe['builtin_sizes']):
637 print_warning(['The compiler does not provide the macro __WINT_TYPE__',
638 'for defining the compiler-native type wint_t. We are',
639 'forced to define wint_t as a hardwired type int32_t.',
640 COMPILER_WARNING])
641 fnd = False
642
643 if (probe['builtin_sizes']['wint']['value'] != 4):
644 print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
645 'the compiler-native type wint_t is not compliant with',
646 'HelenOS. We are forced to define wint_t as a hardwired',
647 'type int32_t.',
648 COMPILER_WARNING])
649 fnd = False
650
651 if (not fnd):
652 macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
653 else:
654 macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
655
656 if (not 'wint' in probe['builtin_signs']):
657 print_error(['Unable to determine whether wint_t is signed or unsigned.',
658 COMPILER_FAIL])
659
660 if (probe['builtin_signs']['wint'] == 'unsigned'):
661 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_UNSIGNED'})
662 if (probe['builtin_signs']['wint'] == 'signed'):
663 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_SIGNED'})
664
665 return {'macros': macros, 'typedefs': typedefs}
666
667def create_makefile(mkname, common):
668 "Create makefile output"
669
670 outmk = open(mkname, 'w')
671
672 outmk.write('#########################################\n')
673 outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
674 outmk.write('## Generated by: tools/autotool.py ##\n')
675 outmk.write('#########################################\n\n')
676
677 for key, value in common.items():
678 if (type(value) is list):
679 outmk.write('%s = %s\n' % (key, " ".join(value)))
680 else:
681 outmk.write('%s = %s\n' % (key, value))
682
683 outmk.close()
684
685def create_header(hdname, maps):
686 "Create header output"
687
688 outhd = open(hdname, 'w')
689
690 outhd.write('/***************************************\n')
691 outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
692 outhd.write(' * Generated by: tools/autotool.py *\n')
693 outhd.write(' ***************************************/\n\n')
694
695 outhd.write('#ifndef %s\n' % GUARD)
696 outhd.write('#define %s\n\n' % GUARD)
697
698 for macro in maps['macros']:
699 outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
700
701 outhd.write('\n')
702
703 for typedef in maps['typedefs']:
704 outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
705
706 outhd.write('\n#endif\n')
707 outhd.close()
708
709def main():
710 config = {}
711 common = {}
712
713 # Read and check configuration
714 if os.path.exists(CONFIG):
715 read_config(CONFIG, config)
716 else:
717 print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
718 "configuration phase of HelenOS build went OK. Try running",
719 "\"make config\" again."])
720
721 check_config(config, "PLATFORM")
722 check_config(config, "COMPILER")
723 check_config(config, "BARCH")
724
725 # Cross-compiler prefix
726 if ('CROSS_PREFIX' in os.environ):
727 cross_prefix = os.environ['CROSS_PREFIX']
728 else:
729 cross_prefix = "/usr/local/cross"
730
731 # HelenOS cross-compiler prefix
732 if ('CROSS_HELENOS_PREFIX' in os.environ):
733 cross_helenos_prefix = os.environ['CROSS_HELENOS_PREFIX']
734 else:
735 cross_helenos_prefix = "/usr/local/cross-helenos"
736
737 # Prefix binutils tools on Solaris
738 if (os.uname()[0] == "SunOS"):
739 binutils_prefix = "g"
740 else:
741 binutils_prefix = ""
742
743 owd = sandbox_enter()
744
745 try:
746 # Common utilities
747 check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
748 check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
749 check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
750 check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
751 check_app(["find", "--version"], "Find utility", "usually part of findutils")
752 check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
753 check_app(["make", "--version"], "Make utility", "preferably GNU Make")
754 check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
755
756 # Compiler
757 common['CC_ARGS'] = []
758 if (config['COMPILER'] == "gcc_cross"):
759 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
760
761 if (target is None) or (gnu_target is None):
762 print_error(["Unsupported compiler target for GNU GCC.",
763 "Please contact the developers of HelenOS."])
764
765 path = "%s/%s/bin" % (cross_prefix, target)
766 prefix = "%s-" % gnu_target
767
768 check_gcc(path, prefix, common, PACKAGE_CROSS)
769 check_binutils(path, prefix, common, PACKAGE_CROSS)
770
771 check_common(common, "GCC")
772 common['CC'] = common['GCC']
773 common['CC_ARGS'].extend(cc_args)
774
775 if (config['COMPILER'] == "gcc_helenos"):
776 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
777
778 if (target is None) or (helenos_target is None):
779 print_error(["Unsupported compiler target for GNU GCC.",
780 "Please contact the developers of HelenOS."])
781
782 path = "%s/%s/bin" % (cross_helenos_prefix, target)
783 prefix = "%s-" % helenos_target
784
785 check_gcc(path, prefix, common, PACKAGE_CROSS)
786 check_binutils(path, prefix, common, PACKAGE_CROSS)
787
788 check_common(common, "GCC")
789 common['CC'] = common['GCC']
790 common['CC_ARGS'].extend(cc_args)
791
792 if (config['COMPILER'] == "gcc_native"):
793 check_gcc(None, "", common, PACKAGE_GCC)
794 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
795
796 check_common(common, "GCC")
797 common['CC'] = common['GCC']
798
799 if (config['COMPILER'] == "icc"):
800 common['CC'] = "icc"
801 check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
802 check_gcc(None, "", common, PACKAGE_GCC)
803 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
804
805 if (config['COMPILER'] == "clang"):
806 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
807
808 if (target is None) or (gnu_target is None) or (clang_target is None):
809 print_error(["Unsupported compiler target for clang.",
810 "Please contact the developers of HelenOS."])
811
812 path = "%s/%s/bin" % (cross_prefix, target)
813 prefix = "%s-" % gnu_target
814
815 check_app(["clang", "--version"], "clang compiler", "preferably version 1.0 or newer")
816 check_gcc(path, prefix, common, PACKAGE_GCC)
817 check_binutils(path, prefix, common, PACKAGE_BINUTILS)
818
819 check_common(common, "GCC")
820 common['CC'] = "clang"
821 common['CC_ARGS'].extend(cc_args)
822 common['CC_ARGS'].append("-target")
823 common['CC_ARGS'].append(clang_target)
824 common['CLANG_TARGET'] = clang_target
825
826 check_python()
827
828 # Platform-specific utilities
829 if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
830 common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
831
832 probe = probe_compiler(common,
833 [
834 {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
835 {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
836 {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
837 {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
838 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
839 ],
840 [
841 {'type': 'long double', 'tag': 'LONG_DOUBLE'},
842 {'type': 'double', 'tag': 'DOUBLE'},
843 {'type': 'float', 'tag': 'FLOAT'}
844 ]
845 )
846
847 maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT'])
848
849 finally:
850 sandbox_leave(owd)
851
852 common['AUTOGEN'] = "%s/autogen.py" % os.path.dirname(os.path.abspath(sys.argv[0]))
853
854 create_makefile(MAKEFILE, common)
855 create_header(HEADER, maps)
856
857 return 0
858
859if __name__ == '__main__':
860 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.