[ce55b43] | 1 | #!/usr/bin/env python2
|
---|
[177e4ea] | 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'
|
---|
[ce55b43] | 45 | GUARD = '_AUTOTOOL_COMMON_H_'
|
---|
[4e9aaf5] | 46 |
|
---|
| 47 | PROBE_SOURCE = 'probe.c'
|
---|
| 48 | PROBE_OUTPUT = 'probe.s'
|
---|
[177e4ea] | 49 |
|
---|
| 50 | PACKAGE_BINUTILS = "usually part of binutils"
|
---|
[a4a0f1d] | 51 | PACKAGE_GCC = "preferably version 4.7.0 or newer"
|
---|
[177e4ea] | 52 | PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
|
---|
[84eb4edd] | 53 | PACKAGE_CLANG = "reasonably recent version of clang needs to be installed"
|
---|
[177e4ea] | 54 |
|
---|
[4e9aaf5] | 55 | COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
|
---|
[96b89acb] | 56 | COMPILER_WARNING = "The compilation of HelenOS might fail."
|
---|
[4e9aaf5] | 57 |
|
---|
[ce55b43] | 58 | PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, tag, name, signedness, base, size, compatible) \\
|
---|
[4e9aaf5] | 59 | asm volatile ( \\
|
---|
[ce55b43] | 60 | "AUTOTOOL_DECLARE\\t" category "\\t" tag "\\t" name "\\t" signedness "\\t" base "\\t%[size_val]\\t%[cmp_val]\\n" \\
|
---|
[4e9aaf5] | 61 | : \\
|
---|
[ce55b43] | 62 | : [size_val] "n" (size), [cmp_val] "n" (compatible) \\
|
---|
[4e9aaf5] | 63 | )
|
---|
| 64 |
|
---|
[96b89acb] | 65 | #define STRING(arg) STRING_ARG(arg)
|
---|
| 66 | #define STRING_ARG(arg) #arg
|
---|
| 67 |
|
---|
| 68 | #define DECLARE_BUILTIN_TYPE(tag, type) \\
|
---|
[ce55b43] | 69 | AUTOTOOL_DECLARE("unsigned long long int", tag, STRING(type), "unsigned", "long long", sizeof(type), __builtin_types_compatible_p(type, unsigned long long int)); \\
|
---|
| 70 | AUTOTOOL_DECLARE("unsigned long int", tag, STRING(type), "unsigned", "long", sizeof(type), __builtin_types_compatible_p(type, unsigned long int)); \\
|
---|
| 71 | AUTOTOOL_DECLARE("unsigned int", tag, STRING(type), "unsigned", "int", sizeof(type), __builtin_types_compatible_p(type, unsigned int)); \\
|
---|
| 72 | AUTOTOOL_DECLARE("unsigned short int", tag, STRING(type), "unsigned", "short", sizeof(type), __builtin_types_compatible_p(type, unsigned short int)); \\
|
---|
| 73 | AUTOTOOL_DECLARE("unsigned char", tag, STRING(type), "unsigned", "char", sizeof(type), __builtin_types_compatible_p(type, unsigned char)); \\
|
---|
| 74 | AUTOTOOL_DECLARE("signed long long int", tag, STRING(type), "signed", "long long", sizeof(type), __builtin_types_compatible_p(type, signed long long int)); \\
|
---|
| 75 | AUTOTOOL_DECLARE("signed long int", tag, STRING(type), "signed", "long", sizeof(type), __builtin_types_compatible_p(type, signed long int)); \\
|
---|
| 76 | AUTOTOOL_DECLARE("signed int", tag, STRING(type), "signed", "int", sizeof(type), __builtin_types_compatible_p(type, signed int)); \\
|
---|
| 77 | AUTOTOOL_DECLARE("signed short int", tag, STRING(type), "signed", "short", sizeof(type), __builtin_types_compatible_p(type, signed short int)); \\
|
---|
| 78 | AUTOTOOL_DECLARE("signed char", tag, STRING(type), "signed", "char", sizeof(type), __builtin_types_compatible_p(type, signed char)); \\
|
---|
| 79 | AUTOTOOL_DECLARE("pointer", tag, STRING(type), "N/A", "pointer", sizeof(type), __builtin_types_compatible_p(type, void*)); \\
|
---|
| 80 | AUTOTOOL_DECLARE("long double", tag, STRING(type), "signed", "long double", sizeof(type), __builtin_types_compatible_p(type, long double)); \\
|
---|
| 81 | AUTOTOOL_DECLARE("double", tag, STRING(type), "signed", "double", sizeof(type), __builtin_types_compatible_p(type, double)); \\
|
---|
| 82 | AUTOTOOL_DECLARE("float", tag, STRING(type), "signed", "float", sizeof(type), __builtin_types_compatible_p(type, float));
|
---|
[a4a0f1d] | 83 |
|
---|
[795e2bf] | 84 | extern int main(int, char *[]);
|
---|
| 85 |
|
---|
[4e9aaf5] | 86 | int main(int argc, char *argv[])
|
---|
| 87 | {
|
---|
| 88 | """
|
---|
| 89 |
|
---|
| 90 | PROBE_TAIL = """}
|
---|
| 91 | """
|
---|
| 92 |
|
---|
[177e4ea] | 93 | def read_config(fname, config):
|
---|
| 94 | "Read HelenOS build configuration"
|
---|
[a35b458] | 95 |
|
---|
[28f4adb] | 96 | inf = open(fname, 'r')
|
---|
[a35b458] | 97 |
|
---|
[177e4ea] | 98 | for line in inf:
|
---|
| 99 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
|
---|
| 100 | if (res):
|
---|
| 101 | config[res.group(1)] = res.group(2)
|
---|
[a35b458] | 102 |
|
---|
[177e4ea] | 103 | inf.close()
|
---|
| 104 |
|
---|
| 105 | def print_error(msg):
|
---|
| 106 | "Print a bold error message"
|
---|
[a35b458] | 107 |
|
---|
[177e4ea] | 108 | sys.stderr.write("\n")
|
---|
| 109 | sys.stderr.write("######################################################################\n")
|
---|
| 110 | sys.stderr.write("HelenOS build sanity check error:\n")
|
---|
| 111 | sys.stderr.write("\n")
|
---|
| 112 | sys.stderr.write("%s\n" % "\n".join(msg))
|
---|
| 113 | sys.stderr.write("######################################################################\n")
|
---|
| 114 | sys.stderr.write("\n")
|
---|
[a35b458] | 115 |
|
---|
[177e4ea] | 116 | sys.exit(1)
|
---|
| 117 |
|
---|
[96b89acb] | 118 | def print_warning(msg):
|
---|
| 119 | "Print a bold error message"
|
---|
[a35b458] | 120 |
|
---|
[96b89acb] | 121 | sys.stderr.write("\n")
|
---|
| 122 | sys.stderr.write("######################################################################\n")
|
---|
| 123 | sys.stderr.write("HelenOS build sanity check warning:\n")
|
---|
| 124 | sys.stderr.write("\n")
|
---|
| 125 | sys.stderr.write("%s\n" % "\n".join(msg))
|
---|
| 126 | sys.stderr.write("######################################################################\n")
|
---|
| 127 | sys.stderr.write("\n")
|
---|
[a35b458] | 128 |
|
---|
[96b89acb] | 129 | time.sleep(5)
|
---|
| 130 |
|
---|
[4e9aaf5] | 131 | def sandbox_enter():
|
---|
| 132 | "Create a temporal sandbox directory for running tests"
|
---|
[a35b458] | 133 |
|
---|
[4e9aaf5] | 134 | if (os.path.exists(SANDBOX)):
|
---|
| 135 | if (os.path.isdir(SANDBOX)):
|
---|
| 136 | try:
|
---|
| 137 | shutil.rmtree(SANDBOX)
|
---|
| 138 | except:
|
---|
| 139 | print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
|
---|
| 140 | else:
|
---|
| 141 | print_error(["Please inspect and remove unexpected directory,",
|
---|
| 142 | "entry \"%s\"." % SANDBOX])
|
---|
[a35b458] | 143 |
|
---|
[4e9aaf5] | 144 | try:
|
---|
| 145 | os.mkdir(SANDBOX)
|
---|
| 146 | except:
|
---|
| 147 | print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
|
---|
[a35b458] | 148 |
|
---|
[4e9aaf5] | 149 | owd = os.getcwd()
|
---|
| 150 | os.chdir(SANDBOX)
|
---|
[a35b458] | 151 |
|
---|
[4e9aaf5] | 152 | return owd
|
---|
| 153 |
|
---|
| 154 | def sandbox_leave(owd):
|
---|
| 155 | "Leave the temporal sandbox directory"
|
---|
[a35b458] | 156 |
|
---|
[4e9aaf5] | 157 | os.chdir(owd)
|
---|
| 158 |
|
---|
[177e4ea] | 159 | def check_config(config, key):
|
---|
| 160 | "Check whether the configuration key exists"
|
---|
[a35b458] | 161 |
|
---|
[177e4ea] | 162 | if (not key in config):
|
---|
| 163 | print_error(["Build configuration of HelenOS does not contain %s." % key,
|
---|
| 164 | "Try running \"make config\" again.",
|
---|
| 165 | "If the problem persists, please contact the developers of HelenOS."])
|
---|
| 166 |
|
---|
[4e9aaf5] | 167 | def check_common(common, key):
|
---|
| 168 | "Check whether the common key exists"
|
---|
[a35b458] | 169 |
|
---|
[4e9aaf5] | 170 | if (not key in common):
|
---|
| 171 | print_error(["Failed to determine the value %s." % key,
|
---|
| 172 | "Please contact the developers of HelenOS."])
|
---|
| 173 |
|
---|
[95e370f8] | 174 | def get_target(config):
|
---|
[b08941d] | 175 | platform = None
|
---|
[39ba6d5] | 176 | gnu_target = None
|
---|
[8f2eca0] | 177 | helenos_target = None
|
---|
[b08941d] | 178 | target = None
|
---|
[7f25c4e] | 179 | cc_args = []
|
---|
[a35b458] | 180 |
|
---|
[39ba6d5] | 181 | if (config['PLATFORM'] == "abs32le"):
|
---|
| 182 | check_config(config, "CROSS_TARGET")
|
---|
[b08941d] | 183 | platform = config['CROSS_TARGET']
|
---|
[a35b458] | 184 |
|
---|
[39ba6d5] | 185 | if (config['CROSS_TARGET'] == "arm32"):
|
---|
| 186 | gnu_target = "arm-linux-gnueabi"
|
---|
[8f2eca0] | 187 | helenos_target = "arm-helenos-gnueabi"
|
---|
[a35b458] | 188 |
|
---|
[39ba6d5] | 189 | if (config['CROSS_TARGET'] == "ia32"):
|
---|
| 190 | gnu_target = "i686-pc-linux-gnu"
|
---|
[8f2eca0] | 191 | helenos_target = "i686-pc-helenos"
|
---|
[a35b458] | 192 |
|
---|
[39ba6d5] | 193 | if (config['CROSS_TARGET'] == "mips32"):
|
---|
[795e2bf] | 194 | cc_args.append("-mabi=32")
|
---|
[39ba6d5] | 195 | gnu_target = "mipsel-linux-gnu"
|
---|
[8f2eca0] | 196 | helenos_target = "mipsel-helenos"
|
---|
[a35b458] | 197 |
|
---|
[39ba6d5] | 198 | if (config['PLATFORM'] == "amd64"):
|
---|
[b08941d] | 199 | platform = config['PLATFORM']
|
---|
[bfdb7c63] | 200 | gnu_target = "amd64-unknown-elf"
|
---|
[8f2eca0] | 201 | helenos_target = "amd64-helenos"
|
---|
[a35b458] | 202 |
|
---|
[39ba6d5] | 203 | if (config['PLATFORM'] == "arm32"):
|
---|
[b08941d] | 204 | platform = config['PLATFORM']
|
---|
[39ba6d5] | 205 | gnu_target = "arm-linux-gnueabi"
|
---|
[8f2eca0] | 206 | helenos_target = "arm-helenos-gnueabi"
|
---|
[a35b458] | 207 |
|
---|
[39ba6d5] | 208 | if (config['PLATFORM'] == "ia32"):
|
---|
[b08941d] | 209 | platform = config['PLATFORM']
|
---|
[39ba6d5] | 210 | gnu_target = "i686-pc-linux-gnu"
|
---|
[8f2eca0] | 211 | helenos_target = "i686-pc-helenos"
|
---|
[a35b458] | 212 |
|
---|
[39ba6d5] | 213 | if (config['PLATFORM'] == "ia64"):
|
---|
[b08941d] | 214 | platform = config['PLATFORM']
|
---|
[39ba6d5] | 215 | gnu_target = "ia64-pc-linux-gnu"
|
---|
[8f2eca0] | 216 | helenos_target = "ia64-pc-helenos"
|
---|
[a35b458] | 217 |
|
---|
[39ba6d5] | 218 | if (config['PLATFORM'] == "mips32"):
|
---|
| 219 | check_config(config, "MACHINE")
|
---|
[7f25c4e] | 220 | cc_args.append("-mabi=32")
|
---|
[a35b458] | 221 |
|
---|
[b183ce0a] | 222 | if ((config['MACHINE'] == "msim") or (config['MACHINE'] == "lmalta")):
|
---|
[b08941d] | 223 | platform = config['PLATFORM']
|
---|
[39ba6d5] | 224 | gnu_target = "mipsel-linux-gnu"
|
---|
[8f2eca0] | 225 | helenos_target = "mipsel-helenos"
|
---|
[a35b458] | 226 |
|
---|
[b183ce0a] | 227 | if ((config['MACHINE'] == "bmalta")):
|
---|
[b08941d] | 228 | platform = "mips32eb"
|
---|
[39ba6d5] | 229 | gnu_target = "mips-linux-gnu"
|
---|
[8f2eca0] | 230 | helenos_target = "mips-helenos"
|
---|
[a35b458] | 231 |
|
---|
[39ba6d5] | 232 | if (config['PLATFORM'] == "mips64"):
|
---|
| 233 | check_config(config, "MACHINE")
|
---|
[7f25c4e] | 234 | cc_args.append("-mabi=64")
|
---|
[a35b458] | 235 |
|
---|
[39ba6d5] | 236 | if (config['MACHINE'] == "msim"):
|
---|
[b08941d] | 237 | platform = config['PLATFORM']
|
---|
[39ba6d5] | 238 | gnu_target = "mips64el-linux-gnu"
|
---|
[8f2eca0] | 239 | helenos_target = "mips64el-helenos"
|
---|
[a35b458] | 240 |
|
---|
[39ba6d5] | 241 | if (config['PLATFORM'] == "ppc32"):
|
---|
[b08941d] | 242 | platform = config['PLATFORM']
|
---|
[39ba6d5] | 243 | gnu_target = "ppc-linux-gnu"
|
---|
[8f2eca0] | 244 | helenos_target = "ppc-helenos"
|
---|
[a35b458] | 245 |
|
---|
[114d098] | 246 | if (config['PLATFORM'] == "riscv64"):
|
---|
[b08941d] | 247 | platform = config['PLATFORM']
|
---|
[114d098] | 248 | gnu_target = "riscv64-unknown-linux-gnu"
|
---|
| 249 | helenos_target = "riscv64-helenos"
|
---|
[a35b458] | 250 |
|
---|
[39ba6d5] | 251 | if (config['PLATFORM'] == "sparc64"):
|
---|
[b08941d] | 252 | platform = config['PLATFORM']
|
---|
[39ba6d5] | 253 | gnu_target = "sparc64-linux-gnu"
|
---|
[8f2eca0] | 254 | helenos_target = "sparc64-helenos"
|
---|
[a35b458] | 255 |
|
---|
[b08941d] | 256 | if (config['COMPILER'] == "gcc_helenos"):
|
---|
| 257 | target = helenos_target
|
---|
| 258 | else:
|
---|
| 259 | target = gnu_target
|
---|
[a35b458] | 260 |
|
---|
[b08941d] | 261 | return (platform, cc_args, target)
|
---|
[39ba6d5] | 262 |
|
---|
[177e4ea] | 263 | def check_app(args, name, details):
|
---|
| 264 | "Check whether an application can be executed"
|
---|
[a35b458] | 265 |
|
---|
[177e4ea] | 266 | try:
|
---|
| 267 | sys.stderr.write("Checking for %s ... " % args[0])
|
---|
| 268 | subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
---|
| 269 | except:
|
---|
| 270 | sys.stderr.write("failed\n")
|
---|
| 271 | print_error(["%s is missing." % name,
|
---|
| 272 | "",
|
---|
| 273 | "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
|
---|
| 274 | "is installed in your system (%s)." % details])
|
---|
[a35b458] | 275 |
|
---|
[177e4ea] | 276 | sys.stderr.write("ok\n")
|
---|
| 277 |
|
---|
[7174403] | 278 | def check_app_alternatives(alts, args, name, details):
|
---|
| 279 | "Check whether an application can be executed (use several alternatives)"
|
---|
[a35b458] | 280 |
|
---|
[7174403] | 281 | tried = []
|
---|
| 282 | found = None
|
---|
[a35b458] | 283 |
|
---|
[7174403] | 284 | for alt in alts:
|
---|
| 285 | working = True
|
---|
| 286 | cmdline = [alt] + args
|
---|
| 287 | tried.append(" ".join(cmdline))
|
---|
[a35b458] | 288 |
|
---|
[7174403] | 289 | try:
|
---|
| 290 | sys.stderr.write("Checking for %s ... " % alt)
|
---|
| 291 | subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
---|
| 292 | except:
|
---|
| 293 | sys.stderr.write("failed\n")
|
---|
| 294 | working = False
|
---|
[a35b458] | 295 |
|
---|
[7174403] | 296 | if (working):
|
---|
| 297 | sys.stderr.write("ok\n")
|
---|
| 298 | found = alt
|
---|
| 299 | break
|
---|
[a35b458] | 300 |
|
---|
[7174403] | 301 | if (found is None):
|
---|
| 302 | print_error(["%s is missing." % name,
|
---|
| 303 | "",
|
---|
| 304 | "Please make sure that it is installed in your",
|
---|
| 305 | "system (%s)." % details,
|
---|
| 306 | "",
|
---|
| 307 | "The following alternatives were tried:"] + tried)
|
---|
[a35b458] | 308 |
|
---|
[7174403] | 309 | return found
|
---|
| 310 |
|
---|
[a0a273e] | 311 | def check_clang(path, prefix, common, details):
|
---|
| 312 | "Check for clang"
|
---|
[a35b458] | 313 |
|
---|
[a0a273e] | 314 | common['CLANG'] = "%sclang" % prefix
|
---|
[a35b458] | 315 |
|
---|
[a0a273e] | 316 | if (not path is None):
|
---|
| 317 | common['CLANG'] = "%s/%s" % (path, common['CLANG'])
|
---|
[a35b458] | 318 |
|
---|
[a0a273e] | 319 | check_app([common['CLANG'], "--version"], "clang", details)
|
---|
| 320 |
|
---|
[177e4ea] | 321 | def check_gcc(path, prefix, common, details):
|
---|
| 322 | "Check for GCC"
|
---|
[a35b458] | 323 |
|
---|
[177e4ea] | 324 | common['GCC'] = "%sgcc" % prefix
|
---|
[a35b458] | 325 |
|
---|
[177e4ea] | 326 | if (not path is None):
|
---|
| 327 | common['GCC'] = "%s/%s" % (path, common['GCC'])
|
---|
[a35b458] | 328 |
|
---|
[177e4ea] | 329 | check_app([common['GCC'], "--version"], "GNU GCC", details)
|
---|
| 330 |
|
---|
| 331 | def check_binutils(path, prefix, common, details):
|
---|
| 332 | "Check for binutils toolchain"
|
---|
[a35b458] | 333 |
|
---|
[177e4ea] | 334 | common['AS'] = "%sas" % prefix
|
---|
| 335 | common['LD'] = "%sld" % prefix
|
---|
| 336 | common['AR'] = "%sar" % prefix
|
---|
| 337 | common['OBJCOPY'] = "%sobjcopy" % prefix
|
---|
| 338 | common['OBJDUMP'] = "%sobjdump" % prefix
|
---|
[a4125fb1] | 339 | common['STRIP'] = "%sstrip" % prefix
|
---|
[a35b458] | 340 |
|
---|
[177e4ea] | 341 | if (not path is None):
|
---|
[a4125fb1] | 342 | for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
|
---|
[177e4ea] | 343 | common[key] = "%s/%s" % (path, common[key])
|
---|
[a35b458] | 344 |
|
---|
[177e4ea] | 345 | check_app([common['AS'], "--version"], "GNU Assembler", details)
|
---|
| 346 | check_app([common['LD'], "--version"], "GNU Linker", details)
|
---|
| 347 | check_app([common['AR'], "--version"], "GNU Archiver", details)
|
---|
| 348 | check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
|
---|
| 349 | check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
|
---|
[a4125fb1] | 350 | check_app([common['STRIP'], "--version"], "GNU strip", details)
|
---|
[177e4ea] | 351 |
|
---|
[96b89acb] | 352 | def decode_value(value):
|
---|
| 353 | "Decode integer value"
|
---|
[a35b458] | 354 |
|
---|
[96b89acb] | 355 | base = 10
|
---|
[a35b458] | 356 |
|
---|
[96b89acb] | 357 | if ((value.startswith('$')) or (value.startswith('#'))):
|
---|
| 358 | value = value[1:]
|
---|
[a35b458] | 359 |
|
---|
[96b89acb] | 360 | if (value.startswith('0x')):
|
---|
| 361 | value = value[2:]
|
---|
| 362 | base = 16
|
---|
[a35b458] | 363 |
|
---|
[96b89acb] | 364 | return int(value, base)
|
---|
| 365 |
|
---|
[ce55b43] | 366 | def probe_compiler(common, typesizes):
|
---|
[4e9aaf5] | 367 | "Generate, compile and parse probing source"
|
---|
[a35b458] | 368 |
|
---|
[4e9aaf5] | 369 | check_common(common, "CC")
|
---|
[a35b458] | 370 |
|
---|
[28f4adb] | 371 | outf = open(PROBE_SOURCE, 'w')
|
---|
[4e9aaf5] | 372 | outf.write(PROBE_HEAD)
|
---|
[a35b458] | 373 |
|
---|
[ce55b43] | 374 | for typedef in typesizes:
|
---|
| 375 | if 'def' in typedef:
|
---|
| 376 | outf.write("#ifdef %s\n" % typedef['def'])
|
---|
| 377 | outf.write("\tDECLARE_BUILTIN_TYPE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
|
---|
| 378 | if 'def' in typedef:
|
---|
| 379 | outf.write("#endif\n")
|
---|
[a35b458] | 380 |
|
---|
[4e9aaf5] | 381 | outf.write(PROBE_TAIL)
|
---|
| 382 | outf.close()
|
---|
[a35b458] | 383 |
|
---|
[a0a273e] | 384 | args = common['CC_AUTOGEN'].split(' ')
|
---|
[2429e4a] | 385 | args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
|
---|
[a35b458] | 386 |
|
---|
[4e9aaf5] | 387 | try:
|
---|
| 388 | sys.stderr.write("Checking compiler properties ... ")
|
---|
| 389 | output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
|
---|
| 390 | except:
|
---|
| 391 | sys.stderr.write("failed\n")
|
---|
| 392 | print_error(["Error executing \"%s\"." % " ".join(args),
|
---|
| 393 | "Make sure that the compiler works properly."])
|
---|
[a35b458] | 394 |
|
---|
[4e9aaf5] | 395 | if (not os.path.isfile(PROBE_OUTPUT)):
|
---|
| 396 | sys.stderr.write("failed\n")
|
---|
[28f4adb] | 397 | print(output[1])
|
---|
[4e9aaf5] | 398 | print_error(["Error executing \"%s\"." % " ".join(args),
|
---|
| 399 | "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
|
---|
| 400 | "",
|
---|
| 401 | output[0],
|
---|
| 402 | output[1]])
|
---|
[a35b458] | 403 |
|
---|
[4e9aaf5] | 404 | sys.stderr.write("ok\n")
|
---|
[a35b458] | 405 |
|
---|
[28f4adb] | 406 | inf = open(PROBE_OUTPUT, 'r')
|
---|
[4e9aaf5] | 407 | lines = inf.readlines()
|
---|
| 408 | inf.close()
|
---|
[a35b458] | 409 |
|
---|
[ce55b43] | 410 | builtins = {}
|
---|
[a35b458] | 411 |
|
---|
[4e9aaf5] | 412 | for j in range(len(lines)):
|
---|
| 413 | tokens = lines[j].strip().split("\t")
|
---|
[a35b458] | 414 |
|
---|
[4e9aaf5] | 415 | if (len(tokens) > 0):
|
---|
| 416 | if (tokens[0] == "AUTOTOOL_DECLARE"):
|
---|
[ce55b43] | 417 | if (len(tokens) < 8):
|
---|
[4e9aaf5] | 418 | print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
[a35b458] | 419 |
|
---|
[4e9aaf5] | 420 | category = tokens[1]
|
---|
[ce55b43] | 421 | tag = tokens[2]
|
---|
| 422 | name = tokens[3]
|
---|
| 423 | signedness = tokens[4]
|
---|
| 424 | base = tokens[5]
|
---|
| 425 | size = tokens[6]
|
---|
| 426 | compatible = tokens[7]
|
---|
[a35b458] | 427 |
|
---|
[ce55b43] | 428 | try:
|
---|
| 429 | compatible_int = decode_value(compatible)
|
---|
| 430 | size_int = decode_value(size)
|
---|
| 431 | except:
|
---|
| 432 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
[a35b458] | 433 |
|
---|
[ce55b43] | 434 | if (compatible_int == 1):
|
---|
| 435 | builtins[tag] = {
|
---|
| 436 | 'tag': tag,
|
---|
| 437 | 'name': name,
|
---|
| 438 | 'sign': signedness,
|
---|
| 439 | 'base': base,
|
---|
| 440 | 'size': size_int,
|
---|
| 441 | }
|
---|
[a35b458] | 442 |
|
---|
[ce55b43] | 443 | for typedef in typesizes:
|
---|
| 444 | if not typedef['tag'] in builtins:
|
---|
| 445 | print_error(['Unable to determine the properties of type %s.' % typedef['tag'],
|
---|
[a4a0f1d] | 446 | COMPILER_FAIL])
|
---|
[ce55b43] | 447 | if 'sname' in typedef:
|
---|
| 448 | builtins[typedef['tag']]['sname'] = typedef['sname']
|
---|
[a35b458] | 449 |
|
---|
[ce55b43] | 450 | return builtins
|
---|
| 451 |
|
---|
| 452 | def get_suffix(type):
|
---|
| 453 | if type['sign'] == 'unsigned':
|
---|
| 454 | return {
|
---|
| 455 | "char": "",
|
---|
| 456 | "short": "",
|
---|
| 457 | "int": "U",
|
---|
| 458 | "long": "UL",
|
---|
| 459 | "long long": "ULL",
|
---|
| 460 | }[type['base']]
|
---|
[96b89acb] | 461 | else:
|
---|
[ce55b43] | 462 | return {
|
---|
| 463 | "char": "",
|
---|
| 464 | "short": "",
|
---|
| 465 | "int": "",
|
---|
| 466 | "long": "L",
|
---|
| 467 | "long long": "LL",
|
---|
| 468 | }[type['base']]
|
---|
| 469 |
|
---|
| 470 | def get_max(type):
|
---|
| 471 | val = (1 << (type['size']*8 - 1))
|
---|
| 472 | if type['sign'] == 'unsigned':
|
---|
| 473 | val *= 2
|
---|
| 474 | return val - 1
|
---|
| 475 |
|
---|
| 476 | def detect_sizes(probe):
|
---|
| 477 | "Detect properties of builtin types"
|
---|
[a35b458] | 478 |
|
---|
[ce55b43] | 479 | macros = {}
|
---|
[a35b458] | 480 |
|
---|
[ce55b43] | 481 | for type in probe.values():
|
---|
| 482 | macros['__SIZEOF_%s__' % type['tag']] = type['size']
|
---|
[a35b458] | 483 |
|
---|
[ce55b43] | 484 | if ('sname' in type):
|
---|
| 485 | macros['__%s_TYPE__' % type['sname']] = type['name']
|
---|
| 486 | macros['__%s_WIDTH__' % type['sname']] = type['size']*8
|
---|
| 487 | macros['__%s_%s__' % (type['sname'], type['sign'].upper())] = "1"
|
---|
| 488 | macros['__%s_C_SUFFIX__' % type['sname']] = get_suffix(type)
|
---|
| 489 | macros['__%s_MAX__' % type['sname']] = "%d%s" % (get_max(type), get_suffix(type))
|
---|
[a35b458] | 490 |
|
---|
[ce55b43] | 491 | if (probe['SIZE_T']['sign'] != 'unsigned'):
|
---|
| 492 | print_error(['The type size_t is not unsigned.', COMPILER_FAIL])
|
---|
[a35b458] | 493 |
|
---|
[ce55b43] | 494 | return macros
|
---|
[4e9aaf5] | 495 |
|
---|
| 496 | def create_makefile(mkname, common):
|
---|
| 497 | "Create makefile output"
|
---|
[a35b458] | 498 |
|
---|
[28f4adb] | 499 | outmk = open(mkname, 'w')
|
---|
[a35b458] | 500 |
|
---|
[4e9aaf5] | 501 | outmk.write('#########################################\n')
|
---|
| 502 | outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
|
---|
[571239a] | 503 | outmk.write('## Generated by: tools/autotool.py ##\n')
|
---|
[4e9aaf5] | 504 | outmk.write('#########################################\n\n')
|
---|
[a35b458] | 505 |
|
---|
[177e4ea] | 506 | for key, value in common.items():
|
---|
[7174403] | 507 | if (type(value) is list):
|
---|
| 508 | outmk.write('%s = %s\n' % (key, " ".join(value)))
|
---|
| 509 | else:
|
---|
| 510 | outmk.write('%s = %s\n' % (key, value))
|
---|
[a35b458] | 511 |
|
---|
[4e9aaf5] | 512 | outmk.close()
|
---|
| 513 |
|
---|
[ce55b43] | 514 | def create_header(hdname, macros):
|
---|
[4e9aaf5] | 515 | "Create header output"
|
---|
[a35b458] | 516 |
|
---|
[28f4adb] | 517 | outhd = open(hdname, 'w')
|
---|
[a35b458] | 518 |
|
---|
[4e9aaf5] | 519 | outhd.write('/***************************************\n')
|
---|
| 520 | outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
|
---|
[571239a] | 521 | outhd.write(' * Generated by: tools/autotool.py *\n')
|
---|
[4e9aaf5] | 522 | outhd.write(' ***************************************/\n\n')
|
---|
[a35b458] | 523 |
|
---|
[4e9aaf5] | 524 | outhd.write('#ifndef %s\n' % GUARD)
|
---|
| 525 | outhd.write('#define %s\n\n' % GUARD)
|
---|
[a35b458] | 526 |
|
---|
[ce55b43] | 527 | for macro in sorted(macros):
|
---|
| 528 | outhd.write('#ifndef %s\n' % macro)
|
---|
| 529 | outhd.write('#define %s %s\n' % (macro, macros[macro]))
|
---|
| 530 | outhd.write('#endif\n\n')
|
---|
[a35b458] | 531 |
|
---|
[4e9aaf5] | 532 | outhd.write('\n#endif\n')
|
---|
| 533 | outhd.close()
|
---|
[177e4ea] | 534 |
|
---|
| 535 | def main():
|
---|
| 536 | config = {}
|
---|
| 537 | common = {}
|
---|
[a35b458] | 538 |
|
---|
[177e4ea] | 539 | # Read and check configuration
|
---|
[4e9aaf5] | 540 | if os.path.exists(CONFIG):
|
---|
| 541 | read_config(CONFIG, config)
|
---|
[177e4ea] | 542 | else:
|
---|
[4e9aaf5] | 543 | print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
|
---|
[177e4ea] | 544 | "configuration phase of HelenOS build went OK. Try running",
|
---|
| 545 | "\"make config\" again."])
|
---|
[a35b458] | 546 |
|
---|
[177e4ea] | 547 | check_config(config, "PLATFORM")
|
---|
| 548 | check_config(config, "COMPILER")
|
---|
| 549 | check_config(config, "BARCH")
|
---|
[a35b458] | 550 |
|
---|
[177e4ea] | 551 | # Cross-compiler prefix
|
---|
| 552 | if ('CROSS_PREFIX' in os.environ):
|
---|
| 553 | cross_prefix = os.environ['CROSS_PREFIX']
|
---|
| 554 | else:
|
---|
[603c8740] | 555 | cross_prefix = "/usr/local/cross"
|
---|
[a35b458] | 556 |
|
---|
[8f2eca0] | 557 | # HelenOS cross-compiler prefix
|
---|
| 558 | if ('CROSS_HELENOS_PREFIX' in os.environ):
|
---|
| 559 | cross_helenos_prefix = os.environ['CROSS_HELENOS_PREFIX']
|
---|
| 560 | else:
|
---|
| 561 | cross_helenos_prefix = "/usr/local/cross-helenos"
|
---|
[a35b458] | 562 |
|
---|
[177e4ea] | 563 | # Prefix binutils tools on Solaris
|
---|
| 564 | if (os.uname()[0] == "SunOS"):
|
---|
| 565 | binutils_prefix = "g"
|
---|
| 566 | else:
|
---|
| 567 | binutils_prefix = ""
|
---|
[a35b458] | 568 |
|
---|
[4e9aaf5] | 569 | owd = sandbox_enter()
|
---|
[a35b458] | 570 |
|
---|
[4e9aaf5] | 571 | try:
|
---|
| 572 | # Common utilities
|
---|
| 573 | check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
|
---|
| 574 | check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
|
---|
| 575 | check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
|
---|
| 576 | check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
|
---|
| 577 | check_app(["find", "--version"], "Find utility", "usually part of findutils")
|
---|
| 578 | check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
|
---|
| 579 | check_app(["make", "--version"], "Make utility", "preferably GNU Make")
|
---|
[9ce911d] | 580 | check_app(["unzip"], "unzip utility", "usually part of zip/unzip utilities")
|
---|
[a35b458] | 581 |
|
---|
[b08941d] | 582 | platform, cc_args, target = get_target(config)
|
---|
[a35b458] | 583 |
|
---|
[b08941d] | 584 | if (platform is None) or (target is None):
|
---|
| 585 | print_error(["Unsupported compiler target.",
|
---|
| 586 | "Please contact the developers of HelenOS."])
|
---|
[a35b458] | 587 |
|
---|
[b08941d] | 588 | path = "%s/%s/bin" % (cross_prefix, target)
|
---|
[a35b458] | 589 |
|
---|
[b08941d] | 590 | # Compatibility with earlier toolchain paths.
|
---|
| 591 | if not os.path.exists(path):
|
---|
| 592 | if (config['COMPILER'] == "gcc_helenos"):
|
---|
| 593 | check_path = "%s/%s/%s" % (cross_helenos_prefix, platform, target)
|
---|
| 594 | if not os.path.exists(check_path):
|
---|
| 595 | print_error(["Toolchain for target is not installed, or CROSS_PREFIX is not set correctly."])
|
---|
| 596 | path = "%s/%s/bin" % (cross_helenos_prefix, platform)
|
---|
| 597 | else:
|
---|
| 598 | check_path = "%s/%s/%s" % (cross_prefix, platform, target)
|
---|
| 599 | if not os.path.exists(check_path):
|
---|
| 600 | print_error(["Toolchain for target is not installed, or CROSS_PREFIX is not set correctly."])
|
---|
| 601 | path = "%s/%s/bin" % (cross_prefix, platform)
|
---|
[a35b458] | 602 |
|
---|
[2660ee3] | 603 | common['TARGET'] = target
|
---|
[b08941d] | 604 | prefix = "%s-" % target
|
---|
[a35b458] | 605 |
|
---|
[b08941d] | 606 | # Compiler
|
---|
| 607 | if (config['COMPILER'] == "gcc_cross" or config['COMPILER'] == "gcc_helenos"):
|
---|
[8f2eca0] | 608 | check_gcc(path, prefix, common, PACKAGE_CROSS)
|
---|
| 609 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
---|
[a35b458] | 610 |
|
---|
[8f2eca0] | 611 | check_common(common, "GCC")
|
---|
[a0a273e] | 612 | common['CC'] = " ".join([common['GCC']] + cc_args)
|
---|
| 613 | common['CC_AUTOGEN'] = common['CC']
|
---|
[a35b458] | 614 |
|
---|
[4e9aaf5] | 615 | if (config['COMPILER'] == "gcc_native"):
|
---|
| 616 | check_gcc(None, "", common, PACKAGE_GCC)
|
---|
| 617 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
---|
[a35b458] | 618 |
|
---|
[4e9aaf5] | 619 | check_common(common, "GCC")
|
---|
| 620 | common['CC'] = common['GCC']
|
---|
[a0a273e] | 621 | common['CC_AUTOGEN'] = common['CC']
|
---|
[a35b458] | 622 |
|
---|
[4e9aaf5] | 623 | if (config['COMPILER'] == "clang"):
|
---|
[84eb4edd] | 624 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
---|
| 625 | check_clang(path, prefix, common, PACKAGE_CLANG)
|
---|
[a35b458] | 626 |
|
---|
[a0a273e] | 627 | check_common(common, "CLANG")
|
---|
| 628 | common['CC'] = " ".join([common['CLANG']] + cc_args)
|
---|
| 629 | common['CC_AUTOGEN'] = common['CC'] + " -no-integrated-as"
|
---|
[a35b458] | 630 |
|
---|
[a0a273e] | 631 | if (config['INTEGRATED_AS'] == "yes"):
|
---|
| 632 | common['CC'] += " -integrated-as"
|
---|
[a35b458] | 633 |
|
---|
[a0a273e] | 634 | if (config['INTEGRATED_AS'] == "no"):
|
---|
| 635 | common['CC'] += " -no-integrated-as"
|
---|
[a35b458] | 636 |
|
---|
[4e9aaf5] | 637 | # Platform-specific utilities
|
---|
| 638 | if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
|
---|
[ff87f70] | 639 | common['GENISOIMAGE'] = check_app_alternatives(["genisoimage", "mkisofs", "xorriso"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
|
---|
[b6bbc74] | 640 | if common['GENISOIMAGE'] == 'xorriso':
|
---|
[92c07dc] | 641 | common['GENISOIMAGE'] += ' -as genisoimage'
|
---|
[a35b458] | 642 |
|
---|
[4e9aaf5] | 643 | probe = probe_compiler(common,
|
---|
| 644 | [
|
---|
[ce55b43] | 645 | {'type': 'long long int', 'tag': 'LONG_LONG', 'sname': 'LLONG' },
|
---|
| 646 | {'type': 'long int', 'tag': 'LONG', 'sname': 'LONG' },
|
---|
| 647 | {'type': 'int', 'tag': 'INT', 'sname': 'INT' },
|
---|
| 648 | {'type': 'short int', 'tag': 'SHORT', 'sname': 'SHRT'},
|
---|
| 649 | {'type': 'void*', 'tag': 'POINTER'},
|
---|
[a4a0f1d] | 650 | {'type': 'long double', 'tag': 'LONG_DOUBLE'},
|
---|
| 651 | {'type': 'double', 'tag': 'DOUBLE'},
|
---|
[ce55b43] | 652 | {'type': 'float', 'tag': 'FLOAT'},
|
---|
| 653 | {'type': '__SIZE_TYPE__', 'tag': 'SIZE_T', 'def': '__SIZE_TYPE__', 'sname': 'SIZE' },
|
---|
| 654 | {'type': '__PTRDIFF_TYPE__', 'tag': 'PTRDIFF_T', 'def': '__PTRDIFF_TYPE__', 'sname': 'PTRDIFF' },
|
---|
| 655 | {'type': '__WINT_TYPE__', 'tag': 'WINT_T', 'def': '__WINT_TYPE__', 'sname': 'WINT' },
|
---|
| 656 | {'type': '__WCHAR_TYPE__', 'tag': 'WCHAR_T', 'def': '__WCHAR_TYPE__', 'sname': 'WCHAR' },
|
---|
| 657 | {'type': '__INTMAX_TYPE__', 'tag': 'INTMAX_T', 'def': '__INTMAX_TYPE__', 'sname': 'INTMAX' },
|
---|
| 658 | {'type': 'unsigned __INTMAX_TYPE__', 'tag': 'UINTMAX_T', 'def': '__INTMAX_TYPE__', 'sname': 'UINTMAX' },
|
---|
[4e9aaf5] | 659 | ]
|
---|
| 660 | )
|
---|
[a35b458] | 661 |
|
---|
[ce55b43] | 662 | macros = detect_sizes(probe)
|
---|
[a35b458] | 663 |
|
---|
[4e9aaf5] | 664 | finally:
|
---|
| 665 | sandbox_leave(owd)
|
---|
[a35b458] | 666 |
|
---|
[4e9aaf5] | 667 | create_makefile(MAKEFILE, common)
|
---|
[ce55b43] | 668 | create_header(HEADER, macros)
|
---|
[a35b458] | 669 |
|
---|
[177e4ea] | 670 | return 0
|
---|
| 671 |
|
---|
| 672 | if __name__ == '__main__':
|
---|
| 673 | sys.exit(main())
|
---|