sigrok.m4 15 KB

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