# add all file that you want to generate by default
TODO=guide-utilisateur.pdf analyse-aide-systeme.pdf analyse-tooltips.pdf

RST2XML=./rst2xml
RST2LATEX=./rst2latex2e
RST2HTML=./rst2html

EDPYDOC_MODULES=\
	../glasnost-web/code/*.py \
	../shared/common/*.py \
	../shared/*.py \
	../shared/gcurses/*.py \
	../shared/proxy/*.py \
	../shared/server/*.py \
	../shared/web/*.py \
	../shared/gtk/*.py

#looking for all file needed to create user guide
USERGUIDE=$(shell find guide-utilisateur -name "*.txt" -o -name "*.png")


.PHONY: all clean help link

all: $(TODO)

#add dependance to user guide
glasnost-guide-utilisateur.pdf: $(USERGUIDE)

help: 
	@echo "usage: make <filename>"
	@echo "filename is output file name. example: userguide.ps"

rst2%: rstconversion.py
	ln -sf $< $@

## convert from reStructuredText
%.html: %.txt $(RST2HTML)
	$(RST2HTML) -oiso-8859-1 $< $@

%.tex: %.txt $(RST2LATEX)
	$(RST2LATEX) -oiso-8859-1 $< $@

%.xml: %.txt $(RST2XML)
	$(RST2XML) -oiso-8859-1 --indents --newlines $< $@

## convert from tex generated from reStructuredText
%.dvi: %.tex
	latex $< 
	logfile=`echo "$@" |sed -r "s/(.*)....$$/\\1/"`.log; while [ -f "$$logfile" -a -n "`grep "Rerun to get cross-references right" $$logfile`" ]; do latex $< ; done

%.pdf: %.tex
	pdflatex $<
	logfile=`echo "$@" |sed -r "s/(.*)....$$/\\1/"`.log; while [ -f "$$logfile" -a -n "`grep "Rerun to get cross-references right" $$logfile`" ]; do pdflatex $< ; done

%.ps: %.dvi
	dvips $<

## convert from xml generated from reStructuredText
%.dbkx: %.xml
	xsltproc -o $@ dn2dbk.xsl $<

## convert from docbook

%.man: %.dbkx
	docbook2man $<

%.rtf: %.dbkx
	docbook2rtf $<

epydoc:
	epydoc -o epydoc -n Glasnost -u http://glasnost.entrouvert.org $(EDPYDOC_MODULES)

clean:
	rm -f $(RST2HTML) $(RST2LATEX) $(RST2XML)
	rm -f $(TODO)
	rm -f *.lof *.aux *.log *.out *~
	rm -fr epydoc