]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/macros.at
Add a configure test for C99-ish "for" declarations.
[dxcommon.git] / tests / macros.at
index a085ad6ab50aeb2ff39ca7c300b5f17f60d0b9f9..9aadd038faca7ea15e06601776d22dcca3cf6dac 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2014-2015, 2018-2019, 2021-2022 Nick Bowler
+dnl Copyright © 2014-2015, 2018-2019, 2021-2023 Nick Bowler
 dnl
 dnl License WTFPL2: Do What The Fuck You Want To Public License, version 2.
 dnl This is free software: you are free to do what the fuck you want to.
@@ -597,3 +597,80 @@ done
 exit 1])
 
 AT_CLEANUP
+
+# TEST_FIND_AUTOCONF_VER([to-check], [test-action])
+#
+# For each whitespace-separated version token in to-check, check if we can
+# run program autoconf-VER.  The special token 'default' also checks the
+# unversioned autoconf (or, if set in the environment, $AUTOCONF).
+#
+# Then test-action is expanded such that the shell variable $ac refers
+# to the autoconf program, and $acver is the actual version reported by
+# $ac --version. The action should do nothing if the version is acceptable,
+# or "continue" if the version is unacceptable.
+#
+# If an acceptable version is found, the AUTOCONF environment variable is
+# set accordingly.  Otherwise, the test group is skipped.
+m4_define([TEST_FIND_AUTOCONF],
+[have_ac=false
+for ac in $1; do
+  AS_CASE([$ac], [default], [ac=${AUTOCONF-autoconf}], [ac=autoconf-$ac])
+  acver=`$ac --version | sed -n '1s/.* //p'`
+  set x $acver; test x"$[#]" = x"2" || continue
+  $2
+  have_ac=:; break
+done
+AT_CHECK([$have_ac || exit 77])
+AUTOCONF=$ac; export AUTOCONF
+AT_CHECK([$AUTOCONF --version], [0], [ignore])
+])
+
+m4_define([TEST_DX_C_FOR_DECLARATIONS],
+[cat "$srcdir/m4/fordecl.m4" >aclocal.m4
+AT_DATA([config.h.in],
+[[#undef HAVE_FOR_DECLS
+]])
+TEST_CONFIGURE_AC([m4_ifnblank([$1], [$1])
+[AC_CONFIG_HEADERS([config.h])
+DX_C_FOR_DECLARATIONS
+]])
+AT_CHECK([$AUTOCONF], [0], [], [stderr])
+AT_DATA([test.c],
+[[#if __STDC_VERSION__ < 199901
+#error nope
+char nope[-1];
+#endif
+char yup;
+]])
+AT_CHECK([$CC -c -std=gnu99 test.c || exit 77], [0], [ignore], [ignore])
+TEST_CONFIGURE([CC="$CC" CFLAGS="-std=gnu89"])
+AT_CHECK([grep HAVE_FOR_DECLS config.h], [0],
+[[/* #undef HAVE_FOR_DECLS */
+]])
+TEST_CONFIGURE([CC="$CC -std=gnu99"])
+AT_CHECK([grep HAVE_FOR_DECLS config.h], [0],
+[[#define HAVE_FOR_DECLS 1
+]])
+])
+
+AT_SETUP([DX_C_FOR_DECLARATIONS (<autoconf-2.70)])
+AT_KEYWORDS([DX_C_FOR_DECLARATIONS macro])
+TEST_FIND_AUTOCONF([default 2.69 2.68],
+  [AS_VERSION_COMPARE(["$acver"], [2.70], [], [continue], [continue])])
+TEST_DX_C_FOR_DECLARATIONS([[AC_PROG_CC]])
+TEST_DX_C_FOR_DECLARATIONS([[AC_PROG_CC_C99]])
+AT_CLEANUP
+
+AT_SETUP([DX_C_FOR_DECLARATIONS (=autoconf-2.70)])
+AT_KEYWORDS([DX_C_FOR_DECLARATIONS macro])
+TEST_FIND_AUTOCONF([default 2.70],
+  [AS_VERSION_COMPARE(["$acver"], [2.70], [continue], [], [continue])])
+TEST_DX_C_FOR_DECLARATIONS
+AT_CLEANUP
+
+AT_SETUP([DX_C_FOR_DECLARATIONS (>autoconf-2.70)])
+AT_KEYWORDS([DX_C_FOR_DECLARATIONS macro])
+TEST_FIND_AUTOCONF([default 2.71 2.72 2.73 2.74],
+  [AS_VERSION_COMPARE(["$acver"], [2.70], [continue], [continue], [])])
+TEST_DX_C_FOR_DECLARATIONS
+AT_CLEANUP