| 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 | PROBE_INT128_SOURCE = 'probe_int128.c'
|
|---|
| 51 | PROBE_INT128_OUTPUT = 'probe_int128.s'
|
|---|
| 52 |
|
|---|
| 53 | PACKAGE_BINUTILS = "usually part of binutils"
|
|---|
| 54 | PACKAGE_GCC = "preferably version 4.7.0 or newer"
|
|---|
| 55 | PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
|
|---|
| 56 |
|
|---|
| 57 | COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
|
|---|
| 58 | COMPILER_WARNING = "The compilation of HelenOS might fail."
|
|---|
| 59 |
|
|---|
| 60 | PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
|
|---|
| 61 | asm volatile ( \\
|
|---|
| 62 | "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
|
|---|
| 63 | : \\
|
|---|
| 64 | : [val] "n" (value) \\
|
|---|
| 65 | )
|
|---|
| 66 |
|
|---|
| 67 | #define STRING(arg) STRING_ARG(arg)
|
|---|
| 68 | #define STRING_ARG(arg) #arg
|
|---|
| 69 |
|
|---|
| 70 | #define DECLARE_BUILTIN_TYPE(tag, type) \\
|
|---|
| 71 | AUTOTOOL_DECLARE("builtin_size", "", tag, STRING(type), "", "", sizeof(type)); \\
|
|---|
| 72 | AUTOTOOL_DECLARE("builtin_sign", "unsigned long long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long long int)); \\
|
|---|
| 73 | AUTOTOOL_DECLARE("builtin_sign", "unsigned long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long int)); \\
|
|---|
| 74 | AUTOTOOL_DECLARE("builtin_sign", "unsigned int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned int)); \\
|
|---|
| 75 | AUTOTOOL_DECLARE("builtin_sign", "unsigned short int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned short int)); \\
|
|---|
| 76 | AUTOTOOL_DECLARE("builtin_sign", "unsigned char", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned char)); \\
|
|---|
| 77 | AUTOTOOL_DECLARE("builtin_sign", "signed long long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long long int)); \\
|
|---|
| 78 | AUTOTOOL_DECLARE("builtin_sign", "signed long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long int)); \\
|
|---|
| 79 | AUTOTOOL_DECLARE("builtin_sign", "signed int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed int)); \\
|
|---|
| 80 | AUTOTOOL_DECLARE("builtin_sign", "signed short int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed short int)); \\
|
|---|
| 81 | AUTOTOOL_DECLARE("builtin_sign", "signed char", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed char));
|
|---|
| 82 |
|
|---|
| 83 | #define DECLARE_INTSIZE(tag, type, strc, conc) \\
|
|---|
| 84 | AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\
|
|---|
| 85 | AUTOTOOL_DECLARE("intsize", "signed", tag, #type, strc, conc, sizeof(signed type));
|
|---|
| 86 |
|
|---|
| 87 | #define DECLARE_FLOATSIZE(tag, type) \\
|
|---|
| 88 | AUTOTOOL_DECLARE("floatsize", "", tag, #type, "", "", sizeof(type));
|
|---|
| 89 |
|
|---|
| 90 | extern int main(int, char *[]);
|
|---|
| 91 |
|
|---|
| 92 | int main(int argc, char *argv[])
|
|---|
| 93 | {
|
|---|
| 94 | #ifdef __SIZE_TYPE__
|
|---|
| 95 | DECLARE_BUILTIN_TYPE("size", __SIZE_TYPE__);
|
|---|
| 96 | #endif
|
|---|
| 97 | #ifdef __WCHAR_TYPE__
|
|---|
| 98 | DECLARE_BUILTIN_TYPE("wchar", __WCHAR_TYPE__);
|
|---|
| 99 | #endif
|
|---|
| 100 | #ifdef __WINT_TYPE__
|
|---|
| 101 | DECLARE_BUILTIN_TYPE("wint", __WINT_TYPE__);
|
|---|
| 102 | #endif
|
|---|
| 103 | """
|
|---|
| 104 |
|
|---|
| 105 | PROBE_TAIL = """}
|
|---|
| 106 | """
|
|---|
| 107 |
|
|---|
| 108 | PROBE_INT128_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
|
|---|
| 109 | asm volatile ( \\
|
|---|
| 110 | "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
|
|---|
| 111 | : \\
|
|---|
| 112 | : [val] "n" (value) \\
|
|---|
| 113 | )
|
|---|
| 114 |
|
|---|
| 115 | #define DECLARE_INTSIZE(tag, type) \\
|
|---|
| 116 | AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, "", "", sizeof(unsigned type)); \\
|
|---|
| 117 | AUTOTOOL_DECLARE("intsize", "signed", tag, #type, "", "", sizeof(signed type));
|
|---|
| 118 |
|
|---|
| 119 | extern int main(int, char *[]);
|
|---|
| 120 |
|
|---|
| 121 | int main(int argc, char *argv[])
|
|---|
| 122 | {
|
|---|
| 123 | """
|
|---|
| 124 |
|
|---|
| 125 | PROBE_INT128_TAIL = """}
|
|---|
| 126 | """
|
|---|
| 127 |
|
|---|
| 128 | def read_config(fname, config):
|
|---|
| 129 | "Read HelenOS build configuration"
|
|---|
| 130 |
|
|---|
| 131 | inf = open(fname, 'r')
|
|---|
| 132 |
|
|---|
| 133 | for line in inf:
|
|---|
| 134 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
|
|---|
| 135 | if (res):
|
|---|
| 136 | config[res.group(1)] = res.group(2)
|
|---|
| 137 |
|
|---|
| 138 | inf.close()
|
|---|
| 139 |
|
|---|
| 140 | def print_error(msg):
|
|---|
| 141 | "Print a bold error message"
|
|---|
| 142 |
|
|---|
| 143 | sys.stderr.write("\n")
|
|---|
| 144 | sys.stderr.write("######################################################################\n")
|
|---|
| 145 | sys.stderr.write("HelenOS build sanity check error:\n")
|
|---|
| 146 | sys.stderr.write("\n")
|
|---|
| 147 | sys.stderr.write("%s\n" % "\n".join(msg))
|
|---|
| 148 | sys.stderr.write("######################################################################\n")
|
|---|
| 149 | sys.stderr.write("\n")
|
|---|
| 150 |
|
|---|
| 151 | sys.exit(1)
|
|---|
| 152 |
|
|---|
| 153 | def print_warning(msg):
|
|---|
| 154 | "Print a bold error message"
|
|---|
| 155 |
|
|---|
| 156 | sys.stderr.write("\n")
|
|---|
| 157 | sys.stderr.write("######################################################################\n")
|
|---|
| 158 | sys.stderr.write("HelenOS build sanity check warning:\n")
|
|---|
| 159 | sys.stderr.write("\n")
|
|---|
| 160 | sys.stderr.write("%s\n" % "\n".join(msg))
|
|---|
| 161 | sys.stderr.write("######################################################################\n")
|
|---|
| 162 | sys.stderr.write("\n")
|
|---|
| 163 |
|
|---|
| 164 | time.sleep(5)
|
|---|
| 165 |
|
|---|
| 166 | def sandbox_enter():
|
|---|
| 167 | "Create a temporal sandbox directory for running tests"
|
|---|
| 168 |
|
|---|
| 169 | if (os.path.exists(SANDBOX)):
|
|---|
| 170 | if (os.path.isdir(SANDBOX)):
|
|---|
| 171 | try:
|
|---|
| 172 | shutil.rmtree(SANDBOX)
|
|---|
| 173 | except:
|
|---|
| 174 | print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
|
|---|
| 175 | else:
|
|---|
| 176 | print_error(["Please inspect and remove unexpected directory,",
|
|---|
| 177 | "entry \"%s\"." % SANDBOX])
|
|---|
| 178 |
|
|---|
| 179 | try:
|
|---|
| 180 | os.mkdir(SANDBOX)
|
|---|
| 181 | except:
|
|---|
| 182 | print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
|
|---|
| 183 |
|
|---|
| 184 | owd = os.getcwd()
|
|---|
| 185 | os.chdir(SANDBOX)
|
|---|
| 186 |
|
|---|
| 187 | return owd
|
|---|
| 188 |
|
|---|
| 189 | def sandbox_leave(owd):
|
|---|
| 190 | "Leave the temporal sandbox directory"
|
|---|
| 191 |
|
|---|
| 192 | os.chdir(owd)
|
|---|
| 193 |
|
|---|
| 194 | def check_config(config, key):
|
|---|
| 195 | "Check whether the configuration key exists"
|
|---|
| 196 |
|
|---|
| 197 | if (not key in config):
|
|---|
| 198 | print_error(["Build configuration of HelenOS does not contain %s." % key,
|
|---|
| 199 | "Try running \"make config\" again.",
|
|---|
| 200 | "If the problem persists, please contact the developers of HelenOS."])
|
|---|
| 201 |
|
|---|
| 202 | def check_common(common, key):
|
|---|
| 203 | "Check whether the common key exists"
|
|---|
| 204 |
|
|---|
| 205 | if (not key in common):
|
|---|
| 206 | print_error(["Failed to determine the value %s." % key,
|
|---|
| 207 | "Please contact the developers of HelenOS."])
|
|---|
| 208 |
|
|---|
| 209 | def get_target(config):
|
|---|
| 210 | target = None
|
|---|
| 211 | gnu_target = None
|
|---|
| 212 | clang_target = None
|
|---|
| 213 | helenos_target = None
|
|---|
| 214 | cc_args = []
|
|---|
| 215 |
|
|---|
| 216 | if (config['PLATFORM'] == "abs32le"):
|
|---|
| 217 | check_config(config, "CROSS_TARGET")
|
|---|
| 218 | target = config['CROSS_TARGET']
|
|---|
| 219 |
|
|---|
| 220 | if (config['CROSS_TARGET'] == "arm32"):
|
|---|
| 221 | gnu_target = "arm-linux-gnueabi"
|
|---|
| 222 | clang_target = "arm-unknown-none"
|
|---|
| 223 | helenos_target = "arm-helenos-gnueabi"
|
|---|
| 224 |
|
|---|
| 225 | if (config['CROSS_TARGET'] == "ia32"):
|
|---|
| 226 | gnu_target = "i686-pc-linux-gnu"
|
|---|
| 227 | clang_target = "i686-unknown-none"
|
|---|
| 228 | helenos_target = "i686-pc-helenos"
|
|---|
| 229 |
|
|---|
| 230 | if (config['CROSS_TARGET'] == "mips32"):
|
|---|
| 231 | cc_args.append("-mabi=32")
|
|---|
| 232 | gnu_target = "mipsel-linux-gnu"
|
|---|
| 233 | clang_target = "mipsel-unknown-none"
|
|---|
| 234 | helenos_target = "mipsel-helenos"
|
|---|
| 235 |
|
|---|
| 236 | if (config['PLATFORM'] == "amd64"):
|
|---|
| 237 | target = config['PLATFORM']
|
|---|
| 238 | gnu_target = "amd64-linux-gnu"
|
|---|
| 239 | clang_target = "x86_64-unknown-none"
|
|---|
| 240 | helenos_target = "amd64-helenos"
|
|---|
| 241 |
|
|---|
| 242 | if (config['PLATFORM'] == "arm32"):
|
|---|
| 243 | target = config['PLATFORM']
|
|---|
| 244 | gnu_target = "arm-linux-gnueabi"
|
|---|
| 245 | clang_target = "arm-unknown-none-eabi"
|
|---|
| 246 | helenos_target = "arm-helenos-gnueabi"
|
|---|
| 247 |
|
|---|
| 248 | if (config['PLATFORM'] == "ia32"):
|
|---|
| 249 | target = config['PLATFORM']
|
|---|
| 250 | gnu_target = "i686-pc-linux-gnu"
|
|---|
| 251 | clang_target = "i686-unknown-none"
|
|---|
| 252 | helenos_target = "i686-pc-helenos"
|
|---|
| 253 |
|
|---|
| 254 | if (config['PLATFORM'] == "ia64"):
|
|---|
| 255 | target = config['PLATFORM']
|
|---|
| 256 | gnu_target = "ia64-pc-linux-gnu"
|
|---|
| 257 | helenos_target = "ia64-pc-helenos"
|
|---|
| 258 |
|
|---|
| 259 | if (config['PLATFORM'] == "mips32"):
|
|---|
| 260 | check_config(config, "MACHINE")
|
|---|
| 261 | cc_args.append("-mabi=32")
|
|---|
| 262 |
|
|---|
| 263 | if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
|
|---|
| 264 | target = config['PLATFORM']
|
|---|
| 265 | gnu_target = "mipsel-linux-gnu"
|
|---|
| 266 | clang_target = "mipsel-unknown-none"
|
|---|
| 267 | helenos_target = "mipsel-helenos"
|
|---|
| 268 |
|
|---|
| 269 | if ((config['MACHINE'] == "bmalta")):
|
|---|
| 270 | target = "mips32eb"
|
|---|
| 271 | gnu_target = "mips-linux-gnu"
|
|---|
| 272 | clang_target = "mips-unknown-none"
|
|---|
| 273 | helenos_target = "mips-helenos"
|
|---|
| 274 |
|
|---|
| 275 | if (config['PLATFORM'] == "mips64"):
|
|---|
| 276 | check_config(config, "MACHINE")
|
|---|
| 277 | cc_args.append("-mabi=64")
|
|---|
| 278 |
|
|---|
| 279 | if (config['MACHINE'] == "msim"):
|
|---|
| 280 | target = config['PLATFORM']
|
|---|
| 281 | gnu_target = "mips64el-linux-gnu"
|
|---|
| 282 | clang_target = "mips64el-unknown-none"
|
|---|
| 283 | helenos_target = "mips64el-helenos"
|
|---|
| 284 |
|
|---|
| 285 | if (config['PLATFORM'] == "ppc32"):
|
|---|
| 286 | target = config['PLATFORM']
|
|---|
| 287 | gnu_target = "ppc-linux-gnu"
|
|---|
| 288 | clang_target = "ppc-unknown-none"
|
|---|
| 289 | helenos_target = "ppc-helenos"
|
|---|
| 290 |
|
|---|
| 291 | if (config['PLATFORM'] == "sparc32"):
|
|---|
| 292 | target = config['PLATFORM'];
|
|---|
| 293 | gnu_target = "sparc-leon3-linux-gnu"
|
|---|
| 294 | helenos_target = "sparc-leon3-helenos"
|
|---|
| 295 |
|
|---|
| 296 | if (config['PLATFORM'] == "sparc64"):
|
|---|
| 297 | target = config['PLATFORM']
|
|---|
| 298 | gnu_target = "sparc64-linux-gnu"
|
|---|
| 299 | clang_target = "sparc-unknown-none"
|
|---|
| 300 | helenos_target = "sparc64-helenos"
|
|---|
| 301 |
|
|---|
| 302 | return (target, cc_args, gnu_target, clang_target, helenos_target)
|
|---|
| 303 |
|
|---|
| 304 | def check_app(args, name, details):
|
|---|
| 305 | "Check whether an application can be executed"
|
|---|
| 306 |
|
|---|
| 307 | try:
|
|---|
| 308 | sys.stderr.write("Checking for %s ... " % args[0])
|
|---|
| 309 | subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
|---|
| 310 | except:
|
|---|
| 311 | sys.stderr.write("failed\n")
|
|---|
| 312 | print_error(["%s is missing." % name,
|
|---|
| 313 | "",
|
|---|
| 314 | "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
|
|---|
| 315 | "is installed in your system (%s)." % details])
|
|---|
| 316 |
|
|---|
| 317 | sys.stderr.write("ok\n")
|
|---|
| 318 |
|
|---|
| 319 | def check_app_alternatives(alts, args, name, details):
|
|---|
| 320 | "Check whether an application can be executed (use several alternatives)"
|
|---|
| 321 |
|
|---|
| 322 | tried = []
|
|---|
| 323 | found = None
|
|---|
| 324 |
|
|---|
| 325 | for alt in alts:
|
|---|
| 326 | working = True
|
|---|
| 327 | cmdline = [alt] + args
|
|---|
| 328 | tried.append(" ".join(cmdline))
|
|---|
| 329 |
|
|---|
| 330 | try:
|
|---|
| 331 | sys.stderr.write("Checking for %s ... " % alt)
|
|---|
| 332 | subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
|---|
| 333 | except:
|
|---|
| 334 | sys.stderr.write("failed\n")
|
|---|
| 335 | working = False
|
|---|
| 336 |
|
|---|
| 337 | if (working):
|
|---|
| 338 | sys.stderr.write("ok\n")
|
|---|
| 339 | found = alt
|
|---|
| 340 | break
|
|---|
| 341 |
|
|---|
| 342 | if (found is None):
|
|---|
| 343 | print_error(["%s is missing." % name,
|
|---|
| 344 | "",
|
|---|
| 345 | "Please make sure that it is installed in your",
|
|---|
| 346 | "system (%s)." % details,
|
|---|
| 347 | "",
|
|---|
| 348 | "The following alternatives were tried:"] + tried)
|
|---|
| 349 |
|
|---|
| 350 | return found
|
|---|
| 351 |
|
|---|
| 352 | def check_gcc(path, prefix, common, details):
|
|---|
| 353 | "Check for GCC"
|
|---|
| 354 |
|
|---|
| 355 | common['GCC'] = "%sgcc" % prefix
|
|---|
| 356 |
|
|---|
| 357 | if (not path is None):
|
|---|
| 358 | common['GCC'] = "%s/%s" % (path, common['GCC'])
|
|---|
| 359 |
|
|---|
| 360 | check_app([common['GCC'], "--version"], "GNU GCC", details)
|
|---|
| 361 |
|
|---|
| 362 | def check_binutils(path, prefix, common, details):
|
|---|
| 363 | "Check for binutils toolchain"
|
|---|
| 364 |
|
|---|
| 365 | common['AS'] = "%sas" % prefix
|
|---|
| 366 | common['LD'] = "%sld" % prefix
|
|---|
| 367 | common['AR'] = "%sar" % prefix
|
|---|
| 368 | common['OBJCOPY'] = "%sobjcopy" % prefix
|
|---|
| 369 | common['OBJDUMP'] = "%sobjdump" % prefix
|
|---|
| 370 | common['STRIP'] = "%sstrip" % prefix
|
|---|
| 371 |
|
|---|
| 372 | if (not path is None):
|
|---|
| 373 | for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
|
|---|
| 374 | common[key] = "%s/%s" % (path, common[key])
|
|---|
| 375 |
|
|---|
| 376 | check_app([common['AS'], "--version"], "GNU Assembler", details)
|
|---|
| 377 | check_app([common['LD'], "--version"], "GNU Linker", details)
|
|---|
| 378 | check_app([common['AR'], "--version"], "GNU Archiver", details)
|
|---|
| 379 | check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
|
|---|
| 380 | check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
|
|---|
| 381 | check_app([common['STRIP'], "--version"], "GNU strip", details)
|
|---|
| 382 |
|
|---|
| 383 | def check_python():
|
|---|
| 384 | "Check for Python dependencies"
|
|---|
| 385 |
|
|---|
| 386 | try:
|
|---|
| 387 | sys.stderr.write("Checking for PyYAML ... ")
|
|---|
| 388 | import yaml
|
|---|
| 389 | except ImportError:
|
|---|
| 390 | print_error(["PyYAML is missing.",
|
|---|
| 391 | "",
|
|---|
| 392 | "Please make sure that it is installed in your",
|
|---|
| 393 | "system (usually part of PyYAML package)."])
|
|---|
| 394 |
|
|---|
| 395 | sys.stderr.write("ok\n")
|
|---|
| 396 |
|
|---|
| 397 | def decode_value(value):
|
|---|
| 398 | "Decode integer value"
|
|---|
| 399 |
|
|---|
| 400 | base = 10
|
|---|
| 401 |
|
|---|
| 402 | if ((value.startswith('$')) or (value.startswith('#'))):
|
|---|
| 403 | value = value[1:]
|
|---|
| 404 |
|
|---|
| 405 | if (value.startswith('0x')):
|
|---|
| 406 | value = value[2:]
|
|---|
| 407 | base = 16
|
|---|
| 408 |
|
|---|
| 409 | return int(value, base)
|
|---|
| 410 |
|
|---|
| 411 | def probe_compiler(common, intsizes, floatsizes):
|
|---|
| 412 | "Generate, compile and parse probing source"
|
|---|
| 413 |
|
|---|
| 414 | check_common(common, "CC")
|
|---|
| 415 |
|
|---|
| 416 | outf = open(PROBE_SOURCE, 'w')
|
|---|
| 417 | outf.write(PROBE_HEAD)
|
|---|
| 418 |
|
|---|
| 419 | for typedef in intsizes:
|
|---|
| 420 | outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
|
|---|
| 421 |
|
|---|
| 422 | for typedef in floatsizes:
|
|---|
| 423 | outf.write("\tDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
|
|---|
| 424 |
|
|---|
| 425 | outf.write(PROBE_TAIL)
|
|---|
| 426 | outf.close()
|
|---|
| 427 |
|
|---|
| 428 | args = [common['CC']]
|
|---|
| 429 | args.extend(common['CC_ARGS'])
|
|---|
| 430 | args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
|
|---|
| 431 |
|
|---|
| 432 | try:
|
|---|
| 433 | sys.stderr.write("Checking compiler properties ... ")
|
|---|
| 434 | output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
|
|---|
| 435 | except:
|
|---|
| 436 | sys.stderr.write("failed\n")
|
|---|
| 437 | print_error(["Error executing \"%s\"." % " ".join(args),
|
|---|
| 438 | "Make sure that the compiler works properly."])
|
|---|
| 439 |
|
|---|
| 440 | if (not os.path.isfile(PROBE_OUTPUT)):
|
|---|
| 441 | sys.stderr.write("failed\n")
|
|---|
| 442 | print(output[1])
|
|---|
| 443 | print_error(["Error executing \"%s\"." % " ".join(args),
|
|---|
| 444 | "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
|
|---|
| 445 | "",
|
|---|
| 446 | output[0],
|
|---|
| 447 | output[1]])
|
|---|
| 448 |
|
|---|
| 449 | sys.stderr.write("ok\n")
|
|---|
| 450 |
|
|---|
| 451 | inf = open(PROBE_OUTPUT, 'r')
|
|---|
| 452 | lines = inf.readlines()
|
|---|
| 453 | inf.close()
|
|---|
| 454 |
|
|---|
| 455 | unsigned_sizes = {}
|
|---|
| 456 | signed_sizes = {}
|
|---|
| 457 |
|
|---|
| 458 | unsigned_tags = {}
|
|---|
| 459 | signed_tags = {}
|
|---|
| 460 |
|
|---|
| 461 | unsigned_strcs = {}
|
|---|
| 462 | signed_strcs = {}
|
|---|
| 463 |
|
|---|
| 464 | unsigned_concs = {}
|
|---|
| 465 | signed_concs = {}
|
|---|
| 466 |
|
|---|
| 467 | float_tags = {}
|
|---|
| 468 |
|
|---|
| 469 | builtin_sizes = {}
|
|---|
| 470 | builtin_signs = {}
|
|---|
| 471 |
|
|---|
| 472 | for j in range(len(lines)):
|
|---|
| 473 | tokens = lines[j].strip().split("\t")
|
|---|
| 474 |
|
|---|
| 475 | if (len(tokens) > 0):
|
|---|
| 476 | if (tokens[0] == "AUTOTOOL_DECLARE"):
|
|---|
| 477 | if (len(tokens) < 7):
|
|---|
| 478 | print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 479 |
|
|---|
| 480 | category = tokens[1]
|
|---|
| 481 | subcategory = tokens[2]
|
|---|
| 482 | tag = tokens[3]
|
|---|
| 483 | name = tokens[4]
|
|---|
| 484 | strc = tokens[5]
|
|---|
| 485 | conc = tokens[6]
|
|---|
| 486 | value = tokens[7]
|
|---|
| 487 |
|
|---|
| 488 | if (category == "intsize"):
|
|---|
| 489 | try:
|
|---|
| 490 | value_int = decode_value(value)
|
|---|
| 491 | except:
|
|---|
| 492 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 493 |
|
|---|
| 494 | if (subcategory == "unsigned"):
|
|---|
| 495 | unsigned_sizes[value_int] = name
|
|---|
| 496 | unsigned_tags[tag] = value_int
|
|---|
| 497 | unsigned_strcs[value_int] = strc
|
|---|
| 498 | unsigned_concs[value_int] = conc
|
|---|
| 499 | elif (subcategory == "signed"):
|
|---|
| 500 | signed_sizes[value_int] = name
|
|---|
| 501 | signed_tags[tag] = value_int
|
|---|
| 502 | signed_strcs[value_int] = strc
|
|---|
| 503 | signed_concs[value_int] = conc
|
|---|
| 504 | else:
|
|---|
| 505 | print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 506 |
|
|---|
| 507 | if (category == "floatsize"):
|
|---|
| 508 | try:
|
|---|
| 509 | value_int = decode_value(value)
|
|---|
| 510 | except:
|
|---|
| 511 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 512 |
|
|---|
| 513 | float_tags[tag] = value_int
|
|---|
| 514 |
|
|---|
| 515 | if (category == "builtin_size"):
|
|---|
| 516 | try:
|
|---|
| 517 | value_int = decode_value(value)
|
|---|
| 518 | except:
|
|---|
| 519 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 520 |
|
|---|
| 521 | builtin_sizes[tag] = {'name': name, 'value': value_int}
|
|---|
| 522 |
|
|---|
| 523 | if (category == "builtin_sign"):
|
|---|
| 524 | try:
|
|---|
| 525 | value_int = decode_value(value)
|
|---|
| 526 | except:
|
|---|
| 527 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 528 |
|
|---|
| 529 | if (value_int == 1):
|
|---|
| 530 | if (not tag in builtin_signs):
|
|---|
| 531 | builtin_signs[tag] = strc;
|
|---|
| 532 | elif (builtin_signs[tag] != strc):
|
|---|
| 533 | print_error(["Inconsistent builtin type detection in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 534 |
|
|---|
| 535 | 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, 'float_tags': float_tags, 'builtin_sizes': builtin_sizes, 'builtin_signs': builtin_signs}
|
|---|
| 536 |
|
|---|
| 537 | def probe_int128(common):
|
|---|
| 538 | "Generate, compile and parse probing source for 128-bit integers"
|
|---|
| 539 |
|
|---|
| 540 | check_common(common, "CC")
|
|---|
| 541 |
|
|---|
| 542 | outf = open(PROBE_INT128_SOURCE, 'w')
|
|---|
| 543 | outf.write(PROBE_INT128_HEAD)
|
|---|
| 544 | outf.write("\tDECLARE_INTSIZE(\"INT128\", int __attribute((mode(TI))));\n")
|
|---|
| 545 | outf.write(PROBE_INT128_TAIL)
|
|---|
| 546 | outf.close()
|
|---|
| 547 |
|
|---|
| 548 | args = [common['CC']]
|
|---|
| 549 | args.extend(common['CC_ARGS'])
|
|---|
| 550 | args.extend(["-S", "-o", PROBE_INT128_OUTPUT, PROBE_INT128_SOURCE])
|
|---|
| 551 |
|
|---|
| 552 | try:
|
|---|
| 553 | sys.stderr.write("Checking whether the compiler has intrinsic support for 128-bit integers ... ")
|
|---|
| 554 | output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
|
|---|
| 555 | except:
|
|---|
| 556 | sys.stderr.write("no\n")
|
|---|
| 557 | return False
|
|---|
| 558 |
|
|---|
| 559 | if (not os.path.isfile(PROBE_INT128_OUTPUT)):
|
|---|
| 560 | sys.stderr.write("no\n")
|
|---|
| 561 | return False
|
|---|
| 562 |
|
|---|
| 563 | inf = open(PROBE_INT128_OUTPUT, 'r')
|
|---|
| 564 | lines = inf.readlines()
|
|---|
| 565 | inf.close()
|
|---|
| 566 |
|
|---|
| 567 | for j in range(len(lines)):
|
|---|
| 568 | tokens = lines[j].strip().split("\t")
|
|---|
| 569 |
|
|---|
| 570 | if (len(tokens) > 0):
|
|---|
| 571 | if (tokens[0] == "AUTOTOOL_DECLARE"):
|
|---|
| 572 | if (len(tokens) < 7):
|
|---|
| 573 | print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_INT128_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 574 |
|
|---|
| 575 | category = tokens[1]
|
|---|
| 576 | subcategory = tokens[2]
|
|---|
| 577 | tag = tokens[3]
|
|---|
| 578 | name = tokens[4]
|
|---|
| 579 | strc = tokens[5]
|
|---|
| 580 | conc = tokens[6]
|
|---|
| 581 | value = tokens[7]
|
|---|
| 582 |
|
|---|
| 583 | if (category == "intsize"):
|
|---|
| 584 | try:
|
|---|
| 585 | value_int = decode_value(value)
|
|---|
| 586 | except:
|
|---|
| 587 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_INT128_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 588 |
|
|---|
| 589 | if (subcategory == "unsigned"):
|
|---|
| 590 | if (value_int != 16):
|
|---|
| 591 | sys.stderr.write("no\n")
|
|---|
| 592 | return False
|
|---|
| 593 | elif (subcategory == "signed"):
|
|---|
| 594 | if (value_int != 16):
|
|---|
| 595 | sys.stderr.write("no\n")
|
|---|
| 596 | return False
|
|---|
| 597 | else:
|
|---|
| 598 | print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_INT128_OUTPUT, j), COMPILER_FAIL])
|
|---|
| 599 |
|
|---|
| 600 | sys.stderr.write("yes\n")
|
|---|
| 601 | return True
|
|---|
| 602 |
|
|---|
| 603 | def detect_sizes(probe, bytes, inttags, floattags):
|
|---|
| 604 | "Detect correct types for fixed-size types"
|
|---|
| 605 |
|
|---|
| 606 | macros = []
|
|---|
| 607 | typedefs = []
|
|---|
| 608 |
|
|---|
| 609 | for b in bytes:
|
|---|
| 610 | if (not b in probe['unsigned_sizes']):
|
|---|
| 611 | print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b,
|
|---|
| 612 | COMPILER_FAIL])
|
|---|
| 613 |
|
|---|
| 614 | if (not b in probe['signed_sizes']):
|
|---|
| 615 | print_error(['Unable to find appropriate signed integer type for %u bytes.' % b,
|
|---|
| 616 | COMPILER_FAIL])
|
|---|
| 617 |
|
|---|
| 618 | if (not b in probe['unsigned_strcs']):
|
|---|
| 619 | print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b,
|
|---|
| 620 | COMPILER_FAIL])
|
|---|
| 621 |
|
|---|
| 622 | if (not b in probe['signed_strcs']):
|
|---|
| 623 | print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b,
|
|---|
| 624 | COMPILER_FAIL])
|
|---|
| 625 |
|
|---|
| 626 | if (not b in probe['unsigned_concs']):
|
|---|
| 627 | print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b,
|
|---|
| 628 | COMPILER_FAIL])
|
|---|
| 629 |
|
|---|
| 630 | if (not b in probe['signed_concs']):
|
|---|
| 631 | print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b,
|
|---|
| 632 | COMPILER_FAIL])
|
|---|
| 633 |
|
|---|
| 634 | typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
|
|---|
| 635 | typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
|
|---|
| 636 |
|
|---|
| 637 | macros.append({'oldmacro': "unsigned %s" % probe['unsigned_sizes'][b], 'newmacro': "UINT%u_T" % (b * 8)})
|
|---|
| 638 | macros.append({'oldmacro': "signed %s" % probe['signed_sizes'][b], 'newmacro': "INT%u_T" % (b * 8)})
|
|---|
| 639 |
|
|---|
| 640 | macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
|
|---|
| 641 | macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
|
|---|
| 642 | macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
|
|---|
| 643 | macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
|
|---|
| 644 | macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
|
|---|
| 645 |
|
|---|
| 646 | name = probe['unsigned_concs'][b]
|
|---|
| 647 | if ((name.startswith('@')) or (name == "")):
|
|---|
| 648 | macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
|---|
| 649 | else:
|
|---|
| 650 | macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
|---|
| 651 |
|
|---|
| 652 | name = probe['unsigned_concs'][b]
|
|---|
| 653 | if ((name.startswith('@')) or (name == "")):
|
|---|
| 654 | macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
|
|---|
| 655 | else:
|
|---|
| 656 | macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
|
|---|
| 657 |
|
|---|
| 658 | for tag in inttags:
|
|---|
| 659 | newmacro = "U%s" % tag
|
|---|
| 660 | if (not tag in probe['unsigned_tags']):
|
|---|
| 661 | print_error(['Unable to find appropriate size macro for %s.' % newmacro,
|
|---|
| 662 | COMPILER_FAIL])
|
|---|
| 663 |
|
|---|
| 664 | oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
|
|---|
| 665 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
|---|
| 666 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
|---|
| 667 | macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)})
|
|---|
| 668 |
|
|---|
| 669 | newmacro = tag
|
|---|
| 670 | if (not tag in probe['signed_tags']):
|
|---|
| 671 | print_error(['Unable to find appropriate size macro for %s' % newmacro,
|
|---|
| 672 | COMPILER_FAIL])
|
|---|
| 673 |
|
|---|
| 674 | oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
|
|---|
| 675 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
|---|
| 676 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
|---|
| 677 | macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['signed_tags'][tag] * 8)})
|
|---|
| 678 |
|
|---|
| 679 | for tag in floattags:
|
|---|
| 680 | if (not tag in probe['float_tags']):
|
|---|
| 681 | print_error(['Unable to find appropriate size macro for %s' % tag,
|
|---|
| 682 | COMPILER_FAIL])
|
|---|
| 683 |
|
|---|
| 684 | macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['float_tags'][tag] * 8)})
|
|---|
| 685 |
|
|---|
| 686 | if (not 'size' in probe['builtin_signs']):
|
|---|
| 687 | print_error(['Unable to determine whether size_t is signed or unsigned.',
|
|---|
| 688 | COMPILER_FAIL])
|
|---|
| 689 |
|
|---|
| 690 | if (probe['builtin_signs']['size'] != 'unsigned'):
|
|---|
| 691 | print_error(['The type size_t is not unsigned.',
|
|---|
| 692 | COMPILER_FAIL])
|
|---|
| 693 |
|
|---|
| 694 | fnd = True
|
|---|
| 695 |
|
|---|
| 696 | if (not 'wchar' in probe['builtin_sizes']):
|
|---|
| 697 | print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
|
|---|
| 698 | 'for defining the compiler-native type wchar_t. We are',
|
|---|
| 699 | 'forced to define wchar_t as a hardwired type int32_t.',
|
|---|
| 700 | COMPILER_WARNING])
|
|---|
| 701 | fnd = False
|
|---|
| 702 |
|
|---|
| 703 | if (probe['builtin_sizes']['wchar']['value'] != 4):
|
|---|
| 704 | print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
|
|---|
| 705 | 'the compiler-native type wchar_t is not compliant with',
|
|---|
| 706 | 'HelenOS. We are forced to define wchar_t as a hardwired',
|
|---|
| 707 | 'type int32_t.',
|
|---|
| 708 | COMPILER_WARNING])
|
|---|
| 709 | fnd = False
|
|---|
| 710 |
|
|---|
| 711 | if (not fnd):
|
|---|
| 712 | macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
|
|---|
| 713 | else:
|
|---|
| 714 | macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
|
|---|
| 715 |
|
|---|
| 716 | if (not 'wchar' in probe['builtin_signs']):
|
|---|
| 717 | print_error(['Unable to determine whether wchar_t is signed or unsigned.',
|
|---|
| 718 | COMPILER_FAIL])
|
|---|
| 719 |
|
|---|
| 720 | if (probe['builtin_signs']['wchar'] == 'unsigned'):
|
|---|
| 721 | macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_UNSIGNED'})
|
|---|
| 722 | if (probe['builtin_signs']['wchar'] == 'signed'):
|
|---|
| 723 | macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_SIGNED'})
|
|---|
| 724 |
|
|---|
| 725 | fnd = True
|
|---|
| 726 |
|
|---|
| 727 | if (not 'wint' in probe['builtin_sizes']):
|
|---|
| 728 | print_warning(['The compiler does not provide the macro __WINT_TYPE__',
|
|---|
| 729 | 'for defining the compiler-native type wint_t. We are',
|
|---|
| 730 | 'forced to define wint_t as a hardwired type int32_t.',
|
|---|
| 731 | COMPILER_WARNING])
|
|---|
| 732 | fnd = False
|
|---|
| 733 |
|
|---|
| 734 | if (probe['builtin_sizes']['wint']['value'] != 4):
|
|---|
| 735 | print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
|
|---|
| 736 | 'the compiler-native type wint_t is not compliant with',
|
|---|
| 737 | 'HelenOS. We are forced to define wint_t as a hardwired',
|
|---|
| 738 | 'type int32_t.',
|
|---|
| 739 | COMPILER_WARNING])
|
|---|
| 740 | fnd = False
|
|---|
| 741 |
|
|---|
| 742 | if (not fnd):
|
|---|
| 743 | macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
|
|---|
| 744 | else:
|
|---|
| 745 | macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
|
|---|
| 746 |
|
|---|
| 747 | if (not 'wint' in probe['builtin_signs']):
|
|---|
| 748 | print_error(['Unable to determine whether wint_t is signed or unsigned.',
|
|---|
| 749 | COMPILER_FAIL])
|
|---|
| 750 |
|
|---|
| 751 | if (probe['builtin_signs']['wint'] == 'unsigned'):
|
|---|
| 752 | macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_UNSIGNED'})
|
|---|
| 753 | if (probe['builtin_signs']['wint'] == 'signed'):
|
|---|
| 754 | macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_SIGNED'})
|
|---|
| 755 |
|
|---|
| 756 | return {'macros': macros, 'typedefs': typedefs}
|
|---|
| 757 |
|
|---|
| 758 | def create_makefile(mkname, common):
|
|---|
| 759 | "Create makefile output"
|
|---|
| 760 |
|
|---|
| 761 | outmk = open(mkname, 'w')
|
|---|
| 762 |
|
|---|
| 763 | outmk.write('#########################################\n')
|
|---|
| 764 | outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
|
|---|
| 765 | outmk.write('## Generated by: tools/autotool.py ##\n')
|
|---|
| 766 | outmk.write('#########################################\n\n')
|
|---|
| 767 |
|
|---|
| 768 | for key, value in common.items():
|
|---|
| 769 | if (type(value) is list):
|
|---|
| 770 | outmk.write('%s = %s\n' % (key, " ".join(value)))
|
|---|
| 771 | else:
|
|---|
| 772 | outmk.write('%s = %s\n' % (key, value))
|
|---|
| 773 |
|
|---|
| 774 | outmk.close()
|
|---|
| 775 |
|
|---|
| 776 | def create_header(hdname, maps, int128):
|
|---|
| 777 | "Create header output"
|
|---|
| 778 |
|
|---|
| 779 | outhd = open(hdname, 'w')
|
|---|
| 780 |
|
|---|
| 781 | outhd.write('/***************************************\n')
|
|---|
| 782 | outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
|
|---|
| 783 | outhd.write(' * Generated by: tools/autotool.py *\n')
|
|---|
| 784 | outhd.write(' ***************************************/\n\n')
|
|---|
| 785 |
|
|---|
| 786 | outhd.write('#ifndef %s\n' % GUARD)
|
|---|
| 787 | outhd.write('#define %s\n\n' % GUARD)
|
|---|
| 788 |
|
|---|
| 789 | for macro in maps['macros']:
|
|---|
| 790 | outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
|
|---|
| 791 |
|
|---|
| 792 | outhd.write('\n')
|
|---|
| 793 |
|
|---|
| 794 | for typedef in maps['typedefs']:
|
|---|
| 795 | outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
|
|---|
| 796 |
|
|---|
| 797 | if (int128):
|
|---|
| 798 | outhd.write('typedef unsigned int __attribute((mode(TI))) uint128_t;\n')
|
|---|
| 799 | outhd.write('typedef signed int __attribute((mode(TI))) int128_t;\n')
|
|---|
| 800 |
|
|---|
| 801 | outhd.write('\n#endif\n')
|
|---|
| 802 | outhd.close()
|
|---|
| 803 |
|
|---|
| 804 | def main():
|
|---|
| 805 | config = {}
|
|---|
| 806 | common = {}
|
|---|
| 807 |
|
|---|
| 808 | # Read and check configuration
|
|---|
| 809 | if os.path.exists(CONFIG):
|
|---|
| 810 | read_config(CONFIG, config)
|
|---|
| 811 | else:
|
|---|
| 812 | print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
|
|---|
| 813 | "configuration phase of HelenOS build went OK. Try running",
|
|---|
| 814 | "\"make config\" again."])
|
|---|
| 815 |
|
|---|
| 816 | check_config(config, "PLATFORM")
|
|---|
| 817 | check_config(config, "COMPILER")
|
|---|
| 818 | check_config(config, "BARCH")
|
|---|
| 819 |
|
|---|
| 820 | # Cross-compiler prefix
|
|---|
| 821 | if ('CROSS_PREFIX' in os.environ):
|
|---|
| 822 | cross_prefix = os.environ['CROSS_PREFIX']
|
|---|
| 823 | else:
|
|---|
| 824 | cross_prefix = "/usr/local/cross"
|
|---|
| 825 |
|
|---|
| 826 | # HelenOS cross-compiler prefix
|
|---|
| 827 | if ('CROSS_HELENOS_PREFIX' in os.environ):
|
|---|
| 828 | cross_helenos_prefix = os.environ['CROSS_HELENOS_PREFIX']
|
|---|
| 829 | else:
|
|---|
| 830 | cross_helenos_prefix = "/usr/local/cross-helenos"
|
|---|
| 831 |
|
|---|
| 832 | # Prefix binutils tools on Solaris
|
|---|
| 833 | if (os.uname()[0] == "SunOS"):
|
|---|
| 834 | binutils_prefix = "g"
|
|---|
| 835 | else:
|
|---|
| 836 | binutils_prefix = ""
|
|---|
| 837 |
|
|---|
| 838 | owd = sandbox_enter()
|
|---|
| 839 |
|
|---|
| 840 | try:
|
|---|
| 841 | # Common utilities
|
|---|
| 842 | check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
|
|---|
| 843 | check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
|
|---|
| 844 | check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
|
|---|
| 845 | check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
|
|---|
| 846 | check_app(["find", "--version"], "Find utility", "usually part of findutils")
|
|---|
| 847 | check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
|
|---|
| 848 | check_app(["make", "--version"], "Make utility", "preferably GNU Make")
|
|---|
| 849 | check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
|
|---|
| 850 |
|
|---|
| 851 | # Compiler
|
|---|
| 852 | common['CC_ARGS'] = []
|
|---|
| 853 | if (config['COMPILER'] == "gcc_cross"):
|
|---|
| 854 | target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
|
|---|
| 855 |
|
|---|
| 856 | if (target is None) or (gnu_target is None):
|
|---|
| 857 | print_error(["Unsupported compiler target for GNU GCC.",
|
|---|
| 858 | "Please contact the developers of HelenOS."])
|
|---|
| 859 |
|
|---|
| 860 | path = "%s/%s/bin" % (cross_prefix, target)
|
|---|
| 861 | prefix = "%s-" % gnu_target
|
|---|
| 862 |
|
|---|
| 863 | check_gcc(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 864 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 865 |
|
|---|
| 866 | check_common(common, "GCC")
|
|---|
| 867 | common['CC'] = common['GCC']
|
|---|
| 868 | common['CC_ARGS'].extend(cc_args)
|
|---|
| 869 |
|
|---|
| 870 | if (config['COMPILER'] == "gcc_helenos"):
|
|---|
| 871 | target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
|
|---|
| 872 |
|
|---|
| 873 | if (target is None) or (helenos_target is None):
|
|---|
| 874 | print_error(["Unsupported compiler target for GNU GCC.",
|
|---|
| 875 | "Please contact the developers of HelenOS."])
|
|---|
| 876 |
|
|---|
| 877 | path = "%s/%s/bin" % (cross_helenos_prefix, target)
|
|---|
| 878 | prefix = "%s-" % helenos_target
|
|---|
| 879 |
|
|---|
| 880 | check_gcc(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 881 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 882 |
|
|---|
| 883 | check_common(common, "GCC")
|
|---|
| 884 | common['CC'] = common['GCC']
|
|---|
| 885 | common['CC_ARGS'].extend(cc_args)
|
|---|
| 886 |
|
|---|
| 887 | if (config['COMPILER'] == "gcc_native"):
|
|---|
| 888 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 889 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 890 |
|
|---|
| 891 | check_common(common, "GCC")
|
|---|
| 892 | common['CC'] = common['GCC']
|
|---|
| 893 |
|
|---|
| 894 | if (config['COMPILER'] == "icc"):
|
|---|
| 895 | check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
|
|---|
| 896 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 897 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 898 |
|
|---|
| 899 | common['CC'] = "icc"
|
|---|
| 900 |
|
|---|
| 901 | if (config['COMPILER'] == "clang"):
|
|---|
| 902 | target, cc_args, gnu_target, clang_target, helenos_target = get_target(config)
|
|---|
| 903 |
|
|---|
| 904 | if (target is None) or (gnu_target is None) or (clang_target is None):
|
|---|
| 905 | print_error(["Unsupported compiler target for clang.",
|
|---|
| 906 | "Please contact the developers of HelenOS."])
|
|---|
| 907 |
|
|---|
| 908 | path = "%s/%s/bin" % (cross_prefix, target)
|
|---|
| 909 | prefix = "%s-" % gnu_target
|
|---|
| 910 |
|
|---|
| 911 | check_app(["clang", "--version"], "clang compiler", "preferably version 1.0 or newer")
|
|---|
| 912 | check_gcc(path, prefix, common, PACKAGE_GCC)
|
|---|
| 913 | check_binutils(path, prefix, common, PACKAGE_BINUTILS)
|
|---|
| 914 |
|
|---|
| 915 | check_common(common, "GCC")
|
|---|
| 916 | common['CC'] = "clang"
|
|---|
| 917 | common['CC_ARGS'].extend(cc_args)
|
|---|
| 918 | common['CC_ARGS'].append("-target")
|
|---|
| 919 | common['CC_ARGS'].append(clang_target)
|
|---|
| 920 | common['CLANG_TARGET'] = clang_target
|
|---|
| 921 |
|
|---|
| 922 | check_python()
|
|---|
| 923 |
|
|---|
| 924 | # Platform-specific utilities
|
|---|
| 925 | if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
|
|---|
| 926 | common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
|
|---|
| 927 |
|
|---|
| 928 | probe = probe_compiler(common,
|
|---|
| 929 | [
|
|---|
| 930 | {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
|
|---|
| 931 | {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
|
|---|
| 932 | {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
|
|---|
| 933 | {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
|
|---|
| 934 | {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
|
|---|
| 935 | ],
|
|---|
| 936 | [
|
|---|
| 937 | {'type': 'long double', 'tag': 'LONG_DOUBLE'},
|
|---|
| 938 | {'type': 'double', 'tag': 'DOUBLE'},
|
|---|
| 939 | {'type': 'float', 'tag': 'FLOAT'}
|
|---|
| 940 | ]
|
|---|
| 941 | )
|
|---|
| 942 |
|
|---|
| 943 | int128 = probe_int128(common)
|
|---|
| 944 |
|
|---|
| 945 | maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT'])
|
|---|
| 946 |
|
|---|
| 947 | finally:
|
|---|
| 948 | sandbox_leave(owd)
|
|---|
| 949 |
|
|---|
| 950 | common['AUTOGEN'] = "%s/autogen.py" % os.path.dirname(os.path.abspath(sys.argv[0]))
|
|---|
| 951 |
|
|---|
| 952 | create_makefile(MAKEFILE, common)
|
|---|
| 953 | create_header(HEADER, maps, int128)
|
|---|
| 954 |
|
|---|
| 955 | return 0
|
|---|
| 956 |
|
|---|
| 957 | if __name__ == '__main__':
|
|---|
| 958 | sys.exit(main())
|
|---|