From 14e5d18905938545482d0a73a12333a374bf9525 Mon Sep 17 00:00:00 2001 From: Guido Draheim Date: Mon, 12 Mar 2018 22:47:15 +0100 Subject: [PATCH] add m4/ax_check_enable_debug.m4 --- Makefile.in | 1 + SDL/Makefile.in | 1 + aclocal.m4 | 1 + bins/Makefile.in | 1 + config.h.in | 3 + configure | 100 ++++++++++++++++++++++++ configure.ac | 1 + docs/Makefile.in | 1 + m4/ax_check_enable_debug.m4 | 124 ++++++++++++++++++++++++++++++ m4/ax_not_enable_frame_pointer.m4 | 6 +- test/Makefile.in | 1 + zzip/Makefile.in | 1 + zzipwrap/Makefile.in | 1 + 13 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 m4/ax_check_enable_debug.m4 diff --git a/Makefile.in b/Makefile.in index b60814c..c24b27e 100644 --- a/Makefile.in +++ b/Makefile.in @@ -99,6 +99,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_strict_prototypes.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ + $(top_srcdir)/m4/ax_check_enable_debug.m4 \ $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_enable_builddir.m4 \ diff --git a/SDL/Makefile.in b/SDL/Makefile.in index 8ebf980..3e2c086 100644 --- a/SDL/Makefile.in +++ b/SDL/Makefile.in @@ -102,6 +102,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_strict_prototypes.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ + $(top_srcdir)/m4/ax_check_enable_debug.m4 \ $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_enable_builddir.m4 \ diff --git a/aclocal.m4 b/aclocal.m4 index fc36ce9..c43c3e3 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1195,6 +1195,7 @@ m4_include([m4/ax_cflags_no_writable_strings.m4]) m4_include([m4/ax_cflags_strict_prototypes.m4]) m4_include([m4/ax_cflags_warn_all.m4]) m4_include([m4/ax_check_aligned_access_required.m4]) +m4_include([m4/ax_check_enable_debug.m4]) m4_include([m4/ax_configure_args.m4]) m4_include([m4/ax_create_pkgconfig_info.m4]) m4_include([m4/ax_enable_builddir.m4]) diff --git a/bins/Makefile.in b/bins/Makefile.in index 9273fa2..c31a770 100644 --- a/bins/Makefile.in +++ b/bins/Makefile.in @@ -108,6 +108,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_strict_prototypes.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ + $(top_srcdir)/m4/ax_check_enable_debug.m4 \ $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_enable_builddir.m4 \ diff --git a/config.h.in b/config.h.in index d4c54e1..b267e8b 100644 --- a/config.h.in +++ b/config.h.in @@ -100,6 +100,9 @@ /* Define to the sub-directory where libtool stores uninstalled libraries. */ #undef LT_OBJDIR +/* Define if debugging is disabled */ +#undef NDEBUG + /* Name of package */ #undef PACKAGE diff --git a/configure b/configure index fdac897..b525cf7 100755 --- a/configure +++ b/configure @@ -793,6 +793,7 @@ enable_builddir enable_thread_safe with_zlib enable_silent_rules +enable_debug enable_dependency_tracking enable_shared enable_static @@ -1448,6 +1449,8 @@ Optional Features: --enable-silent-rules less verbose build output (undo: "make V=1") --disable-silent-rules verbose build output (undo: "make V=0") + --enable-debug=[yes/info/profile/no] + compile with debugging --enable-dependency-tracking do not reject slow dependency extractors --disable-dependency-tracking @@ -3628,6 +3631,99 @@ END fi fi + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to enable debugging" >&5 +$as_echo_n "checking whether to enable debugging... " >&6; } + + ax_enable_debug_default=no + ax_enable_debug_is_release=$ax_is_release + + # If this is a release, override the default. + if test "$ax_enable_debug_is_release" = "yes"; then : + ax_enable_debug_default="no" +fi + + + + + # Check whether --enable-debug was given. +if test "${enable_debug+set}" = set; then : + enableval=$enable_debug; +else + enable_debug=$ax_enable_debug_default +fi + + + # empty mean debug yes + if test "x$enable_debug" = "x"; then : + enable_debug="yes" +fi + + # case of debug + case $enable_debug in #( + yes) : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + CFLAGS="${CFLAGS} -g -O0" + CXXFLAGS="${CXXFLAGS} -g -O0" + FFLAGS="${FFLAGS} -g -O0" + FCFLAGS="${FCFLAGS} -g -O0" + OBJCFLAGS="${OBJCFLAGS} -g -O0" + ;; #( + info) : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: info" >&5 +$as_echo "info" >&6; } + CFLAGS="${CFLAGS} -g" + CXXFLAGS="${CXXFLAGS} -g" + FFLAGS="${FFLAGS} -g" + FCFLAGS="${FCFLAGS} -g" + OBJCFLAGS="${OBJCFLAGS} -g" + ;; #( + profile) : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: profile" >&5 +$as_echo "profile" >&6; } + CFLAGS="${CFLAGS} -g -pg" + CXXFLAGS="${CXXFLAGS} -g -pg" + FFLAGS="${FFLAGS} -g -pg" + FCFLAGS="${FCFLAGS} -g -pg" + OBJCFLAGS="${OBJCFLAGS} -g -pg" + LDFLAGS="${LDFLAGS} -pg" + ;; #( + *) : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + if test "x${CFLAGS+set}" != "xset"; then : + CFLAGS="" +fi + if test "x${CXXFLAGS+set}" != "xset"; then : + CXXFLAGS="" +fi + if test "x${FFLAGS+set}" != "xset"; then : + FFLAGS="" +fi + if test "x${FCFLAGS+set}" != "xset"; then : + FCFLAGS="" +fi + if test "x${OBJCFLAGS+set}" != "xset"; then : + OBJCFLAGS="" +fi + ;; +esac + + if test "x$enable_debug" = "xyes"; then : + +else + +$as_echo "#define NDEBUG /**/" >>confdefs.h + +fi + ax_enable_debug=$enable_debug + ac_ext=c ac_cpp='$CPP $CPPFLAGS' ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' @@ -15367,6 +15463,10 @@ if test "${enable_frame_pointer+set}" = set; then : enableval=$enable_frame_pointer; fi +if test ".$enable_frame_pointer" = "."; then + case ".$enable_debug" in .|.no|.no,*) : ;; *) enable_frame_pointer="$enable_debug" ;; esac + case ".$with_debug" in .|.no|.no,*) : ;; *) enable_frame_pointer="$with_debug" ;; esac +fi case ".$enable_frame_pointer" in .|.no|.no,*) test ".$enable_frame_pointer" = "." && enable_frame_pointer="no" CFLAGS=`echo " $CFLAGS " | sed -e 's/ -g / /'` diff --git a/configure.ac b/configure.ac index 804be64..737fea3 100644 --- a/configure.ac +++ b/configure.ac @@ -64,6 +64,7 @@ AC_SUBST(ZLIB_LDIR) # ----------------------------------------------------------------------- AX_SPEC_DEFAULTS AM_INIT_AUTOMAKE($PACKAGE,$VERSION) +AX_CHECK_ENABLE_DEBUG() dnl test ".$CFLAGS" = "." && CFLAGS="" AC_PROG_CC dnl test ".$CFLAGS" = "." && test "$GCC" = "yes" && CFLAGS="-O3" diff --git a/docs/Makefile.in b/docs/Makefile.in index 74a128d..9a24055 100644 --- a/docs/Makefile.in +++ b/docs/Makefile.in @@ -99,6 +99,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_strict_prototypes.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ + $(top_srcdir)/m4/ax_check_enable_debug.m4 \ $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_enable_builddir.m4 \ diff --git a/m4/ax_check_enable_debug.m4 b/m4/ax_check_enable_debug.m4 new file mode 100644 index 0000000..d36bcdf --- /dev/null +++ b/m4/ax_check_enable_debug.m4 @@ -0,0 +1,124 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_check_enable_debug.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_CHECK_ENABLE_DEBUG([enable by default=yes/info/profile/no], [ENABLE DEBUG VARIABLES ...], [DISABLE DEBUG VARIABLES NDEBUG ...], [IS-RELEASE]) +# +# DESCRIPTION +# +# Check for the presence of an --enable-debug option to configure, with +# the specified default value used when the option is not present. Return +# the value in the variable $ax_enable_debug. +# +# Specifying 'yes' adds '-g -O0' to the compilation flags for all +# languages. Specifying 'info' adds '-g' to the compilation flags. +# Specifying 'profile' adds '-g -pg' to the compilation flags and '-pg' to +# the linking flags. Otherwise, nothing is added. +# +# Define the variables listed in the second argument if debug is enabled, +# defaulting to no variables. Defines the variables listed in the third +# argument if debug is disabled, defaulting to NDEBUG. All lists of +# variables should be space-separated. +# +# If debug is not enabled, ensure AC_PROG_* will not add debugging flags. +# Should be invoked prior to any AC_PROG_* compiler checks. +# +# IS-RELEASE can be used to change the default to 'no' when making a +# release. Set IS-RELEASE to 'yes' or 'no' as appropriate. By default, it +# uses the value of $ax_is_release, so if you are using the AX_IS_RELEASE +# macro, there is no need to pass this parameter. +# +# AX_IS_RELEASE([git-directory]) +# AX_CHECK_ENABLE_DEBUG() +# +# LICENSE +# +# Copyright (c) 2011 Rhys Ulerich +# Copyright (c) 2014, 2015 Philip Withnall +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +#serial 8 + +AC_DEFUN([AX_CHECK_ENABLE_DEBUG],[ + AC_BEFORE([$0],[AC_PROG_CC])dnl + AC_BEFORE([$0],[AC_PROG_CXX])dnl + AC_BEFORE([$0],[AC_PROG_F77])dnl + AC_BEFORE([$0],[AC_PROG_FC])dnl + + AC_MSG_CHECKING(whether to enable debugging) + + ax_enable_debug_default=m4_tolower(m4_normalize(ifelse([$1],,[no],[$1]))) + ax_enable_debug_is_release=m4_tolower(m4_normalize(ifelse([$4],, + [$ax_is_release], + [$4]))) + + # If this is a release, override the default. + AS_IF([test "$ax_enable_debug_is_release" = "yes"], + [ax_enable_debug_default="no"]) + + m4_define(ax_enable_debug_vars,[m4_normalize(ifelse([$2],,,[$2]))]) + m4_define(ax_disable_debug_vars,[m4_normalize(ifelse([$3],,[NDEBUG],[$3]))]) + + AC_ARG_ENABLE(debug, + [AS_HELP_STRING([--enable-debug=]@<:@yes/info/profile/no@:>@,[compile with debugging])], + [],enable_debug=$ax_enable_debug_default) + + # empty mean debug yes + AS_IF([test "x$enable_debug" = "x"], + [enable_debug="yes"]) + + # case of debug + AS_CASE([$enable_debug], + [yes],[ + AC_MSG_RESULT(yes) + CFLAGS="${CFLAGS} -g -O0" + CXXFLAGS="${CXXFLAGS} -g -O0" + FFLAGS="${FFLAGS} -g -O0" + FCFLAGS="${FCFLAGS} -g -O0" + OBJCFLAGS="${OBJCFLAGS} -g -O0" + ], + [info],[ + AC_MSG_RESULT(info) + CFLAGS="${CFLAGS} -g" + CXXFLAGS="${CXXFLAGS} -g" + FFLAGS="${FFLAGS} -g" + FCFLAGS="${FCFLAGS} -g" + OBJCFLAGS="${OBJCFLAGS} -g" + ], + [profile],[ + AC_MSG_RESULT(profile) + CFLAGS="${CFLAGS} -g -pg" + CXXFLAGS="${CXXFLAGS} -g -pg" + FFLAGS="${FFLAGS} -g -pg" + FCFLAGS="${FCFLAGS} -g -pg" + OBJCFLAGS="${OBJCFLAGS} -g -pg" + LDFLAGS="${LDFLAGS} -pg" + ], + [ + AC_MSG_RESULT(no) + dnl Ensure AC_PROG_CC/CXX/F77/FC/OBJC will not enable debug flags + dnl by setting any unset environment flag variables + AS_IF([test "x${CFLAGS+set}" != "xset"], + [CFLAGS=""]) + AS_IF([test "x${CXXFLAGS+set}" != "xset"], + [CXXFLAGS=""]) + AS_IF([test "x${FFLAGS+set}" != "xset"], + [FFLAGS=""]) + AS_IF([test "x${FCFLAGS+set}" != "xset"], + [FCFLAGS=""]) + AS_IF([test "x${OBJCFLAGS+set}" != "xset"], + [OBJCFLAGS=""]) + ]) + + dnl Define various variables if debugging is disabled. + dnl assert.h is a NOP if NDEBUG is defined, so define it by default. + AS_IF([test "x$enable_debug" = "xyes"], + [m4_map_args_w(ax_enable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is enabled])])], + [m4_map_args_w(ax_disable_debug_vars, [AC_DEFINE(], [,,[Define if debugging is disabled])])]) + ax_enable_debug=$enable_debug +]) diff --git a/m4/ax_not_enable_frame_pointer.m4 b/m4/ax_not_enable_frame_pointer.m4 index 7499962..9c44f90 100644 --- a/m4/ax_not_enable_frame_pointer.m4 +++ b/m4/ax_not_enable_frame_pointer.m4 @@ -8,7 +8,7 @@ dnl default is "--disable-frame-pointer" dnl dnl @category C dnl @author Guido U. Draheim -dnl @version 2005-01-22 +dnl @version 2018-02-22 dnl @license GPLWithACException AC_DEFUN([AX_NOT_ENABLE_FRAME_POINTER],[dnl @@ -16,6 +16,10 @@ AS_VAR_PUSHDEF([VAR],[enable_frame_pointer])dnl AC_MSG_CHECKING([m4_ifval($1,$1,CFLAGS) frame-pointer]) AC_ARG_ENABLE([frame-pointer], AC_HELP_STRING( [--enable-frame-pointer],[enable callframe generation for debugging])) +if test ".$VAR" = "."; then + case ".$enable_debug" in .|.no|.no,*) : ;; *) VAR="$enable_debug" ;; esac + case ".$with_debug" in .|.no|.no,*) : ;; *) VAR="$with_debug" ;; esac +fi case ".$VAR" in .|.no|.no,*) test ".$VAR" = "." && VAR="no" m4_ifval($1,$1,CFLAGS)=`echo dnl diff --git a/test/Makefile.in b/test/Makefile.in index 33ae72c..92fa312 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -101,6 +101,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_strict_prototypes.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ + $(top_srcdir)/m4/ax_check_enable_debug.m4 \ $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_enable_builddir.m4 \ diff --git a/zzip/Makefile.in b/zzip/Makefile.in index e6d0fc9..62aecb4 100644 --- a/zzip/Makefile.in +++ b/zzip/Makefile.in @@ -101,6 +101,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_strict_prototypes.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ + $(top_srcdir)/m4/ax_check_enable_debug.m4 \ $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_enable_builddir.m4 \ diff --git a/zzipwrap/Makefile.in b/zzipwrap/Makefile.in index c4a3301..37f7ed9 100644 --- a/zzipwrap/Makefile.in +++ b/zzipwrap/Makefile.in @@ -103,6 +103,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/ac_compile_check_sizeof.m4 \ $(top_srcdir)/m4/ax_cflags_strict_prototypes.m4 \ $(top_srcdir)/m4/ax_cflags_warn_all.m4 \ $(top_srcdir)/m4/ax_check_aligned_access_required.m4 \ + $(top_srcdir)/m4/ax_check_enable_debug.m4 \ $(top_srcdir)/m4/ax_configure_args.m4 \ $(top_srcdir)/m4/ax_create_pkgconfig_info.m4 \ $(top_srcdir)/m4/ax_enable_builddir.m4 \ -- 2.40.0