configure: Leverage gcc warn options to enable safe use of C99 features where possible.
authorJose Fonseca <jfonseca@vmware.com>
Thu, 26 Feb 2015 16:46:48 +0000 (16:46 +0000)
committerJose Fonseca <jfonseca@vmware.com>
Fri, 27 Feb 2015 14:30:36 +0000 (14:30 +0000)
The main objective of this change is to enable Linux developers to use
more of C99 throughout Mesa, with confidence that the portions that need
to be built with MSVC -- and only those portions --, stay portable.

This is achieved by using the appropriate -Werror= options only on the
places they need to be used.

Unfortunately we still need MSVC 2008 on a few portions of the code
(namely llvmpipe and its dependencies).  I hope to eventually eliminate
this so that we can use C99 everywhere, but there are technical/logistic
challenges (specifically, newer Windows SDKs no longer bundle MSVC,
instead require a full installation of Visual Studio, and that has
hindered adoption of newer MSVC versions on our build processes.)
Thankfully we have more directy control over our OpenGL driver, which is
why we're now able to migrate to MSVC 2013 for most of the tree.

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
configure.ac
src/egl/main/Makefile.am
src/gallium/auxiliary/Makefile.am
src/gallium/drivers/llvmpipe/Makefile.am
src/gallium/state_trackers/egl/Makefile.am
src/gallium/targets/egl-static/Makefile.am
src/glsl/Makefile.am
src/loader/Makefile.am
src/mapi/Makefile.am
src/mesa/Makefile.am
src/util/Makefile.am

index 5fbb7bc31dae3f18e52abf74eac30328a8a69427..22dc023abc7ab19b965debce79a8f9647d200ac7 100644 (file)
@@ -263,6 +263,18 @@ if test "x$GCC" = xyes; then
     # gcc's builtin memcmp is slower than glibc's
     # http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43052
     CFLAGS="$CFLAGS -fno-builtin-memcmp"
+
+    # Flags to help ensure that certain portions of the code -- and only those
+    # portions -- can be built with MSVC:
+    # - src/util, src/gallium/auxiliary, and src/gallium/drivers/llvmpipe needs
+    #   to build with Windows SDK 7.0.7600, which bundles MSVC 2008
+    # - non-Linux/Posix OpenGL portions needs to build on MSVC 2013 (which
+    #   supports most of C99)
+    # - the rest has no compiler compiler restrictions
+    MSVC2013_COMPAT_CFLAGS="-Werror=vla -Werror=pointer-arith"
+    MSVC2013_COMPAT_CXXFLAGS="-Werror=vla -Werror=pointer-arith"
+    MSVC2008_COMPAT_CFLAGS="$MSVC2013_COMPAT_CFLAGS -Werror=declaration-after-statement"
+    MSVC2008_COMPAT_CXXFLAGS="$MSVC2013_COMPAT_CXXFLAGS"
 fi
 if test "x$GXX" = xyes; then
     CXXFLAGS="$CXXFLAGS -Wall"
@@ -288,6 +300,11 @@ if test "x$GXX" = xyes; then
     CXXFLAGS="$CXXFLAGS -fno-builtin-memcmp"
 fi
 
+AC_SUBST([MSVC2013_COMPAT_CFLAGS])
+AC_SUBST([MSVC2013_COMPAT_CXXFLAGS])
+AC_SUBST([MSVC2008_COMPAT_CFLAGS])
+AC_SUBST([MSVC2008_COMPAT_CXXFLAGS])
+
 dnl even if the compiler appears to support it, using visibility attributes isn't
 dnl going to do anything useful currently on cygwin apart from emit lots of warnings
 case "$host_os" in
index d21d8a9eb5aeba30aeee2a4fe1a3258051ee9925..a4db21016e94cfb86ea8c74f57ca7b93f251d0c7 100644 (file)
@@ -26,6 +26,7 @@ AM_CFLAGS = \
        -I$(top_srcdir)/src/gbm/main \
        $(DEFINES) \
        $(VISIBILITY_CFLAGS) \
+       $(MSVC2013_COMPAT_CFLAGS) \
        $(EGL_CFLAGS) \
        -D_EGL_NATIVE_PLATFORM=$(EGL_NATIVE_PLATFORM) \
        -D_EGL_DRIVER_SEARCH_DIR=\"$(libdir)/egl\" \
index 4b6205797ef9ba9cc23ffb6ed3b7e8955f14022c..27a8b3fe4201e8a874794eb48ca905b981d0e164 100644 (file)
@@ -12,9 +12,12 @@ noinst_LTLIBRARIES = libgallium.la
 AM_CFLAGS = \
        -I$(top_srcdir)/src/gallium/auxiliary/util \
        $(GALLIUM_CFLAGS) \
-       $(VISIBILITY_CFLAGS)
+       $(VISIBILITY_CFLAGS) \
+       $(MSVC2008_COMPAT_CXXFLAGS)
 
-AM_CXXFLAGS = $(VISIBILITY_CXXFLAGS)
+AM_CXXFLAGS = \
+       $(VISIBILITY_CXXFLAGS) \
+       $(MSVC2008_COMPAT_CXXFLAGS)
 
 libgallium_la_SOURCES = \
        $(C_SOURCES) \
index 0bd4282632ad00a05c26b55e5266da26d18bb146..1d3853e41a6d4a1693d624ae35a2b99bc0c09c7a 100644 (file)
@@ -25,10 +25,12 @@ include $(top_srcdir)/src/gallium/Automake.inc
 
 AM_CFLAGS = \
        $(GALLIUM_DRIVER_CFLAGS) \
-       $(LLVM_CFLAGS)
+       $(LLVM_CFLAGS) \
+       $(MSVC2008_COMPAT_CFLAGS)
 AM_CXXFLAGS= \
        $(GALLIUM_DRIVER_CXXFLAGS) \
-       $(LLVM_CXXFLAGS)
+       $(LLVM_CXXFLAGS) \
+       $(MSVC2008_COMPAT_CXXFLAGS)
 
 noinst_LTLIBRARIES = libllvmpipe.la
 
index 31546a778cff4bbca930ccce227f7fc15bd91025..f13fcb2ccb8a18d8ef38eb7b5c24c10edcf131c9 100644 (file)
@@ -27,7 +27,8 @@ include $(top_srcdir)/src/gallium/Automake.inc
 
 AM_CFLAGS = \
        $(GALLIUM_CFLAGS) \
-       $(VISIBILITY_CFLAGS)
+       $(VISIBILITY_CFLAGS) \
+       $(MSVC2013_COMPAT_CFLAGS)
 
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/egl/main \
index 85f2ac1b785498fc4623809193c010e6b701a6d1..51c3f052acd04f7bb73997294569af36df7a988d 100644 (file)
@@ -31,7 +31,8 @@
 include $(top_srcdir)/src/gallium/Automake.inc
 
 AM_CFLAGS = \
-       $(GALLIUM_TARGET_CFLAGS)
+       $(GALLIUM_TARGET_CFLAGS) \
+       $(MSVC2013_COMPAT_CFLAGS)
 
 AM_CPPFLAGS = \
        -I$(top_srcdir)/src/gallium/state_trackers/egl \
index 5a0a643daf2ab3905b17fc3536e75535be5f1b16..b466a3b5c522d405bcfdb6a64c76b5121d3b3195 100644 (file)
@@ -33,8 +33,12 @@ AM_CPPFLAGS = \
        -I$(top_srcdir)/src/gtest/include \
        -I$(top_builddir)/src/glsl/nir \
        $(DEFINES)
-AM_CFLAGS = $(VISIBILITY_CFLAGS)
-AM_CXXFLAGS = $(VISIBILITY_CXXFLAGS)
+AM_CFLAGS = \
+       $(VISIBILITY_CFLAGS) \
+       $(MSVC2013_COMPAT_CFLAGS)
+AM_CXXFLAGS = \
+       $(VISIBILITY_CXXFLAGS) \
+       $(MSVC2013_COMPAT_CXXFLAGS)
 
 EXTRA_DIST = tests glcpp/tests README TODO glcpp/README        \
        glsl_lexer.ll                                   \
index 36ddba82bd39daf57312ce86779615d8e8ae34cc..3d32279ea26da64e1d809cbc45fa29d86e858150 100644 (file)
@@ -30,6 +30,7 @@ libloader_la_CPPFLAGS = \
        -I$(top_srcdir)/include \
        -I$(top_srcdir)/src \
        $(VISIBILITY_CFLAGS) \
+       $(MSVC2013_COMPAT_CFLAGS) \
        $(LIBUDEV_CFLAGS)
 
 libloader_la_SOURCES = $(LOADER_C_FILES)
index 67946829198247a53251cd2669e93ef4ce8d23eb..b0a6c8ca2d82d819eaf6f63d2271cda94d983435 100644 (file)
@@ -39,7 +39,9 @@ EXTRA_DIST = \
        glapi/SConscript \
        shared-glapi/SConscript
 
-AM_CFLAGS = $(PTHREAD_CFLAGS)
+AM_CFLAGS = \
+       $(PTHREAD_CFLAGS) \
+       $(MSVC2013_COMPAT_CFLAGS)
 AM_CPPFLAGS =                                                  \
        $(DEFINES)                                              \
        $(SELINUX_CFLAGS)                                       \
index b6cb8f1117be509e41ca9227598c3b38bea8d136..5e9a82098fb07cd41707f86d01e1d86ed3606957 100644 (file)
@@ -136,8 +136,14 @@ noinst_LTLIBRARIES += libmesagallium.la
 endif
 
 AM_CPPFLAGS = $(DEFINES) $(INCLUDE_DIRS)
-AM_CFLAGS = $(LLVM_CFLAGS) $(VISIBILITY_CFLAGS)
-AM_CXXFLAGS = $(LLVM_CFLAGS) $(VISIBILITY_CXXFLAGS)
+AM_CFLAGS = \
+       $(LLVM_CFLAGS) \
+       $(VISIBILITY_CFLAGS) \
+       $(MSVC2013_COMPAT_CFLAGS)
+AM_CXXFLAGS = \
+       $(LLVM_CFLAGS) \
+       $(VISIBILITY_CXXFLAGS) \
+       $(MSVC2013_COMPAT_CXXFLAGS)
 
 ARCH_LIBS =
 
index 9af233059bbcb4f8cf664f258e05486f0e22a1bc..29b66e70e9d6c1922900c7e6175d88f3fe0268a1 100644 (file)
@@ -34,7 +34,8 @@ libmesautil_la_CPPFLAGS = \
        -I$(top_srcdir)/src/gallium/include \
        -I$(top_srcdir)/src/gallium/auxiliary \
        $(SHA1_CFLAGS) \
-       $(VISIBILITY_CFLAGS)
+       $(VISIBILITY_CFLAGS) \
+       $(MSVC2008_COMPAT_CFLAGS)
 
 libmesautil_la_SOURCES = \
        $(MESA_UTIL_FILES) \