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 shutil
|
---|
37 | import re
|
---|
38 | import time
|
---|
39 | import subprocess
|
---|
40 |
|
---|
41 | SANDBOX = 'autotool'
|
---|
42 | CONFIG = 'Makefile.config'
|
---|
43 | MAKEFILE = 'Makefile.common'
|
---|
44 | HEADER = 'common.h'
|
---|
45 | GUARD = 'AUTOTOOL_COMMON_H_'
|
---|
46 |
|
---|
47 | PROBE_SOURCE = 'probe.c'
|
---|
48 | PROBE_OUTPUT = 'probe.s'
|
---|
49 |
|
---|
50 | PACKAGE_BINUTILS = "usually part of binutils"
|
---|
51 | PACKAGE_GCC = "preferably version 4.7.0 or newer"
|
---|
52 | PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain"
|
---|
53 |
|
---|
54 | COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
|
---|
55 | COMPILER_WARNING = "The compilation of HelenOS might fail."
|
---|
56 |
|
---|
57 | PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
|
---|
58 | asm volatile ( \\
|
---|
59 | "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\
|
---|
60 | : \\
|
---|
61 | : [val] "n" (value) \\
|
---|
62 | )
|
---|
63 |
|
---|
64 | #define STRING(arg) STRING_ARG(arg)
|
---|
65 | #define STRING_ARG(arg) #arg
|
---|
66 |
|
---|
67 | #define DECLARE_BUILTIN_TYPE(tag, type) \\
|
---|
68 | AUTOTOOL_DECLARE("builtin_size", "", tag, STRING(type), "", "", sizeof(type)); \\
|
---|
69 | AUTOTOOL_DECLARE("builtin_sign", "unsigned long long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long long int)); \\
|
---|
70 | AUTOTOOL_DECLARE("builtin_sign", "unsigned long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long int)); \\
|
---|
71 | AUTOTOOL_DECLARE("builtin_sign", "unsigned int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned int)); \\
|
---|
72 | AUTOTOOL_DECLARE("builtin_sign", "unsigned short int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned short int)); \\
|
---|
73 | AUTOTOOL_DECLARE("builtin_sign", "unsigned char", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned char)); \\
|
---|
74 | AUTOTOOL_DECLARE("builtin_sign", "signed long long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long long int)); \\
|
---|
75 | AUTOTOOL_DECLARE("builtin_sign", "signed long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long int)); \\
|
---|
76 | AUTOTOOL_DECLARE("builtin_sign", "signed int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed int)); \\
|
---|
77 | AUTOTOOL_DECLARE("builtin_sign", "signed short int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed short int)); \\
|
---|
78 | AUTOTOOL_DECLARE("builtin_sign", "signed char", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed char));
|
---|
79 |
|
---|
80 | #define DECLARE_INTSIZE(tag, type, strc, conc) \\
|
---|
81 | AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\
|
---|
82 | AUTOTOOL_DECLARE("intsize", "signed", tag, #type, strc, conc, sizeof(signed type));
|
---|
83 |
|
---|
84 | #define DECLARE_FLOATSIZE(tag, type) \\
|
---|
85 | AUTOTOOL_DECLARE("floatsize", "", tag, #type, "", "", sizeof(type));
|
---|
86 |
|
---|
87 | int main(int argc, char *argv[])
|
---|
88 | {
|
---|
89 | #ifdef __SIZE_TYPE__
|
---|
90 | DECLARE_BUILTIN_TYPE("size", __SIZE_TYPE__);
|
---|
91 | #endif
|
---|
92 | #ifdef __WCHAR_TYPE__
|
---|
93 | DECLARE_BUILTIN_TYPE("wchar", __WCHAR_TYPE__);
|
---|
94 | #endif
|
---|
95 | #ifdef __WINT_TYPE__
|
---|
96 | DECLARE_BUILTIN_TYPE("wint", __WINT_TYPE__);
|
---|
97 | #endif
|
---|
98 | """
|
---|
99 |
|
---|
100 | PROBE_TAIL = """}
|
---|
101 | """
|
---|
102 |
|
---|
103 | def read_config(fname, config):
|
---|
104 | "Read HelenOS build configuration"
|
---|
105 |
|
---|
106 | inf = open(fname, 'r')
|
---|
107 |
|
---|
108 | for line in inf:
|
---|
109 | res = re.match(r'^(?:#!# )?([^#]\w*)\s*=\s*(.*?)\s*$', line)
|
---|
110 | if (res):
|
---|
111 | config[res.group(1)] = res.group(2)
|
---|
112 |
|
---|
113 | inf.close()
|
---|
114 |
|
---|
115 | def print_error(msg):
|
---|
116 | "Print a bold error message"
|
---|
117 |
|
---|
118 | sys.stderr.write("\n")
|
---|
119 | sys.stderr.write("######################################################################\n")
|
---|
120 | sys.stderr.write("HelenOS build sanity check error:\n")
|
---|
121 | sys.stderr.write("\n")
|
---|
122 | sys.stderr.write("%s\n" % "\n".join(msg))
|
---|
123 | sys.stderr.write("######################################################################\n")
|
---|
124 | sys.stderr.write("\n")
|
---|
125 |
|
---|
126 | sys.exit(1)
|
---|
127 |
|
---|
128 | def print_warning(msg):
|
---|
129 | "Print a bold error message"
|
---|
130 |
|
---|
131 | sys.stderr.write("\n")
|
---|
132 | sys.stderr.write("######################################################################\n")
|
---|
133 | sys.stderr.write("HelenOS build sanity check warning:\n")
|
---|
134 | sys.stderr.write("\n")
|
---|
135 | sys.stderr.write("%s\n" % "\n".join(msg))
|
---|
136 | sys.stderr.write("######################################################################\n")
|
---|
137 | sys.stderr.write("\n")
|
---|
138 |
|
---|
139 | time.sleep(5)
|
---|
140 |
|
---|
141 | def sandbox_enter():
|
---|
142 | "Create a temporal sandbox directory for running tests"
|
---|
143 |
|
---|
144 | if (os.path.exists(SANDBOX)):
|
---|
145 | if (os.path.isdir(SANDBOX)):
|
---|
146 | try:
|
---|
147 | shutil.rmtree(SANDBOX)
|
---|
148 | except:
|
---|
149 | print_error(["Unable to cleanup the directory \"%s\"." % SANDBOX])
|
---|
150 | else:
|
---|
151 | print_error(["Please inspect and remove unexpected directory,",
|
---|
152 | "entry \"%s\"." % SANDBOX])
|
---|
153 |
|
---|
154 | try:
|
---|
155 | os.mkdir(SANDBOX)
|
---|
156 | except:
|
---|
157 | print_error(["Unable to create sandbox directory \"%s\"." % SANDBOX])
|
---|
158 |
|
---|
159 | owd = os.getcwd()
|
---|
160 | os.chdir(SANDBOX)
|
---|
161 |
|
---|
162 | return owd
|
---|
163 |
|
---|
164 | def sandbox_leave(owd):
|
---|
165 | "Leave the temporal sandbox directory"
|
---|
166 |
|
---|
167 | os.chdir(owd)
|
---|
168 |
|
---|
169 | def check_config(config, key):
|
---|
170 | "Check whether the configuration key exists"
|
---|
171 |
|
---|
172 | if (not key in config):
|
---|
173 | print_error(["Build configuration of HelenOS does not contain %s." % key,
|
---|
174 | "Try running \"make config\" again.",
|
---|
175 | "If the problem persists, please contact the developers of HelenOS."])
|
---|
176 |
|
---|
177 | def check_common(common, key):
|
---|
178 | "Check whether the common key exists"
|
---|
179 |
|
---|
180 | if (not key in common):
|
---|
181 | print_error(["Failed to determine the value %s." % key,
|
---|
182 | "Please contact the developers of HelenOS."])
|
---|
183 |
|
---|
184 | def get_target(config, needs_clang = False):
|
---|
185 | target = None
|
---|
186 | gnu_target = None
|
---|
187 | clang_target = None
|
---|
188 | cc_args = []
|
---|
189 |
|
---|
190 | if (config['PLATFORM'] == "abs32le"):
|
---|
191 | check_config(config, "CROSS_TARGET")
|
---|
192 | target = config['CROSS_TARGET']
|
---|
193 |
|
---|
194 | if (config['CROSS_TARGET'] == "arm32"):
|
---|
195 | gnu_target = "arm-linux-gnueabi"
|
---|
196 |
|
---|
197 | if (config['CROSS_TARGET'] == "ia32"):
|
---|
198 | gnu_target = "i686-pc-linux-gnu"
|
---|
199 |
|
---|
200 | if (config['CROSS_TARGET'] == "mips32"):
|
---|
201 | gnu_target = "mipsel-linux-gnu"
|
---|
202 | common['CC_ARGS'].append("-mabi=32")
|
---|
203 |
|
---|
204 | if (config['PLATFORM'] == "amd64"):
|
---|
205 | target = config['PLATFORM']
|
---|
206 | gnu_target = "amd64-linux-gnu"
|
---|
207 | clang_target = "x86_64-uknown-linux"
|
---|
208 |
|
---|
209 | if (config['PLATFORM'] == "arm32"):
|
---|
210 | target = config['PLATFORM']
|
---|
211 | gnu_target = "arm-linux-gnueabi"
|
---|
212 |
|
---|
213 | if (config['PLATFORM'] == "ia32"):
|
---|
214 | target = config['PLATFORM']
|
---|
215 | gnu_target = "i686-pc-linux-gnu"
|
---|
216 | clang_target = "i386-uknown-linux"
|
---|
217 |
|
---|
218 | if (config['PLATFORM'] == "ia64"):
|
---|
219 | target = config['PLATFORM']
|
---|
220 | gnu_target = "ia64-pc-linux-gnu"
|
---|
221 |
|
---|
222 | if (config['PLATFORM'] == "mips32"):
|
---|
223 | check_config(config, "MACHINE")
|
---|
224 | cc_args.append("-mabi=32")
|
---|
225 |
|
---|
226 | if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
|
---|
227 | target = config['PLATFORM']
|
---|
228 | gnu_target = "mipsel-linux-gnu"
|
---|
229 |
|
---|
230 | if (config['MACHINE'] == "bgxemul"):
|
---|
231 | target = "mips32eb"
|
---|
232 | gnu_target = "mips-linux-gnu"
|
---|
233 |
|
---|
234 | if (config['PLATFORM'] == "mips64"):
|
---|
235 | check_config(config, "MACHINE")
|
---|
236 | cc_args.append("-mabi=64")
|
---|
237 |
|
---|
238 | if (config['MACHINE'] == "msim"):
|
---|
239 | target = config['PLATFORM']
|
---|
240 | gnu_target = "mips64el-linux-gnu"
|
---|
241 |
|
---|
242 | if (config['PLATFORM'] == "ppc32"):
|
---|
243 | target = config['PLATFORM']
|
---|
244 | gnu_target = "ppc-linux-gnu"
|
---|
245 |
|
---|
246 | if (config['PLATFORM'] == "sparc64"):
|
---|
247 | target = config['PLATFORM']
|
---|
248 | gnu_target = "sparc64-linux-gnu"
|
---|
249 |
|
---|
250 | if (target is None) or (gnu_target is None) or (clang_target is None and needs_clang):
|
---|
251 | print_error(["Failed to determine target for compiler.",
|
---|
252 | "Please contact the developers of HelenOS."])
|
---|
253 |
|
---|
254 | return (target, cc_args, gnu_target, clang_target)
|
---|
255 |
|
---|
256 | def check_app(args, name, details):
|
---|
257 | "Check whether an application can be executed"
|
---|
258 |
|
---|
259 | try:
|
---|
260 | sys.stderr.write("Checking for %s ... " % args[0])
|
---|
261 | subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
---|
262 | except:
|
---|
263 | sys.stderr.write("failed\n")
|
---|
264 | print_error(["%s is missing." % name,
|
---|
265 | "",
|
---|
266 | "Execution of \"%s\" has failed. Please make sure that it" % " ".join(args),
|
---|
267 | "is installed in your system (%s)." % details])
|
---|
268 |
|
---|
269 | sys.stderr.write("ok\n")
|
---|
270 |
|
---|
271 | def check_app_alternatives(alts, args, name, details):
|
---|
272 | "Check whether an application can be executed (use several alternatives)"
|
---|
273 |
|
---|
274 | tried = []
|
---|
275 | found = None
|
---|
276 |
|
---|
277 | for alt in alts:
|
---|
278 | working = True
|
---|
279 | cmdline = [alt] + args
|
---|
280 | tried.append(" ".join(cmdline))
|
---|
281 |
|
---|
282 | try:
|
---|
283 | sys.stderr.write("Checking for %s ... " % alt)
|
---|
284 | subprocess.Popen(cmdline, stdout = subprocess.PIPE, stderr = subprocess.PIPE).wait()
|
---|
285 | except:
|
---|
286 | sys.stderr.write("failed\n")
|
---|
287 | working = False
|
---|
288 |
|
---|
289 | if (working):
|
---|
290 | sys.stderr.write("ok\n")
|
---|
291 | found = alt
|
---|
292 | break
|
---|
293 |
|
---|
294 | if (found is None):
|
---|
295 | print_error(["%s is missing." % name,
|
---|
296 | "",
|
---|
297 | "Please make sure that it is installed in your",
|
---|
298 | "system (%s)." % details,
|
---|
299 | "",
|
---|
300 | "The following alternatives were tried:"] + tried)
|
---|
301 |
|
---|
302 | return found
|
---|
303 |
|
---|
304 | def check_gcc(path, prefix, common, details):
|
---|
305 | "Check for GCC"
|
---|
306 |
|
---|
307 | common['GCC'] = "%sgcc" % prefix
|
---|
308 |
|
---|
309 | if (not path is None):
|
---|
310 | common['GCC'] = "%s/%s" % (path, common['GCC'])
|
---|
311 |
|
---|
312 | check_app([common['GCC'], "--version"], "GNU GCC", details)
|
---|
313 |
|
---|
314 | def check_binutils(path, prefix, common, details):
|
---|
315 | "Check for binutils toolchain"
|
---|
316 |
|
---|
317 | common['AS'] = "%sas" % prefix
|
---|
318 | common['LD'] = "%sld" % prefix
|
---|
319 | common['AR'] = "%sar" % prefix
|
---|
320 | common['OBJCOPY'] = "%sobjcopy" % prefix
|
---|
321 | common['OBJDUMP'] = "%sobjdump" % prefix
|
---|
322 | common['STRIP'] = "%sstrip" % prefix
|
---|
323 |
|
---|
324 | if (not path is None):
|
---|
325 | for key in ["AS", "LD", "AR", "OBJCOPY", "OBJDUMP", "STRIP"]:
|
---|
326 | common[key] = "%s/%s" % (path, common[key])
|
---|
327 |
|
---|
328 | check_app([common['AS'], "--version"], "GNU Assembler", details)
|
---|
329 | check_app([common['LD'], "--version"], "GNU Linker", details)
|
---|
330 | check_app([common['AR'], "--version"], "GNU Archiver", details)
|
---|
331 | check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
|
---|
332 | check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
|
---|
333 | check_app([common['STRIP'], "--version"], "GNU strip", details)
|
---|
334 |
|
---|
335 | def decode_value(value):
|
---|
336 | "Decode integer value"
|
---|
337 |
|
---|
338 | base = 10
|
---|
339 |
|
---|
340 | if ((value.startswith('$')) or (value.startswith('#'))):
|
---|
341 | value = value[1:]
|
---|
342 |
|
---|
343 | if (value.startswith('0x')):
|
---|
344 | value = value[2:]
|
---|
345 | base = 16
|
---|
346 |
|
---|
347 | return int(value, base)
|
---|
348 |
|
---|
349 | def probe_compiler(common, intsizes, floatsizes):
|
---|
350 | "Generate, compile and parse probing source"
|
---|
351 |
|
---|
352 | check_common(common, "CC")
|
---|
353 |
|
---|
354 | outf = open(PROBE_SOURCE, 'w')
|
---|
355 | outf.write(PROBE_HEAD)
|
---|
356 |
|
---|
357 | for typedef in intsizes:
|
---|
358 | outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc']))
|
---|
359 |
|
---|
360 | for typedef in floatsizes:
|
---|
361 | outf.write("\nDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type']))
|
---|
362 |
|
---|
363 | outf.write(PROBE_TAIL)
|
---|
364 | outf.close()
|
---|
365 |
|
---|
366 | args = [common['CC']]
|
---|
367 | args.extend(common['CC_ARGS'])
|
---|
368 | args.extend(["-S", "-o", PROBE_OUTPUT, PROBE_SOURCE])
|
---|
369 |
|
---|
370 | try:
|
---|
371 | sys.stderr.write("Checking compiler properties ... ")
|
---|
372 | output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
|
---|
373 | except:
|
---|
374 | sys.stderr.write("failed\n")
|
---|
375 | print_error(["Error executing \"%s\"." % " ".join(args),
|
---|
376 | "Make sure that the compiler works properly."])
|
---|
377 |
|
---|
378 | if (not os.path.isfile(PROBE_OUTPUT)):
|
---|
379 | sys.stderr.write("failed\n")
|
---|
380 | print(output[1])
|
---|
381 | print_error(["Error executing \"%s\"." % " ".join(args),
|
---|
382 | "The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
|
---|
383 | "",
|
---|
384 | output[0],
|
---|
385 | output[1]])
|
---|
386 |
|
---|
387 | sys.stderr.write("ok\n")
|
---|
388 |
|
---|
389 | inf = open(PROBE_OUTPUT, 'r')
|
---|
390 | lines = inf.readlines()
|
---|
391 | inf.close()
|
---|
392 |
|
---|
393 | unsigned_sizes = {}
|
---|
394 | signed_sizes = {}
|
---|
395 |
|
---|
396 | unsigned_tags = {}
|
---|
397 | signed_tags = {}
|
---|
398 |
|
---|
399 | unsigned_strcs = {}
|
---|
400 | signed_strcs = {}
|
---|
401 |
|
---|
402 | unsigned_concs = {}
|
---|
403 | signed_concs = {}
|
---|
404 |
|
---|
405 | float_tags = {}
|
---|
406 |
|
---|
407 | builtin_sizes = {}
|
---|
408 | builtin_signs = {}
|
---|
409 |
|
---|
410 | for j in range(len(lines)):
|
---|
411 | tokens = lines[j].strip().split("\t")
|
---|
412 |
|
---|
413 | if (len(tokens) > 0):
|
---|
414 | if (tokens[0] == "AUTOTOOL_DECLARE"):
|
---|
415 | if (len(tokens) < 7):
|
---|
416 | print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
417 |
|
---|
418 | category = tokens[1]
|
---|
419 | subcategory = tokens[2]
|
---|
420 | tag = tokens[3]
|
---|
421 | name = tokens[4]
|
---|
422 | strc = tokens[5]
|
---|
423 | conc = tokens[6]
|
---|
424 | value = tokens[7]
|
---|
425 |
|
---|
426 | if (category == "intsize"):
|
---|
427 | try:
|
---|
428 | value_int = decode_value(value)
|
---|
429 | except:
|
---|
430 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
431 |
|
---|
432 | if (subcategory == "unsigned"):
|
---|
433 | unsigned_sizes[value_int] = name
|
---|
434 | unsigned_tags[tag] = value_int
|
---|
435 | unsigned_strcs[value_int] = strc
|
---|
436 | unsigned_concs[value_int] = conc
|
---|
437 | elif (subcategory == "signed"):
|
---|
438 | signed_sizes[value_int] = name
|
---|
439 | signed_tags[tag] = value_int
|
---|
440 | signed_strcs[value_int] = strc
|
---|
441 | signed_concs[value_int] = conc
|
---|
442 | else:
|
---|
443 | print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
444 |
|
---|
445 | if (category == "floatsize"):
|
---|
446 | try:
|
---|
447 | value_int = decode_value(value)
|
---|
448 | except:
|
---|
449 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
450 |
|
---|
451 | float_tags[tag] = value_int
|
---|
452 |
|
---|
453 | if (category == "builtin_size"):
|
---|
454 | try:
|
---|
455 | value_int = decode_value(value)
|
---|
456 | except:
|
---|
457 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
458 |
|
---|
459 | builtin_sizes[tag] = {'name': name, 'value': value_int}
|
---|
460 |
|
---|
461 | if (category == "builtin_sign"):
|
---|
462 | try:
|
---|
463 | value_int = decode_value(value)
|
---|
464 | except:
|
---|
465 | print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
466 |
|
---|
467 | if (value_int == 1):
|
---|
468 | if (not tag in builtin_signs):
|
---|
469 | builtin_signs[tag] = strc;
|
---|
470 | elif (builtin_signs[tag] != strc):
|
---|
471 | print_error(["Inconsistent builtin type detection in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
|
---|
472 |
|
---|
473 | return {'unsigned_sizes': unsigned_sizes, 'signed_sizes': signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags, 'unsigned_strcs': unsigned_strcs, 'signed_strcs': signed_strcs, 'unsigned_concs': unsigned_concs, 'signed_concs': signed_concs, 'float_tags': float_tags, 'builtin_sizes': builtin_sizes, 'builtin_signs': builtin_signs}
|
---|
474 |
|
---|
475 | def detect_sizes(probe, bytes, inttags, floattags):
|
---|
476 | "Detect correct types for fixed-size types"
|
---|
477 |
|
---|
478 | macros = []
|
---|
479 | typedefs = []
|
---|
480 |
|
---|
481 | for b in bytes:
|
---|
482 | if (not b in probe['unsigned_sizes']):
|
---|
483 | print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b,
|
---|
484 | COMPILER_FAIL])
|
---|
485 |
|
---|
486 | if (not b in probe['signed_sizes']):
|
---|
487 | print_error(['Unable to find appropriate signed integer type for %u bytes.' % b,
|
---|
488 | COMPILER_FAIL])
|
---|
489 |
|
---|
490 | if (not b in probe['unsigned_strcs']):
|
---|
491 | print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b,
|
---|
492 | COMPILER_FAIL])
|
---|
493 |
|
---|
494 | if (not b in probe['signed_strcs']):
|
---|
495 | print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b,
|
---|
496 | COMPILER_FAIL])
|
---|
497 |
|
---|
498 | if (not b in probe['unsigned_concs']):
|
---|
499 | print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b,
|
---|
500 | COMPILER_FAIL])
|
---|
501 |
|
---|
502 | if (not b in probe['signed_concs']):
|
---|
503 | print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b,
|
---|
504 | COMPILER_FAIL])
|
---|
505 |
|
---|
506 | typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
|
---|
507 | typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
|
---|
508 |
|
---|
509 | macros.append({'oldmacro': "unsigned %s" % probe['unsigned_sizes'][b], 'newmacro': "UINT%u_T" % (b * 8)})
|
---|
510 | macros.append({'oldmacro': "signed %s" % probe['signed_sizes'][b], 'newmacro': "INT%u_T" % (b * 8)})
|
---|
511 |
|
---|
512 | macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
|
---|
513 | macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
|
---|
514 | macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
|
---|
515 | macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
|
---|
516 | macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
|
---|
517 |
|
---|
518 | name = probe['unsigned_concs'][b]
|
---|
519 | if ((name.startswith('@')) or (name == "")):
|
---|
520 | macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
---|
521 | else:
|
---|
522 | macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
|
---|
523 |
|
---|
524 | name = probe['unsigned_concs'][b]
|
---|
525 | if ((name.startswith('@')) or (name == "")):
|
---|
526 | macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
|
---|
527 | else:
|
---|
528 | macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
|
---|
529 |
|
---|
530 | for tag in inttags:
|
---|
531 | newmacro = "U%s" % tag
|
---|
532 | if (not tag in probe['unsigned_tags']):
|
---|
533 | print_error(['Unable to find appropriate size macro for %s.' % newmacro,
|
---|
534 | COMPILER_FAIL])
|
---|
535 |
|
---|
536 | oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
|
---|
537 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
---|
538 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
---|
539 | macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)})
|
---|
540 |
|
---|
541 | newmacro = tag
|
---|
542 | if (not tag in probe['signed_tags']):
|
---|
543 | print_error(['Unable to find appropriate size macro for %s' % newmacro,
|
---|
544 | COMPILER_FAIL])
|
---|
545 |
|
---|
546 | oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
|
---|
547 | macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
|
---|
548 | macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
|
---|
549 | macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['signed_tags'][tag] * 8)})
|
---|
550 |
|
---|
551 | for tag in floattags:
|
---|
552 | if (not tag in probe['float_tags']):
|
---|
553 | print_error(['Unable to find appropriate size macro for %s' % tag,
|
---|
554 | COMPILER_FAIL])
|
---|
555 |
|
---|
556 | macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['float_tags'][tag] * 8)})
|
---|
557 |
|
---|
558 | if (not 'size' in probe['builtin_signs']):
|
---|
559 | print_error(['Unable to determine whether size_t is signed or unsigned.',
|
---|
560 | COMPILER_FAIL])
|
---|
561 |
|
---|
562 | if (probe['builtin_signs']['size'] != 'unsigned'):
|
---|
563 | print_error(['The type size_t is not unsigned.',
|
---|
564 | COMPILER_FAIL])
|
---|
565 |
|
---|
566 | fnd = True
|
---|
567 |
|
---|
568 | if (not 'wchar' in probe['builtin_sizes']):
|
---|
569 | print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
|
---|
570 | 'for defining the compiler-native type wchar_t. We are',
|
---|
571 | 'forced to define wchar_t as a hardwired type int32_t.',
|
---|
572 | COMPILER_WARNING])
|
---|
573 | fnd = False
|
---|
574 |
|
---|
575 | if (probe['builtin_sizes']['wchar']['value'] != 4):
|
---|
576 | print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
|
---|
577 | 'the compiler-native type wchar_t is not compliant with',
|
---|
578 | 'HelenOS. We are forced to define wchar_t as a hardwired',
|
---|
579 | 'type int32_t.',
|
---|
580 | COMPILER_WARNING])
|
---|
581 | fnd = False
|
---|
582 |
|
---|
583 | if (not fnd):
|
---|
584 | macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
|
---|
585 | else:
|
---|
586 | macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
|
---|
587 |
|
---|
588 | if (not 'wchar' in probe['builtin_signs']):
|
---|
589 | print_error(['Unable to determine whether wchar_t is signed or unsigned.',
|
---|
590 | COMPILER_FAIL])
|
---|
591 |
|
---|
592 | if (probe['builtin_signs']['wchar'] == 'unsigned'):
|
---|
593 | macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_UNSIGNED'})
|
---|
594 | if (probe['builtin_signs']['wchar'] == 'signed'):
|
---|
595 | macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_SIGNED'})
|
---|
596 |
|
---|
597 | fnd = True
|
---|
598 |
|
---|
599 | if (not 'wint' in probe['builtin_sizes']):
|
---|
600 | print_warning(['The compiler does not provide the macro __WINT_TYPE__',
|
---|
601 | 'for defining the compiler-native type wint_t. We are',
|
---|
602 | 'forced to define wint_t as a hardwired type int32_t.',
|
---|
603 | COMPILER_WARNING])
|
---|
604 | fnd = False
|
---|
605 |
|
---|
606 | if (probe['builtin_sizes']['wint']['value'] != 4):
|
---|
607 | print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
|
---|
608 | 'the compiler-native type wint_t is not compliant with',
|
---|
609 | 'HelenOS. We are forced to define wint_t as a hardwired',
|
---|
610 | 'type int32_t.',
|
---|
611 | COMPILER_WARNING])
|
---|
612 | fnd = False
|
---|
613 |
|
---|
614 | if (not fnd):
|
---|
615 | macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
|
---|
616 | else:
|
---|
617 | macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
|
---|
618 |
|
---|
619 | if (not 'wint' in probe['builtin_signs']):
|
---|
620 | print_error(['Unable to determine whether wint_t is signed or unsigned.',
|
---|
621 | COMPILER_FAIL])
|
---|
622 |
|
---|
623 | if (probe['builtin_signs']['wint'] == 'unsigned'):
|
---|
624 | macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_UNSIGNED'})
|
---|
625 | if (probe['builtin_signs']['wint'] == 'signed'):
|
---|
626 | macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_SIGNED'})
|
---|
627 |
|
---|
628 | return {'macros': macros, 'typedefs': typedefs}
|
---|
629 |
|
---|
630 | def create_makefile(mkname, common):
|
---|
631 | "Create makefile output"
|
---|
632 |
|
---|
633 | outmk = open(mkname, 'w')
|
---|
634 |
|
---|
635 | outmk.write('#########################################\n')
|
---|
636 | outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
|
---|
637 | outmk.write('## Generated by: tools/autotool.py ##\n')
|
---|
638 | outmk.write('#########################################\n\n')
|
---|
639 |
|
---|
640 | for key, value in common.items():
|
---|
641 | if (type(value) is list):
|
---|
642 | outmk.write('%s = %s\n' % (key, " ".join(value)))
|
---|
643 | else:
|
---|
644 | outmk.write('%s = %s\n' % (key, value))
|
---|
645 |
|
---|
646 | outmk.close()
|
---|
647 |
|
---|
648 | def create_header(hdname, maps):
|
---|
649 | "Create header output"
|
---|
650 |
|
---|
651 | outhd = open(hdname, 'w')
|
---|
652 |
|
---|
653 | outhd.write('/***************************************\n')
|
---|
654 | outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
|
---|
655 | outhd.write(' * Generated by: tools/autotool.py *\n')
|
---|
656 | outhd.write(' ***************************************/\n\n')
|
---|
657 |
|
---|
658 | outhd.write('#ifndef %s\n' % GUARD)
|
---|
659 | outhd.write('#define %s\n\n' % GUARD)
|
---|
660 |
|
---|
661 | for macro in maps['macros']:
|
---|
662 | outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro']))
|
---|
663 |
|
---|
664 | outhd.write('\n')
|
---|
665 |
|
---|
666 | for typedef in maps['typedefs']:
|
---|
667 | outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
|
---|
668 |
|
---|
669 | outhd.write('\n#endif\n')
|
---|
670 | outhd.close()
|
---|
671 |
|
---|
672 | def main():
|
---|
673 | config = {}
|
---|
674 | common = {}
|
---|
675 |
|
---|
676 | # Read and check configuration
|
---|
677 | if os.path.exists(CONFIG):
|
---|
678 | read_config(CONFIG, config)
|
---|
679 | else:
|
---|
680 | print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
|
---|
681 | "configuration phase of HelenOS build went OK. Try running",
|
---|
682 | "\"make config\" again."])
|
---|
683 |
|
---|
684 | check_config(config, "PLATFORM")
|
---|
685 | check_config(config, "COMPILER")
|
---|
686 | check_config(config, "BARCH")
|
---|
687 |
|
---|
688 | # Cross-compiler prefix
|
---|
689 | if ('CROSS_PREFIX' in os.environ):
|
---|
690 | cross_prefix = os.environ['CROSS_PREFIX']
|
---|
691 | else:
|
---|
692 | cross_prefix = "/usr/local/cross"
|
---|
693 |
|
---|
694 | # Prefix binutils tools on Solaris
|
---|
695 | if (os.uname()[0] == "SunOS"):
|
---|
696 | binutils_prefix = "g"
|
---|
697 | else:
|
---|
698 | binutils_prefix = ""
|
---|
699 |
|
---|
700 | owd = sandbox_enter()
|
---|
701 |
|
---|
702 | try:
|
---|
703 | # Common utilities
|
---|
704 | check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
|
---|
705 | check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
|
---|
706 | check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
|
---|
707 | check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
|
---|
708 | check_app(["find", "--version"], "Find utility", "usually part of findutils")
|
---|
709 | check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
|
---|
710 | check_app(["make", "--version"], "Make utility", "preferably GNU Make")
|
---|
711 | check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
|
---|
712 |
|
---|
713 | # Compiler
|
---|
714 | common['CC_ARGS'] = []
|
---|
715 | if (config['COMPILER'] == "gcc_cross"):
|
---|
716 | target, cc_args, gnu_target, clang_target_unused = get_target(config)
|
---|
717 |
|
---|
718 | path = "%s/%s/bin" % (cross_prefix, target)
|
---|
719 | prefix = "%s-" % gnu_target
|
---|
720 |
|
---|
721 | check_gcc(path, prefix, common, PACKAGE_CROSS)
|
---|
722 | check_binutils(path, prefix, common, PACKAGE_CROSS)
|
---|
723 |
|
---|
724 | check_common(common, "GCC")
|
---|
725 | common['CC'] = common['GCC']
|
---|
726 | common['CC_ARGS'].extend(cc_args)
|
---|
727 |
|
---|
728 | if (config['COMPILER'] == "gcc_native"):
|
---|
729 | check_gcc(None, "", common, PACKAGE_GCC)
|
---|
730 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
---|
731 |
|
---|
732 | check_common(common, "GCC")
|
---|
733 | common['CC'] = common['GCC']
|
---|
734 |
|
---|
735 | if (config['COMPILER'] == "icc"):
|
---|
736 | common['CC'] = "icc"
|
---|
737 | check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
|
---|
738 | check_gcc(None, "", common, PACKAGE_GCC)
|
---|
739 | check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
|
---|
740 |
|
---|
741 | if (config['COMPILER'] == "clang"):
|
---|
742 | target, cc_args, gnu_target, clang_target = get_target(config, True)
|
---|
743 | path = "%s/%s/bin" % (cross_prefix, target)
|
---|
744 | prefix = "%s-" % gnu_target
|
---|
745 |
|
---|
746 | common['CC'] = "clang"
|
---|
747 | common['CC_ARGS'].extend(cc_args)
|
---|
748 | common['CC_ARGS'].append("-target")
|
---|
749 | common['CC_ARGS'].append(clang_target)
|
---|
750 | check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
|
---|
751 | check_gcc(path, prefix, common, PACKAGE_GCC)
|
---|
752 | check_binutils(path, prefix, common, PACKAGE_BINUTILS)
|
---|
753 |
|
---|
754 | # Platform-specific utilities
|
---|
755 | if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
|
---|
756 | common['GENISOIMAGE'] = check_app_alternatives(["mkisofs", "genisoimage"], ["--version"], "ISO 9660 creation utility", "usually part of genisoimage")
|
---|
757 |
|
---|
758 | probe = probe_compiler(common,
|
---|
759 | [
|
---|
760 | {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
|
---|
761 | {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
|
---|
762 | {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
|
---|
763 | {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
|
---|
764 | {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
|
---|
765 | ],
|
---|
766 | [
|
---|
767 | {'type': 'long double', 'tag': 'LONG_DOUBLE'},
|
---|
768 | {'type': 'double', 'tag': 'DOUBLE'},
|
---|
769 | {'type': 'float', 'tag': 'FLOAT'}
|
---|
770 | ]
|
---|
771 | )
|
---|
772 |
|
---|
773 | maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT'])
|
---|
774 |
|
---|
775 | finally:
|
---|
776 | sandbox_leave(owd)
|
---|
777 |
|
---|
778 | create_makefile(MAKEFILE, common)
|
---|
779 | create_header(HEADER, maps)
|
---|
780 |
|
---|
781 | return 0
|
---|
782 |
|
---|
783 | if __name__ == '__main__':
|
---|
784 | sys.exit(main())
|
---|