# Makefile for generating DJGPP FAQ list in a variety of formats

SOURCES = djgppfaq.txi faqmacro.txi faq-addr.txi faq-vers.txi

# Set to --djtitles='DJGPP FAQ' on DJ's server
DJTITLES =

# In case they don't have "." in their TEXINPUTS variable
ifdef COMSPEC
export TEXINPUTS := .;$(TEXINPUTS)
else
export TEXINPUTS := .:$(TEXINPUTS)
endif

TEX   = tex
DVIPS = dvips
DVILJ = dvilj4

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

%.lj: %.dvi
	$(DVILJ) $<

all: djgppfaq.info djgppfaq.html djgppfaq.txt djgppfaq.dvi djgppfaq.ps djgppfaq.lj

djgppfaq.inf: djgppfaq.info

djgppfaq.info: djgppfaq.num
	makeinfo --no-split --footnote-style=separate --fill-column 78 -o $@ $<

djgppfaq.num: $(SOURCES) enum
	./enum $< $@

enum: enum.c
	gcc -Wall -O2 -s -o $@ $<

faq.htm: faq.html

faq.html: djgppfaq.html htmsplit
	./htmsplit $(DJTITLES) djgppfaq.html faq

djgppfaq.htm: djgppfaq.html

djgppfaq.html: djgppfaq.num htmlprep.sed concepts.idx programs.idx \
		htmlxref.sed chapters.tmp
	sed -f htmlxref.sed chapters.tmp > htmlxref.tmp
	sed -f htmlprep.sed $< > faq.tmp
	makeinfo --no-validate --no-split --no-headers --fill-column 200 -Dhtml -o - faq.tmp | sed -f htmlxref.tmp > $@

concepts.idx programs.idx: indices.sed htmlidx.sed djgppfaq.info \
			   chapters.tmp htmlchap.sed
	sed -f htmlchap.sed chapters.tmp > chapnum.tmp
	sed -n -f indices.sed djgppfaq.info
	sed -n -f htmlidx.sed concepts.tmp | sed -f chapnum.tmp > concepts.idx
	sed -n -f htmlidx.sed programs.tmp | sed -f chapnum.tmp > programs.idx

htmsplit: htmsplit.c
	gcc -Wall -O2 -s -o $@ $<

djgppfaq.txt: djgppfaq.num chapxref.sed idxref.sed chapters.tmp contents.idx
	sed -f chapxref.sed chapters.tmp > textprep.tmp
	@echo 'The following command may take a long time.  Be patient.'
	sed -f textprep.tmp $< > djgppfaq.tmp
	makeinfo --no-split --no-headers --no-validate --fill-column 78 -Dtext -o txt.tmp djgppfaq.tmp
	sed -f idxref.sed chapters.tmp > textpost.tmp
	sed -f textpost.tmp txt.tmp > $@

contents.idx: djgppfaq.num contents.sed
	sed -n -f contents.sed $< > $@

chapters.tmp: djgppfaq.num chapters.sed
	sed -n -f chapters.sed $< > $@

djgppfaq.dvi: djgppfaq.exp texinfo.tex
	texi2dvi $<

djgppfaq.exp: $(SOURCES)
	makeinfo --no-split -E $@ -o /dev/null $<

macro.exp: djgppfaq.num
	makeinfo --no-split -E $@ -o /dev/null $<

clean:
ifdef COMSPEC
	command > nul /c for %f in (*.tmp *.idx *.exe *.num enum htmsplit djgppfaq.html *.exp) do if exist %f del %f
else
	rm -f *.tmp *.idx *.exe *.num enum htmsplit djgppfaq.htm* *.exp
endif

distclean: clean

realclean: distclean
ifdef COMSPEC
	command > nul /c for %f in (*.htm *.html *.inf *.ps *.dvi *.txt *.lj) do if exist %f del %f
else
	rm -f *.htm* *.inf* *.ps *.dvi *.txt *.lj
endif
love:
	@echo 'Not war!'

coffee:
	@echo 'Not yet.  Maybe in v3.x...'
