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\
  add-utp-z-library-to-db\
  add-utp-z-ext-to-db\
  add-utp-lang-to-db\
  add-utp-alpha-to-db\
  add-utp-theory-to-db\
  add-utp-pred-to-db\
  add-utp-rel-to-db\
  add-utp-des-to-db\
  add-utp-rea-to-db\
  add-utp-csp-to-db\
  add-utp-circus-to-db\
  add-utp-sbmf-to-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.

add-%-to-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-*.th.doc)
DOC_FILES = $(wildcard **/utp-*.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)))
