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