Index: tools/autotool.py
===================================================================
--- tools/autotool.py	(revision 85369b111f458fd417a10d0c8caeffa9462adf19)
+++ tools/autotool.py	(revision 7329e6a6a987bc53fac8c85bd8647e952ae7fb9c)
@@ -53,4 +53,5 @@
 
 COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS."
+COMPILER_WARNING = "The compilation of HelenOS might fail."
 
 PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, strc, conc, value) \\
@@ -61,4 +62,10 @@
 	)
 
+#define STRING(arg)      STRING_ARG(arg)
+#define STRING_ARG(arg)  #arg
+
+#define DECLARE_BUILTIN_TYPE(tag, type) \\
+	AUTOTOOL_DECLARE("builtin", "", tag, STRING(type), "", "", sizeof(type));
+
 #define DECLARE_INTSIZE(tag, type, strc, conc) \\
 	AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\
@@ -67,4 +74,13 @@
 int main(int argc, char *argv[])
 {
+#ifdef __SIZE_TYPE__
+	DECLARE_BUILTIN_TYPE("size", __SIZE_TYPE__);
+#endif
+#ifdef __WCHAR_TYPE__
+	DECLARE_BUILTIN_TYPE("wchar", __WCHAR_TYPE__);
+#endif
+#ifdef __WINT_TYPE__
+	DECLARE_BUILTIN_TYPE("wint", __WINT_TYPE__);
+#endif
 """
 
@@ -96,4 +112,17 @@
 	
 	sys.exit(1)
+
+def print_warning(msg):
+	"Print a bold error message"
+	
+	sys.stderr.write("\n")
+	sys.stderr.write("######################################################################\n")
+	sys.stderr.write("HelenOS build sanity check warning:\n")
+	sys.stderr.write("\n")
+	sys.stderr.write("%s\n" % "\n".join(msg))
+	sys.stderr.write("######################################################################\n")
+	sys.stderr.write("\n")
+	
+	time.sleep(5)
 
 def sandbox_enter():
@@ -186,4 +215,18 @@
 	check_app([common['STRIP'], "--version"], "GNU strip", details)
 
+def decode_value(value):
+	"Decode integer value"
+	
+	base = 10
+	
+	if ((value.startswith('$')) or (value.startswith('#'))):
+		value = value[1:]
+	
+	if (value.startswith('0x')):
+		value = value[2:]
+		base = 16
+	
+	return int(value, base)
+
 def probe_compiler(common, sizes):
 	"Generate, compile and parse probing source"
@@ -237,4 +280,6 @@
 	signed_concs = {}
 	
+	builtins = {}
+	
 	for j in range(len(lines)):
 		tokens = lines[j].strip().split("\t")
@@ -254,34 +299,33 @@
 				
 				if (category == "intsize"):
-					base = 10
-					
-					if ((value.startswith('$')) or (value.startswith('#'))):
-						value = value[1:]
-					
-					if (value.startswith('0x')):
-						value = value[2:]
-						base = 16
-					
 					try:
-						value_int = int(value, base)
+						value_int = decode_value(value)
 					except:
 						print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
 					
 					if (subcategory == "unsigned"):
-						unsigned_sizes[name] = value_int
+						unsigned_sizes[value_int] = name
 						unsigned_tags[tag] = value_int
-						unsigned_strcs[strc] = value_int
-						unsigned_concs[conc] = value_int
+						unsigned_strcs[value_int] = strc
+						unsigned_concs[value_int] = conc
 					elif (subcategory == "signed"):
-						signed_sizes[name] = value_int
+						signed_sizes[value_int] = name
 						signed_tags[tag] = value_int
-						signed_strcs[strc] = value_int
-						signed_concs[conc] = value_int
+						signed_strcs[value_int] = strc
+						signed_concs[value_int] = conc
 					else:
 						print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL])
-	
-	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}
-
-def detect_uints(probe, bytes):
+				
+				if (category == "builtin"):
+					try:
+						value_int = decode_value(value)
+					except:
+						print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL])
+					
+					builtins[tag] = {'name': name, 'value': value_int}
+	
+	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}
+
+def detect_uints(probe, bytes, tags):
 	"Detect correct types for fixed-size integer types"
 	
@@ -290,114 +334,111 @@
 	
 	for b in bytes:
+		if (not b in probe['unsigned_sizes']):
+			print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b,
+			             COMPILER_FAIL])
+		
+		if (not b in probe['signed_sizes']):
+			print_error(['Unable to find appropriate signed integer type for %u bytes' % b,
+			             COMPILER_FAIL])
+		
+		if (not b in probe['unsigned_strcs']):
+			print_error(['Unable to find appropriate unsigned printf formatter for %u bytes' % b,
+			             COMPILER_FAIL])
+		
+		if (not b in probe['signed_strcs']):
+			print_error(['Unable to find appropriate signed printf formatter for %u bytes' % b,
+			             COMPILER_FAIL])
+		
+		if (not b in probe['unsigned_concs']):
+			print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
+			             COMPILER_FAIL])
+		
+		if (not b in probe['signed_concs']):
+			print_error(['Unable to find appropriate signed literal macro for %u bytes' % b,
+			             COMPILER_FAIL])
+		
+		typedefs.append({'oldtype': "unsigned %s" % probe['unsigned_sizes'][b], 'newtype': "uint%u_t" % (b * 8)})
+		typedefs.append({'oldtype': "signed %s" % probe['signed_sizes'][b], 'newtype': "int%u_t" % (b * 8)})
+		
+		macros.append({'oldmacro': "\"%so\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIo%u" % (b * 8)})
+		macros.append({'oldmacro': "\"%su\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIu%u" % (b * 8)})
+		macros.append({'oldmacro': "\"%sx\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIx%u" % (b * 8)})
+		macros.append({'oldmacro': "\"%sX\"" % probe['unsigned_strcs'][b], 'newmacro': "PRIX%u" % (b * 8)})
+		macros.append({'oldmacro': "\"%sd\"" % probe['signed_strcs'][b], 'newmacro': "PRId%u" % (b * 8)})
+		
+		name = probe['unsigned_concs'][b]
+		if ((name.startswith('@')) or (name == "")):
+			macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
+		else:
+			macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
+		
+		name = probe['unsigned_concs'][b]
+		if ((name.startswith('@')) or (name == "")):
+			macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
+		else:
+			macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
+	
+	for tag in tags:
+		newmacro = "U%s" % tag
+		if (not tag in probe['unsigned_tags']):
+			print_error(['Unable to find appropriate size macro for %s' % newmacro,
+			             COMPILER_FAIL])
+		
+		oldmacro = "UINT%s" % (probe['unsigned_tags'][tag] * 8)
+		macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
+		macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
+		
+		newmacro = tag
+		if (not tag in probe['unsigned_tags']):
+			print_error(['Unable to find appropriate size macro for %s' % newmacro,
+			             COMPILER_FAIL])
+		
+		oldmacro = "INT%s" % (probe['signed_tags'][tag] * 8)
+		macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
+		macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
+	
+	fnd = True
+	
+	if (not 'wchar' in probe['builtins']):
+		print_warning(['The compiler does not provide the macro __WCHAR_TYPE__',
+		               'for defining the compiler-native type wchar_t. We are',
+		               'forced to define wchar_t as a hardwired type int32_t.',
+		               COMPILER_WARNING])
 		fnd = False
-		for name, value in probe['unsigned_sizes'].items():
-			if (value == b):
-				typedefs.append({'oldtype': "unsigned %s" % name, 'newtype': "uint%u_t" % (b * 8)})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate unsigned integer type for %u bytes' % b,
-			             COMPILER_FAIL])
-		
-		
+	
+	if (probe['builtins']['wchar']['value'] != 4):
+		print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining',
+		               'the compiler-native type wchar_t is not compliant with',
+		               'HelenOS. We are forced to define wchar_t as a hardwired',
+		               'type int32_t.',
+		               COMPILER_WARNING])
 		fnd = False
-		for name, value in probe['signed_sizes'].items():
-			if (value == b):
-				typedefs.append({'oldtype': "signed %s" % name, 'newtype': "int%u_t" % (b * 8)})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate signed integer type for %u bytes' % b,
-			             COMPILER_FAIL])
-		
-		
+	
+	if (not fnd):
+		macros.append({'oldmacro': "int32_t", 'newmacro': "wchar_t"})
+	else:
+		macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"})
+	
+	fnd = True
+	
+	if (not 'wint' in probe['builtins']):
+		print_warning(['The compiler does not provide the macro __WINT_TYPE__',
+		               'for defining the compiler-native type wint_t. We are',
+		               'forced to define wint_t as a hardwired type int32_t.',
+		               COMPILER_WARNING])
 		fnd = False
-		for name, value in probe['unsigned_strcs'].items():
-			if (value == b):
-				macros.append({'oldmacro': "\"%so\"" % name, 'newmacro': "PRIo%u" % (b * 8)})
-				macros.append({'oldmacro': "\"%su\"" % name, 'newmacro': "PRIu%u" % (b * 8)})
-				macros.append({'oldmacro': "\"%sx\"" % name, 'newmacro': "PRIx%u" % (b * 8)})
-				macros.append({'oldmacro': "\"%sX\"" % name, 'newmacro': "PRIX%u" % (b * 8)})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate unsigned printf formatter for %u bytes' % b,
-			             COMPILER_FAIL])
-		
-		
+	
+	if (probe['builtins']['wint']['value'] != 4):
+		print_warning(['The compiler provided macro __WINT_TYPE__ for defining',
+		               'the compiler-native type wint_t is not compliant with',
+		               'HelenOS. We are forced to define wint_t as a hardwired',
+		               'type int32_t.',
+		               COMPILER_WARNING])
 		fnd = False
-		for name, value in probe['signed_strcs'].items():
-			if (value == b):
-				macros.append({'oldmacro': "\"%sd\"" % name, 'newmacro': "PRId%u" % (b * 8)})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate signed printf formatter for %u bytes' % b,
-			             COMPILER_FAIL])
-		
-		
-		fnd = False
-		for name, value in probe['unsigned_concs'].items():
-			if (value == b):
-				if ((name.startswith('@')) or (name == "")):
-					macros.append({'oldmacro': "c ## U", 'newmacro': "UINT%u_C(c)" % (b * 8)})
-				else:
-					macros.append({'oldmacro': "c ## U%s" % name, 'newmacro': "UINT%u_C(c)" % (b * 8)})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
-			             COMPILER_FAIL])
-		
-		
-		fnd = False
-		for name, value in probe['signed_concs'].items():
-			if (value == b):
-				if ((name.startswith('@')) or (name == "")):
-					macros.append({'oldmacro': "c", 'newmacro': "INT%u_C(c)" % (b * 8)})
-				else:
-					macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate unsigned literal macro for %u bytes' % b,
-			             COMPILER_FAIL])
-	
-	for tag in ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG']:
-		fnd = False;
-		newmacro = "U%s" % tag
-		
-		for name, value in probe['unsigned_tags'].items():
-			if (name == tag):
-				oldmacro = "UINT%s" % (value * 8)
-				macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
-				macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate size macro for %s' % newmacro,
-			             COMPILER_FAIL])
-		
-		fnd = False;
-		newmacro = tag
-		
-		for name, value in probe['signed_tags'].items():
-			if (name == tag):
-				oldmacro = "INT%s" % (value * 8)
-				macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro})
-				macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro})
-				fnd = True
-				break
-		
-		if (not fnd):
-			print_error(['Unable to find appropriate size macro for %s' % newmacro,
-			             COMPILER_FAIL])
+	
+	if (not fnd):
+		macros.append({'oldmacro': "int32_t", 'newmacro': "wint_t"})
+	else:
+		macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"})
 	
 	return {'macros': macros, 'typedefs': typedefs}
@@ -571,13 +612,13 @@
 		probe = probe_compiler(common,
 			[
-				{'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'},
+				{'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'},
+				{'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
+				{'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
 				{'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'},
-				{'type': 'int', 'tag': 'INT', 'strc': '""', 'conc': '""'},
-				{'type': 'long int', 'tag': 'LONG', 'strc': '"l"', 'conc': '"L"'},
-				{'type': 'long long int', 'tag': 'LLONG', 'strc': '"ll"', 'conc': '"LL"'}
+				{'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'}
 			]
 		)
 		
-		maps = detect_uints(probe, [1, 2, 4, 8])
+		maps = detect_uints(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'])
 		
 	finally:
