# /*
#  * The Termprocessor Kimwitu
#  *
#  * Copyright (c) 1991-1993 University of Twente, Dept TIOS.
#  * All rights reserved.
#  *
#  */
#
ALLSOURCES = $(NONTEXSOURCES) $(SOURCES)
SOURCES = $(PATCHLEVELFILE) Makefile		\
          tp.man.tex license.tex		\
          tp.man.bib					\
          ${LGRIND_K_SOURCES:k=tex}		\
          ${LGRIND_L_SOURCES:l=tex}		\
          ${LGRIND_C_SOURCES:c=tex}		\
          ${LGRIND_Y_SOURCES:y=tex}		\
          ${LGRIND_MAKE_SOURCES:make=tex}
NONTEXSOURCES = 				\
          ${LGRIND_K_SOURCES}			\
          ${LGRIND_L_SOURCES}			\
          ${LGRIND_C_SOURCES}			\
          ${LGRIND_Y_SOURCES}			\
          ${LGRIND_MAKE_SOURCES}
LGRIND_K_SOURCES =								\
          phylum_example.k list_phylum_example.k attributed_phylum_example.k	\
          alternative_attribute_initialisation.k uniq_phylum_example.k		\
          symbol_table_example.k non_uniq_declaration_example.k			\
          storage_classes_example.k redefine_LARGEPRIME_example.k		\
          function_definition_example_newest.k		\
          foreach_statement_example.k foreach_with_statement_example.k		\
          foreach_pattern_statement_example.k rewrite_rule_example.k		\
          rewrite_rule_function_example.k unparse_definition_example.k		\
          unparse_escaped_brackets_example.k unparse_views_example.k		\
          unparse_view_declaration_example.k printer_function_example.k		\
          including_in_generated_files_example.k include_redirection_example.k	\
          generated_data_type_example.k include_redirection_symbol_example.k	\
          yacc_abstract_syntax_example.k					\
          structure_file_abstract_syntax_example.k				\
          funny.k unparse_control_sequences.k					\
          unparse_output.k printer_function_with_indentation.k knuth1.k		\
          knuth2.k knuth3.k knuth4.k nats_newer.k ski.k				\
          fibonacci.k fibonacci_memo.k comsub.k					\
	  printer_function_with_view_indentation.k				\
	  printer_function_with_control_view_indentation.k			\
	  unparse_view_sequences.k						\
	  unparse_control_view_sequences.k \
	  rewrite_rule_general_example.k \
	  rewrite_views_example.k \
	  unparse_rule_general.k \
	  rewrite_rule_general.k \
	  function_definition_example_dollar.k \
	  function_definition_equiv.k \
	  foreach_equiv.k \
	  foreach_equiv_afterforeach.k \
	  pattern_parameterized.k \
	  pattern_equivalence.k \
	  foreach_equivalence.k \
	  rewrite_view_declaration_example.k
LGRIND_Y_SOURCES = yacc_input_example.y  skiy.y kimwitu_syntax.y
LGRIND_C_SOURCES = csgoutmain.c csginmain.c natsmain.c skimain.c
LGRIND_L_SOURCES = skil.l lex_input_example.l
LGRIND_MAKE_SOURCES = makefile.make

all: tp.man.dvi
pdf: tp.man.pdf
ps:  tp.man.ps

tp.man.dvi.no-tgrind: tp.man.tex
	latex tp.man.tex
	latex tp.man.tex
	bibtex tp.man
	makeindex tp.man.idx
	latex tp.man.tex
	latex tp.man.tex

tp.man.dvi: $(SOURCES)
	latex tp.man.tex
	latex tp.man.tex
	bibtex tp.man
	makeindex tp.man.idx
	latex tp.man.tex
	latex tp.man.tex


fast.no-tgrind:  tp.man.tex
	latex tp.man.tex

fast: $(SOURCES)
	latex tp.man.tex

clean:
	-rm -f tp.man.aux  tp.man.dvi  tp.man.ilg  tp.man.log  tp.man.toc \
	tp.man.idx  tp.man.ind

allsources:
	@echo $(ALLSOURCES)

update:	$(SOURCES)

# Apart from the sources, we also have to distribute a4wide.sty, and
# lgrind.sty, since they are not standard.
shar:
	shar a4wide.sty lgrind.sty $(ALLSOURCES) > tp.man.shar

.SUFFIXES: .k .tex .make .dvi .ps .fig .eps .pstex_t .pdf .html

THUMBPDF = perl5 /Text/LaTeX/bin/thumbpdf
#THUMBPDF = thumbpdf

## to be able to generate the thumbnails we first generate a .ps file
## (using a recursive invocation of MAKE)
## because we generate the thumbnails from a ps file and not from a pdf
## file, because our old ghostscript does not understand pdf containing
## images
## We remove the .aux file to force at least two runs, to make sure
## that the .out file is made and used (otherwise, pdflatex may use the
## .aux file generated by latex (while Making $*.ps) and do only one
## 'run')
.tex.pdf:
	$(MAKE) $*.ps
	-rm -f $*.aux
	$(THUMBPDF) $*.ps
	pdflatex '\scrollmode \input '"$*"
	while grep -s 'Rerun to get cross-references right' $*.log ; do \
		echo bibtex $* ; \
		pdflatex '\scrollmode \input '"$*" ; \
	done

.dvi.ps:
	if grep -s 'PRINT THIS DOCUMENT IN LANDSCAPE MODE' $*.log ; then \
		dvips -t landscape $*.dvi -o $@  ; \
	else \
		dvips $*.dvi -o $@  ; \
	fi


.k.tex:
	lgrind -i -lk $<  >  $@
.y.tex:
	lgrind -i -ly $<  >  $@
.make.tex:
	#lgrind -i -lmake $<  > $@
	lgrind -i -lsh  $<  > $@
.l.tex:
	#lgrind -i -ll $<  >  $@
	lgrind -i -lk $<  >  $@
.c.tex:
	lgrind -i -lc $<  >  $@


thesource:
	@echo $(ALLSOURCES)
longsource:
	@ls -lrt $(ALLSOURCES)
writablesource:
	@ls -lrt $(ALLSOURCES) |  grep 'rw-' | awk '{print $$NF}'
#
# RCS stuff
#
PATCHLEVELFILE = patchlvl
# because we use $(MANUALVERSION) as symbolic RCS name,
# MANUALVERSION is *not* allowed to contain dots: we use _ instead
MANUALVERSION = `grep MANUALVERSION $(PATCHLEVELFILE) | awk '{print $$3}' | tail -1`
version:
	@echo $(MANUALVERSION)
release:
	for f in $(ALLSOURCES); do \
	rev=`rlog -h $${f} | grep '^head:' | awk '{printf("%s", $$2)}' ` ; \
	echo "rcs -n$(MANUALVERSION):$${rev} -sRel:$${rev} $${f}" ; \
	rcs -n$(MANUALVERSION):$${rev} -sRel:$${rev} $${f} ; \
	co -r$${rev} $${f} ; \
	done

touch:
	for f in $(NONTEXSOURCES) $(SOURCES); do \
	co  $${f} ; \
	done
