Fix handling of CXXFLAGS in configure.ac.
authorStephen Sinclair <radarsat1@gmail.com>
Thu, 18 Feb 2016 16:17:06 +0000 (13:17 -0300)
committerStephen Sinclair <radarsat1@gmail.com>
Thu, 18 Feb 2016 16:21:38 +0000 (13:21 -0300)
CXXFLAGS should be set before AC_PROG_CXX.  This patch uses a syntax
allowing it to be overridden during "env CXXFLAGS=... ./configure",
"./configure CXXFLAGS=..." or during "make CXXFLAGS=..."

Keeps previous behaviour of -O3 for normal builds, -g -O0 for debug
builds, and keeps the define __RTAUDIO_DEBUG__, however this is done
using AC_DEFINE.

configure.ac

index 8d0a34c77560e3d39307f550ffb55ca951ca4b4c..68aadbb7f90b2b6673582c5c237e7e696bca4d7c 100644 (file)
@@ -58,6 +58,13 @@ m4_define_default([PKG_CHECK_MODULES],
 AC_MSG_RESULT([no])
 $4])
 
+# Check for debug
+AC_MSG_CHECKING(whether to compile debug version)
+AC_ARG_ENABLE(debug,
+  [AS_HELP_STRING([--enable-debug],[enable various debug output])],
+  [: ${CXXFLAGS="-g -O0"};] [AC_DEFINE([__RTAUDIO_DEBUG__])],
+  [: ${CXXFLAGS="-O3"}])
+
 # Checks for programs.
 AC_PROG_CXX(g++ CC c++ cxx)
 AM_PROG_AR
@@ -74,36 +81,18 @@ AC_CONFIG_MACRO_DIR([m4])
 AC_HEADER_STDC
 AC_CHECK_HEADERS(sys/ioctl.h unistd.h)
 
-# Check for debug
-AC_MSG_CHECKING(whether to compile debug version)
-AC_ARG_ENABLE(debug,
-  [  --enable-debug = enable various debug output],
-  [AC_SUBST( cppflag, [-D__RTAUDIO_DEBUG__] ) AC_SUBST( cxxflag, [-g] ) AC_SUBST( object_path, [Debug] ) AC_MSG_RESULT(yes)],
-  [AC_SUBST( cppflag, [] ) AC_SUBST( cxxflag, [-O2] ) AC_SUBST( object_path, [Release] ) AC_MSG_RESULT(no)])
+# Check compiler and use -Wall if gnu
+if test x"$GXX" = "xyes"; then
+  CXXFLAGS="${CXXFLAGS} -Wall -Wextra"
+  # Add -Werror in debug mode
+  if test x"${enable_debug+set}" = xset; then
+    CXXFLAGS="${CXXFLAGS} -Werror"
+  fi
+fi
 
 # Checks for functions
 AC_CHECK_FUNC(gettimeofday, [cppflag="$cppflag -DHAVE_GETTIMEOFDAY"], )
 
-# Set paths if prefix is defined
-if test "x$prefix" != "x" && test "x$prefix" != "xNONE"; then
-  LIBS="$LIBS -L$prefix/lib"
-  CPPFLAGS="$CPPFLAGS -I$prefix/include"
-fi
-
-# For -I and -D flags
-CPPFLAGS="$CPPFLAGS $cppflag"
-
-# For debugging and optimization ... overwrite default because it has both -g and -O2
-#CXXFLAGS="$CXXFLAGS $cxxflag"
-CXXFLAGS="$cxxflag"
-
-# Check compiler and use -Wall if gnu.
-if [test $GXX = "yes" ;] then
-  AC_SUBST( cxxflag, ["-Wall -Wextra"] )
-fi
-
-CXXFLAGS="$CXXFLAGS $cxxflag"
-
 # Checks for doxygen
 AC_CHECK_PROG( DOXYGEN, [doxygen], [doxygen] )
 AM_CONDITIONAL( MAKE_DOC, [test "x${DOXYGEN}" != x] )