source: mainline/tools/autotool.py@ e4c8e751

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

determine CLANG_TARGET in autotool

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