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
RevLine 
[177e4ea]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#
[3c80f2b]29
[177e4ea]30"""
31Detect important prerequisites and parameters for building HelenOS
32"""
33
34import sys
35import os
[4e9aaf5]36import shutil
[177e4ea]37import re
38import time
39import subprocess
40
[4e9aaf5]41SANDBOX = 'autotool'
42CONFIG = 'Makefile.config'
43MAKEFILE = 'Makefile.common'
44HEADER = 'common.h'
45GUARD = 'AUTOTOOL_COMMON_H_'
46
47PROBE_SOURCE = 'probe.c'
48PROBE_OUTPUT = 'probe.s'
[177e4ea]49
50PACKAGE_BINUTILS = "usually part of binutils"
[a4a0f1d]51PACKAGE_GCC = "preferably version 4.7.0 or newer"
[177e4ea]52PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
53
[4e9aaf5]54COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
[96b89acb]55COMPILER_WARNING = "The compilation of HelenOS might fail."
[4e9aaf5]56
[dc0b964]57PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
[4e9aaf5]58 asm volatile ( \\
[dc0b964]59 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
[4e9aaf5]60 : \\
61 : [val] "n" (value) \\
62 )
63
[96b89acb]64#define STRING(arg) STRING_ARG(arg)
65#define STRING_ARG(arg) #arg
66
67#define DECLARE_BUILTIN_TYPE(tag, type) \\
[a4a0f1d]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));
[96b89acb]79
[dc0b964]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));
[4e9aaf5]83
[a4a0f1d]84#define DECLARE_FLOATSIZE(tag, type) \\
85 AUTOTOOL_DECLARE("floatsize", "", tag, #type, "", "", sizeof(type));
86
[4e9aaf5]87int main(int argc, char *argv[])
88{
[96b89acb]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
[4e9aaf5]98"""
99
100PROBE_TAIL = """}
101"""
102
[177e4ea]103def read_config(fname, config):
104 "Read HelenOS build configuration"
105
[28f4adb]106 inf = open(fname, 'r')
[177e4ea]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
[96b89acb]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
[4e9aaf5]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
[177e4ea]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
[4e9aaf5]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
[95e370f8]184def get_target(config):
[39ba6d5]185 target = None
186 gnu_target = None
[26bcc658]187 clang_target = None
[8f2eca0]188 helenos_target = None
[7f25c4e]189 cc_args = []
[39ba6d5]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"
[6db5d4b]197 clang_target = "arm-unknown-linux"
[8f2eca0]198 helenos_target = "arm-helenos-gnueabi"
[39ba6d5]199
200 if (config['CROSS_TARGET'] == "ia32"):
201 gnu_target = "i686-pc-linux-gnu"
[6db5d4b]202 clang_target = "i386-unknown-linux"
[8f2eca0]203 helenos_target = "i686-pc-helenos"
[39ba6d5]204
205 if (config['CROSS_TARGET'] == "mips32"):
206 gnu_target = "mipsel-linux-gnu"
[6db5d4b]207 clang_target = "mipsel-unknown-linux"
[8f2eca0]208 helenos_target = "mipsel-helenos"
[39ba6d5]209 common['CC_ARGS'].append("-mabi=32")
210
211 if (config['PLATFORM'] == "amd64"):
212 target = config['PLATFORM']
213 gnu_target = "amd64-linux-gnu"
[95e370f8]214 clang_target = "x86_64-unknown-linux"
[8f2eca0]215 helenos_target = "amd64-helenos"
[39ba6d5]216
217 if (config['PLATFORM'] == "arm32"):
218 target = config['PLATFORM']
219 gnu_target = "arm-linux-gnueabi"
[6db5d4b]220 clang_target = "arm-unknown-linux"
[8f2eca0]221 helenos_target = "arm-helenos-gnueabi"
[39ba6d5]222
223 if (config['PLATFORM'] == "ia32"):
224 target = config['PLATFORM']
225 gnu_target = "i686-pc-linux-gnu"
[95e370f8]226 clang_target = "i386-unknown-linux"
[8f2eca0]227 helenos_target = "i686-pc-helenos"
[39ba6d5]228
229 if (config['PLATFORM'] == "ia64"):
230 target = config['PLATFORM']
231 gnu_target = "ia64-pc-linux-gnu"
[8f2eca0]232 helenos_target = "ia64-pc-helenos"
[39ba6d5]233
234 if (config['PLATFORM'] == "mips32"):
235 check_config(config, "MACHINE")
[7f25c4e]236 cc_args.append("-mabi=32")
[39ba6d5]237
[b183ce0a]238 if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
[39ba6d5]239 target = config['PLATFORM']
240 gnu_target = "mipsel-linux-gnu"
[6db5d4b]241 clang_target = "mipsel-unknown-linux"
[8f2eca0]242 helenos_target = "mipsel-helenos"
[39ba6d5]243
[b183ce0a]244 if ((config['MACHINE'] == "bmalta")):
[39ba6d5]245 target = "mips32eb"
246 gnu_target = "mips-linux-gnu"
[6db5d4b]247 clang_target = "mips-unknown-linux"
[8f2eca0]248 helenos_target = "mips-helenos"
[39ba6d5]249
250 if (config['PLATFORM'] == "mips64"):
251 check_config(config, "MACHINE")
[7f25c4e]252 cc_args.append("-mabi=64")
[39ba6d5]253
254 if (config['MACHINE'] == "msim"):
255 target = config['PLATFORM']
256 gnu_target = "mips64el-linux-gnu"
[6db5d4b]257 clang_target = "mips64el-unknown-linux"
[8f2eca0]258 helenos_target = "mips64el-helenos"
[39ba6d5]259
260 if (config['PLATFORM'] == "ppc32"):
261 target = config['PLATFORM']
262 gnu_target = "ppc-linux-gnu"
[6db5d4b]263 clang_target = "powerpc-unknown-linux"
[8f2eca0]264 helenos_target = "ppc-helenos"
[39ba6d5]265
[0c2d9bb]266 if (config['PLATFORM'] == "sparc32"):
267 target = config['PLATFORM'];
268 gnu_target = "sparc-leon3-linux-gnu"
269 helenos_target = "sparc-leon3-helenos"
[39ba6d5]270
271 if (config['PLATFORM'] == "sparc64"):
272 target = config['PLATFORM']
273 gnu_target = "sparc64-linux-gnu"
[6db5d4b]274 clang_target = "sparc-unknown-linux"
[8f2eca0]275 helenos_target = "sparc64-helenos"
[39ba6d5]276
[8f2eca0]277 return (target, cc_args, gnu_target, clang_target, helenos_target)
[39ba6d5]278
[177e4ea]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
[7174403]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
[177e4ea]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
[a4125fb1]345 common['STRIP'] = "%sstrip" % prefix
[177e4ea]346
347 if (not path is None):
[a4125fb1]348 for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
[177e4ea]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)
[a4125fb1]356 check_app([common['STRIP'], "--version"], "GNU strip", details)
[177e4ea]357
[ec07933]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
[96b89acb]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
[a4a0f1d]386def probe_compiler(common, intsizes, floatsizes):
[4e9aaf5]387 "Generate, compile and parse probing source"
388
389 check_common(common, "CC")
390
[28f4adb]391 outf = open(PROBE_SOURCE, 'w')
[4e9aaf5]392 outf.write(PROBE_HEAD)
393
[a4a0f1d]394 for typedef in intsizes:
[dc0b964]395 outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
[4e9aaf5]396
[a4a0f1d]397 for typedef in floatsizes:
398 outf.write("\nDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
399
[4e9aaf5]400 outf.write(PROBE_TAIL)
401 outf.close()
402
[2429e4a]403 args = [common['CC']]
404 args.extend(common['CC_ARGS'])
405 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
[4e9aaf5]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")
[28f4adb]417 print(output[1])
[4e9aaf5]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
[28f4adb]426 inf = open(PROBE_OUTPUT, 'r')
[4e9aaf5]427 lines = inf.readlines()
428 inf.close()
429
430 unsigned_sizes = {}
431 signed_sizes = {}
432
[9539be6]433 unsigned_tags = {}
434 signed_tags = {}
435
[dc0b964]436 unsigned_strcs = {}
437 signed_strcs = {}
438
439 unsigned_concs = {}
440 signed_concs = {}
441
[a4a0f1d]442 float_tags = {}
443
444 builtin_sizes = {}
445 builtin_signs = {}
[96b89acb]446
[4e9aaf5]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"):
[dc0b964]452 if (len(tokens) < 7):
[4e9aaf5]453 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
454
455 category = tokens[1]
456 subcategory = tokens[2]
[9539be6]457 tag = tokens[3]
458 name = tokens[4]
[dc0b964]459 strc = tokens[5]
460 conc = tokens[6]
461 value = tokens[7]
[4e9aaf5]462
463 if (category == "intsize"):
464 try:
[96b89acb]465 value_int = decode_value(value)
[4e9aaf5]466 except:
467 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
468
469 if (subcategory == "unsigned"):
[96b89acb]470 unsigned_sizes[value_int] = name
[9539be6]471 unsigned_tags[tag] = value_int
[96b89acb]472 unsigned_strcs[value_int] = strc
473 unsigned_concs[value_int] = conc
[4e9aaf5]474 elif (subcategory == "signed"):
[96b89acb]475 signed_sizes[value_int] = name
[9539be6]476 signed_tags[tag] = value_int
[96b89acb]477 signed_strcs[value_int] = strc
478 signed_concs[value_int] = conc
[4e9aaf5]479 else:
480 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
[96b89acb]481
[a4a0f1d]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"):
[96b89acb]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
[a4a0f1d]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])
[4e9aaf5]509
[a4a0f1d]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}
[4e9aaf5]511
[a4a0f1d]512def detect_sizes(probe, bytes, inttags, floattags):
513 "Detect correct types for fixed-size types"
[4e9aaf5]514
[9539be6]515 macros = []
[4e9aaf5]516 typedefs = []
517
518 for b in bytes:
[96b89acb]519 if (not b in probe['unsigned_sizes']):
[a4a0f1d]520 print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b,
[4e9aaf5]521 COMPILER_FAIL])
522
[96b89acb]523 if (not b in probe['signed_sizes']):
[a4a0f1d]524 print_error(['Unable to find appropriate signed integer type for %u bytes.' % b,
[4e9aaf5]525 COMPILER_FAIL])
[dc0b964]526
[96b89acb]527 if (not b in probe['unsigned_strcs']):
[a4a0f1d]528 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b,
[85369b1]529 COMPILER_FAIL])
[dc0b964]530
[96b89acb]531 if (not b in probe['signed_strcs']):
[a4a0f1d]532 print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b,
[85369b1]533 COMPILER_FAIL])
[dc0b964]534
[96b89acb]535 if (not b in probe['unsigned_concs']):
[a4a0f1d]536 print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b,
[85369b1]537 COMPILER_FAIL])
[dc0b964]538
[96b89acb]539 if (not b in probe['signed_concs']):
[a4a0f1d]540 print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b,
[96b89acb]541 COMPILER_FAIL])
[dc0b964]542
[96b89acb]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)})
[dc0b964]545
[d408ea0]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
[96b89acb]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)})
[9539be6]554
[96b89acb]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)})
[9539be6]560
[96b89acb]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
[a4a0f1d]567 for tag in inttags:
[96b89acb]568 newmacro = "U%s" % tag
569 if (not tag in probe['unsigned_tags']):
[a4a0f1d]570 print_error(['Unable to find appropriate size macro for %s.' % newmacro,
[9539be6]571 COMPILER_FAIL])
572
[96b89acb]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})
[a4a0f1d]576 macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)})
[9539be6]577
[96b89acb]578 newmacro = tag
[a4a0f1d]579 if (not tag in probe['signed_tags']):
[9539be6]580 print_error(['Unable to find appropriate size macro for %s' % newmacro,
581 COMPILER_FAIL])
[96b89acb]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})
[a4a0f1d]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])
[96b89acb]602
603 fnd = True
604
[a4a0f1d]605 if (not 'wchar' in probe['builtin_sizes']):
[96b89acb]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
[a4a0f1d]612 if (probe['builtin_sizes']['wchar']['value'] != 4):
[96b89acb]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
[a4a0f1d]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
[96b89acb]634 fnd = True
635
[a4a0f1d]636 if (not 'wint' in probe['builtin_sizes']):
[96b89acb]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
[a4a0f1d]643 if (probe['builtin_sizes']['wint']['value'] != 4):
[96b89acb]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"})
[9539be6]655
[a4a0f1d]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
[9539be6]665 return {'macros': macros, 'typedefs': typedefs}
[4e9aaf5]666
667def create_makefile(mkname, common):
668 "Create makefile output"
[177e4ea]669
[28f4adb]670 outmk = open(mkname, 'w')
[177e4ea]671
[4e9aaf5]672 outmk.write('#########################################\n')
673 outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
[571239a]674 outmk.write('## Generated by: tools/autotool.py ##\n')
[4e9aaf5]675 outmk.write('#########################################\n\n')
[177e4ea]676
677 for key, value in common.items():
[7174403]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))
[4e9aaf5]682
683 outmk.close()
684
[9539be6]685def create_header(hdname, maps):
[4e9aaf5]686 "Create header output"
687
[28f4adb]688 outhd = open(hdname, 'w')
[4e9aaf5]689
690 outhd.write('/***************************************\n')
691 outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
[571239a]692 outhd.write(' * Generated by: tools/autotool.py *\n')
[4e9aaf5]693 outhd.write(' ***************************************/\n\n')
[177e4ea]694
[4e9aaf5]695 outhd.write('#ifndef %s\n' % GUARD)
696 outhd.write('#define %s\n\n' % GUARD)
697
[9539be6]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']:
[4e9aaf5]704 outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
705
706 outhd.write('\n#endif\n')
707 outhd.close()
[177e4ea]708
709def main():
710 config = {}
711 common = {}
712
713 # Read and check configuration
[4e9aaf5]714 if os.path.exists(CONFIG):
715 read_config(CONFIG, config)
[177e4ea]716 else:
[4e9aaf5]717 print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
[177e4ea]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:
[603c8740]729 cross_prefix = "/usr/local/cross"
[177e4ea]730
[8f2eca0]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
[177e4ea]737 # Prefix binutils tools on Solaris
738 if (os.uname()[0] == "SunOS"):
739 binutils_prefix = "g"
740 else:
741 binutils_prefix = ""
742
[4e9aaf5]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
[2429e4a]757 common['CC_ARGS'] = []
[4e9aaf5]758 if (config['COMPILER'] == "gcc_cross"):
[8f2eca0]759 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
[95e370f8]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
[4e9aaf5]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']
[7f25c4e]773 common['CC_ARGS'].extend(cc_args)
[177e4ea]774
[8f2eca0]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
[4e9aaf5]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']
[177e4ea]798
[4e9aaf5]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)
[177e4ea]804
[4e9aaf5]805 if (config['COMPILER'] == "clang"):
[0dd022ec]806 target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
[95e370f8]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
[39ba6d5]812 path = "%s/%s/bin" % (cross_prefix, target)
813 prefix = "%s-" % gnu_target
814
[95e370f8]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")
[4e9aaf5]820 common['CC'] = "clang"
[7f25c4e]821 common['CC_ARGS'].extend(cc_args)
[26bcc658]822 common['CC_ARGS'].append("-target")
823 common['CC_ARGS'].append(clang_target)
[95e370f8]824 common['CLANG_TARGET'] = clang_target
[177e4ea]825
[ec07933]826 check_python()
827
[4e9aaf5]828 # Platform-specific utilities
829 if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
[7174403]830 common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
[177e4ea]831
[4e9aaf5]832 probe = probe_compiler(common,
833 [
[96b89acb]834 {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
[dc0b964]835 {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
[96b89acb]836 {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
837 {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
838 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
[a4a0f1d]839 ],
840 [
841 {'type': 'long double', 'tag': 'LONG_DOUBLE'},
842 {'type': 'double', 'tag': 'DOUBLE'},
843 {'type': 'float', 'tag': 'FLOAT'}
[4e9aaf5]844 ]
845 )
[177e4ea]846
[a4a0f1d]847 maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT'])
[177e4ea]848
[4e9aaf5]849 finally:
850 sandbox_leave(owd)
851
[57292d3]852 common['AUTOGEN'] = "%s/autogen.py" % os.path.dirname(os.path.abspath(sys.argv[0]))
853
[4e9aaf5]854 create_makefile(MAKEFILE, common)
[9539be6]855 create_header(HEADER, maps)
[177e4ea]856
857 return 0
858
859if __name__ == '__main__':
860 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.