source: mainline/tools/autotool.py@ b4c8a7b

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

remove extra space

  • Property mode set to 100755
File size: 21.8 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
[39ba6d5]180 gnu_target = None
[8f2eca0]181 helenos_target = None
[b08941d]182 target = None
[7f25c4e]183 cc_args = []
[a35b458]184
[39ba6d5]185 if (config['PLATFORM'] == "abs32le"):
186 check_config(config, "CROSS_TARGET")
[b08941d]187 platform = config['CROSS_TARGET']
[a35b458]188
[39ba6d5]189 if (config['CROSS_TARGET'] == "arm32"):
190 gnu_target = "arm-linux-gnueabi"
[232ec3a1]191 helenos_target = "arm-helenos"
[a35b458]192
[39ba6d5]193 if (config['CROSS_TARGET'] == "ia32"):
194 gnu_target = "i686-pc-linux-gnu"
[232ec3a1]195 helenos_target = "i686-helenos"
[a35b458]196
[39ba6d5]197 if (config['CROSS_TARGET'] == "mips32"):
[795e2bf]198 cc_args.append("-mabi=32")
[39ba6d5]199 gnu_target = "mipsel-linux-gnu"
[8f2eca0]200 helenos_target = "mipsel-helenos"
[a35b458]201
[39ba6d5]202 if (config['PLATFORM'] == "amd64"):
[b08941d]203 platform = config['PLATFORM']
[bfdb7c63]204 gnu_target = "amd64-unknown-elf"
[8f2eca0]205 helenos_target = "amd64-helenos"
[a35b458]206
[39ba6d5]207 if (config['PLATFORM'] == "arm32"):
[b08941d]208 platform = config['PLATFORM']
[39ba6d5]209 gnu_target = "arm-linux-gnueabi"
[232ec3a1]210 helenos_target = "arm-helenos"
[a35b458]211
[39ba6d5]212 if (config['PLATFORM'] == "ia32"):
[b08941d]213 platform = config['PLATFORM']
[39ba6d5]214 gnu_target = "i686-pc-linux-gnu"
[232ec3a1]215 helenos_target = "i686-helenos"
[a35b458]216
[39ba6d5]217 if (config['PLATFORM'] == "ia64"):
[b08941d]218 platform = config['PLATFORM']
[39ba6d5]219 gnu_target = "ia64-pc-linux-gnu"
[232ec3a1]220 helenos_target = "ia64-helenos"
[a35b458]221
[39ba6d5]222 if (config['PLATFORM'] == "mips32"):
223 check_config(config, "MACHINE")
[7f25c4e]224 cc_args.append("-mabi=32")
[a35b458]225
[b183ce0a]226 if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
[b08941d]227 platform = config['PLATFORM']
[39ba6d5]228 gnu_target = "mipsel-linux-gnu"
[8f2eca0]229 helenos_target = "mipsel-helenos"
[a35b458]230
[b183ce0a]231 if ((config['MACHINE'] == "bmalta")):
[b08941d]232 platform = "mips32eb"
[39ba6d5]233 gnu_target = "mips-linux-gnu"
[8f2eca0]234 helenos_target = "mips-helenos"
[a35b458]235
[39ba6d5]236 if (config['PLATFORM'] == "mips64"):
237 check_config(config, "MACHINE")
[7f25c4e]238 cc_args.append("-mabi=64")
[a35b458]239
[39ba6d5]240 if (config['MACHINE'] == "msim"):
[b08941d]241 platform = config['PLATFORM']
[39ba6d5]242 gnu_target = "mips64el-linux-gnu"
[8f2eca0]243 helenos_target = "mips64el-helenos"
[a35b458]244
[39ba6d5]245 if (config['PLATFORM'] == "ppc32"):
[b08941d]246 platform = config['PLATFORM']
[39ba6d5]247 gnu_target = "ppc-linux-gnu"
[8f2eca0]248 helenos_target = "ppc-helenos"
[a35b458]249
[114d098]250 if (config['PLATFORM'] == "riscv64"):
[b08941d]251 platform = config['PLATFORM']
[114d098]252 gnu_target = "riscv64-unknown-linux-gnu"
253 helenos_target = "riscv64-helenos"
[a35b458]254
[39ba6d5]255 if (config['PLATFORM'] == "sparc64"):
[b08941d]256 platform = config['PLATFORM']
[39ba6d5]257 gnu_target = "sparc64-linux-gnu"
[8f2eca0]258 helenos_target = "sparc64-helenos"
[a35b458]259
[b08941d]260 if (config['COMPILER'] == "gcc_helenos"):
261 target = helenos_target
262 else:
263 target = gnu_target
[a35b458]264
[b08941d]265 return (platform, cc_args, target)
[39ba6d5]266
[177e4ea]267def check_app(args, name, details):
268 "Check whether an application can be executed"
[a35b458]269
[177e4ea]270 try:
271 sys.stderr.write("Checking for %s ... " % args[0])
272 subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
273 except:
274 sys.stderr.write("failed\n")
275 print_error(["%s is missing." % name,
276 "",
277 "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
278 "is installed in your system (%s)." % details])
[a35b458]279
[177e4ea]280 sys.stderr.write("ok\n")
281
[7174403]282def check_app_alternatives(alts, args, name, details):
283 "Check whether an application can be executed (use several alternatives)"
[a35b458]284
[7174403]285 tried = []
286 found = None
[a35b458]287
[7174403]288 for alt in alts:
289 working = True
290 cmdline = [alt] + args
291 tried.append(" ".join(cmdline))
[a35b458]292
[7174403]293 try:
294 sys.stderr.write("Checking for %s ... " % alt)
295 subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
296 except:
297 sys.stderr.write("failed\n")
298 working = False
[a35b458]299
[7174403]300 if (working):
301 sys.stderr.write("ok\n")
302 found = alt
303 break
[a35b458]304
[7174403]305 if (found is None):
306 print_error(["%s is missing." % name,
307 "",
308 "Please make sure that it is installed in your",
309 "system (%s)." % details,
310 "",
311 "The following alternatives were tried:"] + tried)
[a35b458]312
[7174403]313 return found
314
[a0a273e]315def check_clang(path, prefix, common, details):
316 "Check for clang"
[a35b458]317
[a0a273e]318 common['CLANG'] = "%sclang" % prefix
[a35b458]319
[a0a273e]320 if (not path is None):
321 common['CLANG'] = "%s/%s" % (path, common['CLANG'])
[a35b458]322
[a0a273e]323 check_app([common['CLANG'], "--version"], "clang", details)
324
[177e4ea]325def check_gcc(path, prefix, common, details):
326 "Check for GCC"
[a35b458]327
[177e4ea]328 common['GCC'] = "%sgcc" % prefix
[8e2154e7]329 common['GXX'] = "%sg++" % prefix
[a35b458]330
[177e4ea]331 if (not path is None):
332 common['GCC'] = "%s/%s" % (path, common['GCC'])
[8e2154e7]333 common['GXX'] = "%s/%s" % (path, common['GXX'])
[a35b458]334
[177e4ea]335 check_app([common['GCC'], "--version"], "GNU GCC", details)
336
337def check_binutils(path, prefix, common, details):
338 "Check for binutils toolchain"
[a35b458]339
[177e4ea]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
[a35b458]346
[177e4ea]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])
[a35b458]350
[177e4ea]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"
[a35b458]360
[96b89acb]361 base = 10
[a35b458]362
[96b89acb]363 if ((value.startswith('$')) or (value.startswith('#'))):
364 value = value[1:]
[a35b458]365
[96b89acb]366 if (value.startswith('0x')):
367 value = value[2:]
368 base = 16
[a35b458]369
[96b89acb]370 return int(value, base)
371
[ce55b43]372def probe_compiler(common, typesizes):
[4e9aaf5]373 "Generate, compile and parse probing source"
[a35b458]374
[4e9aaf5]375 check_common(common, "CC")
[a35b458]376
[28f4adb]377 outf = open(PROBE_SOURCE, 'w')
[4e9aaf5]378 outf.write(PROBE_HEAD)
[a35b458]379
[ce55b43]380 for typedef in typesizes:
381 if 'def' in typedef:
382 outf.write("#ifdef %s\n" % typedef['def'])
383 outf.write("\tDECLARE_BUILTIN_TYPE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
384 if 'def' in typedef:
385 outf.write("#endif\n")
[a35b458]386
[4e9aaf5]387 outf.write(PROBE_TAIL)
388 outf.close()
[a35b458]389
[a0a273e]390 args = common['CC_AUTOGEN'].split(' ')
[2429e4a]391 args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
[a35b458]392
[4e9aaf5]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."])
[a35b458]400
[4e9aaf5]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]])
[a35b458]409
[4e9aaf5]410 sys.stderr.write("ok\n")
[a35b458]411
[28f4adb]412 inf = open(PROBE_OUTPUT, 'r')
[4e9aaf5]413 lines = inf.readlines()
414 inf.close()
[a35b458]415
[ce55b43]416 builtins = {}
[a35b458]417
[4e9aaf5]418 for j in range(len(lines)):
419 tokens = lines[j].strip().split("\t")
[a35b458]420
[4e9aaf5]421 if (len(tokens) > 0):
422 if (tokens[0] == "AUTOTOOL_DECLARE"):
[ce55b43]423 if (len(tokens) < 8):
[4e9aaf5]424 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
[a35b458]425
[4e9aaf5]426 category = tokens[1]
[ce55b43]427 tag = tokens[2]
428 name = tokens[3]
429 signedness = tokens[4]
430 base = tokens[5]
431 size = tokens[6]
432 compatible = tokens[7]
[a35b458]433
[ce55b43]434 try:
435 compatible_int = decode_value(compatible)
436 size_int = decode_value(size)
437 except:
438 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
[a35b458]439
[ce55b43]440 if (compatible_int == 1):
441 builtins[tag] = {
442 'tag': tag,
443 'name': name,
444 'sign': signedness,
445 'base': base,
446 'size': size_int,
447 }
[a35b458]448
[ce55b43]449 for typedef in typesizes:
450 if not typedef['tag'] in builtins:
451 print_error(['Unable to determine the properties of type %s.' % typedef['tag'],
[a4a0f1d]452 COMPILER_FAIL])
[ce55b43]453 if 'sname' in typedef:
454 builtins[typedef['tag']]['sname'] = typedef['sname']
[a35b458]455
[ce55b43]456 return builtins
457
458def get_suffix(type):
459 if type['sign'] == 'unsigned':
460 return {
461 "char": "",
462 "short": "",
463 "int": "U",
464 "long": "UL",
465 "long long": "ULL",
466 }[type['base']]
[96b89acb]467 else:
[ce55b43]468 return {
469 "char": "",
470 "short": "",
471 "int": "",
472 "long": "L",
473 "long long": "LL",
474 }[type['base']]
475
476def get_max(type):
477 val = (1 << (type['size']*8 - 1))
478 if type['sign'] == 'unsigned':
479 val *= 2
480 return val - 1
481
482def detect_sizes(probe):
483 "Detect properties of builtin types"
[a35b458]484
[ce55b43]485 macros = {}
[a35b458]486
[ce55b43]487 for type in probe.values():
488 macros['__SIZEOF_%s__' % type['tag']] = type['size']
[a35b458]489
[ce55b43]490 if ('sname' in type):
491 macros['__%s_TYPE__' % type['sname']] = type['name']
492 macros['__%s_WIDTH__' % type['sname']] = type['size']*8
493 macros['__%s_%s__' % (type['sname'], type['sign'].upper())] = "1"
494 macros['__%s_C_SUFFIX__' % type['sname']] = get_suffix(type)
495 macros['__%s_MAX__' % type['sname']] = "%d%s" % (get_max(type), get_suffix(type))
[a35b458]496
[ce55b43]497 if (probe['SIZE_T']['sign'] != 'unsigned'):
498 print_error(['The type size_t is not unsigned.', COMPILER_FAIL])
[a35b458]499
[ce55b43]500 return macros
[4e9aaf5]501
502def create_makefile(mkname, common):
503 "Create makefile output"
[a35b458]504
[28f4adb]505 outmk = open(mkname, 'w')
[a35b458]506
[4e9aaf5]507 outmk.write('#########################################\n')
508 outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
[571239a]509 outmk.write('## Generated by: tools/autotool.py ##\n')
[4e9aaf5]510 outmk.write('#########################################\n\n')
[a35b458]511
[177e4ea]512 for key, value in common.items():
[7174403]513 if (type(value) is list):
514 outmk.write('%s = %s\n' % (key, " ".join(value)))
515 else:
516 outmk.write('%s = %s\n' % (key, value))
[a35b458]517
[4e9aaf5]518 outmk.close()
519
[ce55b43]520def create_header(hdname, macros):
[4e9aaf5]521 "Create header output"
[a35b458]522
[28f4adb]523 outhd = open(hdname, 'w')
[a35b458]524
[4e9aaf5]525 outhd.write('/***************************************\n')
526 outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
[571239a]527 outhd.write(' * Generated by: tools/autotool.py *\n')
[4e9aaf5]528 outhd.write(' ***************************************/\n\n')
[a35b458]529
[4e9aaf5]530 outhd.write('#ifndef %s\n' % GUARD)
531 outhd.write('#define %s\n\n' % GUARD)
[a35b458]532
[ce55b43]533 for macro in sorted(macros):
534 outhd.write('#ifndef %s\n' % macro)
535 outhd.write('#define %s %s\n' % (macro, macros[macro]))
536 outhd.write('#endif\n\n')
[a35b458]537
[4e9aaf5]538 outhd.write('\n#endif\n')
539 outhd.close()
[177e4ea]540
541def main():
542 config = {}
543 common = {}
[a35b458]544
[177e4ea]545 # Read and check configuration
[4e9aaf5]546 if os.path.exists(CONFIG):
547 read_config(CONFIG, config)
[177e4ea]548 else:
[4e9aaf5]549 print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
[177e4ea]550 "configuration phase of HelenOS build went OK. Try running",
551 "\"make config\" again."])
[a35b458]552
[177e4ea]553 check_config(config, "PLATFORM")
554 check_config(config, "COMPILER")
555 check_config(config, "BARCH")
[a35b458]556
[177e4ea]557 # Cross-compiler prefix
558 if ('CROSS_PREFIX' in os.environ):
559 cross_prefix = os.environ['CROSS_PREFIX']
560 else:
[603c8740]561 cross_prefix = "/usr/local/cross"
[a35b458]562
[8f2eca0]563 # HelenOS cross-compiler prefix
564 if ('CROSS_HELENOS_PREFIX' in os.environ):
565 cross_helenos_prefix = os.environ['CROSS_HELENOS_PREFIX']
566 else:
567 cross_helenos_prefix = "/usr/local/cross-helenos"
[a35b458]568
[177e4ea]569 # Prefix binutils tools on Solaris
570 if (os.uname()[0] == "SunOS"):
571 binutils_prefix = "g"
572 else:
573 binutils_prefix = ""
[a35b458]574
[4e9aaf5]575 owd = sandbox_enter()
[a35b458]576
[4e9aaf5]577 try:
578 # Common utilities
579 check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
580 check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
581 check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
582 check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
583 check_app(["find", "--version"], "Find utility", "usually part of findutils")
584 check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
585 check_app(["make", "--version"], "Make utility", "preferably GNU Make")
[9ce911d]586 check_app(["unzip"], "unzip utility", "usually part of zip/unzip utilities")
[75701004]587 check_app(["tar", "--version"], "tar utility", "usually part of tar")
[a35b458]588
[b08941d]589 platform, cc_args, target = get_target(config)
[a35b458]590
[b08941d]591 if (platform is None) or (target is None):
592 print_error(["Unsupported compiler target.",
593 "Please contact the developers of HelenOS."])
[a35b458]594
[b08941d]595 path = "%s/%s/bin" % (cross_prefix, target)
[a35b458]596
[b08941d]597 # Compatibility with earlier toolchain paths.
598 if not os.path.exists(path):
599 if (config['COMPILER'] == "gcc_helenos"):
600 check_path = "%s/%s/%s" % (cross_helenos_prefix, platform, target)
601 if not os.path.exists(check_path):
[12bdbcc6]602 print_error(TOOLCHAIN_FAIL)
[b08941d]603 path = "%s/%s/bin" % (cross_helenos_prefix, platform)
604 else:
605 check_path = "%s/%s/%s" % (cross_prefix, platform, target)
606 if not os.path.exists(check_path):
[12bdbcc6]607 print_error(TOOLCHAIN_FAIL)
[b08941d]608 path = "%s/%s/bin" % (cross_prefix, platform)
[a35b458]609
[2660ee3]610 common['TARGET'] = target
[b08941d]611 prefix = "%s-" % target
[a35b458]612
[b08941d]613 # Compiler
614 if (config['COMPILER'] == "gcc_cross" or config['COMPILER'] == "gcc_helenos"):
[8f2eca0]615 check_gcc(path, prefix, common, PACKAGE_CROSS)
616 check_binutils(path, prefix, common, PACKAGE_CROSS)
[a35b458]617
[8f2eca0]618 check_common(common, "GCC")
[a0a273e]619 common['CC'] = " ".join([common['GCC']] + cc_args)
620 common['CC_AUTOGEN'] = common['CC']
[a35b458]621
[8e2154e7]622 check_common(common, "GXX")
623 common['CXX'] = common['GXX']
[058c240]624
[4e9aaf5]625 if (config['COMPILER'] == "gcc_native"):
626 check_gcc(None, "", common, PACKAGE_GCC)
627 check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
[a35b458]628
[4e9aaf5]629 check_common(common, "GCC")
630 common['CC'] = common['GCC']
[a0a273e]631 common['CC_AUTOGEN'] = common['CC']
[a35b458]632
[4e9aaf5]633 if (config['COMPILER'] == "clang"):
[84eb4edd]634 check_binutils(path, prefix, common, PACKAGE_CROSS)
635 check_clang(path, prefix, common, PACKAGE_CLANG)
[a35b458]636
[a0a273e]637 check_common(common, "CLANG")
638 common['CC'] = " ".join([common['CLANG']] + cc_args)
639 common['CC_AUTOGEN'] = common['CC'] + " -no-integrated-as"
[a35b458]640
[a0a273e]641 if (config['INTEGRATED_AS'] == "yes"):
642 common['CC'] += " -integrated-as"
[a35b458]643
[a0a273e]644 if (config['INTEGRATED_AS'] == "no"):
645 common['CC'] += " -no-integrated-as"
[a35b458]646
[4e9aaf5]647 # Platform-specific utilities
648 if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
[ff87f70]649 common['GENISOIMAGE'] = check_app_alternatives(["genisoimage", "mkisofs", "xorriso"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
[b6bbc74]650 if common['GENISOIMAGE'] == 'xorriso':
[92c07dc]651 common['GENISOIMAGE'] += ' -as genisoimage'
[a35b458]652
[4e9aaf5]653 probe = probe_compiler(common,
654 [
[ce55b43]655 {'type': 'long long int', 'tag': 'LONG_LONG', 'sname': 'LLONG' },
656 {'type': 'long int', 'tag': 'LONG', 'sname': 'LONG' },
657 {'type': 'int', 'tag': 'INT', 'sname': 'INT' },
658 {'type': 'short int', 'tag': 'SHORT', 'sname': 'SHRT'},
659 {'type': 'void*', 'tag': 'POINTER'},
[a4a0f1d]660 {'type': 'long double', 'tag': 'LONG_DOUBLE'},
661 {'type': 'double', 'tag': 'DOUBLE'},
[ce55b43]662 {'type': 'float', 'tag': 'FLOAT'},
663 {'type': '__SIZE_TYPE__', 'tag': 'SIZE_T', 'def': '__SIZE_TYPE__', 'sname': 'SIZE' },
664 {'type': '__PTRDIFF_TYPE__', 'tag': 'PTRDIFF_T', 'def': '__PTRDIFF_TYPE__', 'sname': 'PTRDIFF' },
665 {'type': '__WINT_TYPE__', 'tag': 'WINT_T', 'def': '__WINT_TYPE__', 'sname': 'WINT' },
666 {'type': '__WCHAR_TYPE__', 'tag': 'WCHAR_T', 'def': '__WCHAR_TYPE__', 'sname': 'WCHAR' },
667 {'type': '__INTMAX_TYPE__', 'tag': 'INTMAX_T', 'def': '__INTMAX_TYPE__', 'sname': 'INTMAX' },
668 {'type': 'unsigned __INTMAX_TYPE__', 'tag': 'UINTMAX_T', 'def': '__INTMAX_TYPE__', 'sname': 'UINTMAX' },
[4e9aaf5]669 ]
670 )
[a35b458]671
[ce55b43]672 macros = detect_sizes(probe)
[a35b458]673
[4e9aaf5]674 finally:
675 sandbox_leave(owd)
[a35b458]676
[4e9aaf5]677 create_makefile(MAKEFILE, common)
[ce55b43]678 create_header(HEADER, macros)
[a35b458]679
[177e4ea]680 return 0
681
682if __name__ == '__main__':
683 sys.exit(main())
Note: See TracBrowser for help on using the repository browser.