source: mainline/tools/autotool.py@ 80d9d83

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 80d9d83 was b6b02c0, checked in by Jakub Klama <jakub.klama@…>, 12 years ago

Initial work on sparc32 architecture support.

  • /boot/arch/sparc32 loosely based on arm32 port
  • /kernel/arch/sparc32 based on abs32le template
  • /uspace/lib/c/arch/sparc32 based on sparc64 implementation with incompatible parts temporarily commented out.

Work currently done:

  • AMBA plug and play support in loader
  • initial MMU setup
  • kernel booting
  • register window traps
  • context_save_arch/context_restore_arch

Completed milestones: M1, M2

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