webperimental: killstack decides stack protects.
[freeciv.git] / m4 / debug.m4
blob48d1b98fe5a1656d5dbcefc719cb610348c8e02d
1 AC_DEFUN([FC_DEBUG], [
2 AC_ARG_ENABLE(debug,
3   AS_HELP_STRING([--enable-debug[[=no/some/yes/checks]]], [turn on debugging [default=some]]),
4 [case "${enableval}" in
5   yes)    enable_debug=yes ;;
6   some)   enable_debug=some ;;
7   checks) enable_debug=checks ;;
8   no)     enable_debug=no ;;
9   *)      AC_MSG_ERROR(bad value ${enableval} for --enable-debug) ;;
10 esac], [enable_debug=some])
12 dnl -g is added by AC_PROG_CC if the compiler understands it
14 dnl ==========================================================================
15 dnl Always
16 FC_C_FLAGS([-Wno-tautological-compare -Wno-nonnull-compare],
17            [], [EXTRA_DEBUG_CFLAGS])
18 if test "x$cxx_works" = "xyes" ; then
19   FC_CXX_FLAGS([-Wno-tautological-compare -Wno-nonnull-compare],
20                [], [EXTRA_DEBUG_CXXFLAGS])
23 dnl ==========================================================================
24 dnl debug level == no
25 if test "x$enable_debug" = "xno"; then
26   AC_DEFINE([NDEBUG], [1], [No debugging support at all])
27   AC_DEFINE([FREECIV_NDEBUG], [1], [No freeciv specific debugging support at all])
28   FC_C_FLAGS([-O3 -fomit-frame-pointer], [], [EXTRA_DEBUG_CFLAGS])
29   if test "x$cxx_works" = "xyes" ; then
30     AC_DEFINE([QT_NO_DEBUG], [1], [Qt debugging support disabled])
31     FC_CXX_FLAGS([-O3 -fomit-frame-pointer], [], [EXTRA_DEBUG_CXXFLAGS])
32   fi
35 dnl ==========================================================================
36 dnl debug level >= some
37 if test "x$enable_debug" = "xsome" -o "x$enable_debug" = "xyes" -o \
38         "x$enable_debug" = "xchecks"; then
39   FC_C_FLAGS([-Wall -Wpointer-arith -Wcast-align ],
40              [], [EXTRA_DEBUG_CFLAGS])
41   if test "x$cxx_works" = "xyes" ; then
42     AC_DEFINE([QT_NO_DEBUG], [1], [Qt debugging support disabled])
43     FC_CXX_FLAGS([-Wall -Wpointer-arith -Wcast-align],
44                  [], [EXTRA_DEBUG_CXXFLAGS])
45   fi
48 dnl ==========================================================================
49 dnl debug level >= yes
50 if test "x$enable_debug" = "xyes" -o "x$enable_debug" = "xchecks"; then
51   AC_DEFINE([FREECIV_DEBUG], [1], [Extra debugging support])
52   AC_DEFINE([LUA_USE_APICHECK], [1], [Lua Api checks])
54   FC_C_FLAGS([-Werror -Wmissing-prototypes -Wmissing-declarations \
55               -Wformat -Wformat-security -Wnested-externs \
56               -Wshadow],
57              [], [EXTRA_DEBUG_CFLAGS])
58   if test "x$cxx_works" = "xyes" ; then
59     FC_CXX_FLAGS([-Werror -Wmissing-prototypes -Wmissing-declarations \
60                   -Wformat -Wformat-security],
61                  [], [EXTRA_DEBUG_CXXFLAGS])
62   fi
64   dnl backtrace log callback needs "-rdynamic" in order to work well.
65   FC_LD_FLAGS([-rdynamic -Wl,--no-add-needed], [], [EXTRA_DEBUG_LDFLAGS])
68 dnl ==========================================================================
69 dnl debug level >= checks
70 if test "x$enable_debug" = "xchecks"; then
71   dnl Add additional flags as stated in ./doc/HACKING.
72   FC_C_FLAGS([-Wstrict-prototypes], [], [EXTRA_DEBUG_CFLAGS])