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

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

all: djgppfaq.info faq.html djgppfaq.txt  # djgppfaq.dvi djgppfaq.ps

djgppfaq.inf: djgppfaq.info

djgppfaq.info: djgppfaq.num
	makeinfo --no-split --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 djgppfaq.html faq

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

concepts.idx programs.idx: indices.sed htmlidx.sed djgppfaq.info
	sed -n -f indices.sed djgppfaq.info
	sed -n -f htmlidx.sed concepts.tmp > concepts.idx
	sed -n -f htmlidx.sed programs.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 $< > $@

macro.exp: makefile $(SOURCES) htmlprep.sed
	sed -f htmlprep.sed djgppfaq.txi > faq.tmp
	makeinfo --no-validate --no-split --no-headers --fill-column 100 -Dhtml -E macro.exp -o /dev/null faq.tmp

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

distclean: clean

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

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