~drizzle-trunk/drizzle/jenkins-Drizzle-Builder-155

« back to all changes in this revision

Viewing changes to m4/ax_harden_compiler_flags.m4

  • Committer: Continuous Integration
  • Date: 2013-01-24 09:10:38 UTC
  • mfrom: (2616.1.1 7.2)
  • Revision ID: ci@drizzle.org-20130124091038-cg9n2npx2laqyr90
Merge lp:~brianaker/drizzle/warning-cleanup Build: jenkins-Drizzle-Builder-155

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# ===========================================================================
 
2
#      https://github.com/BrianAker/ddm4/
 
3
# ===========================================================================
 
4
#
 
5
# SYNOPSIS
 
6
#
 
7
#   AX_HARDEN_COMPILER_FLAGS() AX_HARDEN_LINKER_FLAGS()
 
8
#
 
9
# DESCRIPTION
 
10
#
 
11
#   Any compiler flag that "hardens" or tests code. C99 is assumed.
 
12
#
 
13
#   NOTE: Implementation based on AX_APPEND_FLAG.
 
14
#
 
15
# LICENSE
 
16
#
 
17
#  Copyright (C) 2012 Brian Aker
 
18
#  All rights reserved.
 
19
#
 
20
#  Redistribution and use in source and binary forms, with or without
 
21
#  modification, are permitted provided that the following conditions are
 
22
#  met:
 
23
#
 
24
#      * Redistributions of source code must retain the above copyright
 
25
#  notice, this list of conditions and the following disclaimer.
 
26
#
 
27
#      * Redistributions in binary form must reproduce the above
 
28
#  copyright notice, this list of conditions and the following disclaimer
 
29
#  in the documentation and/or other materials provided with the
 
30
#  distribution.
 
31
#
 
32
#      * The names of its contributors may not be used to endorse or
 
33
#  promote products derived from this software without specific prior
 
34
#  written permission.
 
35
#
 
36
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
37
#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
38
#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
39
#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
40
#  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
41
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
42
#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
43
#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
44
#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
45
#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
46
#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
47
 
 
48
# The Following flags are not checked for
 
49
# -Wdeclaration-after-statement is counter to C99
 
50
# _APPEND_COMPILE_FLAGS_ERROR([-std=c++11]) -- Not ready yet
 
51
# _APPEND_COMPILE_FLAGS_ERROR([-pedantic]) --
 
52
# ?  _APPEND_COMPILE_FLAGS_ERROR([-Wlong-long]) -- Don't turn on for
 
53
# compatibility issues memcached_stat_st
 
54
 
 
55
#serial 7
 
56
 
 
57
AC_DEFUN([_WARNINGS_AS_ERRORS],
 
58
    [AC_CACHE_CHECK([if all warnings into errors],[ac_cv_warnings_as_errors],
 
59
      [AS_IF([test "x$ac_cv_vcs_checkout" = xyes],[ac_cv_warnings_as_errors=yes],
 
60
        [ac_cv_warnings_as_errors=no])
 
61
      ])
 
62
    ])
 
63
 
 
64
AC_DEFUN([_APPEND_LINK_FLAGS_ERROR],
 
65
         [AC_REQUIRE([AX_APPEND_LINK_FLAGS])
 
66
         AX_APPEND_LINK_FLAGS([$1],[LIB],[-Werror])
 
67
         ])
 
68
 
 
69
AC_DEFUN([_APPEND_COMPILE_FLAGS_ERROR],
 
70
         [AC_REQUIRE([AX_APPEND_COMPILE_FLAGS])
 
71
         AX_APPEND_COMPILE_FLAGS([$1],,[-Werror])
 
72
         ])
 
73
 
 
74
# Everything above this does the heavy lifting, while what follows does the specifics.
 
75
 
 
76
AC_DEFUN([_HARDEN_LINKER_FLAGS],
 
77
         [_APPEND_LINK_FLAGS_ERROR([-z relro -z now])
 
78
         _APPEND_LINK_FLAGS_ERROR([-pie])
 
79
         AS_IF([test "x$ac_cv_warnings_as_errors" = xyes],
 
80
               [AX_APPEND_LINK_FLAGS([-Werror])])
 
81
         ])
 
82
 
 
83
AC_DEFUN([_HARDEN_CC_COMPILER_FLAGS],
 
84
         [AC_LANG_PUSH([C])dnl
 
85
 
 
86
         AS_IF([test "x$ax_enable_debug" = xyes],
 
87
           [_APPEND_COMPILE_FLAGS_ERROR([-ggdb])
 
88
           _APPEND_COMPILE_FLAGS_ERROR([-g])
 
89
           _APPEND_COMPILE_FLAGS_ERROR([-O0])],
 
90
           [_APPEND_COMPILE_FLAGS_ERROR([-g])
 
91
           _APPEND_COMPILE_FLAGS_ERROR([-O2])])
 
92
 
 
93
         _APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])
 
94
         _APPEND_COMPILE_FLAGS_ERROR([-Wall])
 
95
         _APPEND_COMPILE_FLAGS_ERROR([-Wextra])
 
96
         _APPEND_COMPILE_FLAGS_ERROR([-Wunknown-pragmas])
 
97
         _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail])
 
98
         _APPEND_COMPILE_FLAGS_ERROR([-std=c99])
 
99
# Anything below this comment please keep sorted.
 
100
         _APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1])
 
101
# _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-format-attribute])
 
102
          _APPEND_COMPILE_FLAGS_ERROR([-Wno-attributes])
 
103
          _APPEND_COMPILE_FLAGS_ERROR([-Waddress])
 
104
          _APPEND_COMPILE_FLAGS_ERROR([-Warray-bounds])
 
105
          _APPEND_COMPILE_FLAGS_ERROR([-Wbad-function-cast])
 
106
# Not in use -Wc++-compat
 
107
          _APPEND_COMPILE_FLAGS_ERROR([-Wchar-subscripts])
 
108
          _APPEND_COMPILE_FLAGS_ERROR([-Wcomment])
 
109
          _APPEND_COMPILE_FLAGS_ERROR([-Wfloat-equal])
 
110
          _APPEND_COMPILE_FLAGS_ERROR([-Wformat-security])
 
111
#          _APPEND_COMPILE_FLAGS_ERROR([-Wformat=2])
 
112
          _APPEND_COMPILE_FLAGS_ERROR([-Wlogical-op])
 
113
          _APPEND_COMPILE_FLAGS_ERROR([-Wmaybe-uninitialized])
 
114
          _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-field-initializers])
 
115
          AS_IF([test "x$MINGW" = xyes],
 
116
                [_APPEND_COMPILE_FLAGS_ERROR([-Wno-missing-noreturn])],
 
117
                [_APPEND_COMPILE_FLAGS_ERROR([-Wmissing-noreturn])])
 
118
          _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-prototypes])
 
119
          _APPEND_COMPILE_FLAGS_ERROR([-Wnested-externs])
 
120
          _APPEND_COMPILE_FLAGS_ERROR([-Wnormalized=id])
 
121
          _APPEND_COMPILE_FLAGS_ERROR([-Wold-style-definition])
 
122
          _APPEND_COMPILE_FLAGS_ERROR([-Woverride-init])
 
123
          _APPEND_COMPILE_FLAGS_ERROR([-Wpointer-arith])
 
124
          _APPEND_COMPILE_FLAGS_ERROR([-Wpointer-sign])
 
125
          AS_IF([test "x$MINGW" = xyes],
 
126
                [_APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=const])
 
127
                _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=noreturn])
 
128
                _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=pure])
 
129
                _APPEND_COMPILE_FLAGS_ERROR([-Wno-redundant-decls])],
 
130
                [_APPEND_COMPILE_FLAGS_ERROR([-Wredundant-decls])])
 
131
 
 
132
          _APPEND_COMPILE_FLAGS_ERROR([-Wshadow])
 
133
          _APPEND_COMPILE_FLAGS_ERROR([-Wshorten-64-to-32])
 
134
          _APPEND_COMPILE_FLAGS_ERROR([-Wsign-compare])
 
135
          _APPEND_COMPILE_FLAGS_ERROR([-Wstrict-overflow=1])
 
136
          _APPEND_COMPILE_FLAGS_ERROR([-Wstrict-prototypes])
 
137
#          _APPEND_COMPILE_FLAGS_ERROR([-Wswitch-enum])
 
138
          _APPEND_COMPILE_FLAGS_ERROR([-Wundef])
 
139
          _APPEND_COMPILE_FLAGS_ERROR([-Wunused])
 
140
          _APPEND_COMPILE_FLAGS_ERROR([-Wunused-result])
 
141
          _APPEND_COMPILE_FLAGS_ERROR([-Wunused-variable])
 
142
          _APPEND_COMPILE_FLAGS_ERROR([-Wwrite-strings])
 
143
          _APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all])
 
144
          _APPEND_COMPILE_FLAGS_ERROR([-fwrapv])
 
145
          _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt])
 
146
          _APPEND_COMPILE_FLAGS_ERROR([-pipe])
 
147
 
 
148
          AS_IF([test "x$ax_enable_debug" = xno],
 
149
            [AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
 
150
                  [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])
 
151
                  AS_IF([test "x$ac_c_gcc_recent" = xyes],
 
152
                        [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2])
 
153
                        _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector])
 
154
                        _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector])
 
155
                        _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all])
 
156
                        ])])])
 
157
 
 
158
         AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
 
159
               [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])],
 
160
               [_APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])])
 
161
 
 
162
         AS_IF([test "x$ac_cv_warnings_as_errors" = xyes],
 
163
             [AX_APPEND_FLAG([-Werror])])
 
164
 
 
165
          AC_LANG_POP([C])
 
166
  ])
 
167
 
 
168
AC_DEFUN([_HARDEN_CXX_COMPILER_FLAGS],
 
169
         [AC_LANG_PUSH([C++])
 
170
         AC_REQUIRE([_APPEND_COMPILE_FLAGS_ERROR])
 
171
 
 
172
         AS_IF([test "x$ax_enable_debug" = xyes],
 
173
           [CXXFLAGS=''
 
174
           _APPEND_COMPILE_FLAGS_ERROR([-ggdb])
 
175
           _APPEND_COMPILE_FLAGS_ERROR([-g])
 
176
           _APPEND_COMPILE_FLAGS_ERROR([-O0])],
 
177
           [_APPEND_COMPILE_FLAGS_ERROR([-g])
 
178
           _APPEND_COMPILE_FLAGS_ERROR([-O2])])
 
179
 
 
180
         AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
 
181
           [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])],
 
182
           [_APPEND_COMPILE_FLAGS_ERROR([-Wno-pragmas])])
 
183
 
 
184
         _APPEND_COMPILE_FLAGS_ERROR([-Wall])
 
185
         _APPEND_COMPILE_FLAGS_ERROR([-Wextra])
 
186
         _APPEND_COMPILE_FLAGS_ERROR([-Wunknown-pragmas])
 
187
         _APPEND_COMPILE_FLAGS_ERROR([-Wthis-test-should-fail])
 
188
# Anything below this comment please keep sorted.
 
189
         _APPEND_COMPILE_FLAGS_ERROR([--param=ssp-buffer-size=1])
 
190
# _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-format-attribute])
 
191
          _APPEND_COMPILE_FLAGS_ERROR([-Wno-attributes])
 
192
          _APPEND_COMPILE_FLAGS_ERROR([-Waddress])
 
193
          _APPEND_COMPILE_FLAGS_ERROR([-Warray-bounds])
 
194
          _APPEND_COMPILE_FLAGS_ERROR([-Wchar-subscripts])
 
195
          _APPEND_COMPILE_FLAGS_ERROR([-Wcomment])
 
196
          _APPEND_COMPILE_FLAGS_ERROR([-Wctor-dtor-privacy])
 
197
          _APPEND_COMPILE_FLAGS_ERROR([-Wfloat-equal])
 
198
#          _APPEND_COMPILE_FLAGS_ERROR([-Wformat=2])
 
199
          _APPEND_COMPILE_FLAGS_ERROR([-Wmaybe-uninitialized])
 
200
          _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-field-initializers])
 
201
          _APPEND_COMPILE_FLAGS_ERROR([-Wlogical-op])
 
202
          _APPEND_COMPILE_FLAGS_ERROR([-Wnon-virtual-dtor])
 
203
          _APPEND_COMPILE_FLAGS_ERROR([-Wnormalized=id])
 
204
          _APPEND_COMPILE_FLAGS_ERROR([-Woverloaded-virtual])
 
205
          _APPEND_COMPILE_FLAGS_ERROR([-Wpointer-arith])
 
206
          AS_IF([test "x$MINGW" = xyes],
 
207
                [_APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=const])
 
208
                _APPEND_COMPILE_FLAGS_ERROR([-Wno-missing-noreturn])
 
209
                _APPEND_COMPILE_FLAGS_ERROR([-Wmissing-noreturn])
 
210
                _APPEND_COMPILE_FLAGS_ERROR([-Wno-suggest-attribute=noreturn])
 
211
                _APPEND_COMPILE_FLAGS_ERROR([-Wno-error=suggest-attribute=noreturn])
 
212
                _APPEND_COMPILE_FLAGS_ERROR([-Wno-redundant-decls])],
 
213
                [_APPEND_COMPILE_FLAGS_ERROR([-Wredundant-decls])])
 
214
          _APPEND_COMPILE_FLAGS_ERROR([-Wshadow])
 
215
          _APPEND_COMPILE_FLAGS_ERROR([-Wshorten-64-to-32])
 
216
          _APPEND_COMPILE_FLAGS_ERROR([-Wsign-compare])
 
217
          _APPEND_COMPILE_FLAGS_ERROR([-Wstrict-overflow=1])
 
218
#          _APPEND_COMPILE_FLAGS_ERROR([-Wswitch-enum])
 
219
          _APPEND_COMPILE_FLAGS_ERROR([-Wundef])
 
220
          _APPEND_COMPILE_FLAGS_ERROR([-Wc++11-compat])
 
221
          _APPEND_COMPILE_FLAGS_ERROR([-Wunused])
 
222
          _APPEND_COMPILE_FLAGS_ERROR([-Wunused-result])
 
223
          _APPEND_COMPILE_FLAGS_ERROR([-Wunused-variable])
 
224
          _APPEND_COMPILE_FLAGS_ERROR([-Wwrite-strings])
 
225
          _APPEND_COMPILE_FLAGS_ERROR([-Wformat-security])
 
226
          _APPEND_COMPILE_FLAGS_ERROR([-floop-parallelize-all])
 
227
          _APPEND_COMPILE_FLAGS_ERROR([-fwrapv])
 
228
          _APPEND_COMPILE_FLAGS_ERROR([-fmudflapt])
 
229
          _APPEND_COMPILE_FLAGS_ERROR([-pipe])
 
230
 
 
231
          AS_IF([test "x$ax_enable_debug" = xno],
 
232
          [AS_IF([test "x$ac_cv_vcs_checkout" = xyes],
 
233
                [_APPEND_COMPILE_FLAGS_ERROR([-fstack-check])
 
234
                AS_IF([test "x$ac_c_gcc_recent" = xyes],
 
235
                      [_APPEND_COMPILE_FLAGS_ERROR([-D_FORTIFY_SOURCE=2])
 
236
                      _APPEND_COMPILE_FLAGS_ERROR([-Wstack-protector])
 
237
                      _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector])
 
238
                      _APPEND_COMPILE_FLAGS_ERROR([-fstack-protector-all])
 
239
                      ])])])
 
240
 
 
241
          AS_IF([test "x$ac_cv_warnings_as_errors" = xyes],
 
242
                [AX_APPEND_FLAG([-Werror])])
 
243
          AC_LANG_POP([C++])
 
244
  ])
 
245
 
 
246
# All of the heavy lifting happens in _HARDEN_LINKER_FLAGS,
 
247
# _HARDEN_CC_COMPILER_FLAGS, _HARDEN_CXX_COMPILER_FLAGS
 
248
  AC_DEFUN([AX_HARDEN_COMPILER_FLAGS],
 
249
           [AC_PREREQ([2.63])dnl
 
250
           AC_REQUIRE([_WARNINGS_AS_ERRORS])
 
251
           AC_REQUIRE([AX_APPEND_LINK_FLAGS])
 
252
           AC_REQUIRE([AX_COMPILER_VERSION])
 
253
           AC_REQUIRE([AX_DEBUG])
 
254
           AC_REQUIRE([AX_VCS_CHECKOUT])
 
255
 
 
256
           AC_REQUIRE([gl_VISIBILITY])
 
257
           AS_IF([test -n "$CFLAG_VISIBILITY"],[CPPFLAGS="$CPPFLAGS $CFLAG_VISIBILITY"])
 
258
 
 
259
           AC_REQUIRE([_HARDEN_LINKER_FLAGS])
 
260
           AC_REQUIRE([_HARDEN_CC_COMPILER_FLAGS])
 
261
           AC_REQUIRE([_HARDEN_CXX_COMPILER_FLAGS])
 
262
           ])