]> sigrok.org Git - libsigrok.git/blame - m4/sigrok.m4
output/csv: use intermediate time_t var, silence compiler warning
[libsigrok.git] / m4 / sigrok.m4
CommitLineData
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##
30AC_DEFUN([SR_APPEND],
31[dnl
32m4_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##
43AC_DEFUN([SR_PREPEND],
44[dnl
45m4_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##
51m4_define([_SR_PKG_VERSION_SET],
52[dnl
53m4_assert([$# >= 6])[]dnl
54$1=$4
5bce22ac
GS
55dnl Check if we can get version control details. Re-configure when
56dnl branches change (when HEAD starts pointing somewhere else).
57dnl Track individual revisions at compile time, and only as a local
58dnl dependency of just a part of the library build. In other words:
59dnl Don't re-configure and re-build everything just because a commit
60dnl happened). Checks for tagged sources also happen at compile time.
24138539 61sr_git_deps=
24138539 62sr_head=`git -C "$srcdir" rev-parse --verify --short HEAD 2>&AS_MESSAGE_LOG_FD`
5bce22ac
GS
63AS_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
76AM_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 79AS_IF([test -n "$sr_git_deps"],
5bce22ac 80 [SR_APPEND([CONFIG_STATUS_DEPENDENCIES], ["\$(wildcard $sr_git_deps)"])])
24138539 81AC_SUBST([CONFIG_STATUS_DEPENDENCIES])[]dnl
5bce22ac
GS
82AS_IF([test -n "$sr_git_deps$sr_head_file"],
83 [SR_APPEND([VERSION_GITVERSION_DEPS], ["\$(wildcard $sr_git_deps $sr_head_file)"])])
84AC_SUBST(VERSION_GITVERSION_DEPS)[]dnl
85AC_SUBST(VERSION_SOURCE_DIR, [${ac_abs_confdir}])
86AC_SUBST(VERSION_TAG_PREFIX, [$3])[]dnl
87AC_SUBST(VERSION_TAG_NUMBER, [$4])[]dnl
88AC_SUBST(VERSION_TAG_MATCH, [$3$4])[]dnl
89dnl End of git version control details gathering.
90dnl
24138539
DE
91AC_SUBST([$1])[]dnl
92dnl
93AC_DEFINE([$1_MAJOR], [$5], [Major version number of $2.])[]dnl
94AC_DEFINE([$1_MINOR], [$6], [Minor version number of $2.])[]dnl
95m4_ifval([$7], [AC_DEFINE([$1_MICRO], [$7], [Micro version number of $2.])])[]dnl
5bce22ac 96AC_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##
108AC_DEFUN([SR_PKG_VERSION_SET],
109[dnl
110m4_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##
120m4_define([_SR_LIB_VERSION_SET],
121[dnl
122m4_assert([$# >= 6])[]dnl
123$1=$3
124AC_SUBST([$1])[]dnl
125AC_DEFINE([$1_CURRENT], [$4], [Binary version of $2.])[]dnl
126AC_DEFINE([$1_REVISION], [$5], [Binary revision of $2.])[]dnl
127AC_DEFINE([$1_AGE], [$6], [Binary age of $2.])[]dnl
128AC_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##
139AC_DEFUN([SR_LIB_VERSION_SET],
140[dnl
141m4_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##
153AC_DEFUN([SR_SEARCH_LIBS],
154[dnl
155m4_assert([$# >= 3])[]dnl
156sr_sl_save_LIBS=$LIBS
157AC_SEARCH_LIBS([$2], [$3],,, m4_join([$6], [[$]$1]))
158LIBS=$sr_sl_save_LIBS
159AS_CASE([$ac_cv_search_$2], [no*],,
160 [SR_PREPEND([$1], [$ac_cv_search_$2])])
161m4_ifvaln([$4$5], [AS_IF([test "x$ac_cv_search_$2" = xno], [$5], [$4])])[]dnl
162AC_SUBST([$1])[]dnl
163])
164
1bb196e4
DE
165## _SR_VAR_SUMMARY(tag, var-name, line-leader, align-columns, align-char)
166##
167m4_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##
182AC_DEFUN([SR_VAR_SUMMARY],
183[dnl
184m4_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##
198AC_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##
208AC_DEFUN([SR_PKG_CHECK],
209[dnl
210m4_assert([$# >= 3])[]dnl
211AC_REQUIRE([PKG_PROG_PKG_CONFIG])[]dnl
212AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl
213dnl
214PKG_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##
232AC_DEFUN([SR_VAR_OPT_PKG],
233[dnl
234m4_define([_SR_VAR_OPT_PKG_MODULES], [$1])[]dnl
235m4_define([_SR_VAR_OPT_PKG_FEATURES], [$2])[]dnl
236m4_ifvaln([$1], [$1=])[]dnl
237m4_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 243m4_define([_SR_ARG_OPT_IMPL],
1bb196e4 244[dnl
38662688
DE
245AC_ARG_WITH([$3], [AS_HELP_STRING([--without-$3],
246 [disable $3 support [default=detect]])])
1bb196e4 247AS_IF([test "x$with_$1" = xno], [sr_have_$1=no],
38662688
DE
248 [test "x$sr_have_$1" != xyes], [dnl
249AC_MSG_CHECKING([for $3])
250$6
251AC_MSG_RESULT([$sr_have_$1])[]dnl
252])
1bb196e4 253AS_IF([test "x$with_$1$sr_have_$1" = xyesno],
38662688
DE
254 [AC_MSG_ERROR([$3 support requested, but it was not found.])])
255AS_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
259m4_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##
265m4_define([_SR_ARG_OPT_CHECK],
266[dnl
267_SR_ARG_OPT_IMPL($@)
268sr_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##
286AC_DEFUN([SR_ARG_OPT_CHECK],
287[dnl
288m4_assert([$# >= 4])[]dnl
289AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl
290AC_REQUIRE([SR_VAR_OPT_PKG])[]dnl
291dnl
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##
300m4_define([_SR_ARG_OPT_PKG],
301[dnl
302_SR_ARG_OPT_IMPL([$5], [$1], [$3], [$4], [$2],
303 [SR_PKG_CHECK(m4_shiftn([4], $@))])
304m4_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##
322AC_DEFUN([SR_ARG_OPT_PKG],
323[dnl
324m4_assert([$# >= 4])[]dnl
325AC_REQUIRE([PKG_PROG_PKG_CONFIG])[]dnl
326AC_REQUIRE([SR_PKG_CHECK_SUMMARY])[]dnl
327AC_REQUIRE([SR_VAR_OPT_PKG])[]dnl
328dnl
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##
340AC_DEFUN([SR_PROG_VERSION],
341[dnl
342m4_assert([$# >= 2])[]dnl
343sr_prog_ver=`$1 --version 2>&AS_MESSAGE_LOG_FD | sed 1q 2>&AS_MESSAGE_LOG_FD`
344AS_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##
355AC_DEFUN([SR_PROG_MAKE_ORDER_ONLY],
356[dnl
c2b0f429
DE
357AC_CACHE_CHECK([whether [$]{MAKE:-make} supports order-only prerequisites],
358 [sr_cv_prog_make_order_only], [
359cat >conftest.mk <<'_SREOF'
360a: b | c
361a b c: ; @:
362.PHONY: a b c
363_SREOF
364AS_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])
366rm -f conftest.mk
367])
368AS_IF([test "x$sr_cv_prog_make_order_only" = xyes], [ORDER='|'], [ORDER=])
369AC_SUBST([ORDER])
c1783861 370AM_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##
380AC_DEFUN([SR_CHECK_COMPILE_FLAGS],
381[dnl
382m4_assert([$# >= 3])[]dnl
383AC_MSG_CHECKING([compiler flag for $2])
384sr_ccf_result=no
385sr_ccf_save_CPPFLAGS=$CPPFLAGS
386for sr_flag in $3
387do
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
391done
392CPPFLAGS=$sr_ccf_save_CPPFLAGS
2d2240bb
DE
393AS_IF([test "x$sr_ccf_result" != xno],
394 [SR_APPEND([$1], [$sr_ccf_result])])
b84a7331
DE
395AC_MSG_RESULT([$sr_ccf_result])
396AC_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##
404m4_define([_SR_ARG_ENABLE_WARNINGS_ONCE],
405[dnl
406AC_PROVIDE([$0])[]dnl
407AC_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
412dnl
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.
415sr_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##
440AC_DEFUN([SR_ARG_ENABLE_WARNINGS],
441[dnl
442m4_assert([$# >= 3])[]dnl
443AC_REQUIRE([_SR_ARG_ENABLE_WARNINGS_ONCE])[]dnl
444dnl
445AS_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++]])])
449dnl
450AC_MSG_CHECKING([which $sr_lang compiler warning flags to use])
451sr_warning_flags=
452AC_LANG_CONFTEST([AC_LANG_SOURCE([[
453int main(int argc, char** argv) { return (argv != 0) ? argc : 0; }
454]])])
455AS_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
460rm -f "$sr_conftest"
461AC_SUBST([$1], [$sr_warning_flags])
462AC_MSG_RESULT([[$]{sr_warning_flags:-none}])[]dnl
463])