# -*- makefile -*- mode for emacs
# Makefile,v 1.6 2004/01/22 05:57:25 leavens Exp

# Copyright (C) 2001 Gary T. Leavens and Curtis Clifton

# This file is part of typedscm

# typedscm 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 2, or (at your option)
# any later version.

# typedscm 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 typedscm; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.

# Create both info, dvi, and postscript files

BASENAME = basename
CP = cp
RM = rm -f
DELTREE = $(RM) -r
MV = mv -f
# MV = move # DOS
MKDIR = mkdir

INFO_DIR = /usr/unsup/info
WWW_DIR = /home/bambam/leavens/WWW/ComS342-EOPL2e/docs
FTP_DIR = $(WWW_DIR)
TR_DIR = /home/ftp/pub/techreports/TR05-18

TEXI2DVI	= texi2dvi
TEXI2PDF	= texi2pdf
TEXI2HTMLOPTS   = -number
TEXI2HTML	= texi2html
MAKEINFO	= makeinfo
# MAKEINFO	= emacs -batch -funcall batch-texinfo-format

# texinfo files included by typedscm.texinfo
GRAM_TEXINFO	= collected-grammar.texinfo

DVIPS = dvips

DVIPDF = dvipdf -p letter
# DVIPDF = dvipdfm    # Miktex under Windows

# Tell make about our suffixes: (required to define rules)

.SUFFIXES: .dvi .ps .pdf .texinfo .info \
	.scm.texinfo .def.texinfo

.dvi.ps:
	$(DVIPS) -o $@ $<

.texinfo.info:
	$(MAKEINFO) $<


# Replacements: @ -> @@ , { -> @{ , and  } -> @}
#
SED1=sed -e 's/@/@@/g;s/{/@{/g;s/}/@}/g'
SED2=sed -e '1d'

TEXINFOS = $(GRAM_TEXINFO)

# Implicit Rules (for GNU Make)

$(EXAMPLES)/%.scm.texinfo : $(EXAMPLES)/%.scm
	$(SED1) $< | $(SED2) > $@

# Target Definitions.
#
all : html pdf zip

postscript : typedscm.ps

typedscm.ps  : typedscm.dvi

dvi: typedscm.dvi

typedscm.dvi : typedscm.texinfo $(TEXINFOS)
	rm -f typedscm.aux
	$(TEXI2DVI) typedscm.texinfo

pdf typedscm.pdf: typedscm.texinfo $(TEXINFOS)
	$(TEXI2PDF) typedscm.texinfo

typedscm.dvi.gz : typedscm.dvi
	gzip -f --best typedscm.dvi

typedscm.ps.gz : typedscm.ps
	gzip -f --best typedscm.ps

info : typedscm.info

typedscm.info : typedscm.texinfo $(TEXINFOS)
	$(MAKEINFO) typedscm.texinfo

texinfos: $(TEXINFOS)


html: typedscm/typedscm_toc.html

typedscm/typedscm_toc.html: typedscm.texinfo $(TEXINFOS) \
					adjust-html-file.pl
	$(DELTREE) typedscm
	$(MKDIR) typedscm
	$(TEXI2HTML) $(TEXI2HTMLOPTS) typedscm.texinfo
	for f in *.html ; \
	do \
		perl adjust-html-file.pl < $$f > typedscm/$$f ; \
	done
	$(RM) *.html

$(GRAM_TEXINFO) : typedscm.texinfo collect-grammar.sh
	sh collect-grammar.sh typedscm.texinfo > $@

install: install-docs www

install-docs: typedscm.pdf just-install-docs

just-install-docs:
	$(RM) $(FTP_DIR)/typedscm.pdf
	$(CP) typedscm.pdf $(FTP_DIR)
	chmod 664 $(FTP_DIR)/*.pdf
	chgrp cs342s $(FTP_DIR)/*.pdf

install-tr: typedscm.pdf typedscm.ps.gz
	$(CP) -f typedscm.pdf $(TR_DIR)/TR.pdf
	$(CP) -f typedscm.ps.gz $(TR_DIR)/TR.ps.gz

www: html
	chmod ug+w typedscm typedscm/*.html
	chgrp cs342s typedscm typedscm/*.html
	chmod a+r typedscm/*.html
	chmod a+rx typedscm
	cp -pr typedscm/*.html $(WWW_DIR)/

zip lib342.zip: clean
	makelib342zip

# Clean up stuff
#
clean	:
	$(RM) *.log *.blg core typedscm.dvi
	$(RM) typedscm.aux typedscm.cp typedscm.cps \
		typedscm.fn typedscm.ky typedscm.log \
		typedscm.pg typedscm.pgs typedscm.toc \
		typedscm.tp typedscm.vr 

cleanhtmldir:
	$(DELTREE) typedscm

cleanall: clean cleanhtmldir
	$(RM) *.bak *~
	$(RM) collected-grammar.texinfo *.dvi *.ps *.pdf *.html typedscm.info
