source: mainline/tools/autotool.py@ df8eaba

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since df8eaba was b2aaaa0, checked in by Jiří Zárevúcky <jiri.zarevucky@…>, 7 years ago

Remove duplicate cc_args from autotool.py, fix mips

  • Property mode set to 100755
File size: 20.1 KB
RevLine 
[ce55b43]1#!/usr/bin/env python2
[177e4ea]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'
[cc92076]44HEADER = 'common.h.new'
[ce55b43]45GUARD = '_AUTOTOOL_COMMON_H_'
[4e9aaf5]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"
[84eb4edd]53PACKAGE_CLANG = "reasonably recent version of clang needs to be installed"
[177e4ea]54
[12bdbcc6]55TOOLCHAIN_FAIL = [
[b4c8a7b]56 "Compiler toolchain for target is not installed, or CROSS_PREFIX",
[12bdbcc6]57 "environment variable is not set correctly. Use tools/toolchain.sh",
58 "to (re)build the cross-compiler toolchain."]
[4e9aaf5]59COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
[96b89acb]60COMPILER_WARNING = "The compilation of HelenOS might fail."
[4e9aaf5]61
[ce55b43]62PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, tag, name, signedness, base, size, compatible) \\
[4e9aaf5]63 asm volatile ( \\
[ce55b43]64 "AUTOTOOL_DECLARE\\t" category "\\t" tag "\\t" name "\\t" signedness "\\t" base "\\t%[size_val]\\t%[cmp_val]\\n" \\
[4e9aaf5]65 : \\
[ce55b43]66 : [size_val] "n" (size), [cmp_val] "n" (compatible) \\
[4e9aaf5]67 )
68
[96b89acb]69#define STRING(arg) STRING_ARG(arg)
70#define STRING_ARG(arg) #arg
71
72#define DECLARE_BUILTIN_TYPE(tag, type) \\
[ce55b43]73 AUTOTOOL_DECLARE("unsigned long long int", tag, STRING(type), "unsigned", "long long", sizeof(type), __builtin_types_compatible_p(type, unsigned long long int)); \\
74 AUTOTOOL_DECLARE("unsigned long int", tag, STRING(type), "unsigned", "long", sizeof(type), __builtin_types_compatible_p(type, unsigned long int)); \\
75 AUTOTOOL_DECLARE("unsigned int", tag, STRING(type), "unsigned", "int", sizeof(type), __builtin_types_compatible_p(type, unsigned int)); \\
76 AUTOTOOL_DECLARE("unsigned short int", tag, STRING(type), "unsigned", "short", sizeof(type), __builtin_types_compatible_p(type, unsigned short int)); \\
77 AUTOTOOL_DECLARE("unsigned char", tag, STRING(type), "unsigned", "char", sizeof(type), __builtin_types_compatible_p(type, unsigned char)); \\
78 AUTOTOOL_DECLARE("signed long long int", tag, STRING(type), "signed", "long long", sizeof(type), __builtin_types_compatible_p(type, signed long long int)); \\
79 AUTOTOOL_DECLARE("signed long int", tag, STRING(type), "signed", "long", sizeof(type), __builtin_types_compatible_p(type, signed long int)); \\
80 AUTOTOOL_DECLARE("signed int", tag, STRING(type), "signed", "int", sizeof(type), __builtin_types_compatible_p(type, signed int)); \\
81 AUTOTOOL_DECLARE("signed short int", tag, STRING(type), "signed", "short", sizeof(type), __builtin_types_compatible_p(type, signed short int)); \\
82 AUTOTOOL_DECLARE("signed char", tag, STRING(type), "signed", "char", sizeof(type), __builtin_types_compatible_p(type, signed char)); \\
83 AUTOTOOL_DECLARE("pointer", tag, STRING(type), "N/A", "pointer", sizeof(type), __builtin_types_compatible_p(type, void*)); \\
84 AUTOTOOL_DECLARE("long double", tag, STRING(type), "signed", "long double", sizeof(type), __builtin_types_compatible_p(type, long double)); \\
85 AUTOTOOL_DECLARE("double", tag, STRING(type), "signed", "double", sizeof(type), __builtin_types_compatible_p(type, double)); \\
86 AUTOTOOL_DECLARE("float", tag, STRING(type), "signed", "float", sizeof(type), __builtin_types_compatible_p(type, float));
[a4a0f1d]87
[795e2bf]88extern int main(int, char *[]);
89
[4e9aaf5]90int main(int argc, char *argv[])
91{
92"""
93
94PROBE_TAIL = """}
95"""
96
[177e4ea]97def read_config(fname, config):
98 "Read HelenOS build configuration"
[a35b458]99
[28f4adb]100 inf = open(fname, 'r')
[a35b458]101
[177e4ea]102 for line in inf:
103 res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
104 if (res):
105 config[res.group(1)] = res.group(2)
[a35b458]106
[177e4ea]107 inf.close()
108
109def print_error(msg):
110 "Print a bold error message"
[a35b458]111
[177e4ea]112 sys.stderr.write("\n")
113 sys.stderr.write("######################################################################\n")
114 sys.stderr.write("HelenOS build sanity check error:\n")
115 sys.stderr.write("\n")
116 sys.stderr.write("%s\n" % "\n".join(msg))
117 sys.stderr.write("######################################################################\n")
118 sys.stderr.write("\n")
[a35b458]119
[177e4ea]120 sys.exit(1)
121
[96b89acb]122def print_warning(msg):
123 "Print a bold error message"
[a35b458]124
[96b89acb]125 sys.stderr.write("\n")
126 sys.stderr.write("######################################################################\n")
127 sys.stderr.write("HelenOS build sanity check warning:\n")
128 sys.stderr.write("\n")
129 sys.stderr.write("%s\n" % "\n".join(msg))
130 sys.stderr.write("######################################################################\n")
131 sys.stderr.write("\n")
[a35b458]132
[96b89acb]133 time.sleep(5)
134
[4e9aaf5]135def sandbox_enter():
136 "Create a temporal sandbox directory for running tests"
[a35b458]137
[4e9aaf5]138 if (os.path.exists(SANDBOX)):
139 if (os.path.isdir(SANDBOX)):
140 try:
141 shutil.rmtree(SANDBOX)
142 except:
143 print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
144 else:
145 print_error(["Please inspect and remove unexpected directory,",
146 "entry \"%s\"." % SANDBOX])
[a35b458]147
[4e9aaf5]148 try:
149 os.mkdir(SANDBOX)
150 except:
151 print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
[a35b458]152
[4e9aaf5]153 owd = os.getcwd()
154 os.chdir(SANDBOX)
[a35b458]155
[4e9aaf5]156 return owd
157
158def sandbox_leave(owd):
159 "Leave the temporal sandbox directory"
[a35b458]160
[4e9aaf5]161 os.chdir(owd)
162
[177e4ea]163def check_config(config, key):
164 "Check whether the configuration key exists"
[a35b458]165
[177e4ea]166 if (not key in config):
167 print_error(["Build configuration of HelenOS does not contain %s." % key,
168 "Try running \"make config\" again.",
169 "If the problem persists, please contact the developers of HelenOS."])
170
[4e9aaf5]171def check_common(common, key):
172 "Check whether the common key exists"
[a35b458]173
[4e9aaf5]174 if (not key in common):
175 print_error(["Failed to determine the value %s." % key,
176 "Please contact the developers of HelenOS."])
177
[95e370f8]178def get_target(config):
[b08941d]179 platform = None
180 target = None
[a35b458]181
[39ba6d5]182 if (config['PLATFORM'] == "abs32le"):
183 check_config(config, "CROSS_TARGET")
[b08941d]184 platform = config['CROSS_TARGET']
[a35b458]185
[39ba6d5]186 if (config['CROSS_TARGET'] == "arm32"):
[bbe5e34]187 target = "arm-helenos"
[a35b458]188
[39ba6d5]189 if (config['CROSS_TARGET'] == "ia32"):
[bbe5e34]190 target = "i686-helenos"
[a35b458]191
[39ba6d5]192 if (config['CROSS_TARGET'] == "mips32"):
[bbe5e34]193 target = "mipsel-helenos"
[a35b458]194
[39ba6d5]195 if (config['PLATFORM'] == "amd64"):
[b08941d]196 platform = config['PLATFORM']
[bbe5e34]197 target = "amd64-helenos"
[a35b458]198
[39ba6d5]199 if (config['PLATFORM'] == "arm32"):
[b08941d]200 platform = config['PLATFORM']
[bbe5e34]201 target = "arm-helenos"
[a35b458]202
[39ba6d5]203 if (config['PLATFORM'] == "ia32"):
[b08941d]204 platform = config['PLATFORM']
[bbe5e34]205 target = "i686-helenos"
[a35b458]206
[39ba6d5]207 if (config['PLATFORM'] == "ia64"):
[b08941d]208 platform = config['PLATFORM']
[bbe5e34]209 target = "ia64-helenos"
[a35b458]210
[39ba6d5]211 if (config['PLATFORM'] == "mips32"):
212 check_config(config, "MACHINE")
[a35b458]213
[b183ce0a]214 if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
[b08941d]215 platform = config['PLATFORM']
[bbe5e34]216 target = "mipsel-helenos"
[a35b458]217
[b183ce0a]218 if ((config['MACHINE'] == "bmalta")):
[b08941d]219 platform = "mips32eb"
[bbe5e34]220 target = "mips-helenos"
[a35b458]221
[39ba6d5]222 if (config['PLATFORM'] == "mips64"):
223 check_config(config, "MACHINE")
[a35b458]224
[39ba6d5]225 if (config['MACHINE'] == "msim"):
[b08941d]226 platform = config['PLATFORM']
[bbe5e34]227 target = "mips64el-helenos"
[a35b458]228
[39ba6d5]229 if (config['PLATFORM'] == "ppc32"):
[b08941d]230 platform = config['PLATFORM']
[bbe5e34]231 target = "ppc-helenos"
[a35b458]232
[114d098]233 if (config['PLATFORM'] == "riscv64"):
[b08941d]234 platform = config['PLATFORM']
[bbe5e34]235 target = "riscv64-helenos"
[a35b458]236
[39ba6d5]237 if (config['PLATFORM'] == "sparc64"):
[b08941d]238 platform = config['PLATFORM']
[bbe5e34]239 target = "sparc64-helenos"
[a35b458]240
[b2aaaa0]241 return (platform, target)
[39ba6d5]242
[177e4ea]243def check_app(args, name, details):
244 "Check whether an application can be executed"
[a35b458]245
[177e4ea]246 try:
247 sys.stderr.write("Checking for %s ... " % args[0])
248 subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
249 except:
250 sys.stderr.write("failed\n")
251 print_error(["%s is missing." % name,
252 "",
253 "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
254 "is installed in your system (%s)." % details])
[a35b458]255
[177e4ea]256 sys.stderr.write("ok\n")
257
[bbe5e34]258def check_path_gcc(target):
259 "Check whether GCC for a given target is present in $PATH."
260
261 try:
262 subprocess.Popen([ "%s-gcc" % target, "--version" ], stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
263 return True
264 except:
265 return False
266
[7174403]267def check_app_alternatives(alts, args, name, details):
268 "Check whether an application can be executed (use several alternatives)"
[a35b458]269
[7174403]270 tried = []
271 found = None
[a35b458]272
[7174403]273 for alt in alts:
274 working = True
275 cmdline = [alt] + args
276 tried.append(" ".join(cmdline))
[a35b458]277
[7174403]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
[a35b458]284
[7174403]285 if (working):
286 sys.stderr.write("ok\n")
287 found = alt
288 break
[a35b458]289
[7174403]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)
[a35b458]297
[7174403]298 return found
299
[a0a273e]300def check_clang(path, prefix, common, details):
301 "Check for clang"
[a35b458]302
[a0a273e]303 common['CLANG'] = "%sclang" % prefix
[a35b458]304
[a0a273e]305 if (not path is None):
306 common['CLANG'] = "%s/%s" % (path, common['CLANG'])
[a35b458]307
[a0a273e]308 check_app([common['CLANG'], "--version"], "clang", details)
309
[177e4ea]310def check_gcc(path, prefix, common, details):
311 "Check for GCC"
[a35b458]312
[177e4ea]313 common['GCC'] = "%sgcc" % prefix
[8e2154e7]314 common['GXX'] = "%sg++" % prefix
[a35b458]315
[177e4ea]316 if (not path is None):
317 common['GCC'] = "%s/%s" % (path, common['GCC'])
[8e2154e7]318 common['GXX'] = "%s/%s" % (path, common['GXX'])
[a35b458]319
[177e4ea]320 check_app([common['GCC'], "--version"], "GNU GCC", details)
321
322def check_binutils(path, prefix, common, details):
323 "Check for binutils toolchain"
[a35b458]324
[177e4ea]325 common['AS'] = "%sas" % prefix
326 common['LD'] = "%sld" % prefix
327 common['AR'] = "%sar" % prefix
328 common['OBJCOPY'] = "%sobjcopy" % prefix
329 common['OBJDUMP'] = "%sobjdump" % prefix
[a4125fb1]330 common['STRIP'] = "%sstrip" % prefix
[a35b458]331
[177e4ea]332 if (not path is None):
[a4125fb1]333 for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
[177e4ea]334 common[key] = "%s/%s" % (path, common[key])
[a35b458]335
[177e4ea]336 check_app([common['AS'], "--version"], "GNU Assembler", details)
337 check_app([common['LD'], "--version"], "GNU Linker", details)
338 check_app([common['AR'], "--version"], "GNU Archiver", details)
339 check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
340 check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
[a4125fb1]341 check_app([common['STRIP'], "--version"], "GNU strip", details)
[177e4ea]342
[96b89acb]343def decode_value(value):
344 "Decode integer value"
[a35b458]345
[96b89acb]346 base = 10
[a35b458]347
[96b89acb]348 if ((value.startswith('$')) or (value.startswith('#'))):
349 value = value[1:]
[a35b458]350
[96b89acb]351 if (value.startswith('0x')):
352 value = value[2:]
353 base = 16
[a35b458]354
[96b89acb]355 return int(value, base)
356
[b2aaaa0]357def probe_compiler(cc, common, typesizes):
[4e9aaf5]358 "Generate, compile and parse probing source"
[a35b458]359
[4e9aaf5]360 check_common(common, "CC")
[a35b458]361
[28f4adb]362 outf = open(PROBE_SOURCE, 'w')
[4e9aaf5]363 outf.write(PROBE_HEAD)
[a35b458]364
[ce55b43]365 for typedef in typesizes:
366 if 'def' in typedef:
367 outf.write("#ifdef %s\n" % typedef['def'])
368 outf.write("\tDECLARE_BUILTIN_TYPE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
369 if 'def' in typedef:
370 outf.write("#endif\n")
[a35b458]371
[4e9aaf5]372 outf.write(PROBE_TAIL)
373 outf.close()
[a35b458]374
[b2aaaa0]375 args = cc.split(' ')
[2429e4a]376 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
[a35b458]377
[4e9aaf5]378 try:
379 sys.stderr.write("Checking compiler properties ... ")
380 output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
381 except:
382 sys.stderr.write("failed\n")
383 print_error(["Error executing \"%s\"." % " ".join(args),
384 "Make sure that the compiler works properly."])
[a35b458]385
[4e9aaf5]386 if (not os.path.isfile(PROBE_OUTPUT)):
387 sys.stderr.write("failed\n")
[28f4adb]388 print(output[1])
[4e9aaf5]389 print_error(["Error executing \"%s\"." % " ".join(args),
390 "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
391 "",
392 output[0],
393 output[1]])
[a35b458]394
[4e9aaf5]395 sys.stderr.write("ok\n")
[a35b458]396
[28f4adb]397 inf = open(PROBE_OUTPUT, 'r')
[4e9aaf5]398 lines = inf.readlines()
399 inf.close()
[a35b458]400
[ce55b43]401 builtins = {}
[a35b458]402
[4e9aaf5]403 for j in range(len(lines)):
404 tokens = lines[j].strip().split("\t")
[a35b458]405
[4e9aaf5]406 if (len(tokens) > 0):
407 if (tokens[0] == "AUTOTOOL_DECLARE"):
[ce55b43]408 if (len(tokens) < 8):
[4e9aaf5]409 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
[a35b458]410
[4e9aaf5]411 category = tokens[1]
[ce55b43]412 tag = tokens[2]
413 name = tokens[3]
414 signedness = tokens[4]
415 base = tokens[5]
416 size = tokens[6]
417 compatible = tokens[7]
[a35b458]418
[ce55b43]419 try:
420 compatible_int = decode_value(compatible)
421 size_int = decode_value(size)
422 except:
423 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
[a35b458]424
[ce55b43]425 if (compatible_int == 1):
426 builtins[tag] = {
427 'tag': tag,
428 'name': name,
429 'sign': signedness,
430 'base': base,
431 'size': size_int,
432 }
[a35b458]433
[ce55b43]434 for typedef in typesizes:
435 if not typedef['tag'] in builtins:
436 print_error(['Unable to determine the properties of type %s.' % typedef['tag'],
[a4a0f1d]437 COMPILER_FAIL])
[ce55b43]438 if 'sname' in typedef:
439 builtins[typedef['tag']]['sname'] = typedef['sname']
[a35b458]440
[ce55b43]441 return builtins
442
443def get_suffix(type):
444 if type['sign'] == 'unsigned':
445 return {
446 "char": "",
447 "short": "",
448 "int": "U",
449 "long": "UL",
450 "long long": "ULL",
451 }[type['base']]
[96b89acb]452 else:
[ce55b43]453 return {
454 "char": "",
455 "short": "",
456 "int": "",
457 "long": "L",
458 "long long": "LL",
459 }[type['base']]
460
461def get_max(type):
462 val = (1 << (type['size']*8 - 1))
463 if type['sign'] == 'unsigned':
464 val *= 2
465 return val - 1
466
467def detect_sizes(probe):
468 "Detect properties of builtin types"
[a35b458]469
[ce55b43]470 macros = {}
[a35b458]471
[ce55b43]472 for type in probe.values():
473 macros['__SIZEOF_%s__' % type['tag']] = type['size']
[a35b458]474
[ce55b43]475 if ('sname' in type):
476 macros['__%s_TYPE__' % type['sname']] = type['name']
477 macros['__%s_WIDTH__' % type['sname']] = type['size']*8
478 macros['__%s_%s__' % (type['sname'], type['sign'].upper())] = "1"
479 macros['__%s_C_SUFFIX__' % type['sname']] = get_suffix(type)
480 macros['__%s_MAX__' % type['sname']] = "%d%s" % (get_max(type), get_suffix(type))
[a35b458]481
[ce55b43]482 if (probe['SIZE_T']['sign'] != 'unsigned'):
483 print_error(['The type size_t is not unsigned.', COMPILER_FAIL])
[a35b458]484
[ce55b43]485 return macros
[4e9aaf5]486
487def create_makefile(mkname, common):
488 "Create makefile output"
[a35b458]489
[28f4adb]490 outmk = open(mkname, 'w')
[a35b458]491
[4e9aaf5]492 outmk.write('#########################################\n')
493 outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
[571239a]494 outmk.write('## Generated by: tools/autotool.py ##\n')
[4e9aaf5]495 outmk.write('#########################################\n\n')
[a35b458]496
[177e4ea]497 for key, value in common.items():
[7174403]498 if (type(value) is list):
499 outmk.write('%s = %s\n' % (key, " ".join(value)))
500 else:
501 outmk.write('%s = %s\n' % (key, value))
[a35b458]502
[4e9aaf5]503 outmk.close()
504
[ce55b43]505def create_header(hdname, macros):
[4e9aaf5]506 "Create header output"
[a35b458]507
[28f4adb]508 outhd = open(hdname, 'w')
[a35b458]509
[4e9aaf5]510 outhd.write('/***************************************\n')
511 outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
[571239a]512 outhd.write(' * Generated by: tools/autotool.py *\n')
[4e9aaf5]513 outhd.write(' ***************************************/\n\n')
[a35b458]514
[4e9aaf5]515 outhd.write('#ifndef %s\n' % GUARD)
516 outhd.write('#define %s\n\n' % GUARD)
[a35b458]517
[ce55b43]518 for macro in sorted(macros):
519 outhd.write('#ifndef %s\n' % macro)
520 outhd.write('#define %s %s\n' % (macro, macros[macro]))
521 outhd.write('#endif\n\n')
[a35b458]522
[4e9aaf5]523 outhd.write('\n#endif\n')
524 outhd.close()
[177e4ea]525
526def main():
527 config = {}
528 common = {}
[a35b458]529
[177e4ea]530 # Read and check configuration
[4e9aaf5]531 if os.path.exists(CONFIG):
532 read_config(CONFIG, config)
[177e4ea]533 else:
[4e9aaf5]534 print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
[177e4ea]535 "configuration phase of HelenOS build went OK. Try running",
536 "\"make config\" again."])
[a35b458]537
[177e4ea]538 check_config(config, "PLATFORM")
539 check_config(config, "COMPILER")
540 check_config(config, "BARCH")
[a35b458]541
[177e4ea]542 # Cross-compiler prefix
543 if ('CROSS_PREFIX' in os.environ):
544 cross_prefix = os.environ['CROSS_PREFIX']
545 else:
[603c8740]546 cross_prefix = "/usr/local/cross"
[a35b458]547
[4e9aaf5]548 owd = sandbox_enter()
[a35b458]549
[4e9aaf5]550 try:
551 # Common utilities
552 check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
553 check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
554 check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
555 check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
556 check_app(["find", "--version"], "Find utility", "usually part of findutils")
557 check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
558 check_app(["make", "--version"], "Make utility", "preferably GNU Make")
[9ce911d]559 check_app(["unzip"], "unzip utility", "usually part of zip/unzip utilities")
[75701004]560 check_app(["tar", "--version"], "tar utility", "usually part of tar")
[a35b458]561
[b2aaaa0]562 platform, target = get_target(config)
[a35b458]563
[b08941d]564 if (platform is None) or (target is None):
565 print_error(["Unsupported compiler target.",
566 "Please contact the developers of HelenOS."])
[a35b458]567
[bbe5e34]568 path = None
569
570 if not check_path_gcc(target):
571 path = "%s/bin" % cross_prefix
[a35b458]572
[2660ee3]573 common['TARGET'] = target
[b08941d]574 prefix = "%s-" % target
[a35b458]575
[b2aaaa0]576 cc_autogen = None
577
[b08941d]578 # Compiler
[bbe5e34]579 if (config['COMPILER'] == "gcc_cross"):
[8f2eca0]580 check_gcc(path, prefix, common, PACKAGE_CROSS)
581 check_binutils(path, prefix, common, PACKAGE_CROSS)
[a35b458]582
[8f2eca0]583 check_common(common, "GCC")
[b2aaaa0]584 common['CC'] = common['GCC']
585 cc_autogen = common['CC']
[a35b458]586
[8e2154e7]587 check_common(common, "GXX")
588 common['CXX'] = common['GXX']
[058c240]589
[4e9aaf5]590 if (config['COMPILER'] == "clang"):
[84eb4edd]591 check_binutils(path, prefix, common, PACKAGE_CROSS)
592 check_clang(path, prefix, common, PACKAGE_CLANG)
[a35b458]593
[a0a273e]594 check_common(common, "CLANG")
[b2aaaa0]595 common['CC'] = common['CLANG']
596 cc_autogen = common['CC'] + " -no-integrated-as"
[a35b458]597
[a0a273e]598 if (config['INTEGRATED_AS'] == "yes"):
599 common['CC'] += " -integrated-as"
[a35b458]600
[a0a273e]601 if (config['INTEGRATED_AS'] == "no"):
602 common['CC'] += " -no-integrated-as"
[a35b458]603
[4e9aaf5]604 # Platform-specific utilities
605 if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
[ff87f70]606 common['GENISOIMAGE'] = check_app_alternatives(["genisoimage", "mkisofs", "xorriso"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
[b6bbc74]607 if common['GENISOIMAGE'] == 'xorriso':
[92c07dc]608 common['GENISOIMAGE'] += ' -as genisoimage'
[a35b458]609
[b2aaaa0]610 probe = probe_compiler(cc_autogen, common,
[4e9aaf5]611 [
[ce55b43]612 {'type': 'long long int', 'tag': 'LONG_LONG', 'sname': 'LLONG' },
613 {'type': 'long int', 'tag': 'LONG', 'sname': 'LONG' },
614 {'type': 'int', 'tag': 'INT', 'sname': 'INT' },
615 {'type': 'short int', 'tag': 'SHORT', 'sname': 'SHRT'},
616 {'type': 'void*', 'tag': 'POINTER'},
[a4a0f1d]617 {'type': 'long double', 'tag': 'LONG_DOUBLE'},
618 {'type': 'double', 'tag': 'DOUBLE'},
[ce55b43]619 {'type': 'float', 'tag': 'FLOAT'},
620 {'type': '__SIZE_TYPE__', 'tag': 'SIZE_T', 'def': '__SIZE_TYPE__', 'sname': 'SIZE' },
621 {'type': '__PTRDIFF_TYPE__', 'tag': 'PTRDIFF_T', 'def': '__PTRDIFF_TYPE__', 'sname': 'PTRDIFF' },
622 {'type': '__WINT_TYPE__', 'tag': 'WINT_T', 'def': '__WINT_TYPE__', 'sname': 'WINT' },
623 {'type': '__WCHAR_TYPE__', 'tag': 'WCHAR_T', 'def': '__WCHAR_TYPE__', 'sname': 'WCHAR' },
624 {'type': '__INTMAX_TYPE__', 'tag': 'INTMAX_T', 'def': '__INTMAX_TYPE__', 'sname': 'INTMAX' },
625 {'type': 'unsigned __INTMAX_TYPE__', 'tag': 'UINTMAX_T', 'def': '__INTMAX_TYPE__', 'sname': 'UINTMAX' },
[4e9aaf5]626 ]
627 )
[a35b458]628
[ce55b43]629 macros = detect_sizes(probe)
[a35b458]630
[4e9aaf5]631 finally:
632 sandbox_leave(owd)
[a35b458]633
[4e9aaf5]634 create_makefile(MAKEFILE, common)
[ce55b43]635 create_header(HEADER, macros)
[a35b458]636
[177e4ea]637 return 0
638
639if __name__ == '__main__':
640 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.