-GHC_WARNINGS := -Wall
-GHC_WARNINGS += -fwarn-hi-shadowing
-GHC_WARNINGS += -fwarn-missing-signatures
-GHC_WARNINGS += -fwarn-name-shadowing
-GHC_WARNINGS += -fwarn-orphans
-GHC_WARNINGS += -fwarn-type-defaults
-
-BIN := spline3
-
-.PHONY : test doc src_html hlint
-
-$(BIN): src/*.hs
- ghc -O2 $(GHC_WARNINGS) --make -o bin/${BIN} src/*.hs
-
-all: $(BIN) test_src
-
-test_src: src/Tests/*.hs
- ghc -O2 $(GHC_WARNINGS) --make -o bin/${BIN} src/*.hs src/Tests/*.hs
-
-profile: src/*.hs
- ghc -O2 $(GHC_WARNINGS) -prof -auto-all --make -o bin/$(BIN) src/*.hs
+PN = spline3
+BIN = dist/build/$(PN)/$(PN)
+SRCS := $(shell find src/ -type f -name '*.hs')
+
+BIN = dist/build/spline3/spline3
+DOCTESTS_BIN = dist/build/doctests/doctests
+TESTSUITE_BIN = dist/build/testsuite/testsuite
+
+.PHONY : test doc dist hlint
+
+$(BIN): $(PN).cabal $(SRCS)
+ runghc Setup.hs configure \
+ --user \
+ --prefix=/ \
+ --flags=${FLAGS}
+ runghc Setup.hs build
+
+$(DOCTESTS_BIN): $(SRCS) test/Doctests.hs
+ runghc Setup.hs configure \
+ --user \
+ --prefix=/ \
+ --flags=${FLAGS} \
+ --enable-tests
+ runghc Setup.hs build
+
+$(TESTSUITE_BIN): $(SRCS) test/TestSuite.hs
+ runghc Setup.hs configure \
+ --user \
+ --prefix=/ \
+ --flags=${FLAGS} \
+ --enable-tests
+ runghc Setup.hs build