Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / nlunit-test / repo / third_party / nlbuild-autotools / repo / autoconf / m4 / nl_werror.m4
1 #
2 #    Copyright 2015-2018 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 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).
23 #
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
28 #      NL_RESTORE_WERROR.
29 #
30
31
32 # _NL_SAVE_WERROR_FOR_VAR(variable)
33 #
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=<...>).
37 #
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]).
42 #
43 #------------------------------------------------------------------------------
44 AC_DEFUN([_NL_SAVE_WERROR_FOR_VAR],
45 [
46     if echo "${$1}" | grep -q '\-Werror'; then
47         $1="`echo ${$1} | sed -e 's,-Werror\(=[[[:alnum:]_-]]\+\)*\([[[:space:]]]\),-Wno-error\1\2,g'`"
48         nl_had_$1_werror=yes
49     else
50         nl_had_$1_werror=no
51     fi
52 ])
53
54 #
55 # _NL_RESTORE_WERROR_FOR_VAR(variable)
56 #
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
59 #              such.
60 #
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.
65 #
66 #------------------------------------------------------------------------------
67 AC_DEFUN([_NL_RESTORE_WERROR_FOR_VAR],
68 [
69     if test "${nl_had_$1_werror}" = "yes"; then
70         $1="`echo ${$1} | sed -e 's,-Wno-error\(=[[[:alnum:]_-]]\+\)*\([[[:space:]]]\),-Werror\1\2,g'`"
71     fi
72
73     unset nl_had_$1_werror
74 ])
75
76
77 # NL_SAVE_WERROR
78 #
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.
83 #
84 #------------------------------------------------------------------------------
85 AC_DEFUN([NL_SAVE_WERROR],
86 [
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])
92 ])
93
94 #
95 # NL_RESTORE_WERROR
96 #
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.
101 #
102 #------------------------------------------------------------------------------
103 AC_DEFUN([NL_RESTORE_WERROR],
104 [
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])
110 ])