
TYPES:=.txt .html _p.pdf _i.pdf
SOURCES:=ttdpatch.tex $(wildcard *.inc)

# *.fig are vector graphics produced by xfig
# *.gif are image graphics, will be converted appropriately
# No gif will be part of the output, they're all converted
# No other image formats supported as input, to make the Makefile simpler

FIGURES = ${basename $(wildcard *.fig)}
IMAGES	= ${basename $(wildcard *.gif)}

EPSFILES = $(addsuffix .eps,${FIGURES} ${IMAGES})
PDFFILES = $(addsuffix .pdf,${FIGURES})
PNGFILES = $(addsuffix .png,${FIGURES} ${IMAGES})
BRACEOPEN = {
BRACECLOSE = }
ASCIIFILES = ${addprefix ${BRACEOPEN},$(addsuffix .asc$(BRACECLOSE),${FIGURES} ${IMAGES})}

all:	$(addprefix out/ttdpatch,${TYPES}) ${addprefix out/,$(PNGFILES)}

out/% : %
	cp $< $@

check:
ifneq ($(LANG),en)
	@echo "Wrong language $(LANG), do export LANG=en";
	@exit 1;
endif
	@exit 0;

ttdpatch.mtxt:	ttdpatch.texi ${ASCIIFILES}
	makeinfo --force --number-sections --no-split --no-validate -D TXT -o ttdpatch.etxt $<
	./denode.pl $< ttdpatch.etxt > $@

ttdpatch.html:	ttdpatch.texi
	@mkdir -p out
	makeinfo --html --no-validate --number-sections -D HTML -o out $<
	makeinfo --html --no-validate --number-sections -D HTML --no-split $<

#--no-split -o /dev/null
ttdpatch_p.texi:	ttdpatch.texi ${EPSFILES}
	-makeinfo -D PDFP $< -E $@ --force --error-limit=0 -o /dev/null &>/dev/null

ttdpatch_i.texi:	ttdpatch.texi $(PDFFILES) $(PNGFILES)
	-makeinfo -D PDFI $< -E $@ --force --error-limit=0 -o /dev/null &>/dev/null

ttdpatch_i.pdf: ttdpatch_i.texi
	texi2pdf --texinfo="@set PDFI" $<

ttdpatch.tex_unix:	${SOURCES}
	recode ibmpc..lat1 < $< > $@

ttdpatch.texi:	ttdpatch.tex_unix
	./metanode.pl < $< > $@

ttdpatch.txt:	ttdpatch.mtxt
	recode lat1..ibmpc < $< > $@

%.ps : %.dvi $(EPSFILES)
	dvips -Ppdf $<
%.pdf : %.ps $(EPSFILES)
	ps2pdf $< $@

%.dvi : %.texi $(EPSFILES)
	texi2dvi --texinfo="@set PDFP" $<

%.info : %.texi
	makeinfo -D TXT --no-validate $<

%.eps : %.fig
	fig2dev -L ps $^ $@

%.gif : %.fig
	fig2dev -L gif -m 1.5 -t "#ffffff" $^ $@

%.png : %.fig
	fig2dev -L png -m 1.5 $^ $@

%.png : %.gif
	giftopnm $^ | pnmtopng > $@

%.pdf : %.eps
	epstopdf $^

%.eps : %.png
	pngtopnm $< | pnmtops -noturn -dpi 96 > $@

{%.asc} : %.asc
	cp $< $@

clean:	
	rm -f *.tmp *.pg *.info* *.ky *.log *.vr &> /dev/null
	rm -f *.aux *.cp* *.texi* *.mtxt *_unix *~ &> /dev/null
	rm -f *.toc *.tp *.fn *.etxt *.txt {*} &> /dev/null
	rm -f *.eps *.png *.pdf *.dvi *.ps *.html &> /dev/null

manual.zip:	clean
	zip -o -D manual * -x *.zip

manual_out.zip:
	cd out && zip manual_out * && cd .. && mv out/manual_out.zip .

