From e5bd9de5b80fc5d0d1cb48da30f69d2d0e27f867 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 21 Mar 2011 11:00:06 +0100
Subject: [PATCH] configure.ac: add checks for Haskell compiler/libs

This patch adds an enable/disable option for htools (--enable-htools),
and associated tests for determining whether GHC (the compiler we use
for htools) and required libraries are present.

The method to do so is not very nice; usually, Haskell programs are
configured and compiled using cabal (http://www.haskell.org/cabal/, a
tool similar to Python's setuptools)), but that doesn't suit itself to
nice integration with autoconf/automake, so we test for the modules
presence manually.

In the end, we set a few variables:

- GHC: the path to the ghc compiler
- HTOOLS_MODULES: command line option for ghc to select the wanted
  'parallel' module
- HTOOLS_NOCURL: set to -DNO_CURL if we don't want to enable curl (and
  thus RAPI) support in htools
- HTOOLS: set to 'yes' if we should compile/install the htools
  programs
- HTOOLS_APIDOC: set to yes if we should build/install the htools
  API documentation
- WANT_HTOOLS, WANT_HTOOLSAPIDOC: two automake conditionals for later
  use in Makefile.am

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 configure.ac | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 104 insertions(+)

diff --git a/configure.ac b/configure.ac
index 6713ea184..00198c132 100644
--- a/configure.ac
+++ b/configure.ac
@@ -240,6 +240,14 @@ then
 fi
 AC_SUBST(SYSLOG_USAGE, $SYSLOG)
 
+# --enable-htools
+HTOOLS=
+AC_ARG_ENABLE([htools],
+        [AS_HELP_STRING([--enable-htools],
+        [enable use of htools (needs GHC and libraries, default: check)])],
+        [],
+        [enable_htools=check])
+
 # --with-disk-separator=...
 AC_ARG_WITH([disk-separator],
   [AS_HELP_STRING([--with-disk-separator=STRING],
@@ -293,6 +301,102 @@ then
   AC_MSG_ERROR([socat not found])
 fi
 
+if test "$enable_htools" != "no"; then
+
+# Check for ghc
+AC_ARG_VAR(GHC, [ghc path])
+AC_PATH_PROG(GHC, [ghc], [])
+if test -z "$GHC"; then
+  if test "$enable_htools" != "check"; then
+    AC_MSG_FAILURE([ghc not found, htools compilation will not possible])
+  fi
+fi
+
+# Check for ghc-pkg
+HTOOLS_MODULES=
+AC_ARG_VAR(GHC_PKG, [ghc-pkg path])
+AC_PATH_PROG(GHC_PKG, [ghc-pkg], [])
+if test -z "$GHC_PKG"; then
+  if test "$enable_htools" != "check"; then
+    AC_MSG_FAILURE([ghc-pkg not found, htools compilation will not be possible])
+  fi
+else
+  # check for modules
+  AC_MSG_NOTICE([checking for required haskell modules])
+  AC_MSG_CHECKING([curl])
+  GHC_PKG_CURL=$($GHC_PKG latest curl)
+  if test -z "$GHC_PKG_CURL"; then
+    AC_MSG_WARN([The curl library not found, htools will be compiled
+                 without RAPI support])
+    AC_SUBST(HTOOLS_NOCURL, [-DNO_CURL])
+  fi
+  AC_MSG_RESULT($GHC_PKG_CURL)
+  AC_SUBST(GHC_PKG_CURL)
+  AC_MSG_CHECKING([parallel])
+  GHC_PKG_PARALLEL=$($GHC_PKG --simple-output list 'parallel-2.*')
+  if test -z "$GHC_PKG_PARALLEL"
+  then
+    GHC_PKG_PARALLEL=$($GHC_PKG --simple-output list 'parallel-1.*')
+  fi
+  AC_SUBST(GHC_PKG_PARALLEL)
+  AC_MSG_RESULT($GHC_PKG_PARALLEL)
+  AC_MSG_CHECKING([json])
+  GHC_PKG_JSON=$($GHC_PKG latest json)
+  AC_MSG_RESULT($GHC_PKG_JSON)
+  AC_MSG_CHECKING([network])
+  GHC_PKG_NETWORK=$($GHC_PKG latest network)
+  AC_MSG_RESULT($GHC_PKG_NETWORK)
+  if test -z "$GHC_PKG_PARALLEL" || test -z "$GHC_PKG_JSON" || \
+     test -z "$GHC_PKG_NETWORK"; then
+    if test "$enable_htools" != "check"; then
+      AC_MSG_FAILURE([Required Haskell modules not found, htools compilation
+                      disabled])
+
+    fi
+  else
+    # we leave the other modules to be auto-selected
+    HTOOLS_MODULES="-package $GHC_PKG_PARALLEL"
+  fi
+fi
+AC_SUBST(HTOOLS_MODULES)
+
+if test "$enable_htools" != "no"; then
+  if test -z "$GHC" || test -z "$HTOOLS_MODULES"; then
+    AC_MSG_WARN([Haskell compiler/required libraries not found, htools
+                 compilation disabled])
+  else
+    HTOOLS=yes
+  fi
+fi
+AC_SUBST(HTOOLS)
+
+# Check for HsColour
+HTOOLS_APIDOC=no
+AC_ARG_VAR(HSCOLOUR, [HsColour path])
+AC_PATH_PROG(HSCOLOUR, [HsColour], [])
+if test -z "$HSCOLOUR"; then
+  AC_MSG_WARN([HsColour not found, htools API documentation will not be
+               generated])
+fi
+
+# Check for haddock
+AC_ARG_VAR(HADDOCK, [haddock path])
+AC_PATH_PROG(HADDOCK, [haddock], [])
+if test -z "$HADDOCK"; then
+  AC_MSG_WARN([haddock not found, htools API documentation will not be
+               generated])
+fi
+if test "$HADDOCK" && test "$HSCOLOUR"; then
+  HTOOLS_APIDOC=yes
+fi
+AC_SUBST(HTOOLS_APIDOC)
+
+fi # end if enable_htools, define automake conditions
+
+AM_CONDITIONAL([WANT_HTOOLS], [test x$HTOOLS = xyes])
+AM_CONDITIONAL([WANT_HTOOLSAPIDOC], [test x$HTOOLS_APIDOC = xyes])
+
+
 SOCAT_USE_ESCAPE=
 AC_ARG_ENABLE([socat-escape],
   [AS_HELP_STRING([--enable-socat-escape],
-- 
GitLab