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