| 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 | #
|
|---|
| 29 |
|
|---|
| 30 | """
|
|---|
| 31 | Detect important prerequisites and parameters for building HelenOS
|
|---|
| 32 | """
|
|---|
| 33 |
|
|---|
| 34 | import sys
|
|---|
| 35 | import os
|
|---|
| 36 | import shutil
|
|---|
| 37 | import re
|
|---|
| 38 | import time
|
|---|
| 39 | import subprocess
|
|---|
| 40 |
|
|---|
| 41 | SANDBOX = 'autotool'
|
|---|
| 42 | CONFIG = 'Makefile.config'
|
|---|
| 43 | MAKEFILE = 'Makefile.common'
|
|---|
| 44 | HEADER = 'common.h'
|
|---|
| 45 | GUARD = 'AUTOTOOL_COMMON_H_'
|
|---|
| 46 |
|
|---|
| 47 | PROBE_SOURCE = 'probe.c'
|
|---|
| 48 | PROBE_OUTPUT = 'probe.s'
|
|---|
| 49 |
|
|---|
| 50 | PACKAGE_BINUTILS = "usually part of binutils"
|
|---|
| 51 | PACKAGE_GCC = "preferably version 4.5.1 or newer"
|
|---|
| 52 | PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
|
|---|
| 53 |
|
|---|
| 54 | COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
|
|---|
| 55 | COMPILER_WARNING = "The compilation of HelenOS might fail."
|
|---|
| 56 |
|
|---|
| 57 | PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
|
|---|
| 58 | asm volatile ( \\
|
|---|
| 59 | "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
|
|---|
| 60 | : \\
|
|---|
| 61 | : [val] "n" (value) \\
|
|---|
| 62 | )
|
|---|
| 63 |
|
|---|
| 64 | #define STRING(arg) STRING_ARG(arg)
|
|---|
| 65 | #define STRING_ARG(arg) #arg
|
|---|
| 66 |
|
|---|
| 67 | #define DECLARE_BUILTIN_TYPE(tag, type) \\
|
|---|
| 68 | AUTOTOOL_DECLARE("builtin", "", tag, STRING(type), "", "", sizeof(type));
|
|---|
| 69 |
|
|---|
| 70 | #define DECLARE_INTSIZE(tag, type, strc, conc) \\
|
|---|
| 71 | AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\
|
|---|
| 72 | AUTOTOOL_DECLARE("intsize", "signed", tag, #type, strc, conc, sizeof(signed type));
|
|---|
| 73 |
|
|---|
| 74 | int main(int argc, char *argv[])
|
|---|
| 75 | {
|
|---|
| 76 | #ifdef __SIZE_TYPE__
|
|---|
| 77 | DECLARE_BUILTIN_TYPE("size", __SIZE_TYPE__);
|
|---|
| 78 | #endif
|
|---|
| 79 | #ifdef __WCHAR_TYPE__
|
|---|
| 80 | DECLARE_BUILTIN_TYPE("wchar", __WCHAR_TYPE__);
|
|---|
| 81 | #endif
|
|---|
| 82 | #ifdef __WINT_TYPE__
|
|---|
| 83 | DECLARE_BUILTIN_TYPE("wint", __WINT_TYPE__);
|
|---|
| 84 | #endif
|
|---|
| 85 | """
|
|---|
| 86 |
|
|---|
| 87 | PROBE_TAIL = """}
|
|---|
| 88 | """
|
|---|
| 89 |
|
|---|
| 90 | def read_config(fname, config):
|
|---|
| 91 | "Read HelenOS build configuration"
|
|---|
| 92 |
|
|---|
| 93 | inf = open(fname, 'r')
|
|---|
| 94 |
|
|---|
| 95 | for line in inf:
|
|---|
| 96 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
|
|---|
| 97 | if (res):
|
|---|
| 98 | config[res.group(1)] = res.group(2)
|
|---|
| 99 |
|
|---|
| 100 | inf.close()
|
|---|
| 101 |
|
|---|
| 102 | def print_error(msg):
|
|---|
| 103 | "Print a bold error message"
|
|---|
| 104 |
|
|---|
| 105 | sys.stderr.write("\n")
|
|---|
| 106 | sys.stderr.write("######################################################################\n")
|
|---|
| 107 | sys.stderr.write("HelenOS build sanity check error:\n")
|
|---|
| 108 | sys.stderr.write("\n")
|
|---|
| 109 | sys.stderr.write("%s\n" % "\n".join(msg))
|
|---|
| 110 | sys.stderr.write("######################################################################\n")
|
|---|
| 111 | sys.stderr.write("\n")
|
|---|
| 112 |
|
|---|
| 113 | sys.exit(1)
|
|---|
| 114 |
|
|---|
| 115 | def print_warning(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 warning:\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 | time.sleep(5)
|
|---|
| 127 |
|
|---|
| 128 | def sandbox_enter():
|
|---|
| 129 | "Create a temporal sandbox directory for running tests"
|
|---|
| 130 |
|
|---|
| 131 | if (os.path.exists(SANDBOX)):
|
|---|
| 132 | if (os.path.isdir(SANDBOX)):
|
|---|
| 133 | try:
|
|---|
| 134 | shutil.rmtree(SANDBOX)
|
|---|
| 135 | except:
|
|---|
| 136 | print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
|
|---|
| 137 | else:
|
|---|
| 138 | print_error(["Please inspect and remove unexpected directory,",
|
|---|
| 139 | "entry \"%s\"." % SANDBOX])
|
|---|
| 140 |
|
|---|
| 141 | try:
|
|---|
| 142 | os.mkdir(SANDBOX)
|
|---|
| 143 | except:
|
|---|
| 144 | print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
|
|---|
| 145 |
|
|---|
| 146 | owd = os.getcwd()
|
|---|
| 147 | os.chdir(SANDBOX)
|
|---|
| 148 |
|
|---|
| 149 | return owd
|
|---|
| 150 |
|
|---|
| 151 | def sandbox_leave(owd):
|
|---|
| 152 | "Leave the temporal sandbox directory"
|
|---|
| 153 |
|
|---|
| 154 | os.chdir(owd)
|
|---|
| 155 |
|
|---|
| 156 | def check_config(config, key):
|
|---|
| 157 | "Check whether the configuration key exists"
|
|---|
| 158 |
|
|---|
| 159 | if (not key in config):
|
|---|
| 160 | print_error(["Build configuration of HelenOS does not contain %s." % key,
|
|---|
| 161 | "Try running \"make config\" again.",
|
|---|
| 162 | "If the problem persists, please contact the developers of HelenOS."])
|
|---|
| 163 |
|
|---|
| 164 | def check_common(common, key):
|
|---|
| 165 | "Check whether the common key exists"
|
|---|
| 166 |
|
|---|
| 167 | if (not key in common):
|
|---|
| 168 | print_error(["Failed to determine the value %s." % key,
|
|---|
| 169 | "Please contact the developers of HelenOS."])
|
|---|
| 170 |
|
|---|
| 171 | def check_app(args, name, details):
|
|---|
| 172 | "Check whether an application can be executed"
|
|---|
| 173 |
|
|---|
| 174 | try:
|
|---|
| 175 | sys.stderr.write("Checking for %s ... " % args[0])
|
|---|
| 176 | subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
|---|
| 177 | except:
|
|---|
| 178 | sys.stderr.write("failed\n")
|
|---|
| 179 | print_error(["%s is missing." % name,
|
|---|
| 180 | "",
|
|---|
| 181 | "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
|
|---|
| 182 | "is installed in your system (%s)." % details])
|
|---|
| 183 |
|
|---|
| 184 | sys.stderr.write("ok\n")
|
|---|
| 185 |
|
|---|
| 186 | def check_gcc(path, prefix, common, details):
|
|---|
| 187 | "Check for GCC"
|
|---|
| 188 |
|
|---|
| 189 | common['GCC'] = "%sgcc" % prefix
|
|---|
| 190 |
|
|---|
| 191 | if (not path is None):
|
|---|
| 192 | common['GCC'] = "%s/%s" % (path, common['GCC'])
|
|---|
| 193 |
|
|---|
| 194 | check_app([common['GCC'], "--version"], "GNU GCC", details)
|
|---|
| 195 |
|
|---|
| 196 | def check_binutils(path, prefix, common, details):
|
|---|
| 197 | "Check for binutils toolchain"
|
|---|
| 198 |
|
|---|
| 199 | common['AS'] = "%sas" % prefix
|
|---|
| 200 | common['LD'] = "%sld" % prefix
|
|---|
| 201 | common['AR'] = "%sar" % prefix
|
|---|
| 202 | common['OBJCOPY'] = "%sobjcopy" % prefix
|
|---|
| 203 | common['OBJDUMP'] = "%sobjdump" % prefix
|
|---|
| 204 | common['STRIP'] = "%sstrip" % prefix
|
|---|
| 205 |
|
|---|
| 206 | if (not path is None):
|
|---|
| 207 | for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
|
|---|
| 208 | common[key] = "%s/%s" % (path, common[key])
|
|---|
| 209 |
|
|---|
| 210 | check_app([common['AS'], "--version"], "GNU Assembler", details)
|
|---|
| 211 | check_app([common['LD'], "--version"], "GNU Linker", details)
|
|---|
| 212 | check_app([common['AR'], "--version"], "GNU Archiver", details)
|
|---|
| 213 | check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
|
|---|
| 214 | check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
|
|---|
| 215 | check_app([common['STRIP'], "--version"], "GNU strip", details)
|
|---|
| 216 |
|
|---|
| 217 | def decode_value(value):
|
|---|
| 218 | "Decode integer value"
|
|---|
| 219 |
|
|---|
| 220 | base = 10
|
|---|
| 221 |
|
|---|
| 222 | if ((value.startswith('$')) or (value.startswith('#'))):
|
|---|
| 223 | value = value[1:]
|
|---|
| 224 |
|
|---|
| 225 | if (value.startswith('0x')):
|
|---|
| 226 | value = value[2:]
|
|---|
| 227 | base = 16
|
|---|
| 228 |
|
|---|
| 229 | return int(value, base)
|
|---|
| 230 |
|
|---|
| 231 | def probe_compiler(common, sizes):
|
|---|
| 232 | "Generate, compile and parse probing source"
|
|---|
| 233 |
|
|---|
| 234 | check_common(common, "CC")
|
|---|
| 235 |
|
|---|
| 236 | outf = open(PROBE_SOURCE, 'w')
|
|---|
| 237 | outf.write(PROBE_HEAD)
|
|---|
| 238 |
|
|---|
| 239 | for typedef in sizes:
|
|---|
| 240 | outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
|
|---|
| 241 |
|
|---|
| 242 | outf.write(PROBE_TAIL)
|
|---|
| 243 | outf.close()
|
|---|
| 244 |
|
|---|
| 245 | args = [common['CC'], "-S", "-o", PROBE_OUTPUT, PROBE_SOURCE]
|
|---|
| 246 |
|
|---|
| 247 | try:
|
|---|
| 248 | sys.stderr.write("Checking compiler properties ... ")
|
|---|
| 249 | output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
|
|---|
| 250 | except:
|
|---|
| 251 | sys.stderr.write("failed\n")
|
|---|
| 252 | print_error(["Error executing \"%s\"." % " ".join(args),
|
|---|
| 253 | "Make sure that the compiler works properly."])
|
|---|
| 254 |
|
|---|
| 255 | if (not os.path.isfile(PROBE_OUTPUT)):
|
|---|
| 256 | sys.stderr.write("failed\n")
|
|---|
| 257 | print(output[1])
|
|---|
| 258 | print_error(["Error executing \"%s\"." % " ".join(args),
|
|---|
| 259 | "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
|
|---|
| 260 | "",
|
|---|
| 261 | output[0],
|
|---|
| 262 | output[1]])
|
|---|
| 263 |
|
|---|
| 264 | sys.stderr.write("ok\n")
|
|---|
| 265 |
|
|---|
| 266 | inf = open(PROBE_OUTPUT, 'r')
|
|---|
| 267 | lines = inf.readlines()
|
|---|
| 268 | inf.close()
|
|---|
| 269 |
|
|---|
| 270 | unsigned_sizes = {}
|
|---|
| 271 | signed_sizes = {}
|
|---|
| 272 |
|
|---|
| 273 | unsigned_tags = {}
|
|---|
| 274 | signed_tags = {}
|
|---|
| 275 |
|
|---|
| 276 | unsigned_strcs = {}
|
|---|
| 277 | signed_strcs = {}
|
|---|
| 278 |
|
|---|
| 279 | unsigned_concs = {}
|
|---|
| 280 | signed_concs = {}
|
|---|
| 281 |
|
|---|
| 282 | builtins = {}
|
|---|
| 283 |
|
|---|
| 284 | for j in range(len(lines)):
|
|---|
| 285 | tokens = lines[j].strip().split("\t")
|
|---|
| 286 |
|
|---|
| 287 | if (len(tokens) > 0):
|
|---|
| 288 | if (tokens[0] == "AUTOTOOL_DECLARE"):
|
|---|
| 289 | if (len(tokens) < 7):
|
|---|
| 290 | print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 291 |
|
|---|
| 292 | category = tokens[1]
|
|---|
| 293 | subcategory = tokens[2]
|
|---|
| 294 | tag = tokens[3]
|
|---|
| 295 | name = tokens[4]
|
|---|
| 296 | strc = tokens[5]
|
|---|
| 297 | conc = tokens[6]
|
|---|
| 298 | value = tokens[7]
|
|---|
| 299 |
|
|---|
| 300 | if (category == "intsize"):
|
|---|
| 301 | try:
|
|---|
| 302 | value_int = decode_value(value)
|
|---|
| 303 | except:
|
|---|
| 304 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 305 |
|
|---|
| 306 | if (subcategory == "unsigned"):
|
|---|
| 307 | unsigned_sizes[value_int] = name
|
|---|
| 308 | unsigned_tags[tag] = value_int
|
|---|
| 309 | unsigned_strcs[value_int] = strc
|
|---|
| 310 | unsigned_concs[value_int] = conc
|
|---|
| 311 | elif (subcategory == "signed"):
|
|---|
| 312 | signed_sizes[value_int] = name
|
|---|
| 313 | signed_tags[tag] = value_int
|
|---|
| 314 | signed_strcs[value_int] = strc
|
|---|
| 315 | signed_concs[value_int] = conc
|
|---|
| 316 | else:
|
|---|
| 317 | print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 318 |
|
|---|
| 319 | if (category == "builtin"):
|
|---|
| 320 | try:
|
|---|
| 321 | value_int = decode_value(value)
|
|---|
| 322 | except:
|
|---|
| 323 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 324 |
|
|---|
| 325 | builtins[tag] = {'name': name, 'value': value_int}
|
|---|
| 326 |
|
|---|
| 327 | 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, 'builtins': builtins}
|
|---|
| 328 |
|
|---|
| 329 | def detect_uints(probe, bytes, tags):
|
|---|
| 330 | "Detect correct types for fixed-size integer types"
|
|---|
| 331 |
|
|---|
| 332 | macros = []
|
|---|
| 333 | typedefs = []
|
|---|
| 334 |
|
|---|
| 335 | for b in bytes:
|
|---|
| 336 | if (not b in probe['unsigned_sizes']):
|
|---|
| 337 | print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b,
|
|---|
| 338 | COMPILER_FAIL])
|
|---|
| 339 |
|
|---|
| 340 | if (not b in probe['signed_sizes']):
|
|---|
| 341 | print_error(['Unable to find appropriate signed integer type for %u bytes' % b,
|
|---|
| 342 | COMPILER_FAIL])
|
|---|
| 343 |
|
|---|
| 344 | if (not b in probe['unsigned_strcs']):
|
|---|
| 345 | print_error(['Unable to find appropriate unsigned printf formatter for %u bytes' % b,
|
|---|
| 346 | COMPILER_FAIL])
|
|---|
| 347 |
|
|---|
| 348 | if (not b in probe['signed_strcs']):
|
|---|
| 349 | print_error(['Unable to find appropriate signed printf formatter for %u bytes' % b,
|
|---|
| 350 | COMPILER_FAIL])
|
|---|
| 351 |
|
|---|
| 352 | if (not b in probe['unsigned_concs']):
|
|---|
| 353 | print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
|
|---|
| 354 | COMPILER_FAIL])
|
|---|
| 355 |
|
|---|
| 356 | if (not b in probe['signed_concs']):
|
|---|
| 357 | print_error(['Unable to find appropriate signed literal macro for %u bytes' % b,
|
|---|
| 358 | COMPILER_FAIL])
|
|---|
| 359 |
|
|---|
| 360 | typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
|
|---|
| 361 | typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
|
|---|
| 362 |
|
|---|
| 363 | macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
|
|---|
| 364 | macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
|
|---|
| 365 | macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
|
|---|
| 366 | macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
|
|---|
| 367 | macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
|
|---|
| 368 |
|
|---|
| 369 | name = probe['unsigned_concs'][b]
|
|---|
| 370 | if ((name.startswith('@')) or (name == "")):
|
|---|
| 371 | macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
|---|
| 372 | else:
|
|---|
| 373 | macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
|---|
| 374 |
|
|---|
| 375 | name = probe['unsigned_concs'][b]
|
|---|
| 376 | if ((name.startswith('@')) or (name == "")):
|
|---|
| 377 | macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
|
|---|
| 378 | else:
|
|---|
| 379 | macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
|
|---|
| 380 |
|
|---|
| 381 | for tag in tags:
|
|---|
| 382 | newmacro = "U%s" % tag
|
|---|
| 383 | if (not tag in probe['unsigned_tags']):
|
|---|
| 384 | print_error(['Unable to find appropriate size macro for %s' % newmacro,
|
|---|
| 385 | COMPILER_FAIL])
|
|---|
| 386 |
|
|---|
| 387 | oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
|
|---|
| 388 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
|---|
| 389 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
|---|
| 390 |
|
|---|
| 391 | newmacro = tag
|
|---|
| 392 | if (not tag in probe['unsigned_tags']):
|
|---|
| 393 | print_error(['Unable to find appropriate size macro for %s' % newmacro,
|
|---|
| 394 | COMPILER_FAIL])
|
|---|
| 395 |
|
|---|
| 396 | oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
|
|---|
| 397 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
|---|
| 398 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
|---|
| 399 |
|
|---|
| 400 | fnd = True
|
|---|
| 401 |
|
|---|
| 402 | if (not 'wchar' in probe['builtins']):
|
|---|
| 403 | print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
|
|---|
| 404 | 'for defining the compiler-native type wchar_t. We are',
|
|---|
| 405 | 'forced to define wchar_t as a hardwired type int32_t.',
|
|---|
| 406 | COMPILER_WARNING])
|
|---|
| 407 | fnd = False
|
|---|
| 408 |
|
|---|
| 409 | if (probe['builtins']['wchar']['value'] != 4):
|
|---|
| 410 | print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
|
|---|
| 411 | 'the compiler-native type wchar_t is not compliant with',
|
|---|
| 412 | 'HelenOS. We are forced to define wchar_t as a hardwired',
|
|---|
| 413 | 'type int32_t.',
|
|---|
| 414 | COMPILER_WARNING])
|
|---|
| 415 | fnd = False
|
|---|
| 416 |
|
|---|
| 417 | if (not fnd):
|
|---|
| 418 | macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
|
|---|
| 419 | else:
|
|---|
| 420 | macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
|
|---|
| 421 |
|
|---|
| 422 | fnd = True
|
|---|
| 423 |
|
|---|
| 424 | if (not 'wint' in probe['builtins']):
|
|---|
| 425 | print_warning(['The compiler does not provide the macro __WINT_TYPE__',
|
|---|
| 426 | 'for defining the compiler-native type wint_t. We are',
|
|---|
| 427 | 'forced to define wint_t as a hardwired type int32_t.',
|
|---|
| 428 | COMPILER_WARNING])
|
|---|
| 429 | fnd = False
|
|---|
| 430 |
|
|---|
| 431 | if (probe['builtins']['wint']['value'] != 4):
|
|---|
| 432 | print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
|
|---|
| 433 | 'the compiler-native type wint_t is not compliant with',
|
|---|
| 434 | 'HelenOS. We are forced to define wint_t as a hardwired',
|
|---|
| 435 | 'type int32_t.',
|
|---|
| 436 | COMPILER_WARNING])
|
|---|
| 437 | fnd = False
|
|---|
| 438 |
|
|---|
| 439 | if (not fnd):
|
|---|
| 440 | macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
|
|---|
| 441 | else:
|
|---|
| 442 | macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
|
|---|
| 443 |
|
|---|
| 444 | return {'macros': macros, 'typedefs': typedefs}
|
|---|
| 445 |
|
|---|
| 446 | def create_makefile(mkname, common):
|
|---|
| 447 | "Create makefile output"
|
|---|
| 448 |
|
|---|
| 449 | outmk = open(mkname, 'w')
|
|---|
| 450 |
|
|---|
| 451 | outmk.write('#########################################\n')
|
|---|
| 452 | outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
|
|---|
| 453 | outmk.write('#########################################\n\n')
|
|---|
| 454 |
|
|---|
| 455 | for key, value in common.items():
|
|---|
| 456 | outmk.write('%s = %s\n' % (key, value))
|
|---|
| 457 |
|
|---|
| 458 | outmk.close()
|
|---|
| 459 |
|
|---|
| 460 | def create_header(hdname, maps):
|
|---|
| 461 | "Create header output"
|
|---|
| 462 |
|
|---|
| 463 | outhd = open(hdname, 'w')
|
|---|
| 464 |
|
|---|
| 465 | outhd.write('/***************************************\n')
|
|---|
| 466 | outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
|
|---|
| 467 | outhd.write(' ***************************************/\n\n')
|
|---|
| 468 |
|
|---|
| 469 | outhd.write('#ifndef %s\n' % GUARD)
|
|---|
| 470 | outhd.write('#define %s\n\n' % GUARD)
|
|---|
| 471 |
|
|---|
| 472 | for macro in maps['macros']:
|
|---|
| 473 | outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
|
|---|
| 474 |
|
|---|
| 475 | outhd.write('\n')
|
|---|
| 476 |
|
|---|
| 477 | for typedef in maps['typedefs']:
|
|---|
| 478 | outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
|
|---|
| 479 |
|
|---|
| 480 | outhd.write('\n#endif\n')
|
|---|
| 481 | outhd.close()
|
|---|
| 482 |
|
|---|
| 483 | def main():
|
|---|
| 484 | config = {}
|
|---|
| 485 | common = {}
|
|---|
| 486 |
|
|---|
| 487 | # Read and check configuration
|
|---|
| 488 | if os.path.exists(CONFIG):
|
|---|
| 489 | read_config(CONFIG, config)
|
|---|
| 490 | else:
|
|---|
| 491 | print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
|
|---|
| 492 | "configuration phase of HelenOS build went OK. Try running",
|
|---|
| 493 | "\"make config\" again."])
|
|---|
| 494 |
|
|---|
| 495 | check_config(config, "PLATFORM")
|
|---|
| 496 | check_config(config, "COMPILER")
|
|---|
| 497 | check_config(config, "BARCH")
|
|---|
| 498 |
|
|---|
| 499 | # Cross-compiler prefix
|
|---|
| 500 | if ('CROSS_PREFIX' in os.environ):
|
|---|
| 501 | cross_prefix = os.environ['CROSS_PREFIX']
|
|---|
| 502 | else:
|
|---|
| 503 | cross_prefix = "/usr/local"
|
|---|
| 504 |
|
|---|
| 505 | # Prefix binutils tools on Solaris
|
|---|
| 506 | if (os.uname()[0] == "SunOS"):
|
|---|
| 507 | binutils_prefix = "g"
|
|---|
| 508 | else:
|
|---|
| 509 | binutils_prefix = ""
|
|---|
| 510 |
|
|---|
| 511 | owd = sandbox_enter()
|
|---|
| 512 |
|
|---|
| 513 | try:
|
|---|
| 514 | # Common utilities
|
|---|
| 515 | check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
|
|---|
| 516 | check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
|
|---|
| 517 | check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
|
|---|
| 518 | check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
|
|---|
| 519 | check_app(["find", "--version"], "Find utility", "usually part of findutils")
|
|---|
| 520 | check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
|
|---|
| 521 | check_app(["make", "--version"], "Make utility", "preferably GNU Make")
|
|---|
| 522 | check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
|
|---|
| 523 |
|
|---|
| 524 | # Compiler
|
|---|
| 525 | if (config['COMPILER'] == "gcc_cross"):
|
|---|
| 526 | if (config['PLATFORM'] == "abs32le"):
|
|---|
| 527 | check_config(config, "CROSS_TARGET")
|
|---|
| 528 | target = config['CROSS_TARGET']
|
|---|
| 529 |
|
|---|
| 530 | if (config['CROSS_TARGET'] == "arm32"):
|
|---|
| 531 | gnu_target = "arm-linux-gnu"
|
|---|
| 532 |
|
|---|
| 533 | if (config['CROSS_TARGET'] == "ia32"):
|
|---|
| 534 | gnu_target = "i686-pc-linux-gnu"
|
|---|
| 535 |
|
|---|
| 536 | if (config['CROSS_TARGET'] == "mips32"):
|
|---|
| 537 | gnu_target = "mipsel-linux-gnu"
|
|---|
| 538 |
|
|---|
| 539 | if (config['PLATFORM'] == "amd64"):
|
|---|
| 540 | target = config['PLATFORM']
|
|---|
| 541 | gnu_target = "amd64-linux-gnu"
|
|---|
| 542 |
|
|---|
| 543 | if (config['PLATFORM'] == "arm32"):
|
|---|
| 544 | target = config['PLATFORM']
|
|---|
| 545 | gnu_target = "arm-linux-gnu"
|
|---|
| 546 |
|
|---|
| 547 | if (config['PLATFORM'] == "ia32"):
|
|---|
| 548 | target = config['PLATFORM']
|
|---|
| 549 | gnu_target = "i686-pc-linux-gnu"
|
|---|
| 550 |
|
|---|
| 551 | if (config['PLATFORM'] == "ia64"):
|
|---|
| 552 | target = config['PLATFORM']
|
|---|
| 553 | gnu_target = "ia64-pc-linux-gnu"
|
|---|
| 554 |
|
|---|
| 555 | if (config['PLATFORM'] == "mips32"):
|
|---|
| 556 | check_config(config, "MACHINE")
|
|---|
| 557 |
|
|---|
| 558 | if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
|
|---|
| 559 | target = config['PLATFORM']
|
|---|
| 560 | gnu_target = "mipsel-linux-gnu"
|
|---|
| 561 |
|
|---|
| 562 | if (config['MACHINE'] == "bgxemul"):
|
|---|
| 563 | target = "mips32eb"
|
|---|
| 564 | gnu_target = "mips-linux-gnu"
|
|---|
| 565 |
|
|---|
| 566 | if (config['PLATFORM'] == "ppc32"):
|
|---|
| 567 | target = config['PLATFORM']
|
|---|
| 568 | gnu_target = "ppc-linux-gnu"
|
|---|
| 569 |
|
|---|
| 570 | if (config['PLATFORM'] == "sparc64"):
|
|---|
| 571 | target = config['PLATFORM']
|
|---|
| 572 | gnu_target = "sparc64-linux-gnu"
|
|---|
| 573 |
|
|---|
| 574 | path = "%s/%s/bin" % (cross_prefix, target)
|
|---|
| 575 | prefix = "%s-" % gnu_target
|
|---|
| 576 |
|
|---|
| 577 | check_gcc(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 578 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 579 |
|
|---|
| 580 | check_common(common, "GCC")
|
|---|
| 581 | common['CC'] = common['GCC']
|
|---|
| 582 |
|
|---|
| 583 | if (config['COMPILER'] == "gcc_native"):
|
|---|
| 584 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 585 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 586 |
|
|---|
| 587 | check_common(common, "GCC")
|
|---|
| 588 | common['CC'] = common['GCC']
|
|---|
| 589 |
|
|---|
| 590 | if (config['COMPILER'] == "icc"):
|
|---|
| 591 | common['CC'] = "icc"
|
|---|
| 592 | check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
|
|---|
| 593 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 594 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 595 |
|
|---|
| 596 | if (config['COMPILER'] == "suncc"):
|
|---|
| 597 | common['CC'] = "suncc"
|
|---|
| 598 | check_app([common['CC'], "-V"], "Sun Studio Compiler", "support is experimental")
|
|---|
| 599 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 600 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 601 |
|
|---|
| 602 | if (config['COMPILER'] == "clang"):
|
|---|
| 603 | common['CC'] = "clang"
|
|---|
| 604 | check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
|
|---|
| 605 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 606 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 607 |
|
|---|
| 608 | # Platform-specific utilities
|
|---|
| 609 | if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
|
|---|
| 610 | check_app(["mkisofs", "--version"], "ISO 9660 creation utility", "usually part of genisoimage")
|
|---|
| 611 |
|
|---|
| 612 | probe = probe_compiler(common,
|
|---|
| 613 | [
|
|---|
| 614 | {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
|
|---|
| 615 | {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
|
|---|
| 616 | {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
|
|---|
| 617 | {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
|
|---|
| 618 | {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
|
|---|
| 619 | ]
|
|---|
| 620 | )
|
|---|
| 621 |
|
|---|
| 622 | maps = detect_uints(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'])
|
|---|
| 623 |
|
|---|
| 624 | finally:
|
|---|
| 625 | sandbox_leave(owd)
|
|---|
| 626 |
|
|---|
| 627 | create_makefile(MAKEFILE, common)
|
|---|
| 628 | create_header(HEADER, maps)
|
|---|
| 629 |
|
|---|
| 630 | return 0
|
|---|
| 631 |
|
|---|
| 632 | if __name__ == '__main__':
|
|---|
| 633 | sys.exit(main())
|
|---|