# Makefile 1.7 96/05/23
# yacht makefile
# Richard Beton
# (C) Roke Manor Research Limited

#{{{  declarations

#OPT=-z
BASICLIBS=basic/lib_$(OS)
MODEL=RDB_Learning

CORE_FILES = COPYING README wotug19.ps.gz configure os put_cdif *.pl *.1 examples
LIB_FILES  = basic/*.html basic/*.inc basic/lib_*/*
BINARY_DIST_FILES = $(CORE_FILES) yacht.$(OS)
SOURCE_DIST_FILES = $(CORE_FILES) Makefile src.mk *.occ yacht*.cdif* $(LIB_FILES)
ASM_DIST_FILES    = $(CORE_FILES) Makefile asm.mk yacht.t yacht*.cdif* $(LIB_FILES)

#}}}  

default: yacht .check yacht.$(OS)

all: yacht
	cd examples; $(MAKE) -f Examples.mk

#{{{  yacht configuration
# this runs the configure script if yacht is older than yacht.pl.
#
# WARNING: this will fail if perl is not located in one of the
# standard directories (see configure script).

yacht: yacht.pl
	echo | ./configure

#}}}  
#{{{  yacht compilation
#
# If youcht.occ is available (source distribution) then the occam
# is compiled using kroc. Otherwise, yacht.t is assembled and
# linked.
#

yacht.$(OS):
	@if [ -f yacht.occ ]; then $(MAKE) -f src.mk BASICLIBS=$(BASICLIBS) ;\
	else $(MAKE) -f asm.mk BASICLIBS=$(BASICLIBS); fi

yacht.t:
	$(MAKE) -f src.mk BASICLIBS=$(BASICLIBS) yacht.t

#}}}  
#{{{  code generation for yacht itself

cgen: cdif yacht .check yacht.$(OS) yacht_parser.occ yacht_gen.occ

yacht_parser.occ: yacht_parser.cdif yacht yacht.$(OS)
	yacht -f yacht_parser.cdif -i yacht_procs1.occ -o $@ \
	    -L$(BASICLIBS) -lcstring -lposix

yacht_gen.occ: yacht_gen.cdif yacht yacht.$(OS)
	yacht -f yacht_gen.cdif -i yacht_procs2.occ -o $@ \
	    -L$(BASICLIBS) -lcstring -lposix

#}}}  
#{{{  CDIF Files for yacht

cdif: yacht_parser.cdif yacht_gen.cdif

yacht_parser.cdif:
	@-if [ ! -w $@ ]; then sccs edit $@; fi
	echo "# %-M-% %-I-%"  | sed 's/-//g' > $@
	twk_get -model $(MODEL) -config $(TWK_CONFIG) \
	  -object 1 -type DFD -noheader -no_notes >> $@
	twk_image -dfd -m $(MODEL) -c $(TWK_CONFIG) \
	  -o 1 > yacht_parser.ps
	@echo

yacht_gen.cdif:
	@-if [ ! -w $@ ]; then sccs edit $@; fi
	echo "# %-M-% %-I-%"  | sed 's/-//g' > $@
	twk_get -model $(MODEL) -config $(TWK_CONFIG) \
	  -object 2 -type DFD -noheader -no_notes >> $@
	twk_image -dfd -m $(MODEL) -c $(TWK_CONFIG) \
	  -o 2 > yacht_gen.ps
	@echo

#}}}  
#{{{  checks on environment variables
#
.check: $(KROC)/lib/libkroc.a $(BASICLIBS)/cstring.inc
	@touch $@

$(KROC)/lib/libkroc.a:
	@if [ "$(KROC)" = "" ]; then echo KROC not defined; exit 1; fi
	@echo Incorrect installation of kroc. Please refer to kroc documentation.
	@exit 1

$(BASICLIBS)/cstring.inc:
	@if [ "$(OS)" = "" ]; then \
	    os=`./os`; echo; echo OS not defined. Set it to $$os;\
	    exit 1; fi
	@if [ ! -d "$(BASICLIBS)" ]; then \
	    os=`./os`; echo; echo OS has invalid value. Set it to $$os;\
	    exit 1; fi
	@echo cstring library not found. Refer to installation instructions.
	@exit 1

#}}}  
#{{{  deliverables

dist: bindist asmdist srcdist

bindist: clean .check yacht.$(OS)
	cd examples; $(MAKE) -f Examples.mk cdif
	tar cfF gzips/yacht.$(OS).tar $(BINARY_DIST_FILES)
	rm -f gzips/yacht.$(OS).tar.gz
	gzip gzips/yacht.$(OS).tar
	@echo

asmdist: clean yacht.t
	cd examples; $(MAKE) -f Examples.mk cdif
	tar cfF gzips/yacht.asm.tar $(ASM_DIST_FILES)
	rm -f gzips/yacht.asm.tar.gz
	gzip gzips/yacht.asm.tar
	@echo

srcdist: clean
	cd examples; $(MAKE) -f Examples.mk cdif
	tar cfF gzips/yacht.src.tar $(SOURCE_DIST_FILES)
	rm -f gzips/yacht.src.tar.gz
	gzip gzips/yacht.src.tar
	@echo

#}}}  
#{{{  cleaning up

clean:
	rm -f *.tco *.[os] core .check yacht liblist
	cd examples; $(MAKE) -f Examples.mk clean

veryclean: clean
	rm -f *.cdif *.ps *.t
	cd examples; $(MAKE) -f Examples.mk veryclean
#        mkdir -p old
#        -mv yacht_parser.occ old
#        -mv yacht_gen.occ    old

what help:
	@echo "  Targets:"
	@egrep '^[a-z].*:' Makefile | cut -f1 -d:

#}}}  
