GHC ?= ghc
GHCFLAGS ?= -O2 -Wall
PYTHON ?= python3

SOURCES := $(wildcard src/Tempo/*.hs) src/Tempo.hs
PACKAGES := -package language-c -package parsec -package mtl -package unix

.PHONY: all test test-demos test-sqlite clean

all: build/tempo

build/tempo: app/Main.hs $(SOURCES)
	mkdir -p build/objects
	$(GHC) --make $(GHCFLAGS) -rtsopts $(PACKAGES) -isrc -outputdir build/objects app/Main.hs -o $@

build/native-api-test: test/Runtime.hs $(SOURCES)
	mkdir -p build/test-objects
	$(GHC) --make $(GHCFLAGS) $(PACKAGES) -isrc -outputdir build/test-objects test/Runtime.hs -o $@

test: build/tempo build/native-api-test
	$(PYTHON) test/integration.py build/tempo
	./build/native-api-test

test-demos: build/tempo
	$(PYTHON) demos/run.py --tempo build/tempo

test-sqlite: build/tempo
	$(PYTHON) test/sqlite.py build/tempo

clean:
	$(RM) -r build
