Skip to content

Commit

Permalink
Extract per-format build rules
Browse files Browse the repository at this point in the history
  • Loading branch information
cdlm committed Oct 19, 2016
1 parent f9246c5 commit f7ebb3e
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 44 deletions.
45 changes: 6 additions & 39 deletions book/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) > $@
22 changes: 22 additions & 0 deletions book/support/makefiles/html.mk
Original file line number Diff line number Diff line change
@@ -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) > $@
26 changes: 26 additions & 0 deletions book/support/makefiles/pdf.mk
Original file line number Diff line number Diff line change
@@ -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 $<
15 changes: 10 additions & 5 deletions book/support/makefiles/prepare.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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)

Expand Down

0 comments on commit f7ebb3e

Please sign in to comment.