121
183
check_app([common['OBJCOPY'], "--version"], "GNU Objcopy utility", details)
122
184
check_app([common['OBJDUMP'], "--version"], "GNU Objdump utility", details)
124
def create_output(cmname, common):
125
"Create common parameters output"
127
outcm = file(cmname, 'w')
129
outcm.write('#########################################\n')
130
outcm.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
131
outcm.write('#########################################\n\n')
186
def probe_compiler(common, sizes):
187
"Generate, compile and parse probing source"
189
check_common(common, "CC")
191
outf = file(PROBE_SOURCE, 'w')
192
outf.write(PROBE_HEAD)
194
for typedef in sizes:
195
outf.write("\tDECLARE_INTSIZE(%s);\n" % typedef)
197
outf.write(PROBE_TAIL)
200
args = [common['CC'], "-S", "-o", PROBE_OUTPUT, PROBE_SOURCE]
203
sys.stderr.write("Checking compiler properties ... ")
204
output = subprocess.Popen(args, stdout = subprocess.PIPE, stderr = subprocess.PIPE).communicate()
206
sys.stderr.write("failed\n")
207
print_error(["Error executing \"%s\"." % " ".join(args),
208
"Make sure that the compiler works properly."])
210
if (not os.path.isfile(PROBE_OUTPUT)):
211
sys.stderr.write("failed\n")
213
print_error(["Error executing \"%s\"." % " ".join(args),
214
"The compiler did not produce the output file \"%s\"." % PROBE_OUTPUT,
219
sys.stderr.write("ok\n")
221
inf = file(PROBE_OUTPUT, 'r')
222
lines = inf.readlines()
228
for j in range(len(lines)):
229
tokens = lines[j].strip().split("\t")
231
if (len(tokens) > 0):
232
if (tokens[0] == "AUTOTOOL_DECLARE"):
233
if (len(tokens) < 5):
234
print_error(["Malformed declaration in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
237
subcategory = tokens[2]
241
if (category == "intsize"):
244
if ((value.startswith('$')) or (value.startswith('#'))):
247
if (value.startswith('0x')):
252
value_int = int(value, base)
254
print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
256
if (subcategory == "unsigned"):
257
unsigned_sizes[name] = value_int
258
elif (subcategory == "signed"):
259
signed_sizes[name] = value_int
261
print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
263
return {'unsigned_sizes' : unsigned_sizes, 'signed_sizes' : signed_sizes}
265
def detect_uints(unsigned_sizes, signed_sizes, bytes):
266
"Detect correct types for fixed-size integer types"
272
newtype = "uint%s_t" % (b * 8)
274
for name, value in unsigned_sizes.items():
276
oldtype = "unsigned %s" % name
277
typedefs.append({'oldtype' : oldtype, 'newtype' : newtype})
282
print_error(['Unable to find appropriate integer type for %s' % newtype,
287
newtype = "int%s_t" % (b * 8)
289
for name, value in signed_sizes.items():
291
oldtype = "signed %s" % name
292
typedefs.append({'oldtype' : oldtype, 'newtype' : newtype})
297
print_error(['Unable to find appropriate integer type for %s' % newtype,
302
def create_makefile(mkname, common):
303
"Create makefile output"
305
outmk = file(mkname, 'w')
307
outmk.write('#########################################\n')
308
outmk.write('## AUTO-GENERATED FILE, DO NOT EDIT!!! ##\n')
309
outmk.write('#########################################\n\n')
133
311
for key, value in common.items():
134
outcm.write('%s = %s\n' % (key, value))
312
outmk.write('%s = %s\n' % (key, value))
316
def create_header(hdname, typedefs):
317
"Create header output"
319
outhd = file(hdname, 'w')
321
outhd.write('/***************************************\n')
322
outhd.write(' * AUTO-GENERATED FILE, DO NOT EDIT!!! *\n')
323
outhd.write(' ***************************************/\n\n')
325
outhd.write('#ifndef %s\n' % GUARD)
326
outhd.write('#define %s\n\n' % GUARD)
328
for typedef in typedefs:
329
outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype']))
331
outhd.write('\n#endif\n')
142
338
# Read and check configuration
143
if os.path.exists(MAKEFILE):
144
read_config(MAKEFILE, config)
339
if os.path.exists(CONFIG):
340
read_config(CONFIG, config)
146
print_error(["Configuration file %s not found! Make sure that the" % MAKEFILE,
342
print_error(["Configuration file %s not found! Make sure that the" % CONFIG,
147
343
"configuration phase of HelenOS build went OK. Try running",
148
344
"\"make config\" again."])
164
360
binutils_prefix = ""
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")
362
owd = sandbox_enter()
177
if (config['COMPILER'] == "gcc_cross"):
178
if (config['PLATFORM'] == "abs32le"):
179
check_config(config, "CROSS_TARGET")
180
target = config['CROSS_TARGET']
182
if (config['CROSS_TARGET'] == "arm32"):
366
check_app(["ln", "--version"], "Symlink utility", "usually part of coreutils")
367
check_app(["rm", "--version"], "File remove utility", "usually part of coreutils")
368
check_app(["mkdir", "--version"], "Directory creation utility", "usually part of coreutils")
369
check_app(["cp", "--version"], "Copy utility", "usually part of coreutils")
370
check_app(["find", "--version"], "Find utility", "usually part of findutils")
371
check_app(["diff", "--version"], "Diff utility", "usually part of diffutils")
372
check_app(["make", "--version"], "Make utility", "preferably GNU Make")
373
check_app(["makedepend", "-f", "-"], "Makedepend utility", "usually part of imake or xutils")
376
if (config['COMPILER'] == "gcc_cross"):
377
if (config['PLATFORM'] == "abs32le"):
378
check_config(config, "CROSS_TARGET")
379
target = config['CROSS_TARGET']
381
if (config['CROSS_TARGET'] == "arm32"):
382
gnu_target = "arm-linux-gnu"
384
if (config['CROSS_TARGET'] == "ia32"):
385
gnu_target = "i686-pc-linux-gnu"
387
if (config['CROSS_TARGET'] == "mips32"):
388
gnu_target = "mipsel-linux-gnu"
390
if (config['PLATFORM'] == "amd64"):
391
target = config['PLATFORM']
392
gnu_target = "amd64-linux-gnu"
394
if (config['PLATFORM'] == "arm32"):
395
target = config['PLATFORM']
183
396
gnu_target = "arm-linux-gnu"
185
if (config['CROSS_TARGET'] == "ia32"):
398
if (config['PLATFORM'] == "ia32"):
399
target = config['PLATFORM']
186
400
gnu_target = "i686-pc-linux-gnu"
188
if (config['CROSS_TARGET'] == "mips32"):
189
gnu_target = "mipsel-linux-gnu"
191
if (config['PLATFORM'] == "amd64"):
192
target = config['PLATFORM']
193
gnu_target = "amd64-linux-gnu"
195
if (config['PLATFORM'] == "arm32"):
196
target = config['PLATFORM']
197
gnu_target = "arm-linux-gnu"
199
if (config['PLATFORM'] == "ia32"):
200
target = config['PLATFORM']
201
gnu_target = "i686-pc-linux-gnu"
203
if (config['PLATFORM'] == "ia64"):
204
target = config['PLATFORM']
205
gnu_target = "ia64-pc-linux-gnu"
207
if (config['PLATFORM'] == "mips32"):
208
check_config(config, "MACHINE")
210
if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
211
target = config['PLATFORM']
212
gnu_target = "mipsel-linux-gnu"
214
if (config['MACHINE'] == "bgxemul"):
216
gnu_target = "mips-linux-gnu"
218
if (config['PLATFORM'] == "ppc32"):
219
target = config['PLATFORM']
220
gnu_target = "ppc-linux-gnu"
222
if (config['PLATFORM'] == "sparc64"):
223
target = config['PLATFORM']
224
gnu_target = "sparc64-linux-gnu"
226
path = "%s/%s/bin" % (cross_prefix, target)
227
prefix = "%s-" % gnu_target
229
check_gcc(path, prefix, common, PACKAGE_CROSS)
230
check_binutils(path, prefix, common, PACKAGE_CROSS)
231
common['CC'] = common['GCC']
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']
238
if (config['COMPILER'] == "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)
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)
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)
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")
260
create_output(COMMON, common)
402
if (config['PLATFORM'] == "ia64"):
403
target = config['PLATFORM']
404
gnu_target = "ia64-pc-linux-gnu"
406
if (config['PLATFORM'] == "mips32"):
407
check_config(config, "MACHINE")
409
if ((config['MACHINE'] == "lgxemul") or (config['MACHINE'] == "msim")):
410
target = config['PLATFORM']
411
gnu_target = "mipsel-linux-gnu"
413
if (config['MACHINE'] == "bgxemul"):
415
gnu_target = "mips-linux-gnu"
417
if (config['PLATFORM'] == "ppc32"):
418
target = config['PLATFORM']
419
gnu_target = "ppc-linux-gnu"
421
if (config['PLATFORM'] == "sparc64"):
422
target = config['PLATFORM']
423
gnu_target = "sparc64-linux-gnu"
425
path = "%s/%s/bin" % (cross_prefix, target)
426
prefix = "%s-" % gnu_target
428
check_gcc(path, prefix, common, PACKAGE_CROSS)
429
check_binutils(path, prefix, common, PACKAGE_CROSS)
431
check_common(common, "GCC")
432
common['CC'] = common['GCC']
434
if (config['COMPILER'] == "gcc_native"):
435
check_gcc(None, "", common, PACKAGE_GCC)
436
check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
438
check_common(common, "GCC")
439
common['CC'] = common['GCC']
441
if (config['COMPILER'] == "icc"):
443
check_app([common['CC'], "-V"], "Intel C++ Compiler", "support is experimental")
444
check_gcc(None, "", common, PACKAGE_GCC)
445
check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
447
if (config['COMPILER'] == "suncc"):
448
common['CC'] = "suncc"
449
check_app([common['CC'], "-V"], "Sun Studio Compiler", "support is experimental")
450
check_gcc(None, "", common, PACKAGE_GCC)
451
check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
453
if (config['COMPILER'] == "clang"):
454
common['CC'] = "clang"
455
check_app([common['CC'], "--version"], "Clang compiler", "preferably version 1.0 or newer")
456
check_gcc(None, "", common, PACKAGE_GCC)
457
check_binutils(None, binutils_prefix, common, PACKAGE_BINUTILS)
459
# Platform-specific utilities
460
if ((config['BARCH'] == "amd64") or (config['BARCH'] == "ia32") or (config['BARCH'] == "ppc32") or (config['BARCH'] == "sparc64")):
461
check_app(["mkisofs", "--version"], "ISO 9660 creation utility", "usually part of genisoimage")
463
probe = probe_compiler(common,
473
typedefs = detect_uints(probe['unsigned_sizes'], probe['signed_sizes'], [1, 2, 4, 8])
478
create_makefile(MAKEFILE, common)
479
create_header(HEADER, typedefs)