ba20da9dc534c47e6d3193b4568cb57875e26760
[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     # Warn for just about everything
96     AMANDA_TEST_GCC_WARNING_FLAG(-Wall, [
97         AMANDA_ADD_WARNING_CFLAG(-Wall)
98     ])
99     
100     # And add any extra warnings too
101     AMANDA_TEST_GCC_WARNING_FLAG(-Wextra, [
102         AMANDA_ADD_WARNING_CFLAG(-Wextra)
103     ], [
104         AMANDA_TEST_GCC_WARNING_FLAG(-W, [
105             AMANDA_ADD_WARNING_CFLAG(-W)
106         ])
107     ])
108     AC_SUBST([AMANDA_WARNING_CFLAGS])
109 ])
110
111 # SYNOPSIS
112 #
113 #   AMANDA_STATIC_FLAGS(new_flags)
114 #
115 # DESCRIPTION
116 #
117 #   Set AMANDA_STATIC_LDFLAGS to -static if --enable-static-binary
118 #
119 AC_DEFUN([AMANDA_STATIC_FLAGS],
120 [
121     AC_ARG_ENABLE(static-binary,
122         AS_HELP_STRING([--enable-static-binary],
123                        [To build statically linked binaries]),
124         [
125             case "$withval" in
126             "" | y | ye | yes)
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])
130                 fi
131                 ;;
132             *n | no)
133                 AMANDA_STATIC_LDFLAGS=
134                 ;;
135             esac
136         ])
137     AC_SUBST([AMANDA_STATIC_LDFLAGS])
138 ])
139
140 # SYNOPSIS
141 #
142 #   AMANDA_ADD_CFLAGS(new_flags)
143 #
144 # DESCRIPTION
145 #
146 #   Add 'new_flags' to CFLAGS.
147 #
148 #   'new_flags' will be enclosed in double quotes in the resulting
149 #   shell assignment.
150 #
151 AC_DEFUN([AMANDA_ADD_CFLAGS],
152     [CFLAGS="$CFLAGS $1"]
153 )
154
155 # SYNOPSIS
156 #
157 #   AMANDA_ADD_CPPFLAGS(new_flags)
158 #
159 # DESCRIPTION
160 #
161 #   Add 'new_flags' to CPPFLAGS.
162 #
163 #   'new_flags' will be enclosed in double quotes in the resulting
164 #   shell assignment.
165 #
166 AC_DEFUN([AMANDA_ADD_CPPFLAGS],
167     [CPPFLAGS="$CPPFLAGS $1"]
168 )
169
170 # SYNOPSIS
171 #
172 #   AMANDA_ADD_LDFLAGS(new_flags)
173 #
174 # DESCRIPTION
175 #
176 #   Add 'new_flags' to LDFLAGS.
177 #
178 #   'new_flags' will be enclosed in double quotes in the resulting
179 #   shell assignment.
180 #
181 AC_DEFUN([AMANDA_ADD_LDFLAGS],
182     [LDFLAGS="$LDFLAGS $1"]
183 )
184
185 # SYNOPSIS
186 #
187 #   AMANDA_ADD_LIBS(new_flags)
188 #
189 # DESCRIPTION
190 #
191 #   Add 'new_flags' to LIBS.
192 #
193 #   'new_flags' will be enclosed in double quotes in the resulting
194 #   shell assignment.
195 #
196 AC_DEFUN([AMANDA_ADD_LIBS],
197     [LIBS="$1 $LIBS"]
198 )
199
200 # SYNOPSIS
201 #
202 #   AMANDA_ADD_WARNING_CFLAG(flag)
203 #
204 # DESCRIPTION
205 #
206 #   Add 'flag' to AMANDA_WARNING_CFLAGS
207 #
208 AC_DEFUN([AMANDA_ADD_WARNING_CFLAG],
209     [AMANDA_WARNING_CFLAGS="$AMANDA_WARNING_CFLAGS $1"]
210 )
211
212 # SYNOPSIS
213 #
214 #   AMANDA_ENABLE_GCC_WARNING(warning)
215 #
216 # OVERVIEW
217 #
218 #   Enable warning 'warning' by adding flag -W'warning' to 
219 #   AMANDA_WARNING_CFLAGS.
220 #
221 AC_DEFUN([AMANDA_ENABLE_GCC_WARNING],
222 [
223     AMANDA_TEST_GCC_WARNING_FLAG(-W$1,
224     [
225         AMANDA_ADD_WARNING_CFLAG(-W$1)
226     ])
227 ])
228
229 # SYNOPSIS
230 #
231 #   AMANDA_DISABLE_GCC_WARNING(warning)
232 #
233 # OVERVIEW
234 #
235 #   Disable warning 'warning' by adding flag -Wno-'warning' to 
236 #   AMANDA_WARNING_CFLAGS.
237 #
238 AC_DEFUN([AMANDA_DISABLE_GCC_WARNING],
239 [
240     # test for -W'warning', then add the 'no-' version.
241     AMANDA_TEST_GCC_WARNING_FLAG(-W$1,
242     [
243         AMANDA_ADD_WARNING_CFLAG(-Wno-$1)
244     ])
245 ])
246
247 # SYNOPSIS
248 #
249 #   AMANDA_TEST_GCC_WARNING_FLAG(flag, action-if-found, action-if-not-found)
250 #
251 # OVERVIEW
252 #
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.
255 #
256 #   Intended for internal use in this file.
257 #
258 AC_DEFUN([AMANDA_TEST_GCC_WARNING_FLAG],
259 [
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
264         changequote(,)dnl
265         $CC -v --help 2>&1 | $EGREP -- '[^[:alnum:]]$1[^[:alnum:]-]' 2>&1 > /dev/null
266         changequote([,])dnl
267         if test $? -eq 0; then
268             found_warning=yes
269             AC_MSG_RESULT(yes)
270         else
271             found_warning=no
272             AC_MSG_RESULT(no)
273         fi
274     else
275         found_warning=no
276         AC_MSG_RESULT(no (not using gcc))
277     fi
278
279     if test x"$found_warning" = x"yes"; then
280         ifelse($2, [], [:], $2)
281     else
282         ifelse($3, [], [:], $3)
283     fi
284 ])
285
286 # SYNOPSIS
287 #
288 #   AMANDA_SHOW_FLAGS_SUMMARY
289 #
290 # OVERVIEW
291 #
292 #   Show a summary of the flags with which Amanda was configured
293 #
294 AC_DEFUN([AMANDA_SHOW_FLAGS_SUMMARY],
295 [
296     echo "Compiler Flags:"
297     echo "  CFLAGS: ${CFLAGS-(none)}"
298     echo "  CPPFLAGS: ${CPPFLAGS-(none)}"
299     echo "  LDFLAGS: ${LDFLAGS-(none)}"
300     echo "  LIBS: ${LIBS-(none)}"
301 ])