Imported Upstream version 0.10.0
[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="-Wp,-D_FORTIFY_SOURCE=2 -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     compiler_flags=
49     for option in $try_compiler_flags; do
50         SAVE_CFLAGS="$CFLAGS"
51         CFLAGS="$CFLAGS $option"
52         AC_MSG_CHECKING([whether gcc understands $option])
53         AC_TRY_LINK([], [],
54                 has_option=yes,
55                 has_option=no,)
56         CFLAGS="$SAVE_CFLAGS"
57         AC_MSG_RESULT($has_option)
58         if test $has_option = yes; then
59           compiler_flags="$compiler_flags $option"
60         fi
61         unset has_option
62         unset SAVE_CFLAGS
63     done
64     unset option
65     unset try_compiler_flags
66
67     AC_ARG_ENABLE(iso-c,
68                   AC_HELP_STRING([--enable-iso-c],
69                                  [Try to warn if code is not ISO C ]),,
70                   [enable_iso_c=no])
71
72     AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
73     complCFLAGS=
74     if test "x$enable_iso_c" != "xno"; then
75         if test "x$GCC" = "xyes"; then
76         case " $CFLAGS " in
77             *[\ \       ]-ansi[\ \      ]*) ;;
78             *) complCFLAGS="$complCFLAGS -ansi" ;;
79         esac
80         case " $CFLAGS " in
81             *[\ \       ]-pedantic[\ \  ]*) ;;
82             *) complCFLAGS="$complCFLAGS -pedantic" ;;
83         esac
84         fi
85     fi
86     AC_MSG_RESULT($complCFLAGS)
87
88     WARN_CFLAGS="$compiler_flags $complCFLAGS"
89     AC_SUBST(WARN_CFLAGS)
90 ])
91
92 dnl
93 dnl Determine readline linker flags in a way that works on RHEL 5
94 dnl Check for rl_completion_matches (missing on OS/X)
95 dnl
96 AC_DEFUN([AUGEAS_CHECK_READLINE], [
97   AC_CHECK_HEADERS([readline/readline.h])
98
99   # Check for readline.
100   AC_CHECK_LIB(readline, readline,
101           [use_readline=yes; READLINE_LIBS=-lreadline],
102           [use_readline=no])
103
104   # If the above test failed, it may simply be that -lreadline requires
105   # some termcap-related code, e.g., from one of the following libraries.
106   # See if adding one of them to LIBS helps.
107   if test $use_readline = no; then
108       saved_libs=$LIBS
109       LIBS=
110       AC_SEARCH_LIBS(tgetent, ncurses curses termcap termlib)
111       case $LIBS in
112         no*) ;;  # handle "no" and "none required"
113         *) # anything else is a -lLIBRARY
114           # Now, check for -lreadline again, also using $LIBS.
115           # Note: this time we use a different function, so that
116           # we don't get a cached "no" result.
117           AC_CHECK_LIB(readline, rl_initialize,
118                   [use_readline=yes
119                    READLINE_LIBS="-lreadline $LIBS"],,
120                   [$LIBS])
121           ;;
122       esac
123       test $use_readline = no &&
124           AC_MSG_WARN([readline library not found])
125       LIBS=$saved_libs
126   fi
127
128   if test $use_readline = no; then
129     AC_MSG_ERROR(Could not find a working readline library (see config.log for details).)
130   fi
131
132   AC_SUBST(READLINE_LIBS)
133
134   if test $use_readline = yes; then
135       saved_libs=$LIBS
136       LIBS=$READLINE_LIBS
137       AC_CHECK_FUNCS([rl_completion_matches])
138       LIBS=$saved_libs
139   fi
140 ])