xref: /freebsd/contrib/lutok/m4/developer-mode.m4 (revision cab6a39d7b343596a5823e65c0f7b426551ec22d)
1dnl Copyright 2010 Google Inc.
2dnl All rights reserved.
3dnl
4dnl Redistribution and use in source and binary forms, with or without
5dnl modification, are permitted provided that the following conditions are
6dnl met:
7dnl
8dnl * Redistributions of source code must retain the above copyright
9dnl   notice, this list of conditions and the following disclaimer.
10dnl * Redistributions in binary form must reproduce the above copyright
11dnl   notice, this list of conditions and the following disclaimer in the
12dnl   documentation and/or other materials provided with the distribution.
13dnl * Neither the name of Google Inc. nor the names of its contributors
14dnl   may be used to endorse or promote products derived from this software
15dnl   without specific prior written permission.
16dnl
17dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29dnl \file developer-mode.m4
30dnl
31dnl "Developer mode" is a mode in which the build system reports any
32dnl build-time warnings as fatal errors.  This helps in minimizing the
33dnl amount of trivial coding problems introduced in the code.
34dnl Unfortunately, this is not bullet-proof due to the wide variety of
35dnl compilers available and their different warning diagnostics.
36dnl
37dnl When developer mode support is added to a package, the compilation will
38dnl gain a bunch of extra warning diagnostics.  These will NOT be enforced
39dnl unless developer mode is enabled.
40dnl
41dnl Developer mode is enabled when the user requests it through the
42dnl configure command line, or when building from the repository.  The
43dnl latter is to minimize the risk of committing new code with warnings
44dnl into the tree.
45
46
47dnl Adds "developer mode" support to the package.
48dnl
49dnl This macro performs the actual definition of the --enable-developer
50dnl flag and implements all of its logic.  See the file-level comment for
51dnl details as to what this implies.
52AC_DEFUN([KYUA_DEVELOPER_MODE], [
53    m4_foreach([language], [$1], [m4_set_add([languages], language)])
54
55    AC_ARG_ENABLE(
56        [developer],
57        AS_HELP_STRING([--enable-developer], [enable developer features]),,
58        [if test -d ${srcdir}/.git; then
59             AC_MSG_NOTICE([building from HEAD; developer mode autoenabled])
60             enable_developer=yes
61         else
62             enable_developer=no
63         fi])
64
65    #
66    # The following warning flags should also be enabled but cannot be.
67    # Reasons given below.
68    #
69    # -Wold-style-cast: Raises errors when using TIOCGWINSZ, at least under
70    #                   Mac OS X.  This is due to the way _IOR is defined.
71    #
72
73    try_c_cxx_flags="-D_FORTIFY_SOURCE=2 \
74                     -Wall \
75                     -Wcast-qual \
76                     -Wextra \
77                     -Wpointer-arith \
78                     -Wredundant-decls \
79                     -Wreturn-type \
80                     -Wshadow \
81                     -Wsign-compare \
82                     -Wswitch \
83                     -Wwrite-strings"
84
85    try_c_flags="-Wmissing-prototypes \
86                 -Wno-traditional \
87                 -Wstrict-prototypes"
88
89    try_cxx_flags="-Wabi \
90                   -Wctor-dtor-privacy \
91                   -Wno-deprecated \
92                   -Wno-non-template-friend \
93                   -Wno-pmf-conversions \
94                   -Wnon-virtual-dtor \
95                   -Woverloaded-virtual \
96                   -Wreorder \
97                   -Wsign-promo \
98                   -Wsynth"
99
100    if test ${enable_developer} = yes; then
101        try_werror=yes
102        try_c_cxx_flags="${try_c_cxx_flags} -g -Werror"
103    else
104        try_werror=no
105        try_c_cxx_flags="${try_c_cxx_flags} -DNDEBUG"
106    fi
107
108    m4_set_contains([languages], [C],
109                    [KYUA_CC_FLAGS(${try_c_cxx_flags} ${try_c_flags})])
110    m4_set_contains([languages], [C++],
111                    [KYUA_CXX_FLAGS(${try_c_cxx_flags} ${try_cxx_flags})])
112])
113