如何在./configure中检查haskell软件包版本?

发布于 2024-12-07 19:41:49 字数 76 浏览 1 评论 0原文

我如何告诉configure检查给定Haskell包的version >= xy

谢谢,

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

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

芸娘子的小脾气 2024-12-14 19:41:49

使用 cabalvchk: http://hackage.haskell.org/package/cabalvchk-0.2

例如,验证parsec 的版本 >= 0.4,您可以发出:

$ cabalvchk parsec '>= 0.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.

夏の忆 2024-12-14 19:41:49

我不太了解configure;你能要求它运行特定的命令吗?如果是这样,那么 ghc-pkglatest 应该可以帮助您。例如,这是在我的机器上运行 zlib 包:

% 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

--global 应该用于系统范围的安装,对于特定于用户的安装根本没有标志装置。仅当您想要检查用户是否本地安装了软件包(可能会覆盖全局安装)时,才应使用 --user 标志。

除非您有理由不这样做,否则我建议放弃 configure 而转而使用 cabal。对于 cabal,这里的解决方案是首先在项目目录中执行 cabal init,然后检查 .cabal 中是否有这样的行创建的文件:

build-depends: zlib >= 0.5

cabal 工具链是 Haskell 项目的标准(因为它自动化并简化了许多事情,包括依赖项追踪)。如果还有其他依赖项,您还可以要求cabal调用configure。如果您想了解更多相关信息,请提出一个单独的问题。

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.

蹲在坟头点根烟 2024-12-14 19:41:49

也许更好的问题是:你应该吗?检查特定版本号是 autoconf 世界中最重要的争论之一,而这场争论的最终胜利者是认为永远不应该这样做的一方。您需要 Haskell 的哪些具体功能?测试一下。作为一个简单的示例(与 haskell 无关),假设您的程序使用 inotify,因此您希望配置测试它是否可用。您可以测试内核版本是否 > 2.6.13,但是当 Joe 尝试在他的 2.4.xx 版本上构建您的程序(在该版本中他已经修补了 inotify 功能)时,他会因为您的程序无法运行而感到非常恼火。

你不关心 Haskell 是否 > xy 可用。相反,您希望在 xy 中引入 Haskell 的一些特定功能;测试该功能。

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.

迟到的我 2024-12-14 19:41:49

使用 ghc-pkg list,您可以按升序获取软件包的已安装版本列表。您应该希望能够过滤此列表以查找匹配项。 (我不知道如何使用 configure 来做到这一点,抱歉)。

$ 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

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
软糖 2024-12-14 19:41:49

尝试这样的事情:

# 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.])

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.])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文