# Makefile pour centraliser les commandes sous Linux
#
# http://ifiction.free.fr/
#

#HISTOIRE = un_nouveau_monde
HISTOIRE = un_nouveau_monde_gbl
#HISTOIRE = who_are_you
#HISTOIRE = sample

TXT2TAGS = txt2tags
PDFREADER = xpdf
BROWSER = midori

info:
	# make: + html / pdf / graph / clean / booklet (for printing) / pdfsmall (2 pages in one) 
	
all:    html graph pdf

#distrib: html clean
#	-rm $(HISTOIRE).zip
#	-rm -fr $(HISTOIRE)
#	-mkdir $(HISTOIRE)
#	-cp * $(HISTOIRE)
#	zip $(HISTOIRE).zip -r $(HISTOIRE) -x $(HISTOIRE).zip


gbl:
	echo -e "$(HISTOIRE)\nPar YourName\n%%date(%Y-%m-%d)" > $(HISTOIRE)_gbl.t2t 
	echo "%!includeconf: txt2cyoa.t2t" >> $(HISTOIRE)_gbl.t2t 
	cat $(HISTOIRE).gbl | sed -e "s/= \(.*\) =/\n=== \1 ===\n/g" |\
	# sed -e "s/=\(.*\)=/\n=== \1 ===\n/g" | sed -e "s/= \(.*\)=/\n=== \1 ===\n/g" | sed -e "s/=\(.*\) =/\n=== \1 ===\n/g" |\
	 sed -e "s/^#\([0-9]*\)# \(.*\)/\n\n== \1 ==\n\n=== \2 ===\n\n/g" | sed -e "s/^>\(.*\)=\([0-9]*\)/- \1, rdv au \2/g" >> $(HISTOIRE)_gbl.t2t 

togbl:
	cat $(HISTOIRE).t2t | sed -e "s/=== \1 ===/ \(.*\) =/g" |\
	 sed -e "s/^#\([0-9]*\)# \(.*\)/\n\n== \1 ==\n\n=== \2 ===\n\n/g" | sed -e "s/^>\(.*\)=\([0-9]*\)/- \1, rdv au \2/g" >> $(HISTOIRE)_export.gbl

graph:	
	echo -e "\n \n \n"  > graph.txt
	-cat txt2cyoa.t2t $(HISTOIRE).t2t |grep -E "^#|^>|^==|^-|preproc|postproc" >> graph.txt
	-$(TXT2TAGS) --no-headers -o graph2.txt -t txt graph.txt 
	-echo "digraph G { " > graph.txt
	-cat graph2.txt | grep -E "\->|;" >> graph.txt
	-echo "} " >> graph.txt
	-cp graph.txt graph2.txt
	#gawk '/->/ { z=$0} /[0-9]+[^->]/ {print z$0}' fichier.txt
	-cat graph2.txt | python lines.py > graph.txt
	-rm graph2.txt
	-dot graph.txt  -Tpng > $(HISTOIRE)_graph.png
	-dot graph.txt  -Tsvg > $(HISTOIRE)_graph.svg
	-mv graph.txt  $(HISTOIRE)_graph.txt

graph0: txt
	-echo "digraph G { " > $(HISTOIRE)_graph2.txt
	-cat $(HISTOIRE)_graph.txt >> $(HISTOIRE)_graph2.txt
	-echo "} " >> $(HISTOIRE)_graph2.txt
	# -dot $(HISTOIRE)_graph2.txt  -Tpng > $(HISTOIRE)_graph.png
	# -dot $(HISTOIRE)_graph2.txt  -Tsvg > $(HISTOIRE)_graph.svg
	
read:
	$(PDFREADER) $(HISTOIRE).pdf


play:
	$(BROWSER) $(HISTOIRE).html

html:
	$(TXT2TAGS) -t xhtml --css-inside --outfile $(HISTOIRE).html $(HISTOIRE).t2t

txt:
	$(TXT2TAGS) --no-headers -t txt $(HISTOIRE).t2t

pdf:
	$(TXT2TAGS) -t tex --outfile $(HISTOIRE).tex $(HISTOIRE).t2t
	-pdflatex $(HISTOIRE).tex

pdfsmall: pdf
	-pdfnup $(HISTOIRE).pdf --nup 2x1

booklet: pdf
	-pdf2ps $(HISTOIRE).pdf
	-psbook $(HISTOIRE).ps | psnup -2 > $(HISTOIRE)_booklet.ps
	-ps2pdf $(HISTOIRE)_booklet.ps
	-rm $(HISTOIRE)_booklet.ps

clean:
	-rm  *~ 
	-rm  *.log 
	-rm  *.out
	-rm  *.aux
	-rm -i *.tex

cleanall:
	-rm  *~ 
	-rm  *.log 
	-rm  *.out
	-rm  *.aux	
	-rm -i *.pdf
	-rm  *.tex
	-rm -i *.html
	-rm -i *graph*		
