# SIMSYNCH, simulate synchronous systems.	-*-makefile-*-
# Copyright (C) 1997, 2010 Aubrey Jaffer

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.

# These are normally set in "config.status"; defaults are here so that
# "make" won't complain about target redefinitions.
snapdir=$(HOME)/pub/
infodir=$(HOME)/info/
htmldir=$(HOME)/public_html/

SHELL = /bin/sh
INSTALL = install
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644
INSTALL_INFO = ginstall-info

CHPAT = $(HOME)/bin/chpat
MAKEDEV = $(MAKE) -f $(HOME)/makefile.dev
TEXI2HTML = /usr/local/bin/texi2html -split -verbose
TEXI2PDF = texi2pdf
SCHEME = scm
RSYNC = rsync -av
Uploadee = csail

intro:	config.status
	@echo
	@echo "Welcome to SIMSYNCH.  Read \"synch.info\" (or \"synch.texi\")"
	@echo "to learn how to use SIMSYNCH."
	@echo

VERSION = 1c5

# ./configure --distdir=${HOME}/dist/ --snapdir=${HOME}/pub/ --htmldir=${HOME}/public_html/ --pdfdir=${HOME}/public_html/

config.status:
	./configure
Makefile: config.status
include config.status

prevdocsdir = prevdocs/
windistdir = /c/Voluntocracy/dist/

docfiles = ANNOUNCE synch.info synch.texi uart.scm
srcfiles = simsynch.scm logic.scm run.scm models.scm usercat \
	   logical.v logical.vhd readtext.vhd
trnfiles = scm2vrlg.scm scm2mach.scm scm2vhdl.scm
pubfiles = configure Makefile COPYING ChangeLog \
	   $(docfiles) version.txi $(srcfiles) $(trnfiles)
tagfiles = Makefile $(docfiles) $(srcfiles) scm2vhdl.scm scm2vrlg.scm

installdirs:
	mkdir -p $(DESTDIR)$(pdfdir)
	mkdir -p $(DESTDIR)$(infodir)
	mkdir -p $(DESTDIR)$(htmldir)
	mkdir -p $(DESTDIR)$(dvidir)

synch.dvi: synch.texi version.txi
	$(TEXI2DVI) -b -c $<
dvi:	synch.dvi
xdvi:	synch.dvi
	xdvi synch.dvi
install-dvi: synch.dvi installdirs
	$(INSTALL_DATA) $< $(DESTDIR)$(dvidir)

synch.pdf: synch.texi version.txi
	$(TEXI2PDF) -b -c $<
pdf:	synch.pdf
xpdf:	synch.pdf
	xpdf $<
install-pdf: synch.pdf installdirs
	$(INSTALL_DATA) $< $(DESTDIR)$(pdfdir)

#For change-barred HTML.
prevdocs:	$(prevdocsdir)synch_toc.html $(prevdocsdir)synch.info
$(prevdocsdir)synch_toc.html:
$(prevdocsdir)synch.info:	Makefile
	cd $(prevdocsdir); unzip -a $(distdir)synch*.zip
	rm $(prevdocsdir)synch/synch*.info
	cd $(prevdocsdir)synch; make synch.info; make synch_toc.html
	cd $(prevdocsdir); mv -f synch/synch-[0-9]*.info ./synch.info
	cd $(prevdocsdir); mv -f synch/*.html ./
	rm -rf $(prevdocsdir)synch
	-rm -f synch-$(VERSION).info

# synch_toc.html: synch.texi version.txi
# 	${TEXI2HTML} $<
# html:	synch_toc.html
# $(DESTDIR)$(htmldir)synch_toc.html: synch_toc.html Makefile
# 	-rm -f synch_stoc.html
# 	if [ -f $(prevdocsdir)synch_toc.html ]; \
# 	  then hitch $(prevdocsdir)synch_\*.html synch_\*.html \
# 		$(DESTDIR)$(htmldir); \
# 	  else $(INSTALL_DATA) synch_*.html $(DESTDIR)$(htmldir);fi
# install-html: $(DESTDIR)$(htmldir)synch_toc.html

html/synch: synch.texi version.txi $(txifiles) $(texifiles)
	mkdir -p html
	rm -rf html/synch
	makeinfo --html $< -o html/synch
html:	html/synch
$(DESTDIR)$(htmldir)synch: html/synch
	-rm -rf $(DESTDIR)$(htmldir)synch
	mkdir -p $(DESTDIR)$(htmldir)synch
	$(INSTALL_DATA) html/synch/*.html $(DESTDIR)$(htmldir)synch
install-html: $(DESTDIR)$(htmldir)synch

synch-$(VERSION).info: synch.texi version.txi
	$(MAKEINFO) $< --no-warn --no-split -o synch-$(VERSION).info
synch.info:	synch-$(VERSION).info
	if [ -f $(prevdocsdir)synch.info ]; \
	  then infobar $(prevdocsdir)synch.info synch-$(VERSION).info \
		synch.info; \
	  else cp synch-$(VERSION).info synch.info;fi
$(DESTDIR)$(infodir)synch.info:	synch.info
	$(INSTALL_DATA) $< $@
	-$(INSTALL_INFO) $@ $(DESTDIR)$(infodir)dir
	-rm $(DESTDIR)$(infodir)synch.info.gz
install-info:	$(DESTDIR)$(infodir)synch.info
info:	install-info

$(DESTDIR)$(infodir)synch.info.gz: $(DESTDIR)$(infodir)synch.info
	gzip -f $<
install-infoz:	$(DESTDIR)$(infodir)synch.info.gz
infoz:	install-infoz

check:
	$(SCHEME) -l fifo8.scm

## Example
# synchdir = ../synch/
# foo.pds: foo.scm
# 	$(SCHEME) -l$(synchdir)run.scm -e"(translate 'foo)"
# foo-plc: foo.scm foo.plc
# 	$(SCHEME) -l$(synchdir)run.scm -e"(compare-plcs 'foo)"

uart_uif.vhd uart_trx.vhd uart_stim.vhd uart_baudx16.vhd uart.vhd: \
		uart.scm scm2vhdl.scm simsynch.scm
	$(SCHEME) -rrun -e"(provide 'lift-bus) (translate 'uart 'vhdl)"

docs:	$(DESTDIR)$(infodir)synch.info.gz \
	$(DESTDIR)$(htmldir)synch_toc.html synch.dvi \
	$(DESTDIR)$(htmldir)synch.pdf

#### Stuff for maintaining SimSynch below ####

ver = $(VERSION)

temp/synch:	$(pubfiles)
	-rm -rf temp
	mkdir -p temp/synch
	ln  $(pubfiles) temp/synch

release: dist pdf
	cp ANNOUNCE $(DESTDIR)$(htmldir)SIMSYNCH_ANNOUNCE.txt
	$(RSYNC) $(DESTDIR)$(htmldir)SIMSYNCH.html \
		 $(DESTDIR)$(htmldir)SIMSYNCH_ANNOUNCE.txt \
		 $(Uploadee):public_html/
	$(RSYNC) $(distdir)README $(distdir)synch-$(VERSION).zip \
		 $(Uploadee):dist/
# upload $(distdir)README $(distdir)synch-$(VERSION).zip ftp.gnu.org:gnu/jacal/

upzip:	$(snapdir)synch.zip
	$(RSYNC) $(snapdir)synch.zip $(Uploadee):pub/

dist:	$(distdir)synch-$(VERSION).zip
$(distdir)synch-$(VERSION).zip:	temp/synch
	$(MAKEDEV) DEST=$(distdir) PROD=synch ver=-$(VERSION) zip
	cvs tag -F synch-$(VERSION)
shar:	synch.shar
synch.shar:	temp/synch
	$(MAKEDEV) PROD=synch shar
dclshar:	synch.com
com:	synch.com
synch.com:	temp/synch
	$(MAKEDEV) PROD=synch com
zip:	synch.zip
synch.zip:	temp/synch
	cd temp; zip -r ../synch.zip synch
doszip:	$(windistdir)synch.zip
$(windistdir)synch.zip:	synch.zip
	cp synch.zip $(windistdir)
pubzip:	temp/synch
	$(MAKEDEV) DEST=$(snapdir) PROD=synch zip

diffs:	pubdiffs
pubdiffs:	temp/synch
	$(MAKEDEV) DEST=$(snapdir) PROD=synch pubdiffs
distdiffs:	temp/synch
	$(MAKEDEV) DEST=$(distdir) PROD=synch ver=$(ver) distdiffs

CITERS = ANNOUNCE $(distdir)README ../scm/ANNOUNCE $(htmldir)README.html
CITES = Makefile $(htmldir)SIMSYNCH.html

new:
	$(CHPAT) synch-$(VERSION) synch-$(ver) $(CITERS)
	$(CHPAT) $(VERSION) $(ver) $(CITES)
	echo @set SIMSYNCHVERSION $(ver) > version.txi
	echo @set SIMSYNCHDATE `date +"%B %Y"` >> version.txi
	echo `date -I` \ Aubrey Jaffer \ \<`whoami`@`hostname`\>> change
	echo>> change
	echo '	* Makefile (VERSION): Bumped from $(VERSION) to $(ver).'>>change
	echo>> change
	cat ChangeLog >> change
	mv -f change ChangeLog
	cvs commit -m '(VERSION): Bumped from $(VERSION) to $(ver).'
	cvs tag -F synch-$(ver)

#zip:	synch.zip
#synch.zip:	temp/synch
#	cd temp; zip -r ../synch.zip synch
#pubzip:	temp/synch
#	cd temp; zip -r $(snapdir)synch.zip synch
diska:	synch.zip
	mcd a:
	-mdel synch.zip
	mcopy -nm synch.zip a:/
diskb:	synch.zip
	mcd b:
	-mdel synch.zip
	mcopy -nm synch.zip b:/

#pubdiffs:	temp/synch
#	mv temp/synch temp/nsynch
#	cd temp;unzip $(snapdir)synch.zip
#	-rm -f synch.diffs
#	-diff -c temp/synch temp/nsynch > synch.diffs
#	-rm -rf temp
#	ls -l synch.diffs

TAGS:	tags
tags:	$(tagfiles)
	etags $(tagfiles)

clean:	distclean
distclean:
	-rm -f *~ \#* *.orig *.rej a.out core TAGS lints tmp*
#	-rm -f *.pds
	-rm -rf temp
	-rm *.o *.so
	$(MAKE) TAGS
