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