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