-
Notifications
You must be signed in to change notification settings - Fork 200
/
acinclude.m4
148 lines (133 loc) · 4.57 KB
/
acinclude.m4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
dnl
dnl Taken from libvirt/acinclude.m4
dnl
dnl We've added:
dnl -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wredundant-decls
dnl We've removed
dnl CFLAGS="$realsave_CFLAGS"
dnl to avoid clobbering user-specified CFLAGS
dnl
AC_DEFUN([AUGEAS_COMPILE_WARNINGS],[
dnl ******************************
dnl More compiler warnings
dnl ******************************
AC_ARG_ENABLE(compile-warnings,
AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
[Turn on compiler warnings]),,
[enable_compile_warnings="m4_default([$1],[maximum])"])
warnCFLAGS=
common_flags="-fexceptions -fasynchronous-unwind-tables"
case "$enable_compile_warnings" in
no)
try_compiler_flags=""
;;
minimum)
try_compiler_flags="-Wall -Wformat -Wformat-security $common_flags"
;;
yes)
try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes $common_flags"
;;
maximum|error)
try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
try_compiler_flags="$try_compiler_flags -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return"
try_compiler_flags="$try_compiler_flags -Wstrict-prototypes -Wredundant-decls -Wno-sign-compare"
try_compiler_flags="$try_compiler_flags $common_flags"
if test "$enable_compile_warnings" = "error" ; then
try_compiler_flags="$try_compiler_flags -Werror"
fi
;;
*)
AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
;;
esac
AH_VERBATIM([FORTIFY_SOURCE],
[/* Enable compile-time and run-time bounds-checking, and some warnings,
without upsetting newer glibc. */
#if !defined _FORTIFY_SOURCE && defined __OPTIMIZE__ && __OPTIMIZE__
# define _FORTIFY_SOURCE 2
#endif
])
compiler_flags=
for option in $try_compiler_flags; do
SAVE_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS $option"
AC_MSG_CHECKING([whether gcc understands $option])
AC_TRY_LINK([], [],
has_option=yes,
has_option=no,)
CFLAGS="$SAVE_CFLAGS"
AC_MSG_RESULT($has_option)
if test $has_option = yes; then
compiler_flags="$compiler_flags $option"
fi
unset has_option
unset SAVE_CFLAGS
done
unset option
unset try_compiler_flags
AC_ARG_ENABLE(iso-c,
AC_HELP_STRING([--enable-iso-c],
[Try to warn if code is not ISO C ]),,
[enable_iso_c=no])
AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
complCFLAGS=
if test "x$enable_iso_c" != "xno"; then
if test "x$GCC" = "xyes"; then
case " $CFLAGS " in
*[\ \ ]-ansi[\ \ ]*) ;;
*) complCFLAGS="$complCFLAGS -ansi" ;;
esac
case " $CFLAGS " in
*[\ \ ]-pedantic[\ \ ]*) ;;
*) complCFLAGS="$complCFLAGS -pedantic" ;;
esac
fi
fi
AC_MSG_RESULT($complCFLAGS)
WARN_CFLAGS="$compiler_flags $complCFLAGS"
AC_SUBST(WARN_CFLAGS)
])
dnl
dnl Determine readline linker flags in a way that works on RHEL 5
dnl Check for rl_completion_matches (missing on OS/X)
dnl
AC_DEFUN([AUGEAS_CHECK_READLINE], [
AC_CHECK_HEADERS([readline/readline.h])
# Check for readline.
AC_CHECK_LIB(readline, readline,
[use_readline=yes; READLINE_LIBS=-lreadline],
[use_readline=no])
# If the above test failed, it may simply be that -lreadline requires
# some termcap-related code, e.g., from one of the following libraries.
# See if adding one of them to LIBS helps.
if test $use_readline = no; then
saved_libs=$LIBS
LIBS=
AC_SEARCH_LIBS(tgetent, ncurses curses termcap termlib)
case $LIBS in
no*) ;; # handle "no" and "none required"
*) # anything else is a -lLIBRARY
# Now, check for -lreadline again, also using $LIBS.
# Note: this time we use a different function, so that
# we don't get a cached "no" result.
AC_CHECK_LIB(readline, rl_initialize,
[use_readline=yes
READLINE_LIBS="-lreadline $LIBS"],,
[$LIBS])
;;
esac
test $use_readline = no &&
AC_MSG_WARN([readline library not found])
LIBS=$saved_libs
fi
if test $use_readline = no; then
AC_MSG_ERROR(Could not find a working readline library (see config.log for details).)
fi
AC_SUBST(READLINE_LIBS)
if test $use_readline = yes; then
saved_libs=$LIBS
LIBS=$READLINE_LIBS
AC_CHECK_FUNCS([rl_completion_matches rl_crlf rl_replace_line])
LIBS=$saved_libs
fi
])