source: mainline/tools/autotool.py@ 57292d3

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 57292d3 was 57292d3, checked in by Jakub Jermar <jakub@…>, 11 years ago

Make autogen.py available for the build system.

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