1#
2#    Copyright 2015-2016 Nest Labs Inc. All Rights Reserved.
3#
4#    Licensed under the Apache License, Version 2.0 (the "License");
5#    you may not use this file except in compliance with the License.
6#    You may obtain a copy of the License at
7#
8#    http://www.apache.org/licenses/LICENSE-2.0
9#
10#    Unless required by applicable law or agreed to in writing, software
11#    distributed under the License is distributed on an "AS IS" BASIS,
12#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13#    See the License for the specific language governing permissions and
14#    limitations under the License.
15#
16
17#
18#    Description:
19#      This file defines a GNU autoconf M4-style macro that adds an
20#      --enable-debug configuration option to the package and controls
21#      whether the package will be built for debug instances of programs
22#      and libraries.
23#
24
25#
26# NL_ENABLE_DEBUG(default)
27#
28#   default - Whether the option should be enabled (yes) or disabled (no)
29#             by default.
30#
31# Adds an --enable-debug configuration option to the package with a
32# default value of 'default' (should be either 'no' or 'yes') and controls
33# whether the package will be built with or without -DDEBUG enabled.
34#
35# The value 'nl_cv_build_debug' will be set to the result. In
36# addition, the contents of CFLAGS, CXXFLAGS, OBJCFLAGS, and
37# OBJCXXFLAGS may be altered by the use of this macro, adding -DDEBUG
38# if this option is asserted.
39#
40#------------------------------------------------------------------------------
41AC_DEFUN([NL_ENABLE_DEBUG],
42[
43    # Check whether or not a default value has been passed in.
44
45    m4_case([$1],
46        [yes],[],
47        [no],[],
48        [m4_fatal([$0: invalid default value '$1'; must be 'yes' or 'no'])])
49
50    AC_CACHE_CHECK([whether to build debug instances of programs and libraries],
51        nl_cv_build_debug,
52        [
53            AC_ARG_ENABLE(debug,
54                [AS_HELP_STRING([--enable-debug],[Enable the generation of debug instances @<:@default=$1@:>@.])],
55                [
56                    case "${enableval}" in
57
58                    no|yes)
59                        nl_cv_build_debug=${enableval}
60                        ;;
61
62                    *)
63                        AC_MSG_ERROR([Invalid value ${enableval} for --enable-debug])
64                        ;;
65
66                    esac
67                ],
68                [
69                    nl_cv_build_debug=$1
70                ])
71
72            if test "${nl_cv_build_debug}" = "yes"; then
73                CFLAGS="${CFLAGS} -DDEBUG"
74                CXXFLAGS="${CXXFLAGS} -DDEBUG"
75                OBJCFLAGS="${OBJCFLAGS} -DDEBUG"
76                OBJCXXFLAGS="${OBJCXXFLAGS} -DDEBUG"
77            fi
78    ])
79])
80