1f67530b5fd6fb28ce0c58bb9ae6ef41b31427e3
[debian/amanda] / config / amanda / flags.m4
1 # OVERVIEW/BACKGROUND
2 #
3 #   This file manages flags in CFLAGS, CPPFLAGS, LDFLAGS, and LIBS.
4 #
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
9 #
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.
13 #
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.
20
21 # SYNOPSIS
22 #
23 #   AMANDA_INIT_FLAGS()
24 #
25 # DESCRIPTION
26 #
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
33 #   --with-libraries
34 #
35 AC_DEFUN([AMANDA_INIT_FLAGS],
36 [
37     # support deprecated ./configure flags to set various compiler flags
38
39     AC_ARG_WITH(cflags,
40         AS_HELP_STRING([--with-cflags=FLAGS],
41                        [deprecated; use ./configure CFLAGS=... ]),
42         [
43             case "$withval" in
44             "" | y | ye | yes | n | no)
45                 AC_MSG_ERROR([*** You must supply an argument to the --with-cflags option.])
46                 ;;
47             esac
48
49             CFLAGS="$withval"
50         ])
51
52     AC_ARG_WITH(includes,
53         AS_HELP_STRING([--with-includes=INCLUDE-DIRS],
54                        [deprecated; use ./configure CPPFLAGS='-I.. -I..']),
55         [
56             case "$withval" in
57             "" | y | ye | yes | n | no)
58                 AC_MSG_ERROR([*** You must supply an argument to the --with-includes option.])
59               ;;
60             esac
61
62             for dir in $withval; do
63                 if test -d "$dir"; then
64                     CPPFLAGS="$CPPFLAGS -I$dir"
65                 else
66                     AMANDA_MSG_WARN([Include directory $dir does not exist.])
67                 fi
68             done
69         ])
70
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)]),
74         [
75             case "$withval" in
76             "" | y | ye | yes | n | no)
77                 AC_MSG_ERROR([*** You must supply an argument to the --with-libraries option.])
78               ;;
79             esac
80
81             for dir in $withval; do
82                 if test -d "$dir"; then
83                     case "$target" in
84                       *-solaris2*,*-netbsd*)
85                             LDFLAGS="$LDFLAGS -R$dir"
86                             ;;
87                     esac
88                     LDFLAGS="$LDFLAGS -L$dir"
89                 else
90                     AMANDA_MSG_WARN([Library directory $dir does not exist.])
91                 fi
92             done
93         ])
94
95     # Disable strict-aliasing optimizations
96     AMANDA_DISABLE_GCC_FEATURE(strict-aliasing)
97
98     # Warn for just about everything
99     AMANDA_ENABLE_GCC_WARNING(all)
100     
101     # And add any extra warnings too
102     AMANDA_TEST_GCC_FLAG(-Wextra, [
103         AMANDA_ADD_WARNING_CFLAG(-Wextra)
104     ], [
105         AMANDA_TEST_GCC_FLAG(-W, [
106             AMANDA_ADD_WARNING_CFLAG(-W)
107         ])
108     ])
109     AC_SUBST([AMANDA_WARNING_CFLAGS])
110 ])
111
112 # SYNOPSIS
113 #
114 #   AMANDA_STATIC_FLAGS(new_flags)
115 #
116 # DESCRIPTION
117 #
118 #   Set AMANDA_STATIC_LDFLAGS to -static if --enable-static-binary
119 #
120 AC_DEFUN([AMANDA_STATIC_FLAGS],
121 [
122     AC_ARG_ENABLE(static-binary,
123         AS_HELP_STRING([--enable-static-binary],
124                        [To build statically linked binaries]),
125         [
126             case "$withval" in
127             "" | y | ye | yes)
128                 AMANDA_STATIC_LDFLAGS=-static
129                 if test x"$enable_static" = x"no"; then
130                         AC_MSG_ERROR([*** --enable-static-binary is incompatible with --disable-static])
131                 fi
132                 ;;
133             *n | no)
134                 AMANDA_STATIC_LDFLAGS=
135                 ;;
136             esac
137         ])
138     AC_SUBST([AMANDA_STATIC_LDFLAGS])
139 ])
140
141 # SYNOPSIS
142 #
143 #   AMANDA_ADD_CFLAGS(new_flags)
144 #
145 # DESCRIPTION
146 #
147 #   Add 'new_flags' to CFLAGS.
148 #
149 #   'new_flags' will be enclosed in double quotes in the resulting
150 #   shell assignment.
151 #
152 AC_DEFUN([AMANDA_ADD_CFLAGS],
153     [CFLAGS="$CFLAGS $1"]
154 )
155
156 # SYNOPSIS
157 #
158 #   AMANDA_ADD_CPPFLAGS(new_flags)
159 #
160 # DESCRIPTION
161 #
162 #   Add 'new_flags' to CPPFLAGS.
163 #
164 #   'new_flags' will be enclosed in double quotes in the resulting
165 #   shell assignment.
166 #
167 AC_DEFUN([AMANDA_ADD_CPPFLAGS],
168     [CPPFLAGS="$CPPFLAGS $1"]
169 )
170
171 # SYNOPSIS
172 #
173 #   AMANDA_ADD_LDFLAGS(new_flags)
174 #
175 # DESCRIPTION
176 #
177 #   Add 'new_flags' to LDFLAGS.
178 #
179 #   'new_flags' will be enclosed in double quotes in the resulting
180 #   shell assignment.
181 #
182 AC_DEFUN([AMANDA_ADD_LDFLAGS],
183     [LDFLAGS="$LDFLAGS $1"]
184 )
185
186 # SYNOPSIS
187 #
188 #   AMANDA_ADD_LIBS(new_flags)
189 #
190 # DESCRIPTION
191 #
192 #   Add 'new_flags' to LIBS.
193 #
194 #   'new_flags' will be enclosed in double quotes in the resulting
195 #   shell assignment.
196 #
197 AC_DEFUN([AMANDA_ADD_LIBS],
198     [LIBS="$1 $LIBS"]
199 )
200
201 # SYNOPSIS
202 #
203 #   AMANDA_DISABLE_GCC_FEATURE(feature)
204 #
205 # OVERVIEW
206 #
207 #   Disable feature 'feature' by adding flag -Wno-'feature' to 
208 #   AMANDA_FEATURE_CFLAGS.
209 #
210 AC_DEFUN([AMANDA_DISABLE_GCC_FEATURE],
211 [
212     # test for -W'feature', then add the 'no-' version.
213     AMANDA_TEST_GCC_FLAG(-f$1,
214     [
215         AMANDA_ADD_CFLAGS(-fno-$1)
216         AMANDA_ADD_CPPFLAGS(-fno-$1)
217     ])
218 ])
219
220 # SYNOPSIS
221 #
222 #   AMANDA_ADD_WARNING_CFLAG(flag)
223 #
224 # DESCRIPTION
225 #
226 #   Add 'flag' to AMANDA_WARNING_CFLAGS
227 #
228 AC_DEFUN([AMANDA_ADD_WARNING_CFLAG],
229     [AMANDA_WARNING_CFLAGS="$AMANDA_WARNING_CFLAGS $1"]
230 )
231
232 # SYNOPSIS
233 #
234 #   AMANDA_ENABLE_GCC_WARNING(warning)
235 #
236 # OVERVIEW
237 #
238 #   Enable warning 'warning' by adding flag -W'warning' to 
239 #   AMANDA_WARNING_CFLAGS.
240 #
241 AC_DEFUN([AMANDA_ENABLE_GCC_WARNING],
242 [
243     AMANDA_TEST_GCC_FLAG(-W$1,
244     [
245         AMANDA_ADD_WARNING_CFLAG(-W$1)
246     ])
247 ])
248
249 # SYNOPSIS
250 #
251 #   AMANDA_DISABLE_GCC_WARNING(warning)
252 #
253 # OVERVIEW
254 #
255 #   Disable warning 'warning' by adding flag -Wno-'warning' to 
256 #   AMANDA_WARNING_CFLAGS.
257 #
258 AC_DEFUN([AMANDA_DISABLE_GCC_WARNING],
259 [
260     # test for -W'warning', then add the 'no-' version.
261     AMANDA_TEST_GCC_FLAG(-W$1,
262     [
263         AMANDA_ADD_WARNING_CFLAG(-Wno-$1)
264     ])
265 ])
266
267 # SYNOPSIS
268 #
269 #   AMANDA_TEST_GCC_FLAG(flag, action-if-found, action-if-not-found)
270 #
271 # OVERVIEW
272 #
273 #   See if CC is gcc, and if gcc -v --help contains the given flag.  If so,
274 #   run action-if-found; otherwise, run action-if-not-found.
275 #
276 #   Intended for internal use in this file.
277 #
278 AC_DEFUN([AMANDA_TEST_GCC_FLAG],
279 [
280     AC_REQUIRE([AC_PROG_CC])
281     AC_REQUIRE([AC_PROG_EGREP])
282     AC_MSG_CHECKING(for gcc flag $1)
283     if test "x$GCC" = "xyes"; then
284         changequote(,)dnl
285         (gcc --help={target,optimizers,warnings,undocumented,params,c} 2>&1 || 
286            $CC -v --help 2>&1) | 
287          $EGREP -- '[^[:alnum:]]$1[^[:alnum:]-]' 2>&1 > /dev/null
288         changequote([,])dnl
289         if test $? -eq 0; then
290             found_warning=yes
291             AC_MSG_RESULT(yes)
292         else
293             found_warning=no
294             AC_MSG_RESULT(no)
295         fi
296     else
297         found_warning=no
298         AC_MSG_RESULT(no (not using gcc))
299     fi
300
301     if test x"$found_warning" = x"yes"; then
302         ifelse($2, [], [:], $2)
303     else
304         ifelse($3, [], [:], $3)
305     fi
306 ])
307
308 # SYNOPSIS
309 #
310 #   AMANDA_SHOW_FLAGS_SUMMARY
311 #
312 # OVERVIEW
313 #
314 #   Show a summary of the flags with which Amanda was configured
315 #
316 AC_DEFUN([AMANDA_SHOW_FLAGS_SUMMARY],
317 [
318     echo "Compiler Flags:"
319     echo "  CFLAGS: ${CFLAGS-(none)}"
320     echo "  CPPFLAGS: ${CPPFLAGS-(none)}"
321     echo "  LDFLAGS: ${LDFLAGS-(none)}"
322     echo "  LIBS: ${LIBS-(none)}"
323 ])