
source = $(word 1,$(wildcard *.xml))
source := $(strip $(source:.xml=))
source := $(strip $(source:=))

all: $(source).xml $(source).xml $(source).pdf $(source).ps.gz $(source).tex \
     $(source).txt $(source).rtf $(source).ps html

html: $(source).xml Makefile
	@echo "Genereting html.." 
	@mkdir -p html && cd html && docbook2html ../$(source).xml 

$(source).txt: $(source).xml Makefile
	@echo "Genereting txt..."	
	@docbook2txt $(source).xml 

$(source).rtf: $(source).xml Makefile
	@echo "Genereting rtf..."	
	@docbook2rtf $(source).xml 

$(source).pdf: $(source).xml Makefile
	@echo "Genereting pdf..."	
	@docbook2pdf $(source).xml 

$(source).ps.gz: $(source).ps Makefile
	@echo "Compressing ps..."
	@gzip -9c < $(source).ps > $(source).ps.gz

$(source).ps: $(source).xml Makefile
	@echo "Genereting ps.."
	@docbook2ps $(source).xml 

$(source).dvi: $(source).tex Makefile
	@echo Generating .dvi version...;\
	 elatex '\nonstopmode\input{$(source).tex}'
	@echo "  Generating index...";\
	 elatex '\nonstopmode\input{$(source).tex}'
	@echo "  Removing temporary files...";\
	 rm -f ./$(source).{log,toc,aux}

$(source).tex: $(source).xml Makefile
	@echo "Genereting tex.."
	@docbook2tex $(source).xml 

clean:
	@echo "Cleaning up"
	@rm -f $(source).{tex,ps,ps.gz,pdf,txt,rtf,log,dvi}
	@rm -rf ./html/

.PHONY: all clean
