[177e4ea] | 1 | #!/usr/bin/env python
|
---|
| 2 | #
|
---|
| 3 | # Copyright (c) 2010 Martin Decky
|
---|
| 4 | # All rights reserved.
|
---|
| 5 | #
|
---|
| 6 | # Redistribution and use in source and binary forms, with or without
|
---|
| 7 | # modification, are permitted provided that the following conditions
|
---|
| 8 | # are met:
|
---|
| 9 | #
|
---|
| 10 | # - Redistributions of source code must retain the above copyright
|
---|
| 11 | # notice, this list of conditions and the following disclaimer.
|
---|
| 12 | # - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | # notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | # documentation and/or other materials provided with the distribution.
|
---|
| 15 | # - The name of the author may not be used to endorse or promote products
|
---|
| 16 | # derived from this software without specific prior written permission.
|
---|
| 17 | #
|
---|
| 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | #
|
---|
[3c80f2b] | 29 |
|
---|
[177e4ea] | 30 | """
|
---|
| 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'
|
---|
| 44 | HEADER = 'common.h'
|
---|
| 45 | GUARD = 'AUTOTOOL_COMMON_H_'
|
---|
| 46 |
|
---|
| 47 | PROBE_SOURCE = 'probe.c'
|
---|
| 48 | PROBE_OUTPUT = 'probe.s'
|
---|
[177e4ea] | 49 |
|
---|
| 50 | PACKAGE_BINUTILS = "usually part of binutils"
|
---|
[dc0b964] | 51 | PACKAGE_GCC = "preferably version 4.5.1 or newer"
|
---|
[177e4ea] | 52 | PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
|
---|
| 53 |
|
---|
[4e9aaf5] | 54 | COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
|
---|
[96b89acb] | 55 | COMPILER_WARNING = "The compilation of HelenOS might fail."
|
---|
[4e9aaf5] | 56 |
|
---|
[dc0b964] | 57 | PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
|
---|
[4e9aaf5] | 58 | asm volatile ( \\
|
---|
[dc0b964] | 59 | "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
|
---|
[4e9aaf5] | 60 | : \\
|
---|
| 61 | : [val] "n" (value) \\
|
---|
| 62 | )
|
---|
| 63 |
|
---|
[96b89acb] | 64 | #define STRING(arg) STRING_ARG(arg)
|
---|
| 65 | #define STRING_ARG(arg) #arg
|
---|
| 66 |
|
---|
| 67 | #define DECLARE_BUILTIN_TYPE(tag, type) \\
|
---|
| 68 | AUTOTOOL_DECLARE("builtin", "", tag, STRING(type), "", "", sizeof(type));
|
---|
| 69 |
|
---|
[dc0b964] | 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));
|
---|
[4e9aaf5] | 73 |
|
---|
| 74 | int main(int argc, char *argv[])
|
---|
| 75 | {
|
---|
[96b89acb] | 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
|
---|
[4e9aaf5] | 85 | """
|
---|
| 86 |
|
---|
| 87 | PROBE_TAIL = """}
|
---|
| 88 | """
|
---|
| 89 |
|
---|
[177e4ea] | 90 | def read_config(fname, config):
|
---|
| 91 | "Read HelenOS build configuration"
|
---|
| 92 |
|
---|
[28f4adb] | 93 | inf = open(fname, 'r')
|
---|
[177e4ea] | 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 |
|
---|
[96b89acb] | 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 |
|
---|
[4e9aaf5] | 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 |
|
---|
[177e4ea] | 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 |
|
---|
[4e9aaf5] | 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 |
|
---|
[177e4ea] | 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 |
|
---|
[7174403] | 186 | def check_app_alternatives(alts, args, name, details):
|
---|
| 187 | "Check whether an application can be executed (use several alternatives)"
|
---|
| 188 |
|
---|
| 189 | tried = []
|
---|
| 190 | found = None
|
---|
| 191 |
|
---|
| 192 | for alt in alts:
|
---|
| 193 | working = True
|
---|
| 194 | cmdline = [alt] + args
|
---|
| 195 | tried.append(" ".join(cmdline))
|
---|
| 196 |
|
---|
| 197 | try:
|
---|
| 198 | sys.stderr.write("Checking for %s ... " % alt)
|
---|
| 199 | subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
---|
| 200 | except:
|
---|
| 201 | sys.stderr.write("failed\n")
|
---|
| 202 | working = False
|
---|
| 203 |
|
---|
| 204 | if (working):
|
---|
| 205 | sys.stderr.write("ok\n")
|
---|
| 206 | found = alt
|
---|
| 207 | break
|
---|
| 208 |
|
---|
| 209 | if (found is None):
|
---|
| 210 | print_error(["%s is missing." % name,
|
---|
| 211 | "",
|
---|
| 212 | "Please make sure that it is installed in your",
|
---|
| 213 | "system (%s)." % details,
|
---|
| 214 | "",
|
---|
| 215 | "The following alternatives were tried:"] + tried)
|
---|
| 216 |
|
---|
| 217 | return found
|
---|
| 218 |
|
---|
[177e4ea] | 219 | def check_gcc(path, prefix, common, details):
|
---|
| 220 | "Check for GCC"
|
---|
| 221 |
|
---|
| 222 | common['GCC'] = "%sgcc" % prefix
|
---|
| 223 |
|
---|
| 224 | if (not path is None):
|
---|
| 225 | common['GCC'] = "%s/%s" % (path, common['GCC'])
|
---|
| 226 |
|
---|
| 227 | check_app([common['GCC'], "--version"], "GNU GCC", details)
|
---|
| 228 |
|
---|
| 229 | def check_binutils(path, prefix, common, details):
|
---|
| 230 | "Check for binutils toolchain"
|
---|
| 231 |
|
---|
| 232 | common['AS'] = "%sas" % prefix
|
---|
| 233 | common['LD'] = "%sld" % prefix
|
---|
| 234 | common['AR'] = "%sar" % prefix
|
---|
| 235 | common['OBJCOPY'] = "%sobjcopy" % prefix
|
---|
| 236 | common['OBJDUMP'] = "%sobjdump" % prefix
|
---|
[a4125fb1] | 237 | common['STRIP'] = "%sstrip" % prefix
|
---|
[177e4ea] | 238 |
|
---|
| 239 | if (not path is None):
|
---|
[a4125fb1] | 240 | for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
|
---|
[177e4ea] | 241 | common[key] = "%s/%s" % (path, common[key])
|
---|
| 242 |
|
---|
| 243 | check_app([common['AS'], "--version"], "GNU Assembler", details)
|
---|
| 244 | check_app([common['LD'], "--version"], "GNU Linker", details)
|
---|
| 245 | check_app([common['AR'], "--version"], "GNU Archiver", details)
|
---|
| 246 | check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
|
---|
| 247 | check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
|
---|
[a4125fb1] | 248 | check_app([common['STRIP'], "--version"], "GNU strip", details)
|
---|
[177e4ea] | 249 |
|
---|
[96b89acb] | 250 | def decode_value(value):
|
---|
| 251 | "Decode integer value"
|
---|
| 252 |
|
---|
| 253 | base = 10
|
---|
| 254 |
|
---|
| 255 | if ((value.startswith('$')) or (value.startswith('#'))):
|
---|
| 256 | value = value[1:]
|
---|
| 257 |
|
---|
| 258 | if (value.startswith('0x')):
|
---|
| 259 | value = value[2:]
|
---|
| 260 | base = 16
|
---|
| 261 |
|
---|
| 262 | return int(value, base)
|
---|
| 263 |
|
---|
[4e9aaf5] | 264 | def probe_compiler(common, sizes):
|
---|
| 265 | "Generate, compile and parse probing source"
|
---|
| 266 |
|
---|
| 267 | check_common(common, "CC")
|
---|
| 268 |
|
---|
[28f4adb] | 269 | outf = open(PROBE_SOURCE, 'w')
|
---|
[4e9aaf5] | 270 | outf.write(PROBE_HEAD)
|
---|
| 271 |
|
---|
| 272 | for typedef in sizes:
|
---|
[dc0b964] | 273 | outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
|
---|
[4e9aaf5] | 274 |
|
---|
| 275 | outf.write(PROBE_TAIL)
|
---|
| 276 | outf.close()
|
---|
| 277 |
|
---|
[2429e4a] | 278 | args = [common['CC']]
|
---|
| 279 | args.extend(common['CC_ARGS'])
|
---|
| 280 | args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
|
---|
[4e9aaf5] | 281 |
|
---|
| 282 | try:
|
---|
| 283 | sys.stderr.write("Checking compiler properties ... ")
|
---|
| 284 | output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
|
---|
| 285 | except:
|
---|
| 286 | sys.stderr.write("failed\n")
|
---|
| 287 | print_error(["Error executing \"%s\"." % " ".join(args),
|
---|
| 288 | "Make sure that the compiler works properly."])
|
---|
| 289 |
|
---|
| 290 | if (not os.path.isfile(PROBE_OUTPUT)):
|
---|
| 291 | sys.stderr.write("failed\n")
|
---|
[28f4adb] | 292 | print(output[1])
|
---|
[4e9aaf5] | 293 | print_error(["Error executing \"%s\"." % " ".join(args),
|
---|
| 294 | "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
|
---|
| 295 | "",
|
---|
| 296 | output[0],
|
---|
| 297 | output[1]])
|
---|
| 298 |
|
---|
| 299 | sys.stderr.write("ok\n")
|
---|
| 300 |
|
---|
[28f4adb] | 301 | inf = open(PROBE_OUTPUT, 'r')
|
---|
[4e9aaf5] | 302 | lines = inf.readlines()
|
---|
| 303 | inf.close()
|
---|
| 304 |
|
---|
| 305 | unsigned_sizes = {}
|
---|
| 306 | signed_sizes = {}
|
---|
| 307 |
|
---|
[9539be6] | 308 | unsigned_tags = {}
|
---|
| 309 | signed_tags = {}
|
---|
| 310 |
|
---|
[dc0b964] | 311 | unsigned_strcs = {}
|
---|
| 312 | signed_strcs = {}
|
---|
| 313 |
|
---|
| 314 | unsigned_concs = {}
|
---|
| 315 | signed_concs = {}
|
---|
| 316 |
|
---|
[96b89acb] | 317 | builtins = {}
|
---|
| 318 |
|
---|
[4e9aaf5] | 319 | for j in range(len(lines)):
|
---|
| 320 | tokens = lines[j].strip().split("\t")
|
---|
| 321 |
|
---|
| 322 | if (len(tokens) > 0):
|
---|
| 323 | if (tokens[0] == "AUTOTOOL_DECLARE"):
|
---|
[dc0b964] | 324 | if (len(tokens) < 7):
|
---|
[4e9aaf5] | 325 | print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
| 326 |
|
---|
| 327 | category = tokens[1]
|
---|
| 328 | subcategory = tokens[2]
|
---|
[9539be6] | 329 | tag = tokens[3]
|
---|
| 330 | name = tokens[4]
|
---|
[dc0b964] | 331 | strc = tokens[5]
|
---|
| 332 | conc = tokens[6]
|
---|
| 333 | value = tokens[7]
|
---|
[4e9aaf5] | 334 |
|
---|
| 335 | if (category == "intsize"):
|
---|
| 336 | try:
|
---|
[96b89acb] | 337 | value_int = decode_value(value)
|
---|
[4e9aaf5] | 338 | except:
|
---|
| 339 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
| 340 |
|
---|
| 341 | if (subcategory == "unsigned"):
|
---|
[96b89acb] | 342 | unsigned_sizes[value_int] = name
|
---|
[9539be6] | 343 | unsigned_tags[tag] = value_int
|
---|
[96b89acb] | 344 | unsigned_strcs[value_int] = strc
|
---|
| 345 | unsigned_concs[value_int] = conc
|
---|
[4e9aaf5] | 346 | elif (subcategory == "signed"):
|
---|
[96b89acb] | 347 | signed_sizes[value_int] = name
|
---|
[9539be6] | 348 | signed_tags[tag] = value_int
|
---|
[96b89acb] | 349 | signed_strcs[value_int] = strc
|
---|
| 350 | signed_concs[value_int] = conc
|
---|
[4e9aaf5] | 351 | else:
|
---|
| 352 | print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
[96b89acb] | 353 |
|
---|
| 354 | if (category == "builtin"):
|
---|
| 355 | try:
|
---|
| 356 | value_int = decode_value(value)
|
---|
| 357 | except:
|
---|
| 358 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
| 359 |
|
---|
| 360 | builtins[tag] = {'name': name, 'value': value_int}
|
---|
[4e9aaf5] | 361 |
|
---|
[96b89acb] | 362 | 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}
|
---|
[4e9aaf5] | 363 |
|
---|
[96b89acb] | 364 | def detect_uints(probe, bytes, tags):
|
---|
[4e9aaf5] | 365 | "Detect correct types for fixed-size integer types"
|
---|
| 366 |
|
---|
[9539be6] | 367 | macros = []
|
---|
[4e9aaf5] | 368 | typedefs = []
|
---|
| 369 |
|
---|
| 370 | for b in bytes:
|
---|
[96b89acb] | 371 | if (not b in probe['unsigned_sizes']):
|
---|
[dc0b964] | 372 | print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b,
|
---|
[4e9aaf5] | 373 | COMPILER_FAIL])
|
---|
| 374 |
|
---|
[96b89acb] | 375 | if (not b in probe['signed_sizes']):
|
---|
[dc0b964] | 376 | print_error(['Unable to find appropriate signed integer type for %u bytes' % b,
|
---|
[4e9aaf5] | 377 | COMPILER_FAIL])
|
---|
[dc0b964] | 378 |
|
---|
[96b89acb] | 379 | if (not b in probe['unsigned_strcs']):
|
---|
[85369b1] | 380 | print_error(['Unable to find appropriate unsigned printf formatter for %u bytes' % b,
|
---|
| 381 | COMPILER_FAIL])
|
---|
[dc0b964] | 382 |
|
---|
[96b89acb] | 383 | if (not b in probe['signed_strcs']):
|
---|
[85369b1] | 384 | print_error(['Unable to find appropriate signed printf formatter for %u bytes' % b,
|
---|
| 385 | COMPILER_FAIL])
|
---|
[dc0b964] | 386 |
|
---|
[96b89acb] | 387 | if (not b in probe['unsigned_concs']):
|
---|
[85369b1] | 388 | print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
|
---|
| 389 | COMPILER_FAIL])
|
---|
[dc0b964] | 390 |
|
---|
[96b89acb] | 391 | if (not b in probe['signed_concs']):
|
---|
| 392 | print_error(['Unable to find appropriate signed literal macro for %u bytes' % b,
|
---|
| 393 | COMPILER_FAIL])
|
---|
[dc0b964] | 394 |
|
---|
[96b89acb] | 395 | typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
|
---|
| 396 | typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
|
---|
[dc0b964] | 397 |
|
---|
[d408ea0] | 398 | macros.append({'oldmacro': "unsigned %s" % probe['unsigned_sizes'][b], 'newmacro': "UINT%u_T" % (b * 8)})
|
---|
| 399 | macros.append({'oldmacro': "signed %s" % probe['signed_sizes'][b], 'newmacro': "INT%u_T" % (b * 8)})
|
---|
| 400 |
|
---|
[96b89acb] | 401 | macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
|
---|
| 402 | macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
|
---|
| 403 | macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
|
---|
| 404 | macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
|
---|
| 405 | macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
|
---|
[9539be6] | 406 |
|
---|
[96b89acb] | 407 | name = probe['unsigned_concs'][b]
|
---|
| 408 | if ((name.startswith('@')) or (name == "")):
|
---|
| 409 | macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
---|
| 410 | else:
|
---|
| 411 | macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
---|
[9539be6] | 412 |
|
---|
[96b89acb] | 413 | name = probe['unsigned_concs'][b]
|
---|
| 414 | if ((name.startswith('@')) or (name == "")):
|
---|
| 415 | macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
|
---|
| 416 | else:
|
---|
| 417 | macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
|
---|
| 418 |
|
---|
| 419 | for tag in tags:
|
---|
| 420 | newmacro = "U%s" % tag
|
---|
| 421 | if (not tag in probe['unsigned_tags']):
|
---|
[9539be6] | 422 | print_error(['Unable to find appropriate size macro for %s' % newmacro,
|
---|
| 423 | COMPILER_FAIL])
|
---|
| 424 |
|
---|
[96b89acb] | 425 | oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
|
---|
| 426 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
---|
| 427 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
---|
[9539be6] | 428 |
|
---|
[96b89acb] | 429 | newmacro = tag
|
---|
| 430 | if (not tag in probe['unsigned_tags']):
|
---|
[9539be6] | 431 | print_error(['Unable to find appropriate size macro for %s' % newmacro,
|
---|
| 432 | COMPILER_FAIL])
|
---|
[96b89acb] | 433 |
|
---|
| 434 | oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
|
---|
| 435 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
---|
| 436 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
---|
| 437 |
|
---|
| 438 | fnd = True
|
---|
| 439 |
|
---|
| 440 | if (not 'wchar' in probe['builtins']):
|
---|
| 441 | print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
|
---|
| 442 | 'for defining the compiler-native type wchar_t. We are',
|
---|
| 443 | 'forced to define wchar_t as a hardwired type int32_t.',
|
---|
| 444 | COMPILER_WARNING])
|
---|
| 445 | fnd = False
|
---|
| 446 |
|
---|
| 447 | if (probe['builtins']['wchar']['value'] != 4):
|
---|
| 448 | print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
|
---|
| 449 | 'the compiler-native type wchar_t is not compliant with',
|
---|
| 450 | 'HelenOS. We are forced to define wchar_t as a hardwired',
|
---|
| 451 | 'type int32_t.',
|
---|
| 452 | COMPILER_WARNING])
|
---|
| 453 | fnd = False
|
---|
| 454 |
|
---|
| 455 | if (not fnd):
|
---|
| 456 | macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
|
---|
| 457 | else:
|
---|
| 458 | macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
|
---|
| 459 |
|
---|
| 460 | fnd = True
|
---|
| 461 |
|
---|
| 462 | if (not 'wint' in probe['builtins']):
|
---|
| 463 | print_warning(['The compiler does not provide the macro __WINT_TYPE__',
|
---|
| 464 | 'for defining the compiler-native type wint_t. We are',
|
---|
| 465 | 'forced to define wint_t as a hardwired type int32_t.',
|
---|
| 466 | COMPILER_WARNING])
|
---|
| 467 | fnd = False
|
---|
| 468 |
|
---|
| 469 | if (probe['builtins']['wint']['value'] != 4):
|
---|
| 470 | print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
|
---|
| 471 | 'the compiler-native type wint_t is not compliant with',
|
---|
| 472 | 'HelenOS. We are forced to define wint_t as a hardwired',
|
---|
| 473 | 'type int32_t.',
|
---|
| 474 | COMPILER_WARNING])
|
---|
| 475 | fnd = False
|
---|
| 476 |
|
---|
| 477 | if (not fnd):
|
---|
| 478 | macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
|
---|
| 479 | else:
|
---|
| 480 | macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
|
---|
[9539be6] | 481 |
|
---|
| 482 | return {'macros': macros, 'typedefs': typedefs}
|
---|
[4e9aaf5] | 483 |
|
---|
| 484 | def create_makefile(mkname, common):
|
---|
| 485 | "Create makefile output"
|
---|
[177e4ea] | 486 |
|
---|
[28f4adb] | 487 | outmk = open(mkname, 'w')
|
---|
[177e4ea] | 488 |
|
---|
[4e9aaf5] | 489 | outmk.write('#########################################\n')
|
---|
| 490 | outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
|
---|
| 491 | outmk.write('#########################################\n\n')
|
---|
[177e4ea] | 492 |
|
---|
| 493 | for key, value in common.items():
|
---|
[7174403] | 494 | if (type(value) is list):
|
---|
| 495 | outmk.write('%s = %s\n' % (key, " ".join(value)))
|
---|
| 496 | else:
|
---|
| 497 | outmk.write('%s = %s\n' % (key, value))
|
---|
[4e9aaf5] | 498 |
|
---|
| 499 | outmk.close()
|
---|
| 500 |
|
---|
[9539be6] | 501 | def create_header(hdname, maps):
|
---|
[4e9aaf5] | 502 | "Create header output"
|
---|
| 503 |
|
---|
[28f4adb] | 504 | outhd = open(hdname, 'w')
|
---|
[4e9aaf5] | 505 |
|
---|
| 506 | outhd.write('/***************************************\n')
|
---|
| 507 | outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
|
---|
| 508 | outhd.write(' ***************************************/\n\n')
|
---|
[177e4ea] | 509 |
|
---|
[4e9aaf5] | 510 | outhd.write('#ifndef %s\n' % GUARD)
|
---|
| 511 | outhd.write('#define %s\n\n' % GUARD)
|
---|
| 512 |
|
---|
[9539be6] | 513 | for macro in maps['macros']:
|
---|
| 514 | outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
|
---|
| 515 |
|
---|
| 516 | outhd.write('\n')
|
---|
| 517 |
|
---|
| 518 | for typedef in maps['typedefs']:
|
---|
[4e9aaf5] | 519 | outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
|
---|
| 520 |
|
---|
| 521 | outhd.write('\n#endif\n')
|
---|
| 522 | outhd.close()
|
---|
[177e4ea] | 523 |
|
---|
| 524 | def main():
|
---|
| 525 | config = {}
|
---|
| 526 | common = {}
|
---|
| 527 |
|
---|
| 528 | # Read and check configuration
|
---|
[4e9aaf5] | 529 | if os.path.exists(CONFIG):
|
---|
| 530 | read_config(CONFIG, config)
|
---|
[177e4ea] | 531 | else:
|
---|
[4e9aaf5] | 532 | print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
|
---|
[177e4ea] | 533 | "configuration phase of HelenOS build went OK. Try running",
|
---|
| 534 | "\"make config\" again."])
|
---|
| 535 |
|
---|
| 536 | check_config(config, "PLATFORM")
|
---|
| 537 | check_config(config, "COMPILER")
|
---|
| 538 | check_config(config, "BARCH")
|
---|
| 539 |
|
---|
| 540 | # Cross-compiler prefix
|
---|
| 541 | if ('CROSS_PREFIX' in os.environ):
|
---|
| 542 | cross_prefix = os.environ['CROSS_PREFIX']
|
---|
| 543 | else:
|
---|
[603c8740] | 544 | cross_prefix = "/usr/local/cross"
|
---|
[177e4ea] | 545 |
|
---|
| 546 | # Prefix binutils tools on Solaris
|
---|
| 547 | if (os.uname()[0] == "SunOS"):
|
---|
| 548 | binutils_prefix = "g"
|
---|
| 549 | else:
|
---|
| 550 | binutils_prefix = ""
|
---|
| 551 |
|
---|
[4e9aaf5] | 552 | owd = sandbox_enter()
|
---|
| 553 |
|
---|
| 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")
|
---|
| 563 | check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
|
---|
| 564 |
|
---|
| 565 | # Compiler
|
---|
[2429e4a] | 566 | common['CC_ARGS'] = []
|
---|
[4e9aaf5] | 567 | if (config['COMPILER'] == "gcc_cross"):
|
---|
| 568 | if (config['PLATFORM'] == "abs32le"):
|
---|
| 569 | check_config(config, "CROSS_TARGET")
|
---|
| 570 | target = config['CROSS_TARGET']
|
---|
| 571 |
|
---|
| 572 | if (config['CROSS_TARGET'] == "arm32"):
|
---|
| 573 | gnu_target = "arm-linux-gnu"
|
---|
| 574 |
|
---|
| 575 | if (config['CROSS_TARGET'] == "ia32"):
|
---|
| 576 | gnu_target = "i686-pc-linux-gnu"
|
---|
| 577 |
|
---|
| 578 | if (config['CROSS_TARGET'] == "mips32"):
|
---|
| 579 | gnu_target = "mipsel-linux-gnu"
|
---|
[2429e4a] | 580 | common['CC_ARGS'].append("-mabi=32")
|
---|
[177e4ea] | 581 |
|
---|
[4e9aaf5] | 582 | if (config['PLATFORM'] == "amd64"):
|
---|
| 583 | target = config['PLATFORM']
|
---|
| 584 | gnu_target = "amd64-linux-gnu"
|
---|
| 585 |
|
---|
| 586 | if (config['PLATFORM'] == "arm32"):
|
---|
| 587 | target = config['PLATFORM']
|
---|
[177e4ea] | 588 | gnu_target = "arm-linux-gnu"
|
---|
| 589 |
|
---|
[4e9aaf5] | 590 | if (config['PLATFORM'] == "ia32"):
|
---|
| 591 | target = config['PLATFORM']
|
---|
[177e4ea] | 592 | gnu_target = "i686-pc-linux-gnu"
|
---|
| 593 |
|
---|
[4e9aaf5] | 594 | if (config['PLATFORM'] == "ia64"):
|
---|
| 595 | target = config['PLATFORM']
|
---|
| 596 | gnu_target = "ia64-pc-linux-gnu"
|
---|
| 597 |
|
---|
| 598 | if (config['PLATFORM'] == "mips32"):
|
---|
| 599 | check_config(config, "MACHINE")
|
---|
[2429e4a] | 600 | common['CC_ARGS'].append("-mabi=32")
|
---|
[4e9aaf5] | 601 |
|
---|
| 602 | if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
|
---|
| 603 | target = config['PLATFORM']
|
---|
| 604 | gnu_target = "mipsel-linux-gnu"
|
---|
| 605 |
|
---|
| 606 | if (config['MACHINE'] == "bgxemul"):
|
---|
| 607 | target = "mips32eb"
|
---|
| 608 | gnu_target = "mips-linux-gnu"
|
---|
| 609 |
|
---|
[2429e4a] | 610 | if (config['PLATFORM'] == "mips64"):
|
---|
| 611 | check_config(config, "MACHINE")
|
---|
| 612 | common['CC_ARGS'].append("-mabi=64")
|
---|
| 613 |
|
---|
| 614 | if (config['MACHINE'] == "msim"):
|
---|
| 615 | target = config['PLATFORM']
|
---|
| 616 | gnu_target = "mips64el-linux-gnu"
|
---|
| 617 |
|
---|
[4e9aaf5] | 618 | if (config['PLATFORM'] == "ppc32"):
|
---|
| 619 | target = config['PLATFORM']
|
---|
| 620 | gnu_target = "ppc-linux-gnu"
|
---|
| 621 |
|
---|
| 622 | if (config['PLATFORM'] == "sparc64"):
|
---|
| 623 | target = config['PLATFORM']
|
---|
| 624 | gnu_target = "sparc64-linux-gnu"
|
---|
| 625 |
|
---|
| 626 | path = "%s/%s/bin" % (cross_prefix, target)
|
---|
| 627 | prefix = "%s-" % gnu_target
|
---|
| 628 |
|
---|
| 629 | check_gcc(path, prefix, common, PACKAGE_CROSS)
|
---|
| 630 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
---|
| 631 |
|
---|
| 632 | check_common(common, "GCC")
|
---|
| 633 | common['CC'] = common['GCC']
|
---|
[177e4ea] | 634 |
|
---|
[4e9aaf5] | 635 | if (config['COMPILER'] == "gcc_native"):
|
---|
| 636 | check_gcc(None, "", common, PACKAGE_GCC)
|
---|
| 637 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
---|
| 638 |
|
---|
| 639 | check_common(common, "GCC")
|
---|
| 640 | common['CC'] = common['GCC']
|
---|
[177e4ea] | 641 |
|
---|
[4e9aaf5] | 642 | if (config['COMPILER'] == "icc"):
|
---|
| 643 | common['CC'] = "icc"
|
---|
| 644 | check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
|
---|
| 645 | check_gcc(None, "", common, PACKAGE_GCC)
|
---|
| 646 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
---|
[177e4ea] | 647 |
|
---|
[4e9aaf5] | 648 | if (config['COMPILER'] == "suncc"):
|
---|
| 649 | common['CC'] = "suncc"
|
---|
| 650 | check_app([common['CC'], "-V"], "Sun Studio Compiler", "support is experimental")
|
---|
| 651 | check_gcc(None, "", common, PACKAGE_GCC)
|
---|
| 652 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
---|
[177e4ea] | 653 |
|
---|
[4e9aaf5] | 654 | if (config['COMPILER'] == "clang"):
|
---|
| 655 | common['CC'] = "clang"
|
---|
| 656 | check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
|
---|
| 657 | check_gcc(None, "", common, PACKAGE_GCC)
|
---|
| 658 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
---|
[177e4ea] | 659 |
|
---|
[4e9aaf5] | 660 | # Platform-specific utilities
|
---|
| 661 | if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
|
---|
[7174403] | 662 | common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
|
---|
[177e4ea] | 663 |
|
---|
[4e9aaf5] | 664 | probe = probe_compiler(common,
|
---|
| 665 | [
|
---|
[96b89acb] | 666 | {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
|
---|
[dc0b964] | 667 | {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
|
---|
[96b89acb] | 668 | {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
|
---|
| 669 | {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
|
---|
| 670 | {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
|
---|
[4e9aaf5] | 671 | ]
|
---|
| 672 | )
|
---|
[177e4ea] | 673 |
|
---|
[96b89acb] | 674 | maps = detect_uints(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'])
|
---|
[177e4ea] | 675 |
|
---|
[4e9aaf5] | 676 | finally:
|
---|
| 677 | sandbox_leave(owd)
|
---|
| 678 |
|
---|
| 679 | create_makefile(MAKEFILE, common)
|
---|
[9539be6] | 680 | create_header(HEADER, maps)
|
---|
[177e4ea] | 681 |
|
---|
| 682 | return 0
|
---|
| 683 |
|
---|
| 684 | if __name__ == '__main__':
|
---|
| 685 | sys.exit(main())
|
---|