1# Compile warning arguments to ./configure
2# by Christian Stimming <stimming@tuhh.de> 2003-11-19
3
4dnl ACX_COMPILE_WARN()
5dnl Add arguments for compile warnings and debug options to ./configure.
6dnl
7AC_DEFUN([ACX_COMPILE_WARN],
8[
9dnl Add compile arguments for debugging and warnings. Macro argument
10dnl $1 is the default argument if --enable-debug is not specified.
11
12dnl If no Macro argument is given, enable the debugging code.
13if test -z "$1"; then
14  default_debug_arg="-g"; else
15  default_debug_arg="$1";
16fi
17
18AC_MSG_CHECKING([for compiler arguments])
19
20dnl For enabling of debugging flags/code
21AC_ARG_ENABLE(debug,
22  [  --enable-debug          enable compile arguments for debugging code],
23  [case "${enableval}" in
24     yes)   CXXFLAGS="${CXXFLAGS} -g"
25	    # Remove -O2
26	    CXXFLAGS=`echo "${CXXFLAGS}" | sed -e 's/-O2//'`
27	    CFLAGS=`echo "${CFLAGS}" | sed -e 's/-O2//'`
28	    CFLAGS="${CFLAGS} -g"
29	    LDFLAGS="${LDFLAGS} -g"
30	    AC_DEFINE(DEBUG,1,[Define if you want debugging code enabled.]) ;;
31     no) ;;
32     *) AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
33   esac
34  ], [
35	# Default value if the argument was not given
36	CXXFLAGS="${CXXFLAGS} ${default_debug_arg}"
37	CFLAGS="${CFLAGS} ${default_debug_arg}"
38	LDFLAGS="${LDFLAGS} ${default_debug_arg}"
39])
40
41dnl If this is gcc, then ...
42if test ${GCC}x = yesx; then
43
44  dnl Enable all warnings
45  AC_ARG_ENABLE(warnings,
46    [  --enable-warnings       enable compilation warnings, default=yes],
47    [case "${enableval}" in
48       yes) CXXFLAGS="${CXXFLAGS} -Wall"
49	    CFLAGS="${CFLAGS} -Wall" ;;
50       all) CXXFLAGS="${CXXFLAGS} -Wall -pedantic -ansi"
51	    CFLAGS="${CFLAGS} -Wall -pedantic -ansi" ;;
52       no) ;;
53       *) AC_MSG_ERROR(bad value ${enableval} for --enable-warnings) ;;
54     esac
55  ], [
56     # Default value if the argument was not given
57     CXXFLAGS="${CXXFLAGS} -Wall"
58     CFLAGS="${CFLAGS} -Wall"
59  ])
60
61  dnl For gcc >= 3.4.x, specifically enable the new warning switch
62  dnl -Wdeclaration-after-statement in order to preserve source code
63  dnl compatibility to gcc 2.95 and other compilers.
64  GCC_VERSION=`${CC} -dumpversion`
65  if test `echo ${GCC_VERSION} | cut -d. -f1` -ge 3; then
66     # This is gcc >= 3.x.x
67     if test `echo ${GCC_VERSION} | cut -d. -f2` -ge 4; then
68	# This is gcc >= 3.4.x
69	CFLAGS="${CFLAGS} -Wdeclaration-after-statement"
70     fi
71  fi
72
73  dnl For enabling error on warnings
74  AC_ARG_ENABLE(error-on-warning,
75    [  --enable-error-on-warning treat all compile warnings as errors, default=no],
76    [case "${enableval}" in
77       yes) CXXFLAGS="${CXXFLAGS} -Werror"
78	    CFLAGS="${CFLAGS} -Werror" ;;
79       no) ;;
80       *) AC_MSG_ERROR(bad value ${enableval} for --enable-error-on-warning) ;;
81     esac
82  ], [
83     # Default value if the argument was not given
84     CXXFLAGS="${CXXFLAGS}"
85     CFLAGS="${CFLAGS}"
86  ])
87fi
88
89# Beautify the CXXFLAGS: remove extra spaces, remove double -g
90CXXFLAGS=`echo "${CXXFLAGS}" | sed -e 's/   */ /g' | sed -e 's/-g -g/-g/'`
91CFLAGS=`echo "${CFLAGS}" | sed -e 's/   */ /g' | sed -e 's/-g -g/-g/'`
92
93# Print the result
94AC_MSG_RESULT($CFLAGS)
95
96])
97