Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I build a simple project with Cabal?

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) $< -o $@

clean:
    rm bin/*
like image 937
Psirus Avatar asked Feb 15 '12 19:02

Psirus


People also ask

What is the difference between stack and cabal?

Package versus projectStack is a build tool and it uses Cabal, a build system. Cabal defines the concept of a package. A package has: A name and version.

Where is cabal installed?

Using Cabal By default stack installs packages to ~/. cabal and ~/. ghc in your home directory.


1 Answers

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>/.

like image 77
hammar Avatar answered Sep 27 '22 21:09

hammar