如何使用 Cabal 构建一个简单的项目?

发布于 2025-01-06 17:24:45 字数 399 浏览 1 评论 0原文

Haskell wiki 指出您应该使用 Cabal 作为构建系统。然而,在我看来,它更倾向于生成包,而不是构建二进制文件。基本上,我想做的就是将 src/ 目录中的每个 *.hs 文件构建到 bin/ 中的单独二进制文件中。这个 makefile 很好地完成了这一点,但我想了解 Cabal,这似乎是一个让我开始的好例子:

GHC = ghc
GHCFLAGS = -outputdir bin
SRC = $(wildcard src/*.hs)
BIN = $(patsubst src/%.hs,%,$(SRC))

all: $(addprefix bin/, $(BIN))

bin/%: src/%.hs
    $(GHC) $(GHCFLAGS) $< -o $@

clean:
    rm bin/*

The Haskell wiki states that you should use Cabal as your build system. However, it seems to me much more directed at producing packages then just building binaries. Basically, all I want to do is build every *.hs file in my src/ directory into a seperate binary in bin/. This makefile accomplishes this nicely, but I want to learn about Cabal and this seems like a good example to get me started:

GHC = ghc
GHCFLAGS = -outputdir bin
SRC = $(wildcard src/*.hs)
BIN = $(patsubst src/%.hs,%,$(SRC))

all: $(addprefix bin/, $(BIN))

bin/%: src/%.hs
    $(GHC) $(GHCFLAGS) 
lt; -o $@

clean:
    rm bin/*

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

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

发布评论

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

评论(1

迷迭香的记忆 2025-01-13 17:24:45

最简单的开始方法是让 Cabal 为您生成一个 .cabal 文件,您可以将其用作起点。为此,请进入您的项目目录并键入它,

$ cabal init

然后它会问您一系列有关您的包的问题。有些问题(例如作者姓名和电子邮件)仅在您计划将包上传到 Hackage 时才真正重要,因此如果您愿意,可以将这些问题留空。完成此操作后,您可以编辑 .cabal 文件进行自定义。生成的文件将包含一堆注释,可以帮助您入门。之后,只需输入

$ cabal configure
$ cabal build

二进制文件将默认放置在 ./dist/build// 中。

The easiest way to get started is to have Cabal generate a .cabal file for you that you can use as a starting point. To do this, go into your project directory and type

$ cabal init

It will then ask you a bunch of questions about your package. Some questions like author name and email only really matter if you plan on uploading your package to Hackage, so you can leave those blank if you want. After doing that, you can then edit the .cabal file to customize it. The generated file will contain a bunch of comments which should help you get started. After that, simply type

$ cabal configure
$ cabal build

The binary will by default be placed in ./dist/build/<name>/.

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