Changes in tools/autotool.py [28f4adb:603c8740] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/autotool.py
r28f4adb r603c8740 49 49 50 50 PACKAGE_BINUTILS = "usually part of binutils" 51 PACKAGE_GCC = "preferably version 4. 4.3or newer"51 PACKAGE_GCC = "preferably version 4.5.1 or newer" 52 52 PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain" 53 53 54 54 COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS." 55 56 PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, value) \\ 55 COMPILER_WARNING = "The compilation of HelenOS might fail." 56 57 PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\ 57 58 asm volatile ( \\ 58 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t %[val]\\n" \\59 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t" strc "\\t" conc "\\t%[val]\\n" \\ 59 60 : \\ 60 61 : [val] "n" (value) \\ 61 62 ) 62 63 63 #define DECLARE_INTSIZE(tag, type) \\ 64 AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, sizeof(unsigned type)); \\ 65 AUTOTOOL_DECLARE("intsize", "signed", tag, #type, sizeof(signed type)) 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", "", tag, STRING(type), "", "", sizeof(type)); 69 70 #define DECLARE_INTSIZE(tag, type, strc, conc) \\ 71 AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\ 72 AUTOTOOL_DECLARE("intsize", "signed", tag, #type, strc, conc, sizeof(signed type)); 66 73 67 74 int main(int argc, char *argv[]) 68 75 { 76 #ifdef __SIZE_TYPE__ 77 DECLARE_BUILTIN_TYPE("size", __SIZE_TYPE__); 78 #endif 79 #ifdef __WCHAR_TYPE__ 80 DECLARE_BUILTIN_TYPE("wchar", __WCHAR_TYPE__); 81 #endif 82 #ifdef __WINT_TYPE__ 83 DECLARE_BUILTIN_TYPE("wint", __WINT_TYPE__); 84 #endif 69 85 """ 70 86 … … 96 112 97 113 sys.exit(1) 114 115 def print_warning(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 warning:\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 time.sleep(5) 98 127 99 128 def sandbox_enter(): … … 186 215 check_app([common['STRIP'], "--version"], "GNU strip", details) 187 216 217 def decode_value(value): 218 "Decode integer value" 219 220 base = 10 221 222 if ((value.startswith('$')) or (value.startswith('#'))): 223 value = value[1:] 224 225 if (value.startswith('0x')): 226 value = value[2:] 227 base = 16 228 229 return int(value, base) 230 188 231 def probe_compiler(common, sizes): 189 232 "Generate, compile and parse probing source" … … 195 238 196 239 for typedef in sizes: 197 outf.write("\tDECLARE_INTSIZE(\"%s\", %s );\n" % (typedef['tag'], typedef['type']))240 outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc'])) 198 241 199 242 outf.write(PROBE_TAIL) … … 231 274 signed_tags = {} 232 275 276 unsigned_strcs = {} 277 signed_strcs = {} 278 279 unsigned_concs = {} 280 signed_concs = {} 281 282 builtins = {} 283 233 284 for j in range(len(lines)): 234 285 tokens = lines[j].strip().split("\t") … … 236 287 if (len(tokens) > 0): 237 288 if (tokens[0] == "AUTOTOOL_DECLARE"): 238 if (len(tokens) < 5):289 if (len(tokens) < 7): 239 290 print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL]) 240 291 … … 243 294 tag = tokens[3] 244 295 name = tokens[4] 245 value = tokens[5] 296 strc = tokens[5] 297 conc = tokens[6] 298 value = tokens[7] 246 299 247 300 if (category == "intsize"): 248 base = 10249 250 if ((value.startswith('$')) or (value.startswith('#'))):251 value = value[1:]252 253 if (value.startswith('0x')):254 value = value[2:]255 base = 16256 257 301 try: 258 value_int = int(value, base)302 value_int = decode_value(value) 259 303 except: 260 304 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL]) 261 305 262 306 if (subcategory == "unsigned"): 263 unsigned_sizes[ name] = value_int307 unsigned_sizes[value_int] = name 264 308 unsigned_tags[tag] = value_int 309 unsigned_strcs[value_int] = strc 310 unsigned_concs[value_int] = conc 265 311 elif (subcategory == "signed"): 266 signed_sizes[ name] = value_int312 signed_sizes[value_int] = name 267 313 signed_tags[tag] = value_int 314 signed_strcs[value_int] = strc 315 signed_concs[value_int] = conc 268 316 else: 269 317 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL]) 270 271 return {'unsigned_sizes' : unsigned_sizes, 'signed_sizes' : signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags} 272 273 def detect_uints(probe, bytes): 318 319 if (category == "builtin"): 320 try: 321 value_int = decode_value(value) 322 except: 323 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL]) 324 325 builtins[tag] = {'name': name, 'value': value_int} 326 327 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, 'builtins': builtins} 328 329 def detect_uints(probe, bytes, tags): 274 330 "Detect correct types for fixed-size integer types" 275 331 … … 278 334 279 335 for b in bytes: 336 if (not b in probe['unsigned_sizes']): 337 print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b, 338 COMPILER_FAIL]) 339 340 if (not b in probe['signed_sizes']): 341 print_error(['Unable to find appropriate signed integer type for %u bytes' % b, 342 COMPILER_FAIL]) 343 344 if (not b in probe['unsigned_strcs']): 345 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes' % b, 346 COMPILER_FAIL]) 347 348 if (not b in probe['signed_strcs']): 349 print_error(['Unable to find appropriate signed printf formatter for %u bytes' % b, 350 COMPILER_FAIL]) 351 352 if (not b in probe['unsigned_concs']): 353 print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b, 354 COMPILER_FAIL]) 355 356 if (not b in probe['signed_concs']): 357 print_error(['Unable to find appropriate signed literal macro for %u bytes' % b, 358 COMPILER_FAIL]) 359 360 typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)}) 361 typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)}) 362 363 macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)}) 364 macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)}) 365 macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)}) 366 macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)}) 367 macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)}) 368 369 name = probe['unsigned_concs'][b] 370 if ((name.startswith('@')) or (name == "")): 371 macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)}) 372 else: 373 macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)}) 374 375 name = probe['unsigned_concs'][b] 376 if ((name.startswith('@')) or (name == "")): 377 macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)}) 378 else: 379 macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)}) 380 381 for tag in tags: 382 newmacro = "U%s" % tag 383 if (not tag in probe['unsigned_tags']): 384 print_error(['Unable to find appropriate size macro for %s' % newmacro, 385 COMPILER_FAIL]) 386 387 oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8) 388 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 389 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 390 391 newmacro = tag 392 if (not tag in probe['unsigned_tags']): 393 print_error(['Unable to find appropriate size macro for %s' % newmacro, 394 COMPILER_FAIL]) 395 396 oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8) 397 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 398 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 399 400 fnd = True 401 402 if (not 'wchar' in probe['builtins']): 403 print_warning(['The compiler does not provide the macro __WCHAR_TYPE__', 404 'for defining the compiler-native type wchar_t. We are', 405 'forced to define wchar_t as a hardwired type int32_t.', 406 COMPILER_WARNING]) 280 407 fnd = False 281 newtype = "uint%s_t" % (b * 8) 282 283 for name, value in probe['unsigned_sizes'].items(): 284 if (value == b): 285 oldtype = "unsigned %s" % name 286 typedefs.append({'oldtype' : oldtype, 'newtype' : newtype}) 287 fnd = True 288 break 289 290 if (not fnd): 291 print_error(['Unable to find appropriate integer type for %s' % newtype, 292 COMPILER_FAIL]) 293 294 408 409 if (probe['builtins']['wchar']['value'] != 4): 410 print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining', 411 'the compiler-native type wchar_t is not compliant with', 412 'HelenOS. We are forced to define wchar_t as a hardwired', 413 'type int32_t.', 414 COMPILER_WARNING]) 295 415 fnd = False 296 newtype = "int%s_t" % (b * 8) 297 298 for name, value in probe['signed_sizes'].items(): 299 if (value == b): 300 oldtype = "signed %s" % name 301 typedefs.append({'oldtype' : oldtype, 'newtype' : newtype}) 302 fnd = True 303 break 304 305 if (not fnd): 306 print_error(['Unable to find appropriate integer type for %s' % newtype, 307 COMPILER_FAIL]) 308 309 for tag in ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG']: 310 fnd = False; 311 newmacro = "U%s" % tag 312 313 for name, value in probe['unsigned_tags'].items(): 314 if (name == tag): 315 oldmacro = "UINT%s" % (value * 8) 316 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 317 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 318 fnd = True 319 break 320 321 if (not fnd): 322 print_error(['Unable to find appropriate size macro for %s' % newmacro, 323 COMPILER_FAIL]) 324 325 fnd = False; 326 newmacro = tag 327 328 for name, value in probe['signed_tags'].items(): 329 if (name == tag): 330 oldmacro = "INT%s" % (value * 8) 331 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 332 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 333 fnd = True 334 break 335 336 if (not fnd): 337 print_error(['Unable to find appropriate size macro for %s' % newmacro, 338 COMPILER_FAIL]) 416 417 if (not fnd): 418 macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"}) 419 else: 420 macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"}) 421 422 fnd = True 423 424 if (not 'wint' in probe['builtins']): 425 print_warning(['The compiler does not provide the macro __WINT_TYPE__', 426 'for defining the compiler-native type wint_t. We are', 427 'forced to define wint_t as a hardwired type int32_t.', 428 COMPILER_WARNING]) 429 fnd = False 430 431 if (probe['builtins']['wint']['value'] != 4): 432 print_warning(['The compiler provided macro __WINT_TYPE__ for defining', 433 'the compiler-native type wint_t is not compliant with', 434 'HelenOS. We are forced to define wint_t as a hardwired', 435 'type int32_t.', 436 COMPILER_WARNING]) 437 fnd = False 438 439 if (not fnd): 440 macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"}) 441 else: 442 macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"}) 339 443 340 444 return {'macros': macros, 'typedefs': typedefs} … … 397 501 cross_prefix = os.environ['CROSS_PREFIX'] 398 502 else: 399 cross_prefix = "/usr/local "503 cross_prefix = "/usr/local/cross" 400 504 401 505 # Prefix binutils tools on Solaris … … 508 612 probe = probe_compiler(common, 509 613 [ 510 {'type': ' char', 'tag': 'CHAR'},511 {'type': ' short int', 'tag': 'SHORT'},512 {'type': 'int', 'tag': 'INT' },513 {'type': ' long int', 'tag': 'LONG'},514 {'type': ' long long int', 'tag': 'LLONG'}614 {'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'}, 615 {'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'}, 616 {'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'}, 617 {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'}, 618 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'} 515 619 ] 516 620 ) 517 621 518 maps = detect_uints(probe, [1, 2, 4, 8] )622 maps = detect_uints(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG']) 519 623 520 624 finally:
Note:
See TracChangeset
for help on using the changeset viewer.