1 | from __future__ import print_function |
---|
2 | |
---|
3 | import os |
---|
4 | import sys |
---|
5 | import tools |
---|
6 | |
---|
7 | try : |
---|
8 | sys.path.append(os.getcwd()) |
---|
9 | import config |
---|
10 | |
---|
11 | SRCDIR = os.path.abspath(config.SRCDIR) |
---|
12 | BUILDDIR = os.path.abspath(config.BUILDDIR) |
---|
13 | except: |
---|
14 | print('ERROR: missing config.py, re-run configure script.', file=sys.stderr) |
---|
15 | sys.exit(1) |
---|
16 | |
---|
17 | class Architecture: |
---|
18 | KnownArchitectures = { |
---|
19 | 'x64' : 'x64', |
---|
20 | 'x86-64' : 'x64', |
---|
21 | 'x86_64' : 'x64', |
---|
22 | 'x86' : 'x86', |
---|
23 | 'i386' : 'x86', |
---|
24 | 'i486' : 'x86', |
---|
25 | 'i686' : 'x86', |
---|
26 | 'Intel 80386' : 'x86', |
---|
27 | 'arm' : 'arm', |
---|
28 | 'ARM' : 'arm', |
---|
29 | } |
---|
30 | |
---|
31 | CrossCompileFlags = { |
---|
32 | 'x64' : 'ARCH_FLAGS=-m64', |
---|
33 | 'x86' : 'ARCH_FLAGS=-m32', |
---|
34 | } |
---|
35 | |
---|
36 | def __init__(self, arch): |
---|
37 | try: |
---|
38 | canonical_host = Architecture.makeCanonical( config.HOSTARCH ) |
---|
39 | except KeyError: |
---|
40 | print("Unkown host architecture %s" % config.HOSTARCH, file=sys.stderr) |
---|
41 | sys.exit(1) |
---|
42 | |
---|
43 | if arch: |
---|
44 | try: |
---|
45 | arch = Architecture.makeCanonical( arch ) |
---|
46 | except KeyError: |
---|
47 | print("Unkown architecture %s" % arch, file=sys.stderr) |
---|
48 | sys.exit(1) |
---|
49 | |
---|
50 | if arch and arch != canonical_host: |
---|
51 | self.target = arch |
---|
52 | self.cross_compile = True |
---|
53 | try : |
---|
54 | self.flags = Architecture.CrossCompileFlags[arch] |
---|
55 | except KeyError: |
---|
56 | print("Cross compilation not available for architecture %s" % arch, file=sys.stderr) |
---|
57 | sys.exit(1) |
---|
58 | |
---|
59 | else: |
---|
60 | self.target = canonical_host |
---|
61 | self.cross_compile = False |
---|
62 | self.flags = "" |
---|
63 | |
---|
64 | self.string = self.target |
---|
65 | |
---|
66 | def update(self): |
---|
67 | if not self.cross_compile: |
---|
68 | self.target = machine_default() |
---|
69 | self.string = self.target |
---|
70 | print("updated to %s" % self.target) |
---|
71 | |
---|
72 | def match(self, arch): |
---|
73 | return True if not arch else self.target == arch |
---|
74 | |
---|
75 | @classmethod |
---|
76 | def makeCanonical(_, arch): |
---|
77 | return Architecture.KnownArchitectures[arch] |
---|
78 | |
---|
79 | |
---|
80 | class Debug: |
---|
81 | def __init__(self, value): |
---|
82 | self.string = "debug" if value else "no debug" |
---|
83 | self.flags = """DEBUG_FLAGS="%s" """ % ("-debug -O0" if value else "-nodebug -O2") |
---|
84 | |
---|
85 | class Install: |
---|
86 | def __init__(self, value): |
---|
87 | self.string = "installed" if value else "in-tree" |
---|
88 | self.flags = """INSTALL_FLAGS="%s" """ % ("" if value else "-in-tree") |
---|
89 | |
---|
90 | def init( options ): |
---|
91 | global arch |
---|
92 | global dry_run |
---|
93 | global generating |
---|
94 | global make |
---|
95 | global debug |
---|
96 | global install |
---|
97 | |
---|
98 | dry_run = options.dry_run |
---|
99 | generating = options.regenerate_expected |
---|
100 | make = 'make' |
---|
101 | debug = Debug(options.debug) |
---|
102 | install = Install(options.install) |
---|
103 | arch = Architecture(options.arch) |
---|
104 | |
---|
105 | |
---|
106 | def updateMakeCmd(force, jobs): |
---|
107 | global make |
---|
108 | |
---|
109 | make = "make" if not force else ("make -j%i" % jobs) |
---|
110 | |
---|
111 | def validate(): |
---|
112 | make_ret, _ = tools.make( ".validate", error_file = ".validate.err", redirects = "2> /dev/null 1> /dev/null", ) |
---|
113 | if make_ret != 0: |
---|
114 | with open (".validate.err", "r") as myfile: |
---|
115 | error=myfile.read() |
---|
116 | print("ERROR: Invalid configuration %s:%s" % (arch.string, debug.string), file=sys.stderr) |
---|
117 | print(" verify returned : \n%s" % error, file=sys.stderr) |
---|
118 | tools.rm("%s/.validate.err" % BUILDDIR) |
---|
119 | sys.exit(1) |
---|
120 | |
---|
121 | tools.rm("%s/.validate.err" % BUILDDIR) |
---|