How to check for haskell package versions in ./configure?
Asked Answered
I

5

7

how can I tell configure to check for version >= x.y of a given Haskell package?

Thanks,

Incommunicado answered 4/10, 2011 at 9:29 Comment(0)
G
4

Use cabalvchk: http://hackage.haskell.org/package/cabalvchk-0.2

For example, to verify that the version of parsec is >= 0.4, you could issue:

$ cabalvchk parsec '>= 0.4'

The return code will be zero if the version constraint is satisfied and non-zero otherwise. The version constraint can be anything cabal understands. An optional third parameter can be non-blank to request verbose output.

Gad answered 11/10, 2011 at 8:36 Comment(2)
This is indeed cool, even if it means that I must introduce a new dependency.Incommunicado
Thanks! Longer term I could petition the cabal tool folks to add this functionality directly into cabal which would reduce the dependencies, but this additional dependency would be necessary for your immediate needs.Gad
C
3

I don't know much about configure; can you ask it to run a particular command? If so, then ghc-pkg latest should help you out. For example, here's a run on my machine for the zlib package:

% ghc-pkg latest zlib
zlib-0.5.3.1
% ghc-pkg latest --global zlib
zlib-0.5.3.1
% ghc-pkg latest --user zlib
ghc-pkg: cannot find package zlib
zsh: exit 1     ghc-pkg latest --user zlib

The --global should be used for system-wide installations, and no flag at all for user-specific installations. The --user flag should only be used when you want to check whether a user has a local installation of a package (that may override the global one).

Unless you have a reason not to, I recommend ditching configure in favor of cabal. For cabal, the solution here is to first cabal init in your project's directory, then check that you have a line like this in the .cabal file that's created:

build-depends: zlib >= 0.5

The cabal toolchain is the standard for Haskell projects (because it automates and simplifies many things, including dependency-chasing). You can also ask cabal to invoke configure if there are other dependencies. Open a separate question if you'd like more information about this.

Chirpy answered 4/10, 2011 at 17:10 Comment(1)
Thanks for the answer. I already use ghc-pkg, but I don't know of a way of saying I need version >= x.y. The reason for using configure is that the haskell scripts are a part of a bigger program mainly written in python, and all the dependencies are already managed through configure.Incommunicado
R
1

Perhaps the better question is: should you? Checking for a specific version number is one of the great arguments in the autoconf world, and the general winner of the debate is the side which says you should never do it. What specific feature of Haskell do you need? Test for that. As a simple example (unrelated to haskell), suppose your program uses inotify so you want the configury to test if it is available. You could just test if the kernel version is > 2.6.13, but then when Joe tries to build your program on his 2.4.xx version in which he has patched in inotify capability, he's going to be really irritated that your program won't work.

You do not care if Haskell > x.y is available. Instead, there is some specific feature of Haskell that you want that was introduced in x.y; test for that feature.

Rosenwald answered 9/10, 2011 at 21:12 Comment(0)
T
0

Using ghc-pkg list, you can get a list of installed versions of a package in ascending order. You should hopefully be able to filter through this list looking for a match. (I don't know how to do this with configure, sorry).

$ ghc-pkg list yesod
/home/ahammar/.haskell/lib/ghc-7.0.2/package.conf.d
/home/ahammar/.ghc/x86_64-linux-7.0.2/package.conf.d
   yesod-0.8.2.1
   yesod-0.9.1
   yesod-0.9.2.2
Tankage answered 4/10, 2011 at 17:49 Comment(0)
P
0

Try something like this:

# Find ghc-pkg, so we can do version checks
AC_ARG_VAR([GHC_PKG], [Path to ghc-pkg])
AC_PATH_PROG([GHC_PKG], [ghc-pkg])
AS_IF([test -z "$GHC_PKG"], [AC_MSG_ERROR([Cannot find ghc-pkg.])])

# Check that the package actually exists
AC_MSG_CHECKING([for Haskell package foo])
AS_IF([$GHC_PKG latest foo > /dev/null 2>&1],
  [AC_MSG_RESULT([yes])],
  [AC_MSG_RESULT([no])
AC_MSG_ERROR([Cannot find foo])])

# Check its version
AC_MSG_CHECKING([if foo is new enough])
foo_ver=`$GHC_PKG latest foo | sed 's/^foo-//'`
# At this point you have the version of foo and the minimum version you want.
# The rest of the test is pretty easy to write, use cut and test to compare the
# version numbers. If it's new enough, AC_MSG_RESULT([yes]).
# If not, AC_MSG_RESULT([no]) and AC_MSG_ERROR([foo is not new enough.])
Prolongation answered 8/10, 2011 at 21:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.