Browse code

Adding M4 macro to check for presence of BH package

Samuela Pollack authored on 12/02/2019 21:22:05
Showing 1 changed files

1 1
new file mode 100644
... ...
@@ -0,0 +1,61 @@
1
+# ===========================================================================
2
+#       https://www.gnu.org/software/autoconf-archive/ax_r_package.html
3
+# ===========================================================================
4
+#
5
+# SYNOPSIS
6
+#
7
+#   AX_R_PACKAGE(pkgname[, version, R])
8
+#
9
+# DESCRIPTION
10
+#
11
+#   Checks for an R package.
12
+#
13
+#   Optionally checks for the version when a second argument is given. A
14
+#   different R can be used by providing a third argument.
15
+#
16
+# LICENSE
17
+#
18
+#   Copyright (c) 2017 Ricardo Wurmus
19
+#
20
+#   Copying and distribution of this file, with or without modification, are
21
+#   permitted in any medium without royalty provided the copyright notice
22
+#   and this notice are preserved. This file is offered as-is, without any
23
+#   warranty.
24
+
25
+#serial 1
26
+
27
+AC_DEFUN([AX_R_PACKAGE], [
28
+    pushdef([PKG],$1)
29
+    pushdef([VERSION],$2)
30
+
31
+    if test -z $R;
32
+    then
33
+        if test -z "$3";
34
+        then
35
+            R="R"
36
+        else
37
+            R="$3"
38
+        fi
39
+    fi
40
+
41
+    AC_MSG_CHECKING([R package PKG VERSION])
42
+
43
+    TEST=$( $R --silent --vanilla -e 'if(is.na(packageDescription("PKG"))) stop("not found")' 2>/dev/null )
44
+    AS_IF([test $? -eq 0], [], [
45
+      AC_MSG_RESULT([no])
46
+      AC_MSG_ERROR([R package PKG not found.])
47
+    ])
48
+
49
+    if test -n "VERSION"
50
+    then
51
+      TEST=$( $R --silent --vanilla -e 'if(!(packageDescription("PKG")$Version >= "VERSION")) stop("not found")' 2>/dev/null )
52
+      AS_IF([test $? -eq 0], [], [
53
+        AC_MSG_RESULT([no])
54
+        AC_MSG_ERROR([You need at least version VERSION of the R package PKG.])
55
+      ])
56
+    fi
57
+
58
+    AC_MSG_RESULT(yes)
59
+    popdef([PKG])
60
+    popdef([VERSION])
61
+])