如何使用 Cabal 构建一个简单的项目?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最简单的开始方法是让 Cabal 为您生成一个
.cabal
文件,您可以将其用作起点。为此,请进入您的项目目录并键入它,然后它会问您一系列有关您的包的问题。有些问题(例如作者姓名和电子邮件)仅在您计划将包上传到 Hackage 时才真正重要,因此如果您愿意,可以将这些问题留空。完成此操作后,您可以编辑
.cabal
文件进行自定义。生成的文件将包含一堆注释,可以帮助您入门。之后,只需输入二进制文件将默认放置在
./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 typeIt 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 typeThe binary will by default be placed in
./dist/build/<name>/
.