#---------------------------------------------------------
#
#
#----------------------------------------------------------

.PRECIOUS: %.pdf

FIGDIR=./figs
OBJPDF=./objpdf

# Le main
MAIN=lv6-ref-man

# Sources latex
SRCS= \
	$(MAIN).tex \
	preambule.tex \
	touch.tex

# targets: fig 2 latex 2 pdf
FIGS=\
	$(OBJPDF)/patate.tex \
	$(OBJPDF)/edge.tex \
	$(OBJPDF)/df.tex \
	$(OBJPDF)/map1.tex \
	$(OBJPDF)/red1.tex \
	$(OBJPDF)/fill1.tex \
	$(OBJPDF)/fillred1.tex


# targets: lus 2 latex
LUS2TEX= \
	$(OBJPDF)/struct.lus.tex \
	$(OBJPDF)/consensus2.lus.tex \
	$(OBJPDF)/count.lus.tex \
	$(OBJPDF)/EDGE.lus.tex \
	$(OBJPDF)/STABLE.lus.tex \
	$(OBJPDF)/TIME_STABLE.lus.tex \
	$(OBJPDF)/TIME_STABLE1.lus.tex \
	$(OBJPDF)/COUNTER.lus.tex \
	$(OBJPDF)/SWITCH.lus.tex \
	$(OBJPDF)/SWITCH1.lus.tex \
	$(OBJPDF)/FALLING_EDGE.lus.tex \
	$(OBJPDF)/sincos.lus.tex \
	$(OBJPDF)/integrator.lus.tex \
	$(OBJPDF)/type_decl.lus.tex \
	$(OBJPDF)/merge.lus.tex \
	$(OBJPDF)/enum0.lus.tex \
	$(OBJPDF)/param_node.lus.tex \
	$(OBJPDF)/param_node2.lus.tex \

# target: summary
SUMMARY=$(OBJPDF)/syntax_summary.tex


# target: mly 2 latex
PARSER=$(OBJPDF)/parser.tex


all: $(OBJPDF) $(MAIN).pdf

.PHONY: dofigs
dofigs:  $(FIGS)

$(OBJPDF) :
	mkdir $(OBJPDF)

# 
$(OBJPDF)/syntax_summary.tex: $(SRCS)
	grep  newcommand $(SRCS) | grep "\\\syntax" | sed -e 's/{/\ /g' | sed -e 's/}/\ /g' | awk '{printf "%s\n", $$2}' > $@ 

#------------------------------
#------------------------------
h:$(SRCS)
	$(HOME)/i386-linux/hyperlatex $(SRCS)


#------------------------------
#------------------------------
$(MAIN).pdf : $(PARSER) $(SRCS) $(LUS2TEX) $(SUMMARY) $(FIGS)
	(cd objpdf; pdflatex ../$(MAIN).tex)
	mv objpdf/$(MAIN).pdf .

#------------------------------
# Special : fig 2 latex 2 pdf
#------------------------------
$(OBJPDF)/%.tex : $(FIGDIR)/%.fig
	cp $(FIGDIR)/$*.fig $(OBJPDF)/$*.fig
	fig2dev -Lpstex $(OBJPDF)/$*.fig > $(OBJPDF)/$*.ps
	cd $(OBJPDF); epstopdf $*.ps
	cd $(OBJPDF); fig2dev -Lpstex_t  -p $*.pdf $*.fig > $*.tex

clean:
	rm -f $(OBJPDF)/*

#------------------------------
# Special : mly 2 latex
#------------------------------

$(PARSER): ../src/parser.mly
	mly2bnf  $<  -t lustokens | grep -v XXX > $@

rere:
	touch ../src/parser.mly
	make parser
	make re 
re:
	touch touch.tex
	make
	touch touch.tex
	make
#################################################
# direct inclusion of lustre non-reg files into the manual

#LUSTRE_DIR=$(HOME)//lus2lic/src/test/should_work
LUSTRE_DIR=../src/test/should_work
#LUS2TEX=$(HOME)/TeXinputs/lus2tex

# Generic rule for .lus.tex targets
# - All lus files must be in some subdir of LUSTRE_DIR
$(OBJPDF)/%.lus.tex : $(LUSTRE_DIR)/*/%.lus
	utils/lus2tex $< > $@

lus2tex: $(EXEMPLES)

# obsolete
#lus2tex:
#	for f in ${EXEMPLES}; do \
#		$(LUS2TEX) $$f > `basename $$f`.tex ;\
#	done
#################################################