GHCI7 = ghci -XCPP -DNoImplicitPrelude=RebindableSyntax
BUILDDIR = dist/repl
DIRS = -i:src:example:testsuite:alsa:jack -hidir $(BUILDDIR) -odir $(BUILDDIR) -stubdir $(BUILDDIR)

# Option -fobject-code is required to handle the foreign import of the FunPtr.
ghci:
	ghci -Wall -fobject-code $(DIRS) example/Synthesizer/LLVM/Test.hs

ghci7:
	$(GHCI7) -Wall -fobject-code $(DIRS) example/Synthesizer/LLVM/Test.hs

ghci-inst:
	ghci -Wall -i:example example/Synthesizer/LLVM/LNdW2011.hs

ghci7-inst:
	$(GHCI7) -hide-package llvm -Wall example/Synthesizer/LLVM/LNdW2011.hs

ghci-server:
	ghci -Wall server/Synthesizer/LLVM/Server.hs server/Synthesizer/LLVM/Server/*.hs

runserver:
	./dist/build/synthi-llvm-server/synthi-llvm-server --device tee:default,'server-llvm.f32',raw +RTS -M16m -RTS

test:
#	runhaskell Setup configure --with-ghc=ghc-7.4.1 --with-haddock=haddock-ghc-7.4.1 --user -fbuildExamples -fbuildTests --disable-library-profiling --enable-shared --enable-executable-dynamic
	runhaskell Setup configure --user -fbuildExamples --enable-test --disable-library-profiling
	runhaskell Setup build
	runhaskell Setup haddock
	./dist/build/synthi-llvm-test/synthi-llvm-test

%.s:	%.bc
	llc $<

# This would lead to a cycle with llvm-as.
# %.ll:	%.bc
#	llvm-dis $<

%-dis.ll:	%.bc
	llvm-dis -o $@ $<

%.bc:	%.ll
	llvm-as $<

%-opt.bc:	%.bc
	opt -O3 < $< > $@
