]> git.draconx.ca Git - dxcommon.git/commitdiff
Add GOBject Builder detection macro.
authorNick Bowler <nbowler@draconx.ca>
Mon, 27 Jan 2020 20:29:07 +0000 (15:29 -0500)
committerNick Bowler <nbowler@draconx.ca>
Mon, 27 Jan 2020 23:06:27 +0000 (18:06 -0500)
m4/gob2.m4 [new file with mode: 0644]
t/gob2.sh [new file with mode: 0755]
tests/programs.at [new file with mode: 0644]
testsuite.at

diff --git a/m4/gob2.m4 b/m4/gob2.m4
new file mode 100644 (file)
index 0000000..48a503c
--- /dev/null
@@ -0,0 +1,52 @@
+dnl Copyright © 2020 Nick Bowler
+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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+dnl DX_PROG_GOB2([min-version], [action-if-found], [action-if-not-found])
+dnl
+dnl Search PATH for a working gob2 utility with the given minimum version,
+dnl which may be empty to accept any version.  If found, the GOB2 variable
+dnl (which is substituted with AC_SUBST) is set with the result, and
+dnl action-if-found is executed.  Otherwise, action-if-found is executed
+dnl if nonempty, else configure will exit with a fatal error.
+
+AC_DEFUN([DX_PROG_GOB2], [AC_ARG_VAR([GOB2], [GOBject Builder command])dnl
+AC_PREREQ([2.62])dnl
+cat >conftest.gob <<'EOF'
+m4_ifnblank([$1], [requires $1
+])dnl
+class :Conftest from G:Object
+{
+}
+EOF
+AC_CACHE_CHECK([for GObject Builder], [ac_cv_path_GOB2],
+[dx_cv_gob_found=:
+AC_PATH_PROGS_FEATURE_CHECK([GOB2], [gob2],
+[rm -f conftest.c
+$ac_path_GOB2 conftest.gob >&AS_MESSAGE_LOG_FD 2>&1 && test -f conftest.c && {
+  gob_relcmd=${ac_path_GOB2##*/}
+  gob_bypath=`command -v "$gob_relcmd"` # ''
+  ac_cv_path_GOB2=$ac_path_GOB2
+  test x"$gob_bypath" = x"$ac_path_GOB2" && ac_cv_path_GOB2=$gob_relcmd
+  ac_path_GOB2_found=:
+  dx_cv_gob_works=yes
+}], [ac_cv_path_GOB2=no dx_cv_gob_found=false])
+])
+AS_IF([$dx_cv_gob_found],
+[GOB2=$ac_cv_path_GOB2
+AC_CACHE_CHECK([whether $GOB2 works], [dx_cv_gob_works],
+[rm -f conftest.c
+if $GOB2 conftest.gob >&AS_MESSAGE_LOG_FD 2>&1 && test -f conftest.c; then
+  dx_cv_gob_works=yes
+else
+  dx_cv_gob_works=no
+fi])])
+AS_IF([test x"$dx_cv_gob_works" = x"yes"],
+  [$2], [m4_default([$3], [AC_MSG_FAILURE(
+[GObject Builder m4_ifnblank([$1], [version at least $1 ])is required.
+
+The latest version may be found at <https://draconx.ca/projects/gob-dx/>.
+])])])
+rm -f conftest*
+])
diff --git a/t/gob2.sh b/t/gob2.sh
new file mode 100755 (executable)
index 0000000..0e16794
--- /dev/null
+++ b/t/gob2.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+#
+# Copyright © 2020 Nick Bowler
+#
+# Fake gob2 program for testing the gob2 detection macro.
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
+
+: "${FAKE_GOB2_VERSION=2.0.0}"
+
+argv0=$0
+
+infile=
+for arg
+do
+  case $arg in
+  *.gob)
+    infile=$arg
+  esac
+done
+
+if test x"$infile" = x""; then
+  printf '%s: error: no input file\n' "$argv0" 1>&2
+  exit 1
+fi
+
+exec 3<"$infile"
+save_IFS=$IFS
+while IFS=$IFS. read a b c d e <&3; do
+  case $a in
+  requires)
+    IFS=$IFS.
+    set x $FAKE_GOB2_VERSION; shift
+    IFS=$save_IFS
+
+    { test "${1:-0}" -gt "${b:-0}" ||
+      { test "${1:-0}" -eq "${b:-0}" &&
+        { test "${2:-0}" -gt "${c:-0}" ||
+          { test "${2:-0}" -eq "${c:-0}" && test "${3:-0}" -ge "${d:-}"
+            }; }; }; } ||
+    { printf '%s: error: minimum version not met\n' "$argv0"; exit; }
+    ;;
+  esac
+done
+
+cat >conftest.c <<'EOF'
+int conftest_get_type(void) { }
+EOF
diff --git a/tests/programs.at b/tests/programs.at
new file mode 100644 (file)
index 0000000..0228ac3
--- /dev/null
@@ -0,0 +1,90 @@
+dnl Copyright © 2020 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.
+dnl There is NO WARRANTY, to the extent permitted by law.
+
+AT_BANNER([Program tests])
+
+AT_SETUP([gob2 probes])
+
+mkdir bin
+cp -P "$srcdir/t/gob2.sh" bin
+
+AT_DATA([test.in],
+[[@HAVE_GOB2@
+@GOB2@
+]])
+
+# Unversioned tests
+TEST_CONFIGURE_AC([[DX_PROG_GOB2([], [HAVE_GOB2=yes], [HAVE_GOB2=no])
+AC_SUBST([GOB2])
+AC_SUBST([HAVE_GOB2])
+
+set x conftest*; shift
+if test -f $[]1; then
+  AC_MSG_ERROR([conftest* left behind by [DX_PROG_GOB2]])
+fi
+
+AC_CONFIG_FILES([test])
+]])
+TEST_AUTORECONF
+
+# Check the search via path lookup
+save_PATH=$PATH
+PATH=$PWD/bin${PATH:+":$PATH"}
+TEST_CONFIGURE
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+gob2
+])
+PATH=$save_PATH
+
+# Check the search via user override
+TEST_CONFIGURE([GOB2="$srcdir/t/gob2.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+$srcdir/t/gob2.sh
+])
+
+# Check that a bogus program doesn't come back as valid.
+TEST_CONFIGURE([GOB2=true])
+AT_CHECK_UNQUOTED([cat test], [0], [no
+true
+])
+
+# min-version tests
+mv configure.ac configure.old
+[sed 's/DX_PROG_GOB2(\[\]/DX_PROG_GOB2([2.1.3]/' configure.old >configure.ac]
+TEST_AUTORECONF
+
+FAKE_GOB2_VERSION=2.0.0
+export FAKE_GOB2_VERSION
+TEST_CONFIGURE([GOB2="$srcdir/t/gob2.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [no
+$srcdir/t/gob2.sh
+])
+
+FAKE_GOB2_VERSION=3.0.0
+TEST_CONFIGURE([GOB2="$srcdir/t/gob2.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+$srcdir/t/gob2.sh
+])
+
+FAKE_GOB2_VERSION=2.5.0
+TEST_CONFIGURE([GOB2="$srcdir/t/gob2.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+$srcdir/t/gob2.sh
+])
+
+FAKE_GOB2_VERSION=2.1.2
+TEST_CONFIGURE([GOB2="$srcdir/t/gob2.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [no
+$srcdir/t/gob2.sh
+])
+
+FAKE_GOB2_VERSION=2.1.3
+TEST_CONFIGURE([GOB2="$srcdir/t/gob2.sh"])
+AT_CHECK_UNQUOTED([cat test], [0], [yes
+$srcdir/t/gob2.sh
+])
+
+AT_CLEANUP
index 11b48a6b144e1ae6b7ccebf4bfa83b809a3b1414..3c5fdacefd5e4952838e769e10cb3dce305b4399 100644 (file)
@@ -1,4 +1,4 @@
-dnl Copyright © 2015 Nick Bowler
+dnl Copyright © 2015,2019-2020 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.
@@ -28,4 +28,5 @@ AT_CHECK([./configure $1], [0], [ignore])])
 
 m4_include([tests/macros.at])
 m4_include([tests/functions.at])
+m4_include([tests/programs.at])
 m4_include([tests/libs.at])