LYXFILES := ac-compilerman.lyx ac-languageref.lyx ac-firststeps.lyx ac-progguide.lyx ac-quickref.lyx
DIRS := CompilerManual LanguageReference FirstSteps ProgrammingGuide QuickRef
PDFFILES := $(patsubst %.lyx,gen/%.pdf,$(LYXFILES))
XHTMLFILES := $(patsubst %.lyx,gen/%.xhtml,$(LYXFILES))

VPATH = CompilerManual:LanguageReference:FirstSteps:ProgrammingGuide:QuickRef

all: $(PDFFILES) $(XHTMLFILES)

gen/%.pdf: %.lyx ac-manual.layout
	@echo Exporting $@
	@lyx -E pdf2 $@ $< > gen/logpdf.txt

gen/%.xhtml: %.lyx ac-manual.layout
	@echo Exporting $@
	@lyx -E xhtml $@ $< > gen/logxhtml.txt
	@echo Transforming export file: step 1
	@xsltproc gen/fixhtml1.xsl $@ > $@.trans1
	@echo Transforming export file: step 2
	@xsltproc --novalid gen/fixhtml2.xsl $@.trans1 > $@.trans2
	@cp $@.trans2 $@
	@rm $@.trans*
	@echo Renaming SVGs
	@cd gen; for f in `find . -name "e_*.svg"`; do n=`echo $$f | cut -d _ -f3-` ; echo "  $$f -> img_$$n"; mv $$f img_$$n; done

gen/ac-quickref.xhtml: ac-quickref.lyx ac-quickref.html-template
	@echo Splitting QuickRef PDF into pages
	@pdfseparate gen/ac-quickref.pdf gen/ac-quickref-%d.pdf
	@echo Converting QuickRef pages into SVGs
	@cd gen && soffice --convert-to svg ac-quickref-1.pdf
	@cd gen && soffice --convert-to svg ac-quickref-2.pdf
	@rm gen/ac-quickref-1.pdf gen/ac-quickref-2.pdf
	@echo Copying template HTML file
	@cp QuickRef/ac-quickref.html-template $@

clean:
	@rm -rf $(PDFFILES) $(XHTMLFILES) gen/log*.txt gen/*~ gen/img_*.svg gen/*.trans* gen/ac-quickref-*
