From b9d80fa4e8af57d14a8bdff646fe55a699065a8f Mon Sep 17 00:00:00 2001
From: James Zern <jzern@google.com>
Date: Wed, 16 Dec 2015 13:15:53 -0800
Subject: [PATCH] configure: disable asserts by default

--enable-asserts can be used to avoid defining NDEBUG

Change-Id: I6216668e3f79f69bd8c453f0b36cecb3b585688e
---
 configure.ac         | 12 ++++++++++++
 examples/Makefile.am |  2 +-
 src/dec/Makefile.am  |  2 +-
 src/dsp/Makefile.am  |  4 +++-
 src/enc/Makefile.am  |  2 +-
 5 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 0fa16930..e9640874 100644
--- a/configure.ac
+++ b/configure.ac
@@ -31,6 +31,18 @@ AC_ARG_ENABLE([everything],
                SET_IF_UNSET([enable_libwebpextras], [$enableval])
                SET_IF_UNSET([enable_libwebpmux], [$enableval])])
 
+dnl === If --enable-asserts is not defined, define NDEBUG
+
+AC_MSG_CHECKING(whether asserts are enabled)
+AC_ARG_ENABLE([asserts],
+              AS_HELP_STRING([--enable-asserts],
+                             [Enable assert checks]))
+if test "x${enable_asserts-no}" = "xno"; then
+  AM_CPPFLAGS="${AM_CPPFLAGS} -DNDEBUG"
+fi
+AC_MSG_RESULT(${enable_asserts-no})
+AC_SUBST([AM_CPPFLAGS])
+
 AC_ARG_WITH([pkgconfigdir], AS_HELP_STRING([--with-pkgconfigdir=DIR],
             [Path to the pkgconfig directory @<:@LIBDIR/pkgconfig@:>@]),
             [pkgconfigdir="$withval"], [pkgconfigdir='${libdir}/pkgconfig'])
diff --git a/examples/Makefile.am b/examples/Makefile.am
index f3781b19..81970ce1 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src
+AM_CPPFLAGS += -I$(top_builddir)/src -I$(top_srcdir)/src
 
 bin_PROGRAMS = dwebp cwebp
 if BUILD_VWEBP
diff --git a/src/dec/Makefile.am b/src/dec/Makefile.am
index f83e6ed0..7a0b4e81 100644
--- a/src/dec/Makefile.am
+++ b/src/dec/Makefile.am
@@ -24,5 +24,5 @@ libwebpdecodeinclude_HEADERS += ../webp/types.h
 noinst_HEADERS =
 noinst_HEADERS += ../webp/format_constants.h
 
-libwebpdecode_la_CPPFLAGS = $(USE_EXPERIMENTAL_CODE)
+libwebpdecode_la_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
 libwebpdecodeincludedir = $(includedir)/webp
diff --git a/src/dsp/Makefile.am b/src/dsp/Makefile.am
index 7f493e27..01ca685d 100644
--- a/src/dsp/Makefile.am
+++ b/src/dsp/Makefile.am
@@ -98,7 +98,9 @@ noinst_HEADERS =
 noinst_HEADERS += ../dec/decode_vp8.h
 noinst_HEADERS += ../webp/decode.h
 
-libwebpdsp_la_CPPFLAGS = $(USE_EXPERIMENTAL_CODE) $(USE_SWAP_16BIT_CSP)
+libwebpdsp_la_CPPFLAGS =
+libwebpdsp_la_CPPFLAGS += $(AM_CPPFLAGS)
+libwebpdsp_la_CPPFLAGS += $(USE_EXPERIMENTAL_CODE) $(USE_SWAP_16BIT_CSP)
 libwebpdsp_la_LDFLAGS = -lm
 libwebpdsp_la_LIBADD =
 libwebpdsp_la_LIBADD += libwebpdsp_avx2.la libwebpdsp_sse2.la
diff --git a/src/enc/Makefile.am b/src/enc/Makefile.am
index 276233e2..9d388e62 100644
--- a/src/enc/Makefile.am
+++ b/src/enc/Makefile.am
@@ -37,5 +37,5 @@ noinst_HEADERS =
 noinst_HEADERS += ../webp/format_constants.h
 
 libwebpencode_la_LDFLAGS = -lm
-libwebpencode_la_CPPFLAGS = $(USE_EXPERIMENTAL_CODE)
+libwebpencode_la_CPPFLAGS = $(AM_CPPFLAGS) $(USE_EXPERIMENTAL_CODE)
 libwebpencodeincludedir = $(includedir)/webp