from __future__ import print_function import os import sys import tools try : sys.path.append(os.getcwd()) import config SRCDIR = os.path.abspath(config.SRCDIR) BUILDDIR = os.path.abspath(config.BUILDDIR) except: print('ERROR: missing config.py, re-run configure script.', file=sys.stderr) sys.exit(1) class Architecture: KnownArchitectures = { 'x64' : 'x64', 'x86-64' : 'x64', 'x86_64' : 'x64', 'x86' : 'x86', 'i386' : 'x86', 'i486' : 'x86', 'i686' : 'x86', 'Intel 80386' : 'x86', 'arm' : 'arm', 'ARM' : 'arm', } CrossCompileFlags = { 'x64' : 'ARCH_FLAGS=-m64', 'x86' : 'ARCH_FLAGS=-m32', } def __init__(self, arch): try: canonical_host = Architecture.makeCanonical( config.HOSTARCH ) except KeyError: print("Unkown host architecture %s" % config.HOSTARCH, file=sys.stderr) sys.exit(1) if arch: try: arch = Architecture.makeCanonical( arch ) except KeyError: print("Unkown architecture %s" % arch, file=sys.stderr) sys.exit(1) if arch and arch != canonical_host: self.target = arch self.cross_compile = True else: self.target = canonical_host self.cross_compile = False try : self.flags = Architecture.CrossCompileFlags[self.target] except KeyError: print("Cross compilation not available for architecture %s" % self.target, file=sys.stderr) sys.exit(1) self.string = self.target def update(self): if not self.cross_compile: self.target = machine_default() self.string = self.target print("updated to %s" % self.target) def match(self, arch): return True if not arch else self.target == arch @classmethod def makeCanonical(_, arch): return Architecture.KnownArchitectures[arch] class Debug: def __init__(self, value): self.string = "debug" if value else "no debug" self.flags = """DEBUG_FLAGS="%s" """ % ("-debug -O0" if value else "-nodebug -O2") class Install: def __init__(self, value): self.string = "installed" if value else "in-tree" self.flags = """INSTALL_FLAGS="%s" """ % ("" if value else "-in-tree") def init( options ): global arch global dry_run global generating global make global debug global install dry_run = options.dry_run generating = options.regenerate_expected make = 'make' debug = Debug(options.debug) install = Install(options.install) arch = Architecture(options.arch) def updateMakeCmd(force, jobs): global make make = "make" if not force else ("make -j%i" % jobs) def validate(): make_ret, _ = tools.make( ".validate", error_file = ".validate.err", redirects = "2> /dev/null 1> /dev/null", ) if make_ret != 0: with open (".validate.err", "r") as myfile: error=myfile.read() print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr) print(" verify returned : \n%s" % error, file=sys.stderr) tools.rm("%s/.validate.err" % BUILDDIR) sys.exit(1) tools.rm("%s/.validate.err" % BUILDDIR)