#
# default base directory for YAP installation
#
ROOTDIR = /usr/pkg
#
# where the binary should be
#
BINDIR = $(ROOTDIR)/bin
#
# where YAP should look for binary libraries
#
LIBDIR=${exec_prefix}/lib/Yap
#
# where YAP should look for architecture-independent Prolog libraries
#
SHAREDIR=$(ROOTDIR)/share
#
#
# You shouldn't need to change what follows.
#
INSTALL=/usr/bin/install -c -o pbulk -g users
INSTALL_DATA=/usr/bin/install -c -o pbulk -g users -m 644
INSTALL_PROGRAM=/usr/bin/install -c -s -o pbulk -g users -m 755
srcdir=.
YAP_EXTRAS= -DCOROUTINING=1 -DCUT_C=1 -DRATIONAL_TREES=1 -DDEPTH_LIMIT=1 -DTABLING=1 

exdir=./../../exs

# -*- Makefile -*-

##----------------------------------------------------------------------

TARGETS     = prism.pl

PRISM_VERSION     = 2.0

PL_CORE  = $(srcdir)/core/message.pl      \
           $(srcdir)/core/error.pl        \
           $(srcdir)/core/random.pl       \
           $(srcdir)/core/format.pl

PL_TRANS = $(srcdir)/trans/trans.pl       \
           $(srcdir)/trans/dump.pl        \
           $(srcdir)/trans/verify.pl      \
           $(srcdir)/trans/bpif.pl

PL_UP    = $(srcdir)/up/dynamic.pl        \
           $(srcdir)/up/main.pl           \
           $(srcdir)/up/switch.pl         \
           $(srcdir)/up/learn.pl          \
           $(srcdir)/up/prob.pl           \
           $(srcdir)/up/viterbi.pl        \
           $(srcdir)/up/hindsight.pl      \
           $(srcdir)/up/expl.pl           \
           $(srcdir)/up/sample.pl         \
           $(srcdir)/up/dist.pl           \
           $(srcdir)/up/list.pl           \
           $(srcdir)/up/hash.pl           \
           $(srcdir)/up/flags.pl          \
           $(srcdir)/up/util.pl           \
           $(srcdir)/up/bigarray.pl

PL_BAT   = $(srcdir)/up/batch.pl

PL_MP    = $(srcdir)/mp/mp_main.pl        \
           $(srcdir)/mp/mp_learn.pl

PL_BP    = $(srcdir)/bp/eval.pl

PL_UP_ALL   = $(PL_CORE) $(PL_UP) $(PL_TRANS) $(PL_BP) $(srcdir)/prism.yap
PL_MP_ALL   = $(PL_MP)
PL_BAT_ALL  = $(PL_BAT)

EXS    = $(exdir)/README        \
           $(exdir)/alarm.psm     \
	   $(exdir)/alarm.psm.out \
	   $(exdir)/bloodABO.psm \
	   $(exdir)/bloodAaBb.psm \
	   $(exdir)/bloodtype.dat \
	   $(exdir)/dcoin.psm \
	   $(exdir)/direction.psm \
	   $(exdir)/hmm.psm \
	   $(exdir)/jtree \
	   $(exdir)/noisy_or \
	   $(exdir)/pdcg.psm \
	   $(exdir)/pdcg_c.psm \
	   $(exdir)/phmm.dat \
	   $(exdir)/phmm.psm \
	   $(exdir)/plc.dat \
	   $(exdir)/plc.psm \
	   $(exdir)/plc.psm.out \
	   $(exdir)/sbn.psm \
	   $(exdir)/votes.psm

EXS_JTREE    = $(exdir)/jtree/README        \
           $(exdir)/jtree/asia.psm     \
           $(exdir)/jtree/jasia.psm     \
           $(exdir)/jtree/jasia_a.psm

EXS_NOISY_OR    = $(exdir)/noisy_or/README        \
           $(exdir)/noisy_or/alarm_nor_basic.psm     \
           $(exdir)/noisy_or/alarm_nor_generic.psm     \
           $(exdir)/noisy_or/noisy_or.psm

##----------------------------------------------------------------------

all: $(TARGETS)

install: $(TARGETS) install-examples
	mkdir -p $(DESTDIR)$(SHAREDIR)/Yap
	mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/prism
	mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/prism/bp
	mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/prism/core
	mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/prism/mp
	mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/prism/trans
	mkdir -p $(DESTDIR)$(SHAREDIR)/Yap/prism/up
	$(INSTALL_DATA) $(srcdir)/prism.yap $(DESTDIR)$(SHAREDIR)/Yap
	for p in $(PL_BAT); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/prism/up; done
	for p in $(PL_BP); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/prism/bp; done
	for p in $(PL_CORE); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/prism/core; done
	for p in $(PL_MP); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/prism/mp; done
	for p in $(PL_TRANS); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/prism/trans; done
	for p in $(PL_UP); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/Yap/prism/up; done

clean:
	rm -f prism.pl mpprism.pl batch.pl


prism.pl: $(PL_UP_ALL)
	cat $^ > $@

mpprism.pl: $(PL_MP_ALL)
	cat $^ > $@

batch.pl: $(PL_BAT_ALL)
	cat $^ > $@

%.out: %.pl $(COMPILER)
	sh $(COMPILER) $<

.PHONY: all install clean

install-examples:
	mkdir -p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/prism
	mkdir -p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/prism/jtree
	mkdir -p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/prism/noisy_or
	for p in $(EXS); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/prism; done
	for p in $(EXS_JTREE); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/prism/jtree; done
	for p in $(EXS_NOISY_OR); do $(INSTALL_DATA) $$p $(DESTDIR)$(SHAREDIR)/doc/Yap/packages/examples/prism/noisy_or; done
