]>
Commit | Line | Data |
---|---|---|
24138539 DE |
1 | ## |
2 | ## This file is part of the sigrok project. | |
3 | ## | |
64bc73f5 UH |
4 | ## Copyright (C) 2009 Openismus GmbH |
5 | ## Copyright (C) 2015 Daniel Elstner <daniel.kitta@gmail.com> | |
6 | ## | |
7 | ## This program is free software: you can redistribute it and/or modify | |
8 | ## it under the terms of the GNU General Public License as published by | |
24138539 DE |
9 | ## the Free Software Foundation, either version 3 of the License, or |
10 | ## (at your option) any later version. | |
11 | ## | |
64bc73f5 | 12 | ## This program is distributed in the hope that it will be useful, |
24138539 | 13 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
64bc73f5 | 14 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24138539 DE |
15 | ## GNU General Public License for more details. |
16 | ## | |
17 | ## You should have received a copy of the GNU General Public License | |
64bc73f5 UH |
18 | ## along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | ## | |
24138539 | 20 | |
69f68553 | 21 | #serial 20150910 |
24138539 DE |
22 | |
23 | ## SR_APPEND(var-name, [list-sep,] element) | |
24 | ## | |
25 | ## Append the shell word <element> to the shell variable named <var-name>, | |
26 | ## prefixed by <list-sep> unless the list was empty before appending. If | |
27 | ## only two arguments are supplied, <list-sep> defaults to a single space | |
28 | ## character. | |
29 | ## | |
30 | AC_DEFUN([SR_APPEND], | |
31 | [dnl | |
32 | m4_assert([$# >= 2])[]dnl | |
33 | $1=[$]{$1[}]m4_if([$#], [2], [[$]{$1:+' '}$2], [[$]{$1:+$2}$3])[]dnl | |
34 | ]) | |
35 | ||
bc8ff24d DE |
36 | ## SR_PREPEND(var-name, [list-sep,] element) |
37 | ## | |
38 | ## Prepend the shell word <element> to the shell variable named <var-name>, | |
39 | ## suffixed by <list-sep> unless the list was empty before prepending. If | |
40 | ## only two arguments are supplied, <list-sep> defaults to a single space | |
41 | ## character. | |
42 | ## | |
43 | AC_DEFUN([SR_PREPEND], | |
44 | [dnl | |
45 | m4_assert([$# >= 2])[]dnl | |
46 | $1=m4_if([$#], [2], [$2[$]{$1:+' '}], [$3[$]{$1:+$2}])[$]$1[]dnl | |
47 | ]) | |
48 | ||
24138539 DE |
49 | ## _SR_PKG_VERSION_SET(var-prefix, pkg-name, tag-prefix, base-version, major, minor, [micro]) |
50 | ## | |
51 | m4_define([_SR_PKG_VERSION_SET], | |
52 | [dnl | |
53 | m4_assert([$# >= 6])[]dnl | |
54 | $1=$4 | |
5bce22ac GS |
55 | dnl Check if we can get version control details. Re-configure when |
56 | dnl branches change (when HEAD starts pointing somewhere else). | |
57 | dnl Track individual revisions at compile time, and only as a local | |
58 | dnl dependency of just a part of the library build. In other words: | |
59 | dnl Don't re-configure and re-build everything just because a commit | |
60 | dnl happened). Checks for tagged sources also happen at compile time. | |
24138539 | 61 | sr_git_deps= |
24138539 | 62 | sr_head=`git -C "$srcdir" rev-parse --verify --short HEAD 2>&AS_MESSAGE_LOG_FD` |
5bce22ac GS |
63 | AS_IF([test "$?" = 0 && test -n "$sr_head"], [dnl |
64 | test ! -f "$srcdir/.git/HEAD" || \ | |
65 | sr_git_deps="$sr_git_deps ${ac_abs_confdir}/.git/HEAD" | |
24138539 | 66 | sr_head_name=`git -C "$srcdir" rev-parse --symbolic-full-name HEAD 2>&AS_MESSAGE_LOG_FD` |
5bce22ac GS |
67 | AS_IF([test "$?" = 0 && test -f "$srcdir/.git/$sr_head_name"], [dnl |
68 | sr_head_file="${ac_abs_confdir}/.git/$sr_head_name" | |
69 | AC_SUBST(VERSION_HEAD_FILE, [$sr_head_file]) | |
70 | ]) | |
71 | sr_hash=`git -C "$srcdir" describe --match "$3$4" --always --dirty` | |
72 | sr_hash=`echo "$sr_hash" | sed 's/$3$4-//'` && \ | |
73 | $1_STRING_SUFFIX=`git -C "$srcdir" describe --match "$3$4" --exact-match > /dev/null 2> /dev/null || echo "-$sr_hash"` | |
74 | AS_IF([test -n "$1_STRING_SUFFIX"], [$1="[$]$1-git"]) | |
24138539 | 75 | ]) |
5bce22ac GS |
76 | AM_CONDITIONAL([VCS_IS_GIT], [test -n "$sr_git_deps"]) |
77 | # Use $(wildcard) so that things do not break if for whatever reason | |
78 | # these files do not exist anymore at make time. | |
24138539 | 79 | AS_IF([test -n "$sr_git_deps"], |
5bce22ac | 80 | [SR_APPEND([CONFIG_STATUS_DEPENDENCIES], ["\$(wildcard $sr_git_deps)"])]) |
24138539 | 81 | AC_SUBST([CONFIG_STATUS_DEPENDENCIES])[]dnl |
5bce22ac GS |
82 | AS_IF([test -n "$sr_git_deps$sr_head_file"], |
83 | [SR_APPEND([VERSION_GITVERSION_DEPS], ["\$(wildcard $sr_git_deps $sr_head_file)"])]) | |
84 | AC_SUBST(VERSION_GITVERSION_DEPS)[]dnl | |
85 | AC_SUBST(VERSION_SOURCE_DIR, [${ac_abs_confdir}]) | |
86 | AC_SUBST(VERSION_TAG_PREFIX, [$3])[]dnl | |
87 | AC_SUBST(VERSION_TAG_NUMBER, [$4])[]dnl | |
88 | AC_SUBST(VERSION_TAG_MATCH, [$3$4])[]dnl | |
89 | dnl End of git version control details gathering. | |
90 | dnl | |
24138539 DE |
91 | AC_SUBST([$1])[]dnl |
92 | dnl | |
93 | AC_DEFINE([$1_MAJOR], [$5], [Major version number of $2.])[]dnl | |
94 | AC_DEFINE([$1_MINOR], [$6], [Minor version number of $2.])[]dnl | |
95 | m4_ifval([$7], [AC_DEFINE([$1_MICRO], [$7], [Micro version number of $2.])])[]dnl | |
5bce22ac | 96 | AC_DEFINE_UNQUOTED([$1_STRING_PREFIX], ["[$]$1"], [Version of $2.])[]dnl |
24138539 DE |
97 | ]) |
98 | ||
99 | ## SR_PKG_VERSION_SET(var-prefix, version-triple) | |
100 | ## | |
101 | ## Set up substitution variables and macro definitions for the package | |
102 | ## version components. Derive the version suffix from the repository | |
103 | ## revision if possible. | |
104 | ## | |
105 | ## Substitutions: <var-prefix> | |
106 | ## Macro defines: <var-prefix>_{MAJOR,MINOR,MICRO,STRING} | |
107 | ## | |
108 | AC_DEFUN([SR_PKG_VERSION_SET], | |
109 | [dnl | |
110 | m4_assert([$# >= 2])[]dnl | |
111 | _SR_PKG_VERSION_SET([$1], | |
112 | m4_defn([AC_PACKAGE_NAME]), | |
113 | m4_defn([AC_PACKAGE_TARNAME])[-], | |
114 | m4_expand([$2]), | |
115 | m4_unquote(m4_split(m4_expand([$2]), [\.]))) | |
116 | ]) | |
117 | ||
118 | ## _SR_LIB_VERSION_SET(var-prefix, pkg-name, abi-triple, current, revision, age) | |
119 | ## | |
120 | m4_define([_SR_LIB_VERSION_SET], | |
121 | [dnl | |
122 | m4_assert([$# >= 6])[]dnl | |
123 | $1=$3 | |
124 | AC_SUBST([$1])[]dnl | |
125 | AC_DEFINE([$1_CURRENT], [$4], [Binary version of $2.])[]dnl | |
126 | AC_DEFINE([$1_REVISION], [$5], [Binary revision of $2.])[]dnl | |
127 | AC_DEFINE([$1_AGE], [$6], [Binary age of $2.])[]dnl | |
128 | AC_DEFINE([$1_STRING], ["$3"], [Binary version triple of $2.])[]dnl | |
129 | ]) | |
130 | ||
131 | ## SR_LIB_VERSION_SET(var-prefix, abi-triple) | |
132 | ## | |
133 | ## Set up substitution variables and macro definitions for a library | |
134 | ## binary version. | |
135 | ## | |
136 | ## Substitutions: <var-prefix> | |
137 | ## Macro defines: <var-prefix>_{CURRENT,REVISION,AGE,STRING} | |
138 | ## | |
139 | AC_DEFUN([SR_LIB_VERSION_SET], | |
140 | [dnl | |
141 | m4_assert([$# >= 1])[]dnl | |
142 | _SR_LIB_VERSION_SET([$1], | |
143 | m4_defn([AC_PACKAGE_NAME]), | |
144 | [$2], m4_unquote(m4_split([$2], [:]))) | |
145 | ]) | |
146 | ||
bc8ff24d DE |
147 | ## SR_SEARCH_LIBS(libs-var, function, search-libs, |
148 | ## [action-if-found], [action-if-not-found], [other-libs]) | |
149 | ## | |
150 | ## Same as AC_SEARCH_LIBS, except that the result is prepended | |
151 | ## to <libs-var> instead of LIBS. Calls AC_SUBST on <libs-var>. | |
152 | ## | |
153 | AC_DEFUN([SR_SEARCH_LIBS], | |
154 | [dnl | |
155 | m4_assert([$# >= 3])[]dnl | |
156 | sr_sl_save_LIBS=$LIBS | |
157 | AC_SEARCH_LIBS([$2], [$3],,, m4_join([$6], [[$]$1])) | |
158 | LIBS=$sr_sl_save_LIBS | |
159 | AS_CASE([$ac_cv_search_$2], [no*],, | |
160 | [SR_PREPEND([$1], [$ac_cv_search_$2])]) | |
161 | m4_ifvaln([$4$5], [AS_IF([test "x$ac_cv_search_$2" = xno], [$5], [$4])])[]dnl | |
162 | AC_SUBST([$1])[]dnl | |
163 | ]) | |
164 | ||
1bb196e4 DE |
165 | ## _SR_VAR_SUMMARY(tag, var-name, line-leader, align-columns, align-char) |
166 | ## | |
167 | m4_define([_SR_VAR_SUMMARY], [dnl | |
168 | $2= | |
169 | $1_append() { | |
170 | sr_aligned=`printf '%.$4s' "[$][1]m4_for([i], [1], [$4],, [$5])"` | |
171 | $2="[$]{$2}$3$sr_aligned [$]2"' | |
172 | ' | |
173 | } | |
174 | ]) | |
175 | ||
176 | ## SR_VAR_SUMMARY(tag, [var-name = <tag>], | |
177 | ## [line-leader = [ - ]], [align-columns = 32], [align-char = .]) | |
178 | ## | |
179 | ## Define a shell function <tag>_append() to be used for aggregating | |
180 | ## a summary of test results in the shell variable <var-name>. | |
181 | ## | |
182 | AC_DEFUN([SR_VAR_SUMMARY], | |
183 | [dnl | |
184 | m4_assert([$# >= 1])[]dnl | |
185 | _SR_VAR_SUMMARY([$1], | |
186 | m4_default_quoted([$2], [$1]), | |
187 | m4_default_quoted([$3], [ - ]), | |
188 | m4_default_quoted([$4], [32]), | |
189 | m4_default_quoted([$5], [.]))[]dnl | |
190 | ]) | |
191 | ||
192 | ## SR_PKG_CHECK_SUMMARY([var-name = sr_pkg_check_summary], | |
193 | ## [line-leader = [ - ]], [align-columns = 32], [align-char = .]) | |
194 | ## | |
195 | ## Prepare for the aggregation of package check results | |
196 | ## in the shell variable <var-name>. | |
197 | ## | |
198 | AC_DEFUN([SR_PKG_CHECK_SUMMARY], | |
199 | [SR_VAR_SUMMARY([sr_pkg_check_summary], $@)]) | |
200 | ||
201 | ## SR_PKG_CHECK(tag, [collect-var], module...) | |
202 | ## | |
203 | ## Check for each pkg-config <module> in the argument list. <module> may | |
204 | ## include a version constraint. | |
205 | ## | |
206 | ## Output variables: sr_have_<tag>, sr_<tag>_version | |
207 | ## | |
208 | AC_DEFUN([SR_PKG_CHECK], | |
209 | [dnl | |
210 | m4_assert([$# >= 3])[]dnl | |
211 | AC_REQUIRE([PKG_PROG_PKG_CONFIG])[]dnl | |
212 | AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl | |
213 | dnl | |
214 | PKG_CHECK_EXISTS([$3], [dnl | |
215 | sr_have_$1=yes | |
216 | m4_ifval([$2], [SR_APPEND([$2], ["$3"]) | |
217 | ])sr_$1_version=`$PKG_CONFIG --modversion "$3" 2>&AS_MESSAGE_LOG_FD` | |
218 | sr_pkg_check_summary_append "$3" "$sr_$1_version"[]dnl | |
219 | ], [dnl | |
220 | sr_pkg_check_summary_append "$3" no | |
221 | m4_ifval([$4], | |
222 | [SR_PKG_CHECK([$1], [$2], m4_shift3($@))], | |
223 | [sr_have_$1=no sr_$1_version=])[]dnl | |
224 | ]) | |
225 | ]) | |
226 | ||
227 | ## SR_VAR_OPT_PKG([modules-var], [features-var]) | |
228 | ## | |
229 | ## Enable the collection of SR_ARG_OPT_PKG results into the shell variables | |
230 | ## <modules-var> and <features-var>. | |
231 | ## | |
232 | AC_DEFUN([SR_VAR_OPT_PKG], | |
233 | [dnl | |
234 | m4_define([_SR_VAR_OPT_PKG_MODULES], [$1])[]dnl | |
235 | m4_define([_SR_VAR_OPT_PKG_FEATURES], [$2])[]dnl | |
236 | m4_ifvaln([$1], [$1=])[]dnl | |
237 | m4_ifvaln([$2], [$2=])[]dnl | |
238 | ]) | |
239 | ||
38662688 DE |
240 | ## _SR_ARG_OPT_IMPL(sh-name, [features-var], opt-name, |
241 | ## [cpp-name], [cond-name], check-commands) | |
1bb196e4 | 242 | ## |
38662688 | 243 | m4_define([_SR_ARG_OPT_IMPL], |
1bb196e4 | 244 | [dnl |
38662688 DE |
245 | AC_ARG_WITH([$3], [AS_HELP_STRING([--without-$3], |
246 | [disable $3 support [default=detect]])]) | |
1bb196e4 | 247 | AS_IF([test "x$with_$1" = xno], [sr_have_$1=no], |
38662688 DE |
248 | [test "x$sr_have_$1" != xyes], [dnl |
249 | AC_MSG_CHECKING([for $3]) | |
250 | $6 | |
251 | AC_MSG_RESULT([$sr_have_$1])[]dnl | |
252 | ]) | |
1bb196e4 | 253 | AS_IF([test "x$with_$1$sr_have_$1" = xyesno], |
38662688 DE |
254 | [AC_MSG_ERROR([$3 support requested, but it was not found.])]) |
255 | AS_IF([test "x$sr_have_$1" = xyes], [m4_ifval([$2], [ | |
256 | SR_APPEND([$2], ["$3"])])[]m4_ifval([$4], [ | |
257 | AC_DEFINE([HAVE_$4], [1], [Whether $3 is available.])])[]dnl | |
1bb196e4 | 258 | ]) |
38662688 DE |
259 | m4_ifvaln([$5], [AM_CONDITIONAL([$5], [test "x$sr_have_$1" = xyes])])[]dnl |
260 | ]) | |
261 | ||
262 | ## _SR_ARG_OPT_CHECK(sh-name, [features-var], opt-name, [cpp-name], | |
263 | ## [cond-name], check-commands, [summary-result]) | |
264 | ## | |
265 | m4_define([_SR_ARG_OPT_CHECK], | |
266 | [dnl | |
267 | _SR_ARG_OPT_IMPL($@) | |
268 | sr_pkg_check_summary_append "$3" m4_default([$7], ["$sr_have_$1"]) | |
269 | ]) | |
270 | ||
271 | ## SR_ARG_OPT_CHECK(opt-name, [cpp-name], [cond-name], check-commands, | |
272 | ## [summary-result = $sr_have_<opt-name>]) | |
273 | ## | |
274 | ## Provide a --without-<opt-name> configure option for explicit disabling | |
275 | ## of an optional dependency. If not disabled, the availability of the | |
276 | ## optional dependency is auto-detected by running <check-commands>. | |
277 | ## | |
278 | ## The <check-commands> should set the shell variable sr_have_<opt-name> | |
279 | ## to "yes" if the dependency is available, otherwise to "no". Optionally, | |
280 | ## the <summary-result> argument may be used to generate a line in the | |
281 | ## configuration summary. If supplied, it should be a shell word which | |
282 | ## expands to the result to be displayed for the <opt-name> dependency. | |
283 | ## | |
284 | ## Use SR_VAR_OPT_PKG to generate lists of available modules and features. | |
285 | ## | |
286 | AC_DEFUN([SR_ARG_OPT_CHECK], | |
287 | [dnl | |
288 | m4_assert([$# >= 4])[]dnl | |
289 | AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl | |
290 | AC_REQUIRE([SR_VAR_OPT_PKG])[]dnl | |
291 | dnl | |
292 | _SR_ARG_OPT_CHECK(m4_expand([AS_TR_SH([$1])]), | |
293 | m4_defn([_SR_VAR_OPT_PKG_FEATURES]), | |
294 | $@)[]dnl | |
295 | ]) | |
296 | ||
297 | ## _SR_ARG_OPT_PKG([features-var], [cond-name], opt-name, | |
298 | ## [cpp-name], sh-name, [modules-var], module...) | |
299 | ## | |
300 | m4_define([_SR_ARG_OPT_PKG], | |
301 | [dnl | |
302 | _SR_ARG_OPT_IMPL([$5], [$1], [$3], [$4], [$2], | |
303 | [SR_PKG_CHECK(m4_shiftn([4], $@))]) | |
304 | m4_ifvaln([$4], [AS_IF([test "x$sr_have_$5" = xyes], | |
305 | [AC_DEFINE_UNQUOTED([CONF_$4_VERSION], ["$sr_$5_version"], | |
306 | [Build-time version of $3.])])])[]dnl | |
1bb196e4 DE |
307 | ]) |
308 | ||
309 | ## SR_ARG_OPT_PKG(opt-name, [cpp-name], [cond-name], module...) | |
310 | ## | |
311 | ## Provide a --without-<opt-name> configure option for explicit disabling | |
312 | ## of an optional dependency. If not disabled, the availability of the | |
313 | ## optional dependency is auto-detected. | |
314 | ## | |
315 | ## Each pkg-config <module> argument is checked in turn, and the first one | |
316 | ## found is selected. On success, the shell variable sr_have_<opt-name> | |
317 | ## is set to "yes", otherwise to "no". Optionally, a preprocessor macro | |
318 | ## HAVE_<cpp-name> and an Automake conditional <cond-name> are generated. | |
319 | ## | |
320 | ## Use SR_VAR_OPT_PKG to generate lists of available modules and features. | |
321 | ## | |
322 | AC_DEFUN([SR_ARG_OPT_PKG], | |
323 | [dnl | |
324 | m4_assert([$# >= 4])[]dnl | |
325 | AC_REQUIRE([PKG_PROG_PKG_CONFIG])[]dnl | |
326 | AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl | |
327 | AC_REQUIRE([SR_VAR_OPT_PKG])[]dnl | |
328 | dnl | |
38662688 DE |
329 | _SR_ARG_OPT_PKG(m4_defn([_SR_VAR_OPT_PKG_FEATURES]), |
330 | [$3], [$1], [$2], | |
331 | m4_expand([AS_TR_SH([$1])]), | |
1bb196e4 | 332 | m4_defn([_SR_VAR_OPT_PKG_MODULES]), |
38662688 | 333 | m4_shift3($@))[]dnl |
1bb196e4 DE |
334 | ]) |
335 | ||
a6e8a8f7 DE |
336 | ## SR_PROG_VERSION(program, sh-var) |
337 | ## | |
338 | ## Obtain the version of <program> and store it in <sh-var>. | |
339 | ## | |
340 | AC_DEFUN([SR_PROG_VERSION], | |
341 | [dnl | |
342 | m4_assert([$# >= 2])[]dnl | |
343 | sr_prog_ver=`$1 --version 2>&AS_MESSAGE_LOG_FD | sed 1q 2>&AS_MESSAGE_LOG_FD` | |
344 | AS_CASE([[$]?:$sr_prog_ver], | |
345 | [[0:*[0-9].[0-9]*]], [$2=$sr_prog_ver], | |
346 | [$2=unknown])[]dnl | |
347 | ]) | |
348 | ||
c2b0f429 DE |
349 | ## SR_PROG_MAKE_ORDER_ONLY |
350 | ## | |
351 | ## Check whether the make program supports order-only prerequisites. | |
352 | ## If so, set the substitution variable ORDER to '|', or to the empty | |
353 | ## string otherwise. | |
354 | ## | |
355 | AC_DEFUN([SR_PROG_MAKE_ORDER_ONLY], | |
356 | [dnl | |
c2b0f429 DE |
357 | AC_CACHE_CHECK([whether [$]{MAKE:-make} supports order-only prerequisites], |
358 | [sr_cv_prog_make_order_only], [ | |
359 | cat >conftest.mk <<'_SREOF' | |
360 | a: b | c | |
361 | a b c: ; @: | |
362 | .PHONY: a b c | |
363 | _SREOF | |
364 | AS_IF([[$]{MAKE:-make} -f conftest.mk >&AS_MESSAGE_LOG_FD 2>&AS_MESSAGE_LOG_FD], | |
365 | [sr_cv_prog_make_order_only=yes], [sr_cv_prog_make_order_only=no]) | |
366 | rm -f conftest.mk | |
367 | ]) | |
368 | AS_IF([test "x$sr_cv_prog_make_order_only" = xyes], [ORDER='|'], [ORDER=]) | |
369 | AC_SUBST([ORDER]) | |
c1783861 | 370 | AM_SUBST_NOTMAKE([ORDER])[]dnl |
c2b0f429 DE |
371 | ]) |
372 | ||
b84a7331 DE |
373 | ## SR_CHECK_COMPILE_FLAGS(flags-var, description, flags) |
374 | ## | |
375 | ## Find a compiler flag for <description>. For each flag in <flags>, check | |
376 | ## if the compiler for the current language accepts it. On success, stop the | |
377 | ## search and append the last tested flag to <flags-var>. Calls AC_SUBST | |
378 | ## on <flags-var>. | |
379 | ## | |
380 | AC_DEFUN([SR_CHECK_COMPILE_FLAGS], | |
381 | [dnl | |
382 | m4_assert([$# >= 3])[]dnl | |
383 | AC_MSG_CHECKING([compiler flag for $2]) | |
384 | sr_ccf_result=no | |
385 | sr_ccf_save_CPPFLAGS=$CPPFLAGS | |
386 | for sr_flag in $3 | |
387 | do | |
388 | CPPFLAGS="$sr_ccf_save_CPPFLAGS $sr_flag" | |
389 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [sr_ccf_result=$sr_flag]) | |
390 | test "x$sr_ccf_result" = xno || break | |
391 | done | |
392 | CPPFLAGS=$sr_ccf_save_CPPFLAGS | |
2d2240bb DE |
393 | AS_IF([test "x$sr_ccf_result" != xno], |
394 | [SR_APPEND([$1], [$sr_ccf_result])]) | |
b84a7331 DE |
395 | AC_MSG_RESULT([$sr_ccf_result]) |
396 | AC_SUBST([$1]) | |
397 | ]) | |
398 | ||
24138539 DE |
399 | ## _SR_ARG_ENABLE_WARNINGS_ONCE |
400 | ## | |
401 | ## Implementation helper macro of SR_ARG_ENABLE_WARNINGS. Pulled in | |
402 | ## through AC_REQUIRE so that it is only expanded once. | |
403 | ## | |
404 | m4_define([_SR_ARG_ENABLE_WARNINGS_ONCE], | |
405 | [dnl | |
406 | AC_PROVIDE([$0])[]dnl | |
407 | AC_ARG_ENABLE([warnings], | |
408 | [AS_HELP_STRING([[--enable-warnings[=min|max|fatal|no]]], | |
4cf2f34f | 409 | [set compile pedantry level [default=max]])], |
24138539 | 410 | [sr_enable_warnings=$enableval], |
4cf2f34f | 411 | [sr_enable_warnings=max])[]dnl |
24138539 DE |
412 | dnl |
413 | # Test whether the compiler accepts each flag. Look at standard output, | |
414 | # since GCC only shows a warning message if an option is not supported. | |
415 | sr_check_compile_warning_flags() { | |
416 | for sr_flag | |
417 | do | |
418 | sr_cc_out=`$sr_cc $sr_warning_flags $sr_flag -c "$sr_conftest" 2>&1 || echo failed` | |
419 | AS_IF([test "$?$sr_cc_out" = 0], | |
420 | [SR_APPEND([sr_warning_flags], [$sr_flag])], | |
421 | [AS_ECHO(["$sr_cc: $sr_cc_out"]) >&AS_MESSAGE_LOG_FD]) | |
422 | rm -f "conftest.[$]{OBJEXT:-o}" | |
423 | done | |
424 | } | |
425 | ]) | |
426 | ||
427 | ## SR_ARG_ENABLE_WARNINGS(variable, min-flags, max-flags) | |
428 | ## | |
429 | ## Provide the --enable-warnings configure argument, set to "min" by default. | |
430 | ## <min-flags> and <max-flags> should be space-separated lists of compiler | |
431 | ## warning flags to use with --enable-warnings=min or --enable-warnings=max, | |
432 | ## respectively. Warning level "fatal" is the same as "max" but in addition | |
433 | ## enables -Werror mode. | |
434 | ## | |
435 | ## In order to determine the warning options to use with the C++ compiler, | |
436 | ## call AC_LANG([C++]) first to change the current language. If different | |
437 | ## output variables are used, it is also fine to call SR_ARG_ENABLE_WARNINGS | |
438 | ## repeatedly, once for each language setting. | |
439 | ## | |
440 | AC_DEFUN([SR_ARG_ENABLE_WARNINGS], | |
441 | [dnl | |
442 | m4_assert([$# >= 3])[]dnl | |
443 | AC_REQUIRE([_SR_ARG_ENABLE_WARNINGS_ONCE])[]dnl | |
444 | dnl | |
445 | AS_CASE([$ac_compile], | |
446 | [[*'$CXXFLAGS '*]], [sr_lang='C++' sr_cc=$CXX sr_conftest="conftest.[$]{ac_ext:-cc}"], | |
447 | [[*'$CFLAGS '*]], [sr_lang=C sr_cc=$CC sr_conftest="conftest.[$]{ac_ext:-c}"], | |
448 | [AC_MSG_ERROR([[current language is neither C nor C++]])]) | |
449 | dnl | |
450 | AC_MSG_CHECKING([which $sr_lang compiler warning flags to use]) | |
451 | sr_warning_flags= | |
452 | AC_LANG_CONFTEST([AC_LANG_SOURCE([[ | |
453 | int main(int argc, char** argv) { return (argv != 0) ? argc : 0; } | |
454 | ]])]) | |
455 | AS_CASE([$sr_enable_warnings], | |
456 | [no], [], | |
4cf2f34f | 457 | [min], [sr_check_compile_warning_flags $2], |
24138539 | 458 | [fatal], [sr_check_compile_warning_flags $3 -Werror], |
4cf2f34f | 459 | [sr_check_compile_warning_flags $3]) |
24138539 DE |
460 | rm -f "$sr_conftest" |
461 | AC_SUBST([$1], [$sr_warning_flags]) | |
462 | AC_MSG_RESULT([[$]{sr_warning_flags:-none}])[]dnl | |
463 | ]) |