3 # This file manages flags in CFLAGS, CPPFLAGS, LDFLAGS, and LIBS.
5 # Flags can come from two several sources:
6 # - entry to ./configure or on the configure command line (they are
7 # `precious' variables)
8 # - added by autoconf tests during the execution of configure
10 # Although Automake supports overriding variables when invoking 'make',
11 # we don't support it (mostly because autoconf doesn't). Instead, users
12 # should specify such variables when invoking ./configure.
14 # CFLAGS are a little bit more complicated: Amanda has two categories,
15 # mandatory CFLAGS, which should be used everywhere, and warning CFLAGS,
16 # which are only used on Amanda code (not gnulib or yacc-generated code).
17 # To accomplish this, mandatory CFLAGS go directl into CFLAGS, while
18 # warwnings go in AMANDA_WARNING_CFLAGS; these are then added to
19 # AM_CFLAGS by the Makefiles.
27 # Process variables given by the user on the command line,
28 # either as environment variables:
29 # CPPFLAGS=-Dfoo ./configure ...
30 # as assignments in the configure command line:
31 # ./configure LIBS=-lfoo ...
32 # or with the deprecated flags --with-cflags, --with-includes, and
35 AC_DEFUN([AMANDA_INIT_FLAGS],
37 # support deprecated ./configure flags to set various compiler flags
40 AS_HELP_STRING([--with-cflags=FLAGS],
41 [deprecated; use ./configure CFLAGS=... ]),
44 "" | y | ye | yes | n | no)
45 AC_MSG_ERROR([*** You must supply an argument to the --with-cflags option.])
53 AS_HELP_STRING([--with-includes=INCLUDE-DIRS],
54 [deprecated; use ./configure CPPFLAGS='-I.. -I..']),
57 "" | y | ye | yes | n | no)
58 AC_MSG_ERROR([*** You must supply an argument to the --with-includes option.])
62 for dir in $withval; do
63 if test -d "$dir"; then
64 CPPFLAGS="$CPPFLAGS -I$dir"
66 AMANDA_MSG_WARN([Include directory $dir does not exist.])
71 AC_ARG_WITH(libraries,
72 AS_HELP_STRING([--with-libraries=LIBRARY-DIRS],
73 [deprecated; use ./configure LDFLAGS='-L.. -L..' (add -R on Solaris, NetBSD)]),
76 "" | y | ye | yes | n | no)
77 AC_MSG_ERROR([*** You must supply an argument to the --with-libraries option.])
81 for dir in $withval; do
82 if test -d "$dir"; then
84 *-solaris2*,*-netbsd*)
85 LDFLAGS="$LDFLAGS -R$dir"
88 LDFLAGS="$LDFLAGS -L$dir"
90 AMANDA_MSG_WARN([Library directory $dir does not exist.])
95 # Warn for just about everything
96 AMANDA_TEST_GCC_WARNING_FLAG(-Wall, [
97 AMANDA_ADD_WARNING_CFLAG(-Wall)
100 # And add any extra warnings too
101 AMANDA_TEST_GCC_WARNING_FLAG(-Wextra, [
102 AMANDA_ADD_WARNING_CFLAG(-Wextra)
104 AMANDA_TEST_GCC_WARNING_FLAG(-W, [
105 AMANDA_ADD_WARNING_CFLAG(-W)
108 AC_SUBST([AMANDA_WARNING_CFLAGS])
113 # AMANDA_STATIC_FLAGS(new_flags)
117 # Set AMANDA_STATIC_LDFLAGS to -static if --enable-static-binary
119 AC_DEFUN([AMANDA_STATIC_FLAGS],
121 AC_ARG_ENABLE(static-binary,
122 AS_HELP_STRING([--enable-static-binary],
123 [To build statically linked binaries]),
127 AMANDA_STATIC_LDFLAGS=-static
128 if test x"$enable_static" = x"no"; then
129 AC_MSG_ERROR([*** --enable-static-binary is incompatible with --disable-static])
133 AMANDA_STATIC_LDFLAGS=
137 AC_SUBST([AMANDA_STATIC_LDFLAGS])
142 # AMANDA_ADD_CFLAGS(new_flags)
146 # Add 'new_flags' to CFLAGS.
148 # 'new_flags' will be enclosed in double quotes in the resulting
151 AC_DEFUN([AMANDA_ADD_CFLAGS],
152 [CFLAGS="$CFLAGS $1"]
157 # AMANDA_ADD_CPPFLAGS(new_flags)
161 # Add 'new_flags' to CPPFLAGS.
163 # 'new_flags' will be enclosed in double quotes in the resulting
166 AC_DEFUN([AMANDA_ADD_CPPFLAGS],
167 [CPPFLAGS="$CPPFLAGS $1"]
172 # AMANDA_ADD_LDFLAGS(new_flags)
176 # Add 'new_flags' to LDFLAGS.
178 # 'new_flags' will be enclosed in double quotes in the resulting
181 AC_DEFUN([AMANDA_ADD_LDFLAGS],
182 [LDFLAGS="$LDFLAGS $1"]
187 # AMANDA_ADD_LIBS(new_flags)
191 # Add 'new_flags' to LIBS.
193 # 'new_flags' will be enclosed in double quotes in the resulting
196 AC_DEFUN([AMANDA_ADD_LIBS],
202 # AMANDA_ADD_WARNING_CFLAG(flag)
206 # Add 'flag' to AMANDA_WARNING_CFLAGS
208 AC_DEFUN([AMANDA_ADD_WARNING_CFLAG],
209 [AMANDA_WARNING_CFLAGS="$AMANDA_WARNING_CFLAGS $1"]
214 # AMANDA_ENABLE_GCC_WARNING(warning)
218 # Enable warning 'warning' by adding flag -W'warning' to
219 # AMANDA_WARNING_CFLAGS.
221 AC_DEFUN([AMANDA_ENABLE_GCC_WARNING],
223 AMANDA_TEST_GCC_WARNING_FLAG(-W$1,
225 AMANDA_ADD_WARNING_CFLAG(-W$1)
231 # AMANDA_DISABLE_GCC_WARNING(warning)
235 # Disable warning 'warning' by adding flag -Wno-'warning' to
236 # AMANDA_WARNING_CFLAGS.
238 AC_DEFUN([AMANDA_DISABLE_GCC_WARNING],
240 # test for -W'warning', then add the 'no-' version.
241 AMANDA_TEST_GCC_WARNING_FLAG(-W$1,
243 AMANDA_ADD_WARNING_CFLAG(-Wno-$1)
249 # AMANDA_TEST_GCC_WARNING_FLAG(flag, action-if-found, action-if-not-found)
253 # See if CC is gcc, and if gcc -v --help contains the given flag. If so,
254 # run action-if-found; otherwise, run action-if-not-found.
256 # Intended for internal use in this file.
258 AC_DEFUN([AMANDA_TEST_GCC_WARNING_FLAG],
260 AC_REQUIRE([AC_PROG_CC])
261 AC_REQUIRE([AC_PROG_EGREP])
262 AC_MSG_CHECKING(for gcc flag $1)
263 if test "x$GCC" = "xyes"; then
265 $CC -v --help 2>&1 | $EGREP -- '[^[:alnum:]]$1[^[:alnum:]-]' 2>&1 > /dev/null
267 if test $? -eq 0; then
276 AC_MSG_RESULT(no (not using gcc))
279 if test x"$found_warning" = x"yes"; then
280 ifelse($2, [], [:], $2)
282 ifelse($3, [], [:], $3)
288 # AMANDA_SHOW_FLAGS_SUMMARY
292 # Show a summary of the flags with which Amanda was configured
294 AC_DEFUN([AMANDA_SHOW_FLAGS_SUMMARY],
296 echo "Compiler Flags:"
297 echo " CFLAGS: ${CFLAGS-(none)}"
298 echo " CPPFLAGS: ${CPPFLAGS-(none)}"
299 echo " LDFLAGS: ${LDFLAGS-(none)}"
300 echo " LIBS: ${LIBS-(none)}"