Skip to content

Instantly share code, notes, and snippets.

@m6w6
Created November 7, 2013 06:57
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m6w6/7350219 to your computer and use it in GitHub Desktop.
Save m6w6/7350219 to your computer and use it in GitHub Desktop.
--enable-debug for autoconf
# gcc default/debug CFLAGS handling respecting user's CFLAGS
# avoid AC_PROG_CC setting -O2 CFLAGS which will override DEBUG_CFLAGS' -O0
# must be used right after AC_INIT
AC_DEFUN([ACX_DEBUG_CFLAGS], [
# ensure CFLAGS are set
AS_IF([test "${CFLAGS+set}"], [
USE_DEFAULT_CFLAGS=false
], [
USE_DEFAULT_CFLAGS=true
CFLAGS=""
])
AC_PROG_CC
# add --enable-debug arg
AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [enable debug build]), [], [])
AS_IF([test "$enable_debug" = "yes"], [
# add the DEBUG pre-processor define
AC_DEFINE([DEBUG], [1], [debug build])
# gcc/gdb debug options
AS_IF([test "$GCC" = "yes"], [
DEBUG_CFLAGS="-ggdb -O0 -Werror -pedantic -Wno-format-non-iso"
], [
ACX_DEBUG_CFLAGS_G
])
], [
# what AC_PROG_CC would have done if CFLAGS were not set
AS_IF([$USE_DEFAULT_CFLAGS], [
ACX_DEBUG_CFLAGS_G
AS_IF([test "$GCC" = "yes"], [
DEBUG_CFLAGS="$DEBUG_CFLAGS -O2"
])
])
])
AC_SUBST([DEBUG_CFLAGS], [$DEBUG_CFLAGS])
])
AC_DEFUN([ACX_DEBUG_CFLAGS_G], [
# default to -g
AS_IF([test "$ac_cv_prog_cc_g" = "yes"], [
DEBUG_CFLAGS="-g"
], [
DEBUG_CFLAGS=""
])
])
@m6w6
Copy link
Author

m6w6 commented Nov 7, 2013

Don't forget to add $DEBUG_CFLAGS in your Makefile(.am)s:

AM_CFLAGS = $(PTHREAD_CFLAGS) $(DEBUG_CFLAGS)

@0x501D
Copy link

0x501D commented Aug 31, 2020

What is the license of this file? Can it be used in project with BSD license?

@m6w6
Copy link
Author

m6w6 commented Sep 3, 2020

Yes, all my work is usually BSD licensed, so here you go, just to be sure!

Copyright (c) 2013, Michael Wallner <mike@php.net>.
All rights reserved.

Redistribution and use in source and binary forms, with or without 
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, 
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright 
      notice, this list of conditions and the following disclaimer in the 
      documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

@0x501D
Copy link

0x501D commented Sep 3, 2020

Tnx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment