driver = mysql

ifeq (${driver},mysql)
args = -isrc -isrc/hxml-0.2 -isrc/withDB -isrc/mysql
else ifeq (${driver},sqlite)
args = -isrc -isrc/hxml-0.2 -isrc/withDB -isrc/sqlite
else
args = -isrc -isrc/hxml-0.2 -isrc/noDB
endif

parser = src/Text/XML/HXQ/Parser.hs
ghc = ghc -O2 ${args}
src = * src/hxml-0.2/* src/noDB/Text/XML/HXQ/* src/withDB/Text/XML/HXQ/* src/readline/System/Console/* src/Text/XML/HXQ/* src/mysql/* src/sqlite/*

# xquery interpreter
all:    $(parser) Main.hs
	$(ghc) --make Main.hs -o xquery

# generate the XQuery parser using happy
$(parser): XQueryParser.y
	happy -g -a -c -o $(parser) XQueryParser.y

test1:  $(parser) Test1.hs
	$(ghc) --make Test1.hs -o a.out
	./a.out

test2:  $(parser) Test2.hs
	$(ghc) --make Test2.hs -o a.out
	time ./a.out +RTS -H20m

test3:  $(parser) TestDB.hs
	$(ghc) --make TestDB.hs -o a.out
	./a.out

test4:  $(parser) TestDB2.hs
	$(ghc) --make TestDB2.hs -o a.out
	./a.out

dblp1:  $(parser) TestDBLP1.hs
	$(ghc) --make TestDBLP1.hs -o a.out
	./a.out +RTS -H200m -K100m

dblp2:  $(parser) TestDBLP2.hs
	$(ghc) --make TestDBLP2.hs -o a.out
	./a.out

# run in the ghci interpreter and load HXQ
ghci:   $(parser)
	ghci -fth ${args} Main.hs

# create the cabal distribution
cabal:	$(parser)
	runhaskell Setup.lhs configure --ghc -fmysql --user --prefix=$(HOME)
	runhaskell Setup.lhs build
	runhaskell Setup.lhs sdist

clean:
	/bin/rm -f xquery hxqc Temp.hs a.out $(addsuffix .hi,$(src)) $(addsuffix .o,$(src))

distclean: clean
	runhaskell Setup.lhs clean
