mirror of
https://github.com/hendricius/the-sourdough-framework
synced 2025-11-11 05:31:11 -06:00
Ebooks build (#121)
* Use kindlegen for Kindle formats
.mobi and .azw3 are now built directly from .epub saving a few latex
runs, and double build of .mobi.
* Factorize amkefile rules and change coding gudelines
Simplify with a single rule for both serif and sans-serif
several makefiles are that way..
- variables lower-case
- commands/tools upper-case
* Simplify cleaning rules as per new rules
the directory structure has changed, so that shall change as well
This commit is contained in:
101
book/makefile
101
book/makefile
@@ -1,30 +1,29 @@
|
||||
# Macros for commands
|
||||
LATEX := latexmk -cd -pdf -pdflatex="pdflatex -interaction=nonstopmode" -use-make
|
||||
EBOOK := tex4ebook -c tex4ebook.cfg
|
||||
EBOOK := tex4ebook -d epub -c tex4ebook.cfg
|
||||
CLEAN := latexmk -cd -c -use-make
|
||||
EBOOK_CONVERT := kindlegen
|
||||
CHECK_1 := lacheck
|
||||
CHECK_2 := chktex
|
||||
|
||||
# List all files that are dependencies
|
||||
SRC_FIGURES := $(wildcard figures/fig-*.tex)
|
||||
# List all files that are dependencies
|
||||
CHAPTERS = baking basics bread-types flour-types history intro\
|
||||
chapters = baking basics bread-types flour-types history intro\
|
||||
non-wheat-sourdough sourdough-starter storing-bread troubleshooting\
|
||||
wheat-sourdough
|
||||
|
||||
SRC_TABLES := $(wildcard tables/tables-*.tex)
|
||||
SRC_FIGURES := $(wildcard figures/fig-*.tex)
|
||||
src_tables := $(wildcard tables/tables-*.tex)
|
||||
src_figures := $(wildcard figures/fig-*.tex)
|
||||
|
||||
SRC_TEX := $(foreach directory, $(CHAPTERS), $(wildcard $(directory)/*.tex))
|
||||
SRC_TEX := $(SRC_TEX) book.tex book_sans_serif.tex references.bib
|
||||
src_tex := $(foreach directory, $(chapters), $(wildcard $(directory)/*.tex))
|
||||
src_tex += book.tex book_sans_serif.tex references.bib
|
||||
|
||||
IMAGES := $(wildcard images/*/*.jpg)
|
||||
IMAGES := $(IMAGES) $(wildcard images/*/*.png)
|
||||
IMAGES := $(IMAGES) $(foreach directory, $(CHAPTERS), $(wildcard $(directory)/*.jpg))
|
||||
IMAGES := $(IMAGES) $(foreach directory, $(CHAPTERS), $(wildcard $(directory)/*.png))
|
||||
images := $(wildcard images/*/*.jpg)
|
||||
images += $(wildcard images/*/*.png)
|
||||
images += $(foreach directory, $(chapters), $(wildcard $(directory)/*.jpg))
|
||||
images += $(foreach directory, $(chapters), $(wildcard $(directory)/*.png))
|
||||
|
||||
TGT_FIGURES := $(patsubst %.tex, %.pdf,$(SRC_FIGURES))
|
||||
SRC_ALL := $(SRC_TEX) $(SRC_FIGURES) $(SRC_TABLES) tex4ebook.cfg book.mk4 $(IMAGES)
|
||||
tgt_figures := $(patsubst %.tex, %.pdf,$(src_figures))
|
||||
src_all := $(src_tex) $(src_figures) $(src_tables) tex4ebook.cfg book.mk4 $(images)
|
||||
|
||||
# Default rules for pdf and ebooks, getting overwritten when built in a
|
||||
# sub-directory
|
||||
@@ -37,34 +36,17 @@ book_serif/book.pdf: clean_ebook_build $(SRC_ALL)
|
||||
book_sans_serif/book_sans_serif.pdf: clean_ebook_build $(SRC_ALL)
|
||||
$(LATEX) -output-directory=book_sans_serif book_sans_serif.tex
|
||||
|
||||
book-epub/%.epub: %.tex $(SRC_ALL)
|
||||
epub/%.epub: %.tex $(src_all)
|
||||
$(EBOOK) -f epub $<
|
||||
|
||||
book-mobi/%.mobi: %.tex $(SRC_ALL)
|
||||
# not sure why, but I have to generate the mobi twice for the release
|
||||
# command to properly work.
|
||||
$(EBOOK) -f mobi $<
|
||||
$(EBOOK) -f mobi $<
|
||||
epub/%.mobi: epub/%.epub
|
||||
$(EBOOK_CONVERT) $< -o $(notdir $@)
|
||||
|
||||
book-azw3/%.azw3: %.tex $(SRC_ALL)
|
||||
$(EBOOK) -f azw3 $<
|
||||
|
||||
# Not sure if there is a better way with a wildcard?
|
||||
book_sans_serif-epub/%.epub: %.tex $(SRC_ALL)
|
||||
$(EBOOK) -f epub $<
|
||||
|
||||
book_sans_serif-mobi/%.mobi: %.tex $(SRC_ALL)
|
||||
# not sure why, but I have to generate the mobi twice for the release
|
||||
# command to properly work.
|
||||
$(EBOOK) -f mobi $<
|
||||
$(EBOOK) -f mobi $<
|
||||
|
||||
book_sans_serif-azw3/%.azw3: %.tex $(SRC_ALL)
|
||||
$(EBOOK) -f azw3 $<
|
||||
epub/%.azw3: epub/%.epub
|
||||
$(EBOOK_CONVERT) $< -o $(notdir $@)
|
||||
|
||||
# Now with the rules
|
||||
# Expected usual rules first
|
||||
|
||||
.PHONY: default
|
||||
default: build_pdf
|
||||
|
||||
@@ -110,12 +92,12 @@ build_sans_serif_pdf: book_sans_serif/book_sans_serif.pdf
|
||||
build_ebook: build_serif_ebook build_sans_serif_ebook
|
||||
|
||||
.PHONY: build_serif_ebook
|
||||
build_serif_ebook: $(TGT_FIGURES) book-epub/book.epub book-mobi/book.mobi book-azw3/book.azw3 | make_release_dir
|
||||
build_serif_ebook: $(tgt_figures) epub/book.epub epub/book.mobi epub/book.azw3 | make_release_dir
|
||||
|
||||
.PHONY: build_sans_serif_ebook
|
||||
build_sans_serif_ebook: $(TGT_FIGURES) book_sans_serif-epub/book_sans_serif.epub \
|
||||
book_sans_serif-mobi/book_sans_serif.mobi \
|
||||
book_sans_serif-azw3/book_sans_serif.azw3 | make_release_dir
|
||||
build_sans_serif_ebook: $(tgt_figures) epub/book_sans_serif.epub \
|
||||
epub/book_sans_serif.mobi \
|
||||
epub/book_sans_serif.azw3 | make_release_dir
|
||||
|
||||
.PHONY: export_figures
|
||||
# Requires that you have docker running on your computer.
|
||||
@@ -123,7 +105,7 @@ export_figures:
|
||||
cd figures/ && bash export_figures.sh
|
||||
|
||||
.PHONY: figures
|
||||
figures: $(SRC_FIGURES)
|
||||
figures: $(src_figures)
|
||||
$(LATEX) $<
|
||||
|
||||
.PHONY: check
|
||||
@@ -138,7 +120,7 @@ check: $(SRC_TEX)
|
||||
|
||||
.PHONY: clean_figures
|
||||
clean_figures:
|
||||
$(CLEAN) $(SRC_FIGURES)
|
||||
$(CLEAN) $(src_figures)
|
||||
|
||||
.PHONY: clean_ebook_build
|
||||
clean_ebook_build:
|
||||
@@ -150,7 +132,6 @@ clean_ebook_build:
|
||||
-rm book*.4tc
|
||||
-rm book*.4ct
|
||||
-rm book*.dvi
|
||||
-rm book*.epub
|
||||
-rm book.css
|
||||
-rm book_sans_serif.css
|
||||
-rm book*.idv
|
||||
@@ -173,30 +154,20 @@ clean: clean_ebook_build clean_figures
|
||||
-rm -rf book*-epub/META-INF
|
||||
-rm -rf book*-epub/OEBPS
|
||||
-rm book*-epub/mimetype
|
||||
-rm -rf book*-mobi/META-INF
|
||||
-rm -rf book*-mobi/OEBPS
|
||||
-rm book*-mobi/mimetype
|
||||
-rm book*-mobi/book.epub
|
||||
-rm -rf book*-mobi/META-INF
|
||||
-rm -rf book*-azw3/OEBPS
|
||||
-rm -rf book*-azw3/META-INF
|
||||
-rm book*-azw3/book.epub
|
||||
-rm book*-azw3/mimetype
|
||||
|
||||
.PHONY: mrproper
|
||||
mrproper: clean
|
||||
$(CLEAN) -C $(SRC_FIGURES)
|
||||
$(CLEAN) -C $(src_figures)
|
||||
$(CLEAN) -C -output-directory=book_serif book.tex
|
||||
$(CLEAN) -C -output-directory=book_sans_serif book_sans_serif.tex
|
||||
-rm figures/*.pdf
|
||||
-rm figures/*.png
|
||||
rm -rf book*-mobi/
|
||||
rm -rf book*-azw3/
|
||||
rm -rf book*-epub/
|
||||
rm -rf epub/
|
||||
rm -rf release/
|
||||
rm -rf release/
|
||||
rm -rf release_sans_serif/
|
||||
rm -rf release_sans_serif/
|
||||
rm -rf book_serif/
|
||||
rm -rf book_sans_serif/
|
||||
rm -rf book-epub/
|
||||
rm -rf book_sans_serif-epub/
|
||||
|
||||
.PHONY: bake
|
||||
bake: release_default release_sans_serif
|
||||
@@ -208,13 +179,13 @@ make_release_dir:
|
||||
.PHONY: release_default
|
||||
release_default: build_pdf build_ebook | make_release_dir
|
||||
cp book_serif/book.pdf release/TheBreadCode-The-Sourdough-Framework.pdf
|
||||
cp book-mobi/book.mobi release/TheBreadCode-The-Sourdough-Framework.mobi
|
||||
cp book-epub/book.epub release/TheBreadCode-The-Sourdough-Framework.epub
|
||||
cp book-azw3/book.azw3 release/TheBreadCode-The-Sourdough-Framework.azw3
|
||||
cp epub/book.mobi release/TheBreadCode-The-Sourdough-Framework.mobi
|
||||
cp epub/book.epub release/TheBreadCode-The-Sourdough-Framework.epub
|
||||
cp epub/book.azw3 release/TheBreadCode-The-Sourdough-Framework.azw3
|
||||
|
||||
.PHONY: release_sans_serif
|
||||
release_sans_serif: build_sans_serif_pdf build_sans_serif_ebook | make_release_dir
|
||||
cp book_sans_serif/book_sans_serif.pdf release/TheBreadCode-The-Sourdough-Framework-sans-serif.pdf
|
||||
cp book_sans_serif-mobi/book_sans_serif.mobi release/TheBreadCode-The-Sourdough-Framework-sans-serif.mobi
|
||||
cp book_sans_serif-epub/book_sans_serif.epub release/TheBreadCode-The-Sourdough-Framework-sans-serif.epub
|
||||
cp book_sans_serif-azw3/book_sans_serif.azw3 release/TheBreadCode-The-Sourdough-Framework-sans-serif.azw3
|
||||
cp epub/book_sans_serif.mobi release/TheBreadCode-The-Sourdough-Framework-sans-serif.mobi
|
||||
cp epub/book_sans_serif.epub release/TheBreadCode-The-Sourdough-Framework-sans-serif.epub
|
||||
cp epub/book_sans_serif.azw3 release/TheBreadCode-The-Sourdough-Framework-sans-serif.azw3
|
||||
|
||||
Reference in New Issue
Block a user