使用带有cabal的Makefile?

ram*_*ion 8 haskell makefile

我工作的一个玩具项目,以此来从理论上将我的Haskell的享受实用,让自己更舒服cabal,HUnit等等.

我刚刚在我的项目中添加了一个Makefile:

test: dist/build
  cabal-dev test

dist/build: dist/setup-config src/*.hs tests/*.hs
  cabal-dev build
  touch dist/build

dist/setup-config: ToyProject.cabal
  cabal-dev configure --enable-tests
Run Code Online (Sandbox Code Playgroud)

因为:

  • cabal-dev install --enable-tests 看起来有点矫枉过正(并警告我重新安装)
  • cabal-dev configure --enable-tests && cabal-dev build && cabal-dev test 正在做不必要的工作,并保持关于我是否需要重新配置的状态很无聊
  • 而且两者都打字很多

我担心我可能正在使用Make cabal或者cabal-dev已经给我重新创建功能,但是我不熟悉它们是否真的,如果它是,我怎么做.

这里的Makefile是否合适,或者只是使用cabal/ 有更直接的方法cabal-dev吗?

ntc*_*tc2 1

下面是我与 Cabal 包一起使用的 Makefile 的简化版本,我正在与另一个依赖于 Cabal 包的 Haskell 程序并行开发(我经常并行编辑它们,因此我将 Cabal 包作为构建依赖项程序,使用另一个 Makefile :P)。目标是:

  1. cabal当某些源文件实际发生更改时才运行。我在一个非常慢的上网本上使用这个 Makefile ,其中 Cabal 依赖解析步骤需要 10 秒,所以我想cabal install尽可能避免运行。

  2. 在单独的构建目录中进行独立调试和常规构建。默认情况下,如果您使用分析 ( ) 进行 Cabal 构建--ghc-options=-fprof-auto,然后进行不进行分析的 Cabal 构建,Cabal 将重新开始,从头开始重新编译所有文件。将构建放在单独的构建目录中可以避免此问题。

我不确定(2)您是否感兴趣,但(1)可能是,并且我发现您只在成功时才触摸构建目录,而不是在失败时触摸构建目录,我预计这将无法正常工作。

这是生成文件:

cabal-install: dist

cabal-install-debug: prof-dist

# You will need to extend this if your cabal build depends on non
# haskell files (here '.lhs' and '.hs' files).
SOURCE = $(shell find src -name '*.lhs' -o -name '*.hs')

# If 'cabal install' fails in building or installing, the
# timestamp on the build dir -- 'dist' or 'prof-dist', stored in
# the make target variable '$@' here -- may still be updated.  So,
# we set the timestamp on the build dir to a long time in the past
# with 'touch --date "@0" $@' in case cabal fails.
CABAL_INSTALL = \
  cabal install $(CABAL_OPTIONS) \
  || { touch --date "@0" $@ ; \
       exit 42 ; }

dist: $(SOURCE)
    $(CABAL_INSTALL)

# Build in a non-default dir, so that we can have debug and non-debug
# versions compiled at the same time.
#
# Added '--disable-optimization' because '-O' messes with
# 'Debug.Trace.trace' and other 'unsafePerformIO' hacks.
prof-dist: CABAL_OPTIONS += --ghc-options="-fprof-auto" --builddir=prof-dist --disable-optimization
prof-dist: $(SOURCE)
    $(CABAL_INSTALL)
Run Code Online (Sandbox Code Playgroud)