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