PATH := bin:$(PATH)

export DB = circus

all : db

sml :
	makeallth sml

tex :
	makeallth tex

dvi :
	makeallth dvi

pdf :
	makeallth pdf

db : remove-db create-db\
	utp-z-library-db\
	utp-z-ext-db\
	utp-lang-db\
	utp-alpha-db\
	utp-theory-db\
        utp-pred-db\
        utp-rel-db\
        utp-des-db

create-db :
	pp_make_database -p zed db/$(DB)

remove-db :
	rm -f db/$(DB) db/$(DB).polydb

# The use of pattern rules is very useful here i.e. the implicit targets
# <dirname>-db add the relevant theories in the subdirectory <dirname> to
# our theory database.

%-db :
	make -C $* sml
	addtodb $*/$*.sml
	addtodb $*/$*-axioms.sml
	addtodb $*/$*-utils.sml
	addtodb $*/$*-laws.sml
	addtodb $*/$*-dump.sml
	mv -f $*.th.doc $*/

DOC_FILES = $(wildcard **/utp-*.doc)
#DOC_FILES = $(wildcard **/utp-*.th.doc)
PDF_FILES = $(patsubst %.doc,%.pdf,$(DOC_FILES))

docs : db pdf
	mv -f $(PDF_FILES) docs/

clean :
	makeallth clean
	rm -f $(addprefix docs/,$(notdir $(PDF_FILES)))
