[freenos] r412 committed - Added (auto)configure checks for CFLAGS....

  • From: freenos@xxxxxxxxxxxxxx
  • To: freenos@xxxxxxxxxxxxx
  • Date: Wed, 20 Oct 2010 21:29:46 +0000

Revision: 412
Author: nieklinnenbank
Date: Wed Oct 20 14:29:16 2010
Log: Added (auto)configure checks for CFLAGS.
This makes sure that all configured CFLAGS are
a valid flag for the given compiler.

http://code.google.com/p/freenos/source/detail?r=412

Added:
 /branches/scratch/site_scons/autoconf.py
Deleted:
 /branches/scratch/system/x86/pc/config/clang_multi.conf
 /branches/scratch/system/x86/pc/config/gcc_multi.conf
Modified:
 /branches/scratch/build.conf
 /branches/scratch/site_scons/build.py
 /branches/scratch/system/x86/pc/config/clang.conf
 /branches/scratch/system/x86/pc/config/gcc.conf

=======================================
--- /dev/null
+++ /branches/scratch/site_scons/autoconf.py    Wed Oct 20 14:29:16 2010
@@ -0,0 +1,71 @@
+#
+# Copyright (C) 2010 Niek Linnenbank
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+from SCons.SConf  import *
+from SCons.Script import *
+
+#
+# SConf helper function.
+#
+def TryCompileC(context):
+
+    # Print out a debug message.
+    context.Message('Checking for ' + context.env['TRYFLAG'] + ' ... ')
+
+    # Use the simpelest C program possible.
+    source_file = "int main(int argc, char **argv)" \
+                 "{" \
+                 "    return 0;" \
+                 "}\n"
+
+    # Try to compile and link it.
+    result = context.TryLink(source_file, '.c')
+
+    # Return the result status.
+    context.Result(result)
+    return result
+
+#
+# Checks if the compiler in the given environment supports
+# the given command-line CFLAGS, and unsets it if not.
+#
+# Thanks to loonycyborg on #scons for his help!
+#
+def CheckCFlags(env):
+
+    cflags = env['CFLAGS'][:]
+
+    # Loop all CFLAGS.
+    for flag in cflags:
+
+       # Setup a temporary environment.
+        conf = Configure(env.Clone(),
+                        custom_tests = { 'TryCompileC' : TryCompileC })
+        conf.env.Replace(CFLAGS    = flag)
+        conf.env.Replace(LINKFLAGS = flag)
+        conf.env.Replace(TRYFLAG   = flag)
+
+       # Try to link a dummy program.
+       result = conf.TryCompileC()
+
+       # If it failed, mark to remove the CFLAG.
+        if not result:
+           env['CFLAGS'].remove(flag)
+
+       # Done. Try next.
+        conf.Finish()
+
=======================================
--- /branches/scratch/system/x86/pc/config/clang_multi.conf Fri Oct 15 15:25:49 2010
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2010 Niek Linnenbank
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-CC        = 'clang'
-AS        = 'clang'
-LD        = 'clang'
-CFLAGS    = [ '-Wall', '-Werror', '-nostdinc',
-             '-fno-builtin', '-g3', '-ansi', '-m32' ]
-ASFLAGS   = [ '-Wall', '-Werror', '-nostdinc', '-m32' ]
-LINKFLAGS = [ '-static', '-nostdlib', '-nostartfiles', '-nodefaultlibs', '-m32', '-Wl,-whole-archive' ]
-LINKUSER  = [ '-T', 'system/x86/pc/config/user.ld' ]
-LINKKERN  = [ '-T', 'system/x86/pc/config/kernel.ld' ]
-CPPPATH   = [ '#include' ]
-
=======================================
--- /branches/scratch/system/x86/pc/config/gcc_multi.conf Fri Oct 15 15:25:49 2010
+++ /dev/null
@@ -1,28 +0,0 @@
-#
-# Copyright (C) 2010 Niek Linnenbank
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-CC        = 'gcc'
-AS        = 'gcc'
-LD        = 'gcc'
-CFLAGS    = [ '-Wall', '-Werror', '-nostdinc',
-             '-fno-stack-protector', '-fno-builtin', '-g3', '-ansi', '-m32' ]
-ASFLAGS   = [ '-Wall', '-Werror', '-nostdinc', '-m32' ]
-LINKFLAGS = [ '-static', '-nostdlib', '-nostartfiles', '-nodefaultlibs', '-m32', '-Wl,-whole-archive' ]
-LINKUSER  = [ '-T', 'system/x86/pc/config/user.ld' ]
-LINKKERN  = [ '-T', 'system/x86/pc/config/kernel.ld' ]
-CPPPATH   = [ '#include' ]
-
=======================================
--- /branches/scratch/build.conf        Sun Oct 10 16:06:55 2010
+++ /branches/scratch/build.conf        Wed Oct 20 14:29:16 2010
@@ -18,7 +18,7 @@
 VERSION   = '0.1.0'
 ARCH      = 'x86'
 SYSTEM    = 'pc'
-COMPILER  = 'system/' + ARCH + '/' + SYSTEM + '/config/gcc_multi.conf'
+COMPILER  = 'system/' + ARCH + '/' + SYSTEM + '/config/gcc.conf'
 BUILDROOT = 'build/'  + ARCH + '/' + SYSTEM
 VERBOSE   = 'False'

=======================================
--- /branches/scratch/site_scons/build.py       Sat Oct 16 19:56:53 2010
+++ /branches/scratch/site_scons/build.py       Wed Oct 20 14:29:16 2010
@@ -16,6 +16,7 @@
 #

 from SCons.Script import *
+from autoconf import *

 #
 # Prepares a given environment, by adding library dependencies.
@@ -75,6 +76,11 @@
     target['RANLIBCOMSTR'] = host['RANLIBCOMSTR'] = "  LIB $TARGET"
     target['LINKCOMSTR']   = host['LINKCOMSTR']   = "  LD  $TARGET"

+# Verify the configured CFLAGS.
+if not GetOption('clean'):
+    CheckCFlags(target)
+    CheckCFlags(host)
+
 # Kernel environment is the same as target, except for linker scripts.
 kernel = target.Clone()

=======================================
--- /branches/scratch/system/x86/pc/config/clang.conf Fri Oct 15 15:25:49 2010 +++ /branches/scratch/system/x86/pc/config/clang.conf Wed Oct 20 14:29:16 2010
@@ -18,10 +18,10 @@
 CC        = 'clang'
 AS        = 'clang'
 LD        = 'clang'
-CFLAGS    = [ '-Wall', '-Werror', '-nostdinc',
+CFLAGS    = [ '-m32', '-Wall', '-Werror', '-nostdinc',
              '-fno-builtin', '-g3', '-ansi' ]
-ASFLAGS   = [ '-Wall', '-Werror', '-nostdinc' ]
-LINKFLAGS = [ '-static', '-nostdlib', '-nostartfiles', '-nodefaultlibs', '-Wl,-whole-archive' ]
+ASFLAGS   = [ '-m32', '-Wall', '-Werror', '-nostdinc' ]
+LINKFLAGS = [ '-m32', '-static', '-nostdlib', '-nostartfiles', '-nodefaultlibs', '-Wl,-whole-archive' ]
 LINKUSER  = [ '-T', 'system/x86/pc/config/user.ld' ]
 LINKKERN  = [ '-T', 'system/x86/pc/config/kernel.ld' ]
 CPPPATH   = [ '#include' ]
=======================================
--- /branches/scratch/system/x86/pc/config/gcc.conf     Fri Oct 15 15:25:49 2010
+++ /branches/scratch/system/x86/pc/config/gcc.conf     Wed Oct 20 14:29:16 2010
@@ -18,10 +18,11 @@
 CC        = 'gcc'
 AS        = 'gcc'
 LD        = 'gcc'
-CFLAGS    = [ '-Wall', '-Werror', '-nostdinc',
+CFLAGS    = [ '-m32', '-Wall', '-Werror', '-nostdinc',
              '-fno-stack-protector', '-fno-builtin', '-g3', '-ansi' ]
-ASFLAGS   = [ '-Wall', '-Werror', '-nostdinc' ]
-LINKFLAGS = [ '-static', '-nostdlib', '-nostartfiles', '-nodefaultlibs', '-Wl,-whole-archive' ]
+ASFLAGS   = [ '-m32', '-Wall', '-Werror', '-nostdinc' ]
+LINKFLAGS = [ '-m32', '-static', '-nostdlib', '-nostartfiles',
+             '-nodefaultlibs', '-Wl,-whole-archive' ]
 LINKUSER  = [ '-T', 'system/x86/pc/config/user.ld' ]
 LINKKERN  = [ '-T', 'system/x86/pc/config/kernel.ld' ]
 CPPPATH   = [ '#include' ]

Other related posts:

  • » [freenos] r412 committed - Added (auto)configure checks for CFLAGS.... - freenos