
# location of perl version 5.x
PERL = /usr/bin/perl

# location of wish version 8.3 or higher
WISH = /usr/bin/wish

# location of tclsh version 8.3 or higher
TCLSH = /usr/bin/tclsh

# location of tcldot library
TCLDOT = /usr/local/PGA/graphviz/lib/graphviz/tcl

# fontpath for truetype fonts needed for printing in tcldot
# only needed when the installed version of tcldot fails in finding the fonts
DOTFONTPATH = /usr/local/PGA

# define the command for making directory hierarchies
#MKDIRHIER = mkdirhier
MKDIRHIER = mkdir -p

#
CURRENTDIR = /home/bob/PGA/pga-1.8

# where to install the tools
INSTALL = /usr/local/PGA

### DO NOT EDIT BELOW THIS LINE ###

### perl programs ###

BASICS = Generic.pm MPP.pm MPPV.pm HMPPV.pm Genericcore.pm MPPcore.pm MPPVcore.pm \
	HMPPVcore.pm FMN.pm FMNcore.pm MSP.pm MSPcore.pm \
	MSPea.pm MSPeacore.pm MSPeaparse.pm \
	MSPfunc.pm MSPfunccore.pm MSPfuncparse.pm \
	LISP.pm LISPcore.pm MSPio.pm MSPiocore.pm ExtendedFocus.pm \
	HMPPVis.pm HMPPViscore.pm InverseSelect.pm \
	BPP.pm BPPcore.pm
PRIMITIVES = PGLA.pm PGLB.pm PGLC.pm PGLD.pm PGLDg.pm PGLE.pm PGLEc.pm \
	PGLEcr.pm PGLEcm.pm PGLAu.pm PGLBu.pm PGLBg.pm PGLEcw.pm PGLNull.pm \
	SLabel.pm NLabel.pm Directive.pm Thr.pm
OTHERS = Input.pm TUI.pm Options.pm ProgramBase.pm TransSystem.pm \
	PGLATransSystem.pm PGLEcTransSystem.pm Display.pm GUI.pm \
	BI_TB.pm TB.pm SMView.pm Breakpoint.pm Kernel.pm \
	BiSim.pm BiSimArray.pm BiSimQueue.pm \
	FluidTypes.pm FluidValues.pm FluidObjects.pm FluidBase.pm FluidGC.pm \
	CG.pm \
	Fluid_CG.pm HMPPV_CG.pm MSPio_CG.pm PGLEc_CG.pm \
	PIR.pm CIL.pm \
	WebKernel.pm WebUI.pm \
	LineInput.pm \
	ThreadKernel.pm DumbUI.pm
PERLMODULES = $(BASICS) $(PRIMITIVES) $(OTHERS)
PERLTEMPLATES = Global.pm.tmpl
ALLPERLMODULES = $(PERLMODULES) $(PERLTEMPLATES:%.tmpl=%)

PERLPROGRAMS = pglb2pgla pglc2pglb pgld2pglc \
	pgldg2pgld pgle2pgldg pglec2pgle pglecw2pglec \
	pglecr2pglec pglecm2pglecr \
	pglau2pglb pglau2pglbu pglbu2pglbg pglbg2pglb pglau2pgla \
	slabel2nlabel preparse preproc \
	project \
	pgla-jumpopt genparser gensim tb-bi tb-core parsim \
	prog2lts pbisim \
	gencompiler websim \
	threadsim tb-thread threadtrace

PERLHEADER = header

COPROGDIR = coprog

### tcltk programs ###

TCLMODULES = Fluid.tcl ProgView.tcl ComboBox.tcl

TCLPROGRAMS = fluidint gui control statemachines generic \
	threadcontrol threadgui tracedisplay propmem

TCLHEADER = header

### toolbus scripts ###

TBSCRIPTS = parsim.tb threadsim.tb

### Parrot ###

PARROT = 

### doc ###

DOC = Changes pga-user.html pga-user.ps pga-user.txt

### distribute ###

VERSION = 1.9
DISTDIR = pga-$(VERSION)

### rules ###

PROGRAMS = $(PERLPROGRAMS) $(TCLPROGRAMS)

all:: $(ALLPERLMODULES) $(PROGRAMS) pkgIndex.tcl coprog/pkgIndex.tcl

SUFFIXES = .perl .tcl .tclsh
.SUFFIXES: $(SUFFIXES)

#DEVPERLLIB:sh = pwd
#DEVPERLLIB = "`pwd`"
DEVPERLLIB = $(CURRENTDIR)

.perl:
	@echo "making $@"
	@echo "#!$(PERL)" > $@
	@cat $(PERLHEADER) >> $@
	@echo "use lib '$(DEVPERLLIB)';" >> $@
	@echo "" >> $@
	@cat $< >> $@
	@chmod 0755 $@

Global.pm: Global.pm.tmpl Makefile
	sed -e s+@BINDIR@+$(INSTALL)/bin+g \
	    -e s+@LIBDIR@+$(INSTALL)/lib+g \
	    -e s+@WISH@+$(WISH)+g < Global.pm.tmpl > $@

#DEVTCLLIB:sh = pwd
#DEVTCLLIB = "`pwd`"
DEVTCLLIB = $(CURRENTDIR)

.tcl:
	@echo "making $@"
#	@echo "#!$(WISH)" > $@
	@echo "#!/bin/sh" > $@
	@echo "# \\" >> $@
	@echo 'exec $(WISH) $$0 "$$@"' >> $@
	@cat $(TCLHEADER) >> $@
	@echo "lappend auto_path \"$(TCLDOT)\"" >> $@
	@echo "lappend auto_path \"$(DEVTCLLIB)\"" >> $@
	@echo "set env(DOTFONTPATH) $(DOTFONTPATH)" >> $@
	@echo "" >> $@
	@cat $< >> $@
	@chmod 0755 $@

.tclsh:
	@echo "making $@"
#	@echo "#!$(TCLSH)" > $@
	@echo "#!/bin/sh" > $@
	@echo "# \\" >> $@
	@echo 'exec $(TCLSH) $$0 "$$@"' >> $@
	@cat $(TCLHEADER) >> $@
	@echo "lappend auto_path \"$(TCLDOT)\"" >> $@
	@echo "lappend auto_path \"$(DEVTCLLIB)\"" >> $@
	@echo "set env(DOTFONTPATH) $(DOTFONTPATH)" >> $@
	@echo "" >> $@
	@cat $< >> $@
	@chmod 0755 $@

pkgIndex.tcl: $(TCLMODULES)
	@echo "indexing tcl modules in $(DEVTCLLIB)"
	@echo "pkg_mkIndex $(DEVTCLLIB) ; exit" | $(TCLSH)

coprog/pkgIndex.tcl: $(TCLMODULES)
	@echo "indexing tcl modules in coprog"
	@echo "pkg_mkIndex coprog ; exit" | $(TCLSH)

all::
	@echo "making in cbisim"
	@cd cbisim; $(MAKE)

INSTALLBIN = $(INSTALL)/bin
INSTALLIB = $(INSTALL)/lib
INSTALLPERLLIB = $(INSTALL)/lib/perl
INSTALLTCLLIB = $(INSTALL)/lib/tcl
INSTALLTBLIB = $(INSTALL)/lib
INSTALLCOPROG = $(INSTALL)/lib/coprog
INSTALLDOC = $(INSTALL)/doc

install::
	@if [ ! -d $(INSTALLBIN) ]; then set -x; $(MKDIRHIER) $(INSTALLBIN); fi
	@if [ ! -d $(INSTALLTBLIB) ]; then set -x; $(MKDIRHIER) $(INSTALLTBLIB); fi
	@if [ ! -d $(INSTALLPERLLIB) ]; then set -x; $(MKDIRHIER) $(INSTALLPERLLIB); fi
	@if [ ! -d $(INSTALLTCLLIB) ]; then set -x; $(MKDIRHIER) $(INSTALLTCLLIB); fi
	@if [ ! -d $(INSTALLCOPROG) ]; then set -x; $(MKDIRHIER) $(INSTALLCOPROG); fi
	@if [ ! -d $(INSTALLDOC) ]; then set -x; $(MKDIRHIER) $(INSTALLDOC); fi

install:: $(PERLPROGRAMS) $(ALLPERLMODULES)
	@echo "installing $(ALLPERLMODULES) in $(INSTALLPERLLIB)"
	@set +x; for i in $(ALLPERLMODULES); do \
	    cat $(PERLHEADER) $$i > $(INSTALLPERLLIB)/$$i; \
	done
	@set +x; for i in $(PERLPROGRAMS); do \
	    echo "installing $$i in $(INSTALLBIN)"; \
	    sed -e "s+use lib '$(DEVPERLLIB)';+use lib '$(INSTALLPERLLIB)';+" < $$i > $(INSTALLBIN)/$$i; \
	    chmod 0755 $(INSTALLBIN)/$$i; \
	done

install:: $(TCLPROGRAMS) $(TCLMODULES)
	@echo "installing $(TCLMODULES) in $(INSTALLTCLLIB)"
	@set +x; for i in $(TCLMODULES); do \
	    cat $(TCLHEADER) $$i > $(INSTALLTCLLIB)/$$i; \
	done
	@echo "indexing tcl modules in $(INSTALLTCLLIB)"
	@echo "pkg_mkIndex $(INSTALLTCLLIB) ; exit" | $(TCLSH)
	@set +x; for i in $(TCLPROGRAMS); do \
	    echo "installing $$i in $(INSTALLBIN)"; \
	    sed -e "s+lappend auto_path \"$(DEVTCLLIB)\"+lappend auto_path \"$(INSTALLTCLLIB)\";+" < $$i > $(INSTALLBIN)/$$i; \
	    chmod 0755 $(INSTALLBIN)/$$i; \
	done

install:: $(TBSCRIPTS)
	@echo "installing $(TBSCRIPTS) in $(INSTALLTBLIB)"
	@set +x; for i in $(TBSCRIPTS); do \
	    cat $(TBSCRIPTHEADER) $$i > $(INSTALLTBLIB)/$$i; \
	done

install:: $(COPROGDIR)
	@echo "installing $(COPROGDIR)/* in $(INSTALLCOPROG)"
	cp $(COPROGDIR)/*.pm $(INSTALLCOPROG)
	cp $(COPROGDIR)/*.tcl $(INSTALLCOPROG)
	@echo "indexing tcl modules in $(INSTALLCOPROG)"
	@echo "pkg_mkIndex $(INSTALLCOPROG) ; exit" | $(TCLSH)

install::
	@echo "installing in cbisim"
	@cd cbisim; $(MAKE) INSTALLBIN=$(INSTALLBIN) install

install::
	@echo "installing $(DOC) in $(INSTALLDOC)"
	@cd doc; cp $(DOC) $(INSTALLDOC)

clean:
	rm -f $(PROGRAMS) Global.pm pkgIndex.tcl coprog/pkgIndex.tcl

#####

DISTRIBUTE = Makefile header README INSTALL COPYRIGHT \
	$(PERLMODULES) $(PERLTEMPLATES) $(PERLPROGRAMS:%=%.perl) \
	$(TCLMODULES) $(TCLPROGRAMS:%=%.tcl) \
	$(TBSCRIPTS) $(COPROGDIR) $(PARROT)
ARCHIVE = $(DISTRIBUTE) Changes
DEVDOC = doc/pga-user.roff doc/refer.rof doc/Makefile doc/Changes

archive::
	rm -f pga.tar
	tar cf pga.tar $(ARCHIVE) $(DEVDOC)

archive::
	@echo "archiving in cbisim"
	@cd cbisim; $(MAKE) CURRENTDIR=cbisim ARCHIVENAME=pga.tar archive

CVS = $(ARCHIVE) $(DEVDOC)

cvsdiff:
	cvs diff -c $(ARCHIVE)

cvscommit::
	cvs commit $(ARCHIVE)

cvscommit::
	@echo "committing in cbisim"
	@cd cbisim; $(MAKE) cvscommit

distr::
	cd .. ;\
	ln -s src $(DISTDIR) ;\
	tar cf $(DISTDIR).tar $(DISTRIBUTE:%=$(DISTDIR)/%) $(DOC:%=$(DISTDIR)/doc/%)

distr::
	@echo "distr-ing in cbisim"
	cd cbisim; $(MAKE) CURRENTDIR=cbisim DISTDIR=$(DISTDIR) distr

distr::
	cd ..; rm -f $(DISTDIR)
