[Git][NTPsec/ntpsec][master] Add support for detecting specific compilers.

Amar Takhar gitlab at mg.gitlab.com
Thu Dec 10 16:16:44 UTC 2015


Amar Takhar pushed to branch master at NTPsec / ntpsec


Commits:
7f142ff8 by Amar Takhar at 2015-12-10T11:12:56Z
Add support for detecting specific compilers.

This will be used in both the build and testsuite.  It can be used in-source as
well to avoid any quirks.

It defines COMPILER_X eg COMPILER_CLANG, COMPILER_GCC or COMPILER_ICC for now.

- - - - -


2 changed files:

- + pylib/compiler.py
- pylib/configure.py


Changes:

=====================================
pylib/compiler.py
=====================================
--- /dev/null
+++ b/pylib/compiler.py
@@ -0,0 +1,61 @@
+# Some compilers decide they like to mimic GCC as close as possible.  
+# Unfortunately this usually does not apply to #pragma's.  There can also be 
+# quirks that need to be dodged specific to a compiler.
+#
+# There are also differences when it comes to coverage and profiling between 
+# compilers.  We'll want to support all to see how the source reacts under 
+# different compilers and architectures.
+#
+# This file exist as the definitive way to check what compiler we're working 
+# under it defines COMPILER_X in both config.h and the build system.
+
+COMPILER_FRAG = """
+#include <stdio.h>
+
+int main(void) {
+#ifdef __clang__
+	printf("1");
+#elif __INTEL_COMPILER
+	printf("2");
+#elif __GNUC__
+	printf("3");
+#else
+	printf("255");
+#endif
+	return 0;
+}
+"""
+
+
+def check_compiler(ctx):
+
+	defines = {
+		1: ("COMPILER_CLANG",	"clang"),
+		2: ("COMPILER_ICC",		"ICC"),
+		3: ("COMPILER_GCC",		"GCC"),
+		255: ("COMPILER_GCC",	"Unknown (Defaulting to GCC)"),
+	}
+
+	ret = ctx.check_cc(
+		fragment	= COMPILER_FRAG,
+		msg			= "Checking compiler",
+		define_name = "COMPILER_INT",
+		quote		= False,
+		execute		= True,
+		define_ret  = True,
+		mandatory	= True
+	)
+
+	compiler_int = int(ctx.get_define("COMPILER_INT"))
+
+	ctx.undefine("COMPILER_INT") # Not needed.
+
+	define, name = defines[compiler_int]
+
+	ctx.start_msg("Compiler found")
+
+	ctx.define(define, 1) # config.h
+	ctx.env[define] = True # Build system.
+
+	ctx.end_msg(name)
+


=====================================
pylib/configure.py
=====================================
--- a/pylib/configure.py
+++ b/pylib/configure.py
@@ -8,6 +8,13 @@ def cmd_configure(ctx):
 	srcnode = ctx.srcnode.abspath()
 	bldnode = ctx.bldnode.abspath()
 
+	ctx.load('compiler_c')
+	ctx.load('bison')
+
+
+	from compiler import check_compiler
+	check_compiler(ctx)
+
 	from check_type import check_type
 	from check_sizeof import check_sizeof
 	from check_structfield import check_structfield
@@ -23,9 +30,6 @@ def cmd_configure(ctx):
 		return
 
 
-	ctx.load('compiler_c')
-	ctx.load('bison')
-
 	# This needs to be at the top since it modifies CC and AR
 	if ctx.options.enable_fortify:
 		from check_fortify import check_fortify



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/7f142ff8f35da2cef5a62205f3456090ac1fb3c8
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151210/7c25fbc9/attachment.html>


More information about the vc mailing list