SOURCES		:=	$(shell find Data -name "*.hs")
TESTS		:=	$(shell find testsuite -name "*.hs")
HASKELLS	:=	$(shell find . -name "*.hs")

clean:
			@cabal clean && \
			  find . -name '*~' -exec rm -vf {} ';' && \
			  find . -name '*.hi' -exec rm -vf {} ';' && \
			  find . -name '*.o' -exec rm -vf {} ';' && \
			  rm -vf testsuite/Main && \
			  rm -vf graphmod*

nuke:			clean
			@make -C doc nuke && \
			  rm -rvf $(STAGING)

lint:
			hlint $(HASKELLS)

configure:
			cabal configure

build:
			cabal build

haddock:
			cabal haddock

view:
			open dist/doc/html/fsmActions/index.html

sdist:
			cabal sdist

.PHONY: testsuite/Main
testsuite/Main:
			ghc -O2 -Wall -itestsuite --make testsuite/Main

test:			testsuite/Main
			./testsuite/Main

testslow:
			sh testsuite/runtests.sh

all:			test clean configure build haddock doc sdist

.PHONY: doc
doc:
			make -C doc pdf

# Plotting module dependencies

graphmod:
			@graphmod -q --no-cluster $(SOURCES) > graphmod.dot && \
			  dot -T pdf -o graphmod.pdf graphmod.dot && \
			  open graphmod.pdf

# Website

REMOTE_SRV	=	community.haskell.org
REMOTE_PATH	=	/srv/projects/fsmActions
REMOTE		=	$(REMOTE_SRV):$(REMOTE_PATH)

WEBSITE		=	website
STATIC		=	$(WEBSITE)/static
STAGING		=	$(WEBSITE)/staging

staging:		$(STAGING)

$(STAGING):		nuke doc
			@mkdir $(STAGING) && \
			  cp -rvf $(STATIC)/* $(STAGING)/ && \
			  cp doc/fsmActions.pdf $(STAGING)/

publish:		$(STAGING)
			@rsync -av $(STAGING)/* $(REMOTE)/ && \
			  ssh $(REMOTE_SRV) chmod -R a+rx $(REMOTE_PATH)/*

