| 1 | #!/usr/bin/env python
|
|---|
| 2 | #
|
|---|
| 3 | # Copyright (c) 2010 Martin Decky
|
|---|
| 4 | # All rights reserved.
|
|---|
| 5 | #
|
|---|
| 6 | # Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | # modification, are permitted provided that the following conditions
|
|---|
| 8 | # are met:
|
|---|
| 9 | #
|
|---|
| 10 | # - Redistributions of source code must retain the above copyright
|
|---|
| 11 | # notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | # - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | # notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | # documentation and/or other materials provided with the distribution.
|
|---|
| 15 | # - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | # derived from this software without specific prior written permission.
|
|---|
| 17 | #
|
|---|
| 18 | # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | #
|
|---|
| 29 | """
|
|---|
| 30 | Detect important prerequisites and parameters for building HelenOS
|
|---|
| 31 | """
|
|---|
| 32 |
|
|---|
| 33 | import sys
|
|---|
| 34 | import os
|
|---|
| 35 | import re
|
|---|
| 36 | import time
|
|---|
| 37 | import subprocess
|
|---|
| 38 |
|
|---|
| 39 | MAKEFILE = 'Makefile.config'
|
|---|
| 40 | COMMON = 'Makefile.common'
|
|---|
| 41 |
|
|---|
| 42 | PACKAGE_BINUTILS = "usually part of binutils"
|
|---|
| 43 | PACKAGE_GCC = "preferably version 4.4.3 or newer"
|
|---|
| 44 | PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
|
|---|
| 45 |
|
|---|
| 46 | def read_config(fname, config):
|
|---|
| 47 | "Read HelenOS build configuration"
|
|---|
| 48 |
|
|---|
| 49 | inf = file(fname, 'r')
|
|---|
| 50 |
|
|---|
| 51 | for line in inf:
|
|---|
| 52 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
|
|---|
| 53 | if (res):
|
|---|
| 54 | config[res.group(1)] = res.group(2)
|
|---|
| 55 |
|
|---|
| 56 | inf.close()
|
|---|
| 57 |
|
|---|
| 58 | def print_error(msg):
|
|---|
| 59 | "Print a bold error message"
|
|---|
| 60 |
|
|---|
| 61 | sys.stderr.write("\n")
|
|---|
| 62 | sys.stderr.write("######################################################################\n")
|
|---|
| 63 | sys.stderr.write("HelenOS build sanity check error:\n")
|
|---|
| 64 | sys.stderr.write("\n")
|
|---|
| 65 | sys.stderr.write("%s\n" % "\n".join(msg))
|
|---|
| 66 | sys.stderr.write("######################################################################\n")
|
|---|
| 67 | sys.stderr.write("\n")
|
|---|
| 68 |
|
|---|
| 69 | sys.exit(1)
|
|---|
| 70 |
|
|---|
| 71 | def check_config(config, key):
|
|---|
| 72 | "Check whether the configuration key exists"
|
|---|
| 73 |
|
|---|
| 74 | if (not key in config):
|
|---|
| 75 | print_error(["Build configuration of HelenOS does not contain %s." % key,
|
|---|
| 76 | "Try running \"make config\" again.",
|
|---|
| 77 | "If the problem persists, please contact the developers of HelenOS."])
|
|---|
| 78 |
|
|---|
| 79 | def check_app(args, name, details):
|
|---|
| 80 | "Check whether an application can be executed"
|
|---|
| 81 |
|
|---|
| 82 | try:
|
|---|
| 83 | sys.stderr.write("Checking for %s ... " % args[0])
|
|---|
| 84 | subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
|---|
| 85 | except:
|
|---|
| 86 | sys.stderr.write("failed\n")
|
|---|
| 87 | print_error(["%s is missing." % name,
|
|---|
| 88 | "",
|
|---|
| 89 | "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
|
|---|
| 90 | "is installed in your system (%s)." % details])
|
|---|
| 91 |
|
|---|
| 92 | sys.stderr.write("ok\n")
|
|---|
| 93 |
|
|---|
| 94 | def check_gcc(path, prefix, common, details):
|
|---|
| 95 | "Check for GCC"
|
|---|
| 96 |
|
|---|
| 97 | common['GCC'] = "%sgcc" % prefix
|
|---|
| 98 |
|
|---|
| 99 | if (not path is None):
|
|---|
| 100 | common['GCC'] = "%s/%s" % (path, common['GCC'])
|
|---|
| 101 |
|
|---|
| 102 | check_app([common['GCC'], "--version"], "GNU GCC", details)
|
|---|
| 103 |
|
|---|
| 104 | def check_binutils(path, prefix, common, details):
|
|---|
| 105 | "Check for binutils toolchain"
|
|---|
| 106 |
|
|---|
| 107 | common['AS'] = "%sas" % prefix
|
|---|
| 108 | common['LD'] = "%sld" % prefix
|
|---|
| 109 | common['AR'] = "%sar" % prefix
|
|---|
| 110 | common['OBJCOPY'] = "%sobjcopy" % prefix
|
|---|
| 111 | common['OBJDUMP'] = "%sobjdump" % prefix
|
|---|
| 112 |
|
|---|
| 113 | if (not path is None):
|
|---|
| 114 | for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP"]:
|
|---|
| 115 | common[key] = "%s/%s" % (path, common[key])
|
|---|
| 116 |
|
|---|
| 117 | check_app([common['AS'], "--version"], "GNU Assembler", details)
|
|---|
| 118 | check_app([common['LD'], "--version"], "GNU Linker", details)
|
|---|
| 119 | check_app([common['AR'], "--version"], "GNU Archiver", details)
|
|---|
| 120 | check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
|
|---|
| 121 | check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
|
|---|
| 122 |
|
|---|
| 123 | def create_output(cmname, common):
|
|---|
| 124 | "Create common parameters output"
|
|---|
| 125 |
|
|---|
| 126 | outcm = file(cmname, 'w')
|
|---|
| 127 |
|
|---|
| 128 | outcm.write('#########################################\n')
|
|---|
| 129 | outcm.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
|
|---|
| 130 | outcm.write('#########################################\n\n')
|
|---|
| 131 |
|
|---|
| 132 | for key, value in common.items():
|
|---|
| 133 | outcm.write('%s = %s\n' % (key, value))
|
|---|
| 134 |
|
|---|
| 135 | outcm.close()
|
|---|
| 136 |
|
|---|
| 137 | def main():
|
|---|
| 138 | config = {}
|
|---|
| 139 | common = {}
|
|---|
| 140 |
|
|---|
| 141 | # Read and check configuration
|
|---|
| 142 | if os.path.exists(MAKEFILE):
|
|---|
| 143 | read_config(MAKEFILE, config)
|
|---|
| 144 | else:
|
|---|
| 145 | print_error(["Configuration file %s not found! Make sure that the" % MAKEFILE,
|
|---|
| 146 | "configuration phase of HelenOS build went OK. Try running",
|
|---|
| 147 | "\"make config\" again."])
|
|---|
| 148 |
|
|---|
| 149 | check_config(config, "PLATFORM")
|
|---|
| 150 | check_config(config, "COMPILER")
|
|---|
| 151 | check_config(config, "BARCH")
|
|---|
| 152 |
|
|---|
| 153 | # Cross-compiler prefix
|
|---|
| 154 | if ('CROSS_PREFIX' in os.environ):
|
|---|
| 155 | cross_prefix = os.environ['CROSS_PREFIX']
|
|---|
| 156 | else:
|
|---|
| 157 | cross_prefix = "/usr/local"
|
|---|
| 158 |
|
|---|
| 159 | # Prefix binutils tools on Solaris
|
|---|
| 160 | if (os.uname()[0] == "SunOS"):
|
|---|
| 161 | binutils_prefix = "g"
|
|---|
| 162 | else:
|
|---|
| 163 | binutils_prefix = ""
|
|---|
| 164 |
|
|---|
| 165 | # Common utilities
|
|---|
| 166 | check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
|
|---|
| 167 | check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
|
|---|
| 168 | check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
|
|---|
| 169 | check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
|
|---|
| 170 | check_app(["find", "--version"], "Find utility", "usually part of findutils")
|
|---|
| 171 | check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
|
|---|
| 172 | check_app(["make", "--version"], "Make utility", "preferably GNU Make")
|
|---|
| 173 | check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
|
|---|
| 174 |
|
|---|
| 175 | # Compiler
|
|---|
| 176 | if (config['COMPILER'] == "gcc_cross"):
|
|---|
| 177 | if (config['PLATFORM'] == "abs32le"):
|
|---|
| 178 | check_config(config, "CROSS_TARGET")
|
|---|
| 179 | target = config['CROSS_TARGET']
|
|---|
| 180 |
|
|---|
| 181 | if (config['CROSS_TARGET'] == "arm32"):
|
|---|
| 182 | gnu_target = "arm-linux-gnu"
|
|---|
| 183 |
|
|---|
| 184 | if (config['CROSS_TARGET'] == "ia32"):
|
|---|
| 185 | gnu_target = "i686-pc-linux-gnu"
|
|---|
| 186 |
|
|---|
| 187 | if (config['CROSS_TARGET'] == "mips32"):
|
|---|
| 188 | gnu_target = "mipsel-linux-gnu"
|
|---|
| 189 |
|
|---|
| 190 | if (config['PLATFORM'] == "amd64"):
|
|---|
| 191 | target = config['PLATFORM']
|
|---|
| 192 | gnu_target = "amd64-linux-gnu"
|
|---|
| 193 |
|
|---|
| 194 | if (config['PLATFORM'] == "arm32"):
|
|---|
| 195 | target = config['PLATFORM']
|
|---|
| 196 | gnu_target = "arm-linux-gnu"
|
|---|
| 197 |
|
|---|
| 198 | if (config['PLATFORM'] == "ia32"):
|
|---|
| 199 | target = config['PLATFORM']
|
|---|
| 200 | gnu_target = "i686-pc-linux-gnu"
|
|---|
| 201 |
|
|---|
| 202 | if (config['PLATFORM'] == "ia64"):
|
|---|
| 203 | target = config['PLATFORM']
|
|---|
| 204 | gnu_target = "ia64-pc-linux-gnu"
|
|---|
| 205 |
|
|---|
| 206 | if (config['PLATFORM'] == "mips32"):
|
|---|
| 207 | check_config(config, "MACHINE")
|
|---|
| 208 |
|
|---|
| 209 | if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
|
|---|
| 210 | target = config['PLATFORM']
|
|---|
| 211 | gnu_target = "mipsel-linux-gnu"
|
|---|
| 212 |
|
|---|
| 213 | if (config['MACHINE'] == "bgxemul"):
|
|---|
| 214 | target = "mips32eb"
|
|---|
| 215 | gnu_target = "mips-linux-gnu"
|
|---|
| 216 |
|
|---|
| 217 | if (config['PLATFORM'] == "ppc32"):
|
|---|
| 218 | target = config['PLATFORM']
|
|---|
| 219 | gnu_target = "ppc-linux-gnu"
|
|---|
| 220 |
|
|---|
| 221 | if (config['PLATFORM'] == "sparc64"):
|
|---|
| 222 | target = config['PLATFORM']
|
|---|
| 223 | gnu_target = "sparc64-linux-gnu"
|
|---|
| 224 |
|
|---|
| 225 | path = "%s/%s/bin" % (cross_prefix, target)
|
|---|
| 226 | prefix = "%s-" % gnu_target
|
|---|
| 227 |
|
|---|
| 228 | check_gcc(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 229 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
|---|
| 230 | common['CC'] = common['GCC']
|
|---|
| 231 |
|
|---|
| 232 | if (config['COMPILER'] == "gcc_native"):
|
|---|
| 233 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 234 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 235 | common['CC'] = common['GCC']
|
|---|
| 236 |
|
|---|
| 237 | if (config['COMPILER'] == "icc"):
|
|---|
| 238 | common['CC'] = "icc"
|
|---|
| 239 | check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
|
|---|
| 240 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 241 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 242 |
|
|---|
| 243 | if (config['COMPILER'] == "suncc"):
|
|---|
| 244 | common['CC'] = "suncc"
|
|---|
| 245 | check_app([common['CC'], "-V"], "Sun Studio Compiler", "support is experimental")
|
|---|
| 246 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 247 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 248 |
|
|---|
| 249 | if (config['COMPILER'] == "clang"):
|
|---|
| 250 | common['CC'] = "clang"
|
|---|
| 251 | check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
|
|---|
| 252 | check_gcc(None, "", common, PACKAGE_GCC)
|
|---|
| 253 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
|---|
| 254 |
|
|---|
| 255 | # Platform-specific utilities
|
|---|
| 256 | if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
|
|---|
| 257 | check_app(["mkisofs", "--version"], "ISO 9660 creation utility", "usually part of genisoimage")
|
|---|
| 258 |
|
|---|
| 259 | create_output(COMMON, common)
|
|---|
| 260 |
|
|---|
| 261 | return 0
|
|---|
| 262 |
|
|---|
| 263 | if __name__ == '__main__':
|
|---|
| 264 | sys.exit(main())
|
|---|