]> granicus.if.org Git - re2c/commitdiff
Check CXXFLAGS in configure.
authorUlya Trofimovich <skvadrik@gmail.com>
Tue, 2 Jun 2015 15:58:53 +0000 (16:58 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Tue, 2 Jun 2015 15:58:53 +0000 (16:58 +0100)
Instead of unconditionally setting CXXFLAGS in Makefile.am,
check the presence of a flag in configure.ac. If the flag is
present (that is, an attempt to compile an empty C++ program with
this flag is successful), then it is added to CXXFLAGS.

Now one can add *any* compiler flag in configure.ac without
worrying about portability.

re2c/Makefile.am
re2c/configure.ac

index 67b329c056283cba4cf052a4a6dee15788819931..2b87c6bc379364314064ed6df49fd27f8ddcb899 100644 (file)
@@ -1,6 +1,6 @@
 # flags
-AM_CXXFLAGS = -W -Wall -Wextra -Weffc++ -pedantic -Wredundant-decls -O2
-AM_YFLAGS = -y -d --no-lines
+# do *not* add CXXFLAGS here, add them in configure.ac
+BISONFLAGS = -y -d --no-lines
 RE2CFLAGS = -bi
 
 # binary
@@ -149,7 +149,7 @@ TESTS = run_tests.sh
 $(AUTOGEN_PARSER): $(CUSTOM_PARSER)
        @if test $(BISON) = "yes"; \
        then \
-               bison $(YFLAGS) --output=$@ --defines=$(AUTOGEN_PARSER_HDR) $< && \
+               bison $(BISONFLAGS) --output=$@ --defines=$(AUTOGEN_PARSER_HDR) $< && \
                if cmp -s $@ $(top_srcdir)/$(BOOTSTRAP_PARSER); \
                then \
                        cp $@ $(top_srcdir)/$(BOOTSTRAP_PARSER) && \
index caa6a3f4be7952b4faa8afa90e2133475a5b71e5..a76725db2770069ad90c41b0c7cc9e9f657573d5 100644 (file)
@@ -32,6 +32,33 @@ AC_PROG_CXX
 AC_PROG_INSTALL
 
 
+# checks for C++ compiler flags
+AC_DEFUN([TRY_CXXFLAG], [
+    AC_MSG_CHECKING([C++ compiler flag $1])
+    AS_VAR_SET([CXXFLAGS_BACKUP], ["$CXXFLAGS"])
+    AS_VAR_SET([CXXFLAGS], ["$CXXFLAGS $1"])
+    AC_LANG_PUSH([C++])
+    AC_COMPILE_IFELSE(
+        [AC_LANG_PROGRAM()],
+        [AS_VAR_SET([TRY_CXXFLAG_RESULT], [yes])],
+        [
+            AS_VAR_SET([TRY_CXXFLAG_RESULT], [no])
+            AS_VAR_SET([CXXFLAGS], ["$CXXFLAGS_BACKUP"])
+        ]
+    )
+    AC_LANG_POP([C++])
+    AC_MSG_RESULT([$TRY_CXXFLAG_RESULT])
+])
+TRY_CXXFLAG([-W])
+TRY_CXXFLAG([-Wall])
+TRY_CXXFLAG([-Wextra])
+TRY_CXXFLAG([-Weffc++])
+TRY_CXXFLAG([-pedantic])
+TRY_CXXFLAG([-Wredundant-decls])
+TRY_CXXFLAG([-O2])
+TRY_CXXFLAG([-Weverything])
+
+
 # needed by src/c99_stdint.h
 # avoid AC_INCLUDES_DEFAULT
 AC_CHECK_HEADERS([stdint.h], [], [], [[]])