#include <psf_pre.imake>
#include <installmanpage.imake>

TBSIMLIB = $(DESTINATION)/lib/tbsim
ANIMLIB = $(DESTINATION)/lib/animation
TCASIMLIB = $(DESTINATION)/lib/tcasim

TCLSRC = actionchooser.tcltmpl allgui.tcltmpl breakctrl.tcltmpl \
	display.tcltmpl function.tcltmpl process.tcltmpl tracectrl.tcltmpl
TCLTOOLS = $(TCLSRC:.tcltmpl=.tcl)

AllTarget(gosim simkernel-adapter $(TCLTOOLS) rakusim tcasim.raku)

simkernel-adapter: simkernel-adapter.tmpl
	sed -e s+@PROG_MKNOD@+$(PROG_MKNOD)+g \
		< simkernel-adapter.tmpl > simkernel-adapter

gosim: gosim.tmpl
	sed -e s+@PSF_LIB@+$(TBSIMLIB)+g \
	-e s+@TCA_LIB@+$(TCASIMLIB)+g \
	-e s+@PROG_PERL@+$(PROG_PERL)+g \
	-e s+@PROG_WISH@+$(PROG_WISH)+g \
		< gosim.tmpl > gosim
	chmod +x gosim

rakusim: rakusim.tmpl
	sed -e s+@PSF_LIB@+$(TBSIMLIB)+g \
	-e s+@TCA_LIB@+$(TCASIMLIB)+g \
	-e s+@PROG_PERL@+$(PROG_PERL)+g \
	-e s+@PROG_WISH@+$(PROG_WISH)+g \
		< rakusim.tmpl > rakusim
	chmod +x rakusim

tcasim.raku: tcasim.rakutmpl
	sed -e s+@TCASIMLIB@+$(TCASIMLIB)+g \
		< $< > $@
	chmod +x $@

.SUFFIXES: .tcltmpl .tcl

.tcltmpl.tcl:
	sed -e s+@TBSIMLIB@+$(TBSIMLIB)+g \
		-e s+@ANIMLIB@+$(ANIMLIB)+g \
		< $< > $@
	chmod +x $@


InstallProgram(gosim,$(BINDIR))
MakeDirectories(install,$(TCASIMLIB))
InstallNonExecFile(simkernel-adapter,$(TCASIMLIB))
InstallMultiple($(TCLTOOLS),$(TCASIMLIB))
InstallProgram(tcagosim,$(TCASIMLIB))
InstallProgram(rakusim,$(BINDIR))
InstallProgram(tcasim.raku,$(TCASIMLIB))
InstallNonExecFile(BTCA.rakumod,$(TCASIMLIB))

gosim.man: gosim.man.tmpl
	sed -e s+@DEFPSFBINDIR@+$(BINDIR)+g                               \
		< gosim.man.tmpl > gosim.man
clean::
	$(RM) gosim simkernel-adapter $(TCLTOOLS) gosim.man

ARCHIVE = Imakefile gosim.tmpl tcagosim simkernel-adapter.tmpl \
     $(TCLSRC) \
	rakusim.tmpl tcasim.rakutmpl BTCA.rakumod

#include <psf_post.imake>
