2 # Copyright 2015-2018 Nest Labs Inc. All Rights Reserved.
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
19 # This file defines GNU autoconf M4-style macros that ensure the
20 # -Werror (or -Werror=<...>) compiler option(s) for GCC-based or
21 # -compatible compilers do not break some autoconf tests (see
22 # http://lists.gnu.org/archive/html/autoconf-patches/2008-09/msg00014.html).
24 # If -Werror (or -Werror=<...>) has/have been passed transform it
25 # into -Wno-error (or -Wno-error=<...>) for CPPFLAGS, CFLAGS,
26 # CXXFLAGS, OBJCFLAGS, and OBJCXXFLAGS with
27 # NL_SAVE_WERROR. Transform them back again with
32 # _NL_SAVE_WERROR_FOR_VAR(variable)
34 # variable - The compiler flags variable to scan for the presence of
35 # -Werror (or -Werror=<...>) and, if present, transform
36 # to -Wno-error (or -Wno-error=<...>).
38 # This transforms, for the specified compiler flags variable, -Werror
39 # (or -Werror=<...>) to -Wno-error (or -Wno-error=<...>), if it was it
40 # present. The original state may be restored by invoking
41 # _NL_RESTORE_WERROR_FOR_VAR([variable]).
43 #------------------------------------------------------------------------------
44 AC_DEFUN([_NL_SAVE_WERROR_FOR_VAR],
46 if echo "${$1}" | grep -q '\-Werror'; then
47 $1="`echo ${$1} | sed -e 's,-Werror\(=[[[:alnum:]_-]]\+\)*\([[[:space:]]]\),-Wno-error\1\2,g'`"
55 # _NL_RESTORE_WERROR_FOR_VAR(variable)
57 # variable - The compiler flag for which to restore -Wno-error back
58 # to -Werror if it was originally passed in by the user as
61 # This restores, for the specified compiler flags variable, -Werror
62 # (or -Werror=<...>) from -Wno-error (or -Wno-error=<...>), if it was
63 # initially set as -Werror (or -Werror=<...>) at the time
64 # _NL_SAVE_WERROR_FOR_VAR([variable]) was invoked.
66 #------------------------------------------------------------------------------
67 AC_DEFUN([_NL_RESTORE_WERROR_FOR_VAR],
69 if test "${nl_had_$1_werror}" = "yes"; then
70 $1="`echo ${$1} | sed -e 's,-Wno-error\(=[[[:alnum:]_-]]\+\)*\([[[:space:]]]\),-Werror\1\2,g'`"
73 unset nl_had_$1_werror
79 # This transforms, for each of CFLAGS, CXXFLAGS, OBJCFLAGS, and
80 # OBJCXXFLAGS, -Werror (or -Werror=<...>) to -Wno-error (or
81 # -Wno-error=<...>), if it was it present. The original state may be
82 # restored by invoking NL_RESTORE_WERROR.
84 #------------------------------------------------------------------------------
85 AC_DEFUN([NL_SAVE_WERROR],
87 _NL_SAVE_WERROR_FOR_VAR([CPPFLAGS])
88 _NL_SAVE_WERROR_FOR_VAR([CFLAGS])
89 _NL_SAVE_WERROR_FOR_VAR([CXXFLAGS])
90 _NL_SAVE_WERROR_FOR_VAR([OBJCFLAGS])
91 _NL_SAVE_WERROR_FOR_VAR([OBJCXXFLAGS])
97 # This restores, for each of OBJCXXFLAGS, OBJCFLAGS, CXXFLAGS, and
98 # CFLAGS, -Werror (or -Werror=<...>) from -Wno-error (or
99 # -Wno-error=<...>), if it was initially set as -Werror (or
100 # -Werror=<...>) at the time NL_SAVE_WERROR was invoked.
102 #------------------------------------------------------------------------------
103 AC_DEFUN([NL_RESTORE_WERROR],
105 _NL_RESTORE_WERROR_FOR_VAR([OBJCXXFLAGS])
106 _NL_RESTORE_WERROR_FOR_VAR([OBJCFLAGS])
107 _NL_RESTORE_WERROR_FOR_VAR([CXXFLAGS])
108 _NL_RESTORE_WERROR_FOR_VAR([CFLAGS])
109 _NL_RESTORE_WERROR_FOR_VAR([CPPFLAGS])