diff --git a/book/Makefile b/book/Makefile index a95d648..49ea835 100644 --- a/book/Makefile +++ b/book/Makefile @@ -9,50 +9,17 @@ LATEXCHAPTERTEMPLATE = support/templates/chapter.latex.mustache HTMLTEMPLATE = support/templates/html.mustache HTMLCHAPTERTEMPLATE = $(HTMLTEMPLATE) +include support/makefiles/help.mk +include support/makefiles/prepare.mk + .DEFAULT_GOAL = help -.phony: all pdf html book pdfbook htmlbook chapters pdfchapters htmlchapters clean fullclean +.phony: all book chapters all: pdf html ## Build everything in all formats book: pdfbook htmlbook ## Full book only, all formats chapters: pdfchapters htmlchapters ## Separate chapters, all formats -pdf: pdfbook pdfchapters ## Everything PDF -pdfbook: $(OUTPUTDIRECTORY)/$(MAIN).pdf -pdfchapters: $(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.pdf) - -html: htmlbook htmlchapters ## Everything HTML -htmlbook: $(OUTPUTDIRECTORY)/$(MAIN).html -htmlchapters: $(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.html) - -clean: prepare-clean ## Cleanup intermediate build products - for f in $(addprefix $(OUTPUTDIRECTORY)/,$(MAIN) $(CHAPTERS)); do \ - latexmk -cd -f -c "$$f" ; \ - rm -f "$$f.tex" "$$f.tex.json" "$$f.html.json" "$$(dirname $$f)/root" ; \ - done - -fullclean: ## Cleanup everything including final build products - rm -fr ${OUTPUTDIRECTORY} - -include support/makefiles/prepare.mk +include support/makefiles/pdf.mk +include support/makefiles/html.mk include support/makefiles/epub.mk -include support/makefiles/help.mk - -$(OUTPUTDIRECTORY)/%.tex.json: %.pillar prepare - ./pillar export --to="LaTeX" --outputDirectory=$(OUTPUTDIRECTORY) --outputFile=$< $< - -$(OUTPUTDIRECTORY)/$(MAIN).tex: TEMPLATE = $(LATEXTEMPLATE) -$(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.tex): TEMPLATE = $(LATEXCHAPTERTEMPLATE) -$(OUTPUTDIRECTORY)/%.tex: $(OUTPUTDIRECTORY)/%.tex.json $(TEMPLATE) - ./mustache --data=$< --template=$(TEMPLATE) > $@ - -$(OUTPUTDIRECTORY)/%.pdf: $(OUTPUTDIRECTORY)/%.tex - latexmk -cd -use-make $< - -$(OUTPUTDIRECTORY)/%.html.json: %.pillar prepare - ./pillar export --to="HTML" --outputDirectory=$(OUTPUTDIRECTORY) --outputFile=$< $< - -$(OUTPUTDIRECTORY)/$(MAIN).html: TEMPLATE = $(HTMLTEMPLATE) -$(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.html): TEMPLATE = $(HTMLCHAPTERTEMPLATE) -$(OUTPUTDIRECTORY)/%.html: $(OUTPUTDIRECTORY)/%.html.json $(TEMPLATE) - ./mustache --data=$< --template=$(TEMPLATE) > $@ diff --git a/book/support/makefiles/html.mk b/book/support/makefiles/html.mk new file mode 100644 index 0000000..d46ced2 --- /dev/null +++ b/book/support/makefiles/html.mk @@ -0,0 +1,22 @@ +$(call check_defined, HTMLTEMPLATE, Template for main document in HTML) +$(call check_defined, HTMLCHAPTERTEMPLATE, Template for individual chapters in HTML) + +.phony: html htmlbook htmlchapters html-clean + +html: htmlbook htmlchapters ## Everything HTML +htmlbook: $(OUTPUTDIRECTORY)/$(MAIN).html +htmlchapters: $(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.html) + +clean: html-clean +html-clean: + for f in $(addprefix $(OUTPUTDIRECTORY)/,$(MAIN) $(CHAPTERS)); do \ + rm -f "$$f.html.json" ; \ + done + +$(OUTPUTDIRECTORY)/%.html.json: %.pillar prepare + ./pillar export --to="HTML" --outputDirectory=$(OUTPUTDIRECTORY) --outputFile=$< $< + +$(OUTPUTDIRECTORY)/$(MAIN).html: TEMPLATE = $(HTMLTEMPLATE) +$(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.html): TEMPLATE = $(HTMLCHAPTERTEMPLATE) +$(OUTPUTDIRECTORY)/%.html: $(OUTPUTDIRECTORY)/%.html.json $(TEMPLATE) + ./mustache --data=$< --template=$(TEMPLATE) > $@ diff --git a/book/support/makefiles/pdf.mk b/book/support/makefiles/pdf.mk new file mode 100644 index 0000000..dad2ee9 --- /dev/null +++ b/book/support/makefiles/pdf.mk @@ -0,0 +1,26 @@ +$(call check_defined, LATEXTEMPLATE, Template for main document in PDF) +$(call check_defined, LATEXCHAPTERTEMPLATE, Template for individual chapters in PDF) + +.phony: pdf pdfbook pdfchapters pdf-clean + +pdf: pdfbook pdfchapters ## Everything PDF +pdfbook: $(OUTPUTDIRECTORY)/$(MAIN).pdf +pdfchapters: $(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.pdf) + +clean: pdf-clean +pdf-clean: + for f in $(addprefix $(OUTPUTDIRECTORY)/,$(MAIN) $(CHAPTERS)); do \ + latexmk -cd -f -c "$$f" ; \ + rm -f "$$f.tex" "$$f.tex.json" ; \ + done + +$(OUTPUTDIRECTORY)/%.tex.json: %.pillar prepare + ./pillar export --to="LaTeX" --outputDirectory=$(OUTPUTDIRECTORY) --outputFile=$< $< + +$(OUTPUTDIRECTORY)/$(MAIN).tex: TEMPLATE = $(LATEXTEMPLATE) +$(CHAPTERS:%=$(OUTPUTDIRECTORY)/%.tex): TEMPLATE = $(LATEXCHAPTERTEMPLATE) +$(OUTPUTDIRECTORY)/%.tex: $(OUTPUTDIRECTORY)/%.tex.json $(TEMPLATE) + ./mustache --data=$< --template=$(TEMPLATE) > $@ + +$(OUTPUTDIRECTORY)/%.pdf: $(OUTPUTDIRECTORY)/%.tex + latexmk -cd -use-make $< diff --git a/book/support/makefiles/prepare.mk b/book/support/makefiles/prepare.mk index 743e5ec..06ae89a 100644 --- a/book/support/makefiles/prepare.mk +++ b/book/support/makefiles/prepare.mk @@ -2,7 +2,7 @@ $(call check_defined, OUTPUTDIRECTORY, Directory for build products) $(call check_defined, MAIN, Base name of the main document) $(call check_defined, CHAPTERS, Base names of the chapters) -.phony: prepare prepare-build prepare-clean download submodules +.phony: prepare clean wipeout download submodules prepare-build FIGURES := $(shell find . \ -type f \ @@ -23,14 +23,19 @@ pillar mustache: | download download: ## Install Pharo VM & image for Pillar & Mustache wget --quiet --output-document=- "https://raw.githubusercontent.com/pillar-markup/pillar/master/download.sh" | bash -s $$* +clean: ## Cleanup intermediate build products + rm -f $(addprefix $(OUTPUTDIRECTORY)/, support gitHeadLocal.gin) + for f in $(addprefix $(OUTPUTDIRECTORY)/,$(MAIN) $(CHAPTERS)); do \ + rm -f "$$(dirname $$f)/root" ; \ + done + +wipeout: ## Cleanup everything including final build products + rm -fr ${OUTPUTDIRECTORY} + # create & initialize output directory, mirroring stuff that has to match the # repo hierarchy inside the output dir. prepare-build: $(addprefix $(OUTPUTDIRECTORY)/, support gitHeadLocal.gin $(FIGURES)) -# cleanup stuff created in this makefile -prepare-clean: - rm -f $(addprefix $(OUTPUTDIRECTORY)/, support gitHeadLocal.gin) - $(OUTPUTDIRECTORY): mkdir -p $(OUTPUTDIRECTORY)