[commit: ghc] master: Autoconf: detect and set CFLAGS/CPPFLAGS needed for C99 mode (afc48f8)
git at git.haskell.org
git at git.haskell.org
Mon Mar 28 12:59:43 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/afc48f8939b99a1a72b43b3e342d56193ed1f34c/ghc
>---------------------------------------------------------------
commit afc48f8939b99a1a72b43b3e342d56193ed1f34c
Author: Herbert Valerio Riedel <hvr at gnu.org>
Date: Mon Mar 28 14:34:22 2016 +0200
Autoconf: detect and set CFLAGS/CPPFLAGS needed for C99 mode
This is the first phase of addressing #11757 which aims to make C99
support a base-line requirement for GHC and clean up the code-base to
use C99 facilities when sensible.
This patch exploits the logic/heuristic used by `AC_PROG_CC_C99` to
determine the flags needed in case the C compiler isn't able to compile
C99 code in its current mode. We can't use `AC_PROG_CC_C99` directly
though because GHC's build-system expects CC to contain a filename
without any flags, while `AC_PROG_CC_C99` would e.g. result in
`CC="gcc -std=gnu99"`. Morever, we support different `CC`s for
stage0/1/2, so we need a version of `AC_PROG_CC_C99` for which we can
specify the `CC`/`CFLAGS` variables to operate on. This is what
`FP_SET_CFLAGS_C99` does.
Note that Clang has been defaulting to C99+ for a long time, while GCC 5
defaults to C99+ as well. So this has mostly an affect on older GCCs
versions prior to 5.0 and possibly compilers other than GCC/Clang (which
are not officially supported for building GHC anyway).
Reviewers: kgardas, erikd, bgamari, austin
Reviewed By: erikd
Differential Revision: https://phabricator.haskell.org/D2045
>---------------------------------------------------------------
afc48f8939b99a1a72b43b3e342d56193ed1f34c
aclocal.m4 | 42 ++++++++++++++++++++++++++++++++++++++++++
configure.ac | 5 +++++
distrib/configure.ac.in | 5 +++++
includes/Stg.h | 4 ++++
4 files changed, 56 insertions(+)
diff --git a/aclocal.m4 b/aclocal.m4
index 5becadb..6403748 100644
--- a/aclocal.m4
+++ b/aclocal.m4
@@ -514,6 +514,48 @@ AC_DEFUN([FP_SETTINGS],
AC_SUBST(SettingsOptCommand)
])
+# Helper for cloning a shell variable's state
+AC_DEFUN([FP_COPY_SHELLVAR],
+[if test -n "${$1+set}"; then $2="$$1"; else unset $2; fi ])
+
+# FP_SET_CFLAGS_C99
+# ----------------------------------
+# figure out which CFLAGS are needed to place the compiler into C99 mode
+# $1 is name of CC variable (unmodified)
+# $2 is name of CC flags variable (augmented if needed)
+# $3 is name of CPP flags variable (augmented if needed)
+AC_DEFUN([FP_SET_CFLAGS_C99],
+[
+ dnl save current state of AC_PROG_CC_C99
+ FP_COPY_SHELLVAR([CC],[fp_save_CC])
+ FP_COPY_SHELLVAR([CFLAGS],[fp_save_CFLAGS])
+ FP_COPY_SHELLVAR([CPPFLAGS],[fp_save_CPPFLAGS])
+ FP_COPY_SHELLVAR([ac_cv_prog_cc_c99],[fp_save_cc_c99])
+ dnl set local state
+ CC="$$1"
+ CFLAGS="$$2"
+ CPPFLAGS="$$3"
+ unset ac_cv_prog_cc_c99
+ dnl perform detection
+ _AC_PROG_CC_C99
+ fp_cc_c99="$ac_cv_prog_cc_c99"
+ case "x$ac_cv_prog_cc_c99" in
+ x) ;; # noop
+ xno) AC_MSG_ERROR([C99-compatible compiler needed]) ;;
+ *) $2="$$2 $ac_cv_prog_cc_c99"
+ $3="$$3 $ac_cv_prog_cc_c99"
+ ;;
+ esac
+ dnl restore saved state
+ FP_COPY_SHELLVAR([fp_save_CC],[CC])
+ FP_COPY_SHELLVAR([fp_save_CFLAGS],[CFLAGS])
+ FP_COPY_SHELLVAR([fp_save_CPPFLAGS],[CPPFLAGS])
+ FP_COPY_SHELLVAR([fp_save_cc_c99],[ac_cv_prog_cc_c99])
+ dnl cleanup
+ unset fp_save_CC
+ unset fp_save_CFLAGS
+ unset fp_save_cc_c99
+])
# FPTOOLS_SET_C_LD_FLAGS
# ----------------------------------
diff --git a/configure.ac b/configure.ac
index 7d522b0..ac88433 100644
--- a/configure.ac
+++ b/configure.ac
@@ -461,6 +461,11 @@ FP_CPP_CMD_WITH_ARGS(HaskellCPPCmd, HaskellCPPArgs)
AC_SUBST([HaskellCPPCmd])
AC_SUBST([HaskellCPPArgs])
+FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS])
+FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
+FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
+FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
+
dnl ** Which ld to use?
dnl --------------------------------------------------------------
FIND_LD([LdCmd])
diff --git a/distrib/configure.ac.in b/distrib/configure.ac.in
index 99b51f5..1df58d5 100644
--- a/distrib/configure.ac.in
+++ b/distrib/configure.ac.in
@@ -109,6 +109,11 @@ dnl ** Check gcc version and flags we need to pass it **
#
FP_GCC_EXTRA_FLAGS
+FP_SET_CFLAGS_C99([CC],[CFLAGS],[CPPFLAGS])
+dnl FP_SET_CFLAGS_C99([CC_STAGE0],[CONF_CC_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
+FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
+FP_SET_CFLAGS_C99([CC],[CONF_CC_OPTS_STAGE2],[CONF_CPP_OPTS_STAGE2])
+
FPTOOLS_SET_C_LD_FLAGS([target],[CFLAGS],[LDFLAGS],[IGNORE_LINKER_LD_FLAGS],[CPPFLAGS])
FPTOOLS_SET_C_LD_FLAGS([build],[CONF_CC_OPTS_STAGE0],[CONF_GCC_LINKER_OPTS_STAGE0],[CONF_LD_LINKER_OPTS_STAGE0],[CONF_CPP_OPTS_STAGE0])
FPTOOLS_SET_C_LD_FLAGS([target],[CONF_CC_OPTS_STAGE1],[CONF_GCC_LINKER_OPTS_STAGE1],[CONF_LD_LINKER_OPTS_STAGE1],[CONF_CPP_OPTS_STAGE1])
diff --git a/includes/Stg.h b/includes/Stg.h
index b179db6..f1949b1 100644
--- a/includes/Stg.h
+++ b/includes/Stg.h
@@ -26,6 +26,10 @@
#ifndef STG_H
#define STG_H
+#if !(__STDC_VERSION__ >= 199901L)
+# error __STDC_VERSION__ does not advertise C99 or later
+#endif
+
/*
* If we are compiling a .hc file, then we want all the register
* variables. This is the what happens if you #include "Stg.h" first:
More information about the ghc-commits
mailing list