aboutsummaryrefslogtreecommitdiffstats
path: root/m4/developer-mode.m4
blob: ad946056f63ce56dbd3da06940542ebed00bb3c5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
dnl Copyright 2010 The Kyua Authors.
dnl All rights reserved.
dnl
dnl Redistribution and use in source and binary forms, with or without
dnl modification, are permitted provided that the following conditions are
dnl met:
dnl
dnl * Redistributions of source code must retain the above copyright
dnl   notice, this list of conditions and the following disclaimer.
dnl * Redistributions in binary form must reproduce the above copyright
dnl   notice, this list of conditions and the following disclaimer in the
dnl   documentation and/or other materials provided with the distribution.
dnl * Neither the name of Google Inc. nor the names of its contributors
dnl   may be used to endorse or promote products derived from this software
dnl   without specific prior written permission.
dnl
dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

dnl \file developer-mode.m4
dnl
dnl "Developer mode" is a mode in which the build system reports any
dnl build-time warnings as fatal errors.  This helps in minimizing the
dnl amount of trivial coding problems introduced in the code.
dnl Unfortunately, this is not bullet-proof due to the wide variety of
dnl compilers available and their different warning diagnostics.
dnl
dnl When developer mode support is added to a package, the compilation will
dnl gain a bunch of extra warning diagnostics.  These will NOT be enforced
dnl unless developer mode is enabled.
dnl
dnl Developer mode is enabled when the user requests it through the
dnl configure command line, or when building from the repository.  The
dnl latter is to minimize the risk of committing new code with warnings
dnl into the tree.


dnl Adds "developer mode" support to the package.
dnl
dnl This macro performs the actual definition of the --enable-developer
dnl flag and implements all of its logic.  See the file-level comment for
dnl details as to what this implies.
AC_DEFUN([KYUA_DEVELOPER_MODE], [
    m4_foreach([language], [$1], [m4_set_add([languages], language)])

    AC_ARG_ENABLE(
        [developer],
        AS_HELP_STRING([--enable-developer], [enable developer features]),,
        [if test -d "${srcdir}/.git"; then
             AC_MSG_NOTICE([building from HEAD; developer mode autoenabled])
             enable_developer=yes
         else
             enable_developer=no
         fi])

    #
    # The following warning flags should also be enabled but cannot be.
    # Reasons given below.
    #
    # -Wold-style-cast: Raises errors when using TIOCGWINSZ, at least under
    #                   Mac OS X.  This is due to the way _IOR is defined.
    #

    try_c_cxx_flags="-D_FORTIFY_SOURCE=2 \
                     -Wall \
                     -Wcast-qual \
                     -Wextra \
                     -Wpointer-arith \
                     -Wredundant-decls \
                     -Wreturn-type \
                     -Wshadow \
                     -Wsign-compare \
                     -Wswitch \
                     -Wwrite-strings"

    try_c_flags="-Wmissing-prototypes \
                 -Wno-traditional \
                 -Wstrict-prototypes"

    try_cxx_flags="-Wabi \
                   -Wctor-dtor-privacy \
                   -Wno-deprecated \
                   -Wno-non-template-friend \
                   -Wno-pmf-conversions \
                   -Wnon-virtual-dtor \
                   -Woverloaded-virtual \
                   -Wreorder \
                   -Wsign-promo \
                   -Wsynth"

    if test ${enable_developer} = yes; then
        try_werror=yes
        try_c_cxx_flags="${try_c_cxx_flags} -g -Werror"
    else
        try_werror=no
        try_c_cxx_flags="${try_c_cxx_flags} -DNDEBUG"
    fi

    m4_set_contains([languages], [C],
                    [KYUA_CC_FLAGS(${try_c_cxx_flags} ${try_c_flags})])
    m4_set_contains([languages], [C++],
                    [KYUA_CXX_FLAGS(${try_c_cxx_flags} ${try_cxx_flags})])
])