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