b847432141366f6df4e08269e55e5e286c37a770
[awesomized/libmemcached] / m4 / ax_harden_compiler_flags.m4
1 # ===========================================================================
2 # http://www.gnu.org/software/autoconf-archive/ax_append_flag.html
3 # ===========================================================================
4 #
5 # SYNOPSIS
6 #
7 # AX_HARDEN_COMPILER_FLAGS
8 #
9 # DESCRIPTION
10 #
11 # Any compiler flag that "hardens" or tests code.
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 #serial 1
49
50 AC_DEFUN([AX_HARDEN_COMPILER_FLAGS],
51 [AC_REQUIRE([AX_CHECK_COMPILE_FLAG])
52 AC_REQUIRE([AX_APPEND_FLAG])
53 AC_REQUIRE([AX_CHECK_LINK_FLAG])
54 AX_APPEND_COMPILE_FLAGS([-O2])
55 AX_APPEND_COMPILE_FLAGS([-Werror])
56 AX_APPEND_COMPILE_FLAGS([-Wall])
57 AX_APPEND_COMPILE_FLAGS([-Wextra])
58 AX_APPEND_COMPILE_FLAGS([-Wmaybe-uninitialized])
59 AX_APPEND_COMPILE_FLAGS([-Wsign-compare])
60 AX_APPEND_COMPILE_FLAGS([-Wunused-result])
61 AX_APPEND_COMPILE_FLAGS([-Wunused-variable])
62 AX_APPEND_COMPILE_FLAGS([-floop-parallelize-all])
63 AX_APPEND_COMPILE_FLAGS([-fstack-protector-all])
64 AX_APPEND_COMPILE_FLAGS([-ggdb])
65 AX_APPEND_COMPILE_FLAGS([-fstack-protector-all])
66 AX_APPEND_COMPILE_FLAGS([-Wstack-protector])
67 AX_APPEND_COMPILE_FLAGS([-fwrapv])
68 AX_APPEND_COMPILE_FLAGS([-D_FORTIFY_SOURCE=2])
69 AX_APPEND_COMPILE_FLAGS([--param],[ssp-buffer-size=1])
70 AX_CHECK_LINK_FLAG([-Werror])
71 AX_CHECK_LINK_FLAG([-z relro -z now])
72 ])dnl AX_HARDEN_COMPILER_FLAGS