diff --git a/build/autotools/m4/lol-misc.m4 b/build/autotools/m4/lol-misc.m4 new file mode 100644 index 00000000..0beec842 --- /dev/null +++ b/build/autotools/m4/lol-misc.m4 @@ -0,0 +1,32 @@ + +dnl LOL_TRY_CFLAGS (CFLAGS, [ACTION-IF-WORKS], [ACTION-IF-FAILS]) +dnl check if $CC supports a given set of cflags +AC_DEFUN([LOL_TRY_CFLAGS], + [AC_MSG_CHECKING([if $CC supports $1 flags]) + save_CFLAGS="$CFLAGS" + CFLAGS="$1" + AC_TRY_COMPILE([],[],[ac_cv_try_cflags_ok=yes],[ac_cv_try_cflags_ok=no]) + CFLAGS="$save_CFLAGS" + AC_MSG_RESULT([$ac_cv_try_cflags_ok]) + if test x"$ac_cv_try_cflags_ok" = x"yes"; then + ifelse([$2],[],[:],[$2]) + else + ifelse([$3],[],[:],[$3]) + fi]) + +dnl LOL_TRY_CXXFLAGS (CXXFLAGS, [ACTION-IF-WORKS], [ACTION-IF-FAILS]) +dnl check if $CXX supports a given set of cxxflags +AC_DEFUN([LOL_TRY_CXXFLAGS], + [AC_MSG_CHECKING([if $CXX supports $1 flags]) + AC_LANG_PUSH(C++) + save_CXXFLAGS="$CXXFLAGS" + CXXFLAGS="$1" + AC_TRY_COMPILE([],[],[ac_cv_try_cxxflags_ok=yes],[ac_cv_try_cxxflags_ok=no]) + CXXFLAGS="$save_CXXFLAGS" + AC_MSG_RESULT([$ac_cv_try_cxxflags_ok]) + if test x"$ac_cv_try_cxxflags_ok" = x"yes"; then + ifelse([$2],[],[:],[$2]) + else + ifelse([$3],[],[:],[$3]) + fi + AC_LANG_POP(C++)]) diff --git a/configure.ac b/configure.ac index 5645c5c6..e310fc8f 100644 --- a/configure.ac +++ b/configure.ac @@ -139,12 +139,28 @@ AM_CONDITIONAL(BUILD_DOCUMENTATION, test "${DOXYGEN}" != "no") AM_CONDITIONAL(USE_LATEX, test "${LATEX}" != "no") AM_CONDITIONAL(USE_DOT, test "${DOT}" != "no") -dnl No exceptions -AM_CXXFLAGS="${AM_CXXFLAGS} -fno-exceptions -fno-rtti" -dnl Optimizations + +dnl No exceptions +LOL_TRY_CXXFLAGS(-fno-exceptions, [AM_CXXFLAGS="${AM_CXXFLAGS} -fno-exceptions"]) +LOL_TRY_CXXFLAGS(-fno-rtti, [AM_CXXFLAGS="${AM_CXXFLAGS} -fno-rtti"]) + +dnl Optimizations AM_CXXFLAGS="${AM_CXXFLAGS} ${REL} ${OPT}" -dnl Code qui fait des warnings == code de porc == deux baffes dans ta gueule -AM_CPPFLAGS="${AM_CPPFLAGS} -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wshadow -Wsign-compare" + +dnl Code qui fait des warnings == code de porc == deux baffes dans ta gueule +LOL_TRY_CXXFLAGS(-Wall, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wall"]) +LOL_TRY_CXXFLAGS(-Wextra, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wextra"]) +LOL_TRY_CXXFLAGS(-Wpointer-arith, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wpointer-arith"]) +LOL_TRY_CXXFLAGS(-Wcast-align, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-align"]) +LOL_TRY_CXXFLAGS(-Wcast-qual, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wcast-qual"]) +LOL_TRY_CXXFLAGS(-Wshadow, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wshadow"]) +LOL_TRY_CXXFLAGS(-Wsign-compare, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wsign-compare"]) + +dnl Add these even though they're implicitly set, so that we can safely +dnl remove them from within a Makefile. +LOL_TRY_CXXFLAGS(-Wno-maybe-uninitialized, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wno-maybe-uninitialized"]) +LOL_TRY_CXXFLAGS(-Wno-narrowing, [AM_CPPFLAGS="${AM_CPPFLAGS} -Wno-narrowing"]) + AC_CHECK_LIB(m, sin, MATH_LIBS="${MATH_LIBS} -lm") AC_CHECK_LIB(pthread, main, LIBS="$LIBS -lpthread") diff --git a/src/bullet/Makefile.am b/src/bullet/Makefile.am index a5eff758..8ce26047 100644 --- a/src/bullet/Makefile.am +++ b/src/bullet/Makefile.am @@ -3,10 +3,15 @@ include $(top_srcdir)/build/autotools/common.am noinst_LIBRARIES = liblolbullet.a +# Only remove flags that were actually set, because we don't know +# what the compiler actually accepts. +disable_cflags = $(filter $(AM_CPPFLAGS:-W%=-Wno-%), \ + -Wno-shadow -Wno-unused -Wno-cast-qual -Wno-strict-aliasing \ + -Wno-reorder -Wno-maybe-uninitialized, -Wno-narrowing \ + -Wno-parentheses) + liblolbullet_a_SOURCES = $(bullet_sources) -liblolbullet_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir) \ - -Wno-extra -Wno-shadow -Wno-unused -Wno-cast-qual -Wno-strict-aliasing \ - -Wno-parentheses -Wno-reorder +liblolbullet_a_CPPFLAGS = $(AM_CPPFLAGS) -I$(srcdir) $(disable_cflags) bullet_sources =