# Makefile for generating the Atlantis documentation in a variety of formats

MAKEINFO=makeinfo

all: dist

# In order to generate the correctly-named subdirectory in the .tar file, the version number of doku.texinfo is
# extracted.  Thus the version has to be set in one place only.

VERSION_DIR := doku-$(shell grep "@set atlantis" doku.texinfo | cut -d " " -f 3)
TEXI2DVI    := texi2dvi

# End of defines.

# GENERAL rules

%.gz: %
	gzip -c < $< > $@

%.ps: %.dvi
	dvips $<

# TEX
# All rules are Implicit Rules in GNU make.

# INFO:
# Produce Info file.
atlantis.info.gz: doku.ascii-umlaute.tmp
	$(MAKEINFO) --no-split --fill-column 72 -o - $< | gzip -c > $@

# Remove Umlaute.
doku.ascii-umlaute.tmp: doku.num umlaute2ascii.sed
	sed -f umlaute2ascii.sed $< > $@

# HTML: 
doku_toc.html: doku.texinfo texi2html
	perl texi2html -verbose -acc -split_chapter -b "BGCOLOR=\"#FFFFE0\"" doku.texinfo
	echo "ACHTUNG!  doku_1.html#IDX17 und doku_20.html werden von index.html und doku.html verwendet."
	ln -sf $@ index.html

doku.html.tar.gz: doku_toc.html
	tar -czf $@ *.html

doku.html: doku.texinfo texi2html
	perl texi2html -verbose -acc -monolithic -b "BGCOLOR=\"#FFFFE0\"" doku.texinfo

dokuhtml.zip: doku.html
	zip $@ $<

# TEXT:
# Base version for text with chapters and sections numbered.
doku.num: doku.texinfo enum
	./enum $< $@

# Code to do the numbering
enum: enum.c
	gcc -Wall -O2 -s -o $@ $<

# List of nodes, chapters, sections etc.
chapters.tmp: doku.num chapters.sed
	sed -n -f chapters.sed $< > $@

# Numbered and formated contents.
contents.tmp: doku.num contents.sed umlaute2ascii.sed
	sed -n -f contents.sed $< | sed -f umlaute2ascii.sed > $@

# Sed script to change node refs into chapter or section refs, umlaute.
sedprep.tmp: chapters.tmp chapxref.sed chapxre2.sed umlaute2ascii.sed
	sed -f chapxref.sed chapters.tmp > $@
	sed -f chapxre2.sed chapters.tmp >> $@
	cat umlaute2ascii.sed >> $@

# Aply above sed script.
text-1.tmp: doku.num sedprep.tmp
	@echo 'The following command may take a long time.  Be patient.'
	sed -f sedprep.tmp $< > $@

# Make formated text file using makeinfo.
text-2.tmp: text-1.tmp contents.tmp
	$(MAKEINFO) --no-split --no-headers --no-validate --fill-column 72\
					     -Dtext -o $@ $<

# Sed script to replace "*Note" text and change refs in the index around.
sedpost.tmp: idxref.sed chapters.tmp 
	sed -f idxref.sed chapters.tmp > $@
	echo s/\*Note/\*Vgl./>> $@
	echo s/\*note/\*vgl./>> $@

# Aply above sed script.
doku.txt: text-2.tmp sedpost.tmp
	@echo 'The following command may take a long time.  Be patient.'
	sed -f sedpost.tmp $< > $@

doku.zip: doku.txt
	zip $@ $<

# SOURCE
doku.tar.gz: doku.texinfo Makefile enum.c texi2html texinfo.german.tex *.sed
	if test ! -d $(VERSION_DIR); then mkdir $(VERSION_DIR); fi
	ln -f $^ $(VERSION_DIR)
	tar -czf $(VERSION_DIR).tar.gz $(VERSION_DIR)/*
	ln -sf $(VERSION_DIR).tar.gz $@

# CLEANING UP:
mostlyclean:
	rm -f doku.num \#*\# *.tmp *~ *.dvi *.aux *.bbl *.blg *.log *.toc *.cp *.cps *.fn *.ky *.pg *.tp *.vr 
	rm -rf $(VERSION_DIR)

clean: mostlyclean
	rm -f *.inf? *.htm? doku.txt *.ps 

distclean: clean
	rm -f enum *.zip *.gz *.tar

# DISTRIBUTIONS:
dist: doku-www.tar

doku-www.tar: doku.tar.gz doku.txt.gz doku.zip doku.html.gz doku.html.tar.gz dokuhtml.zip atlantis.info.gz doku.ps.gz doku.ps.gz
	tar --create --dereference --file=$@ $^



