forked from ieure/sicp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
70 lines (49 loc) · 2.15 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# TODO: Add potrace for gif -> svg conversion; convert still gives
# rasterized images
LATEX_DIR := src/latex
IMAGES_DIR := src/OEBPS/images
BUILD_DIR := $(LATEX_DIR)/build
HUGE_MARK := $(BUILD_DIR)/huge.mark
NORMAL_MARK := $(BUILD_DIR)/normal.mark
#
# TEX_FILES becomes a list of *.tex files that are in LATEX_DIR
# SVG_FILES becomes the list of what would be the equivalent *.svg
# file names in IMAGES_DIR (even if they don't exist yet)
#
TEX_FILES := $(wildcard $(LATEX_DIR)/*.tex)
SVG_FILES := $(patsubst %.tex,%.svg,$(subst $(LATEX_DIR),$(IMAGES_DIR),$(TEX_FILES)))
GIF_FILES := $(patsubst %.tex,%.gif,$(subst $(LATEX_DIR),$(IMAGES_DIR),$(TEX_FILES)))
CONTENT := $(shell find src -type f -not -name .DS_Store)
XML := $(shell find src -type f -name \*html)
.PHONY : clean tex
all: sicp.epub
sicp.epub: $(CONTENT)
cd src && zip -r ../$@ $(^:src/%=%)
check:
xmllint --noout $(XML)
$(BUILD_DIR)/huge/%_cropped.pdf: $(BUILD_DIR)/huge/ $(LATEX_DIR)/%.tex
sed 's/\\sicpsize}{\\fontsize{16}{18}/\\sicpsize}{\\fontsize{200}{220}/' < $(LATEX_DIR)/sicpstyle.sty > $(LATEX_DIR)/sicpstyle2.sty
mv $(LATEX_DIR)/sicpstyle2.sty $(LATEX_DIR)/sicpstyle.sty
cd $(LATEX_DIR) && pdflatex -output-dir ./build/huge/ ./$*.tex
pdfcrop --clip $(BUILD_DIR)/huge/$*.pdf $(BUILD_DIR)/huge/$*_cropped.pdf
rm -f $(HUGE_MARK)
$(BUILD_DIR)/huge/%.pbm: $(BUILD_DIR)/huge/%_cropped.pdf
convert $(BUILD_DIR)/huge/$*_cropped.pdf $@
$(IMAGES_DIR)/%.svg: $(BUILD_DIR)/huge/%.pbm
potrace -s -o $@ $(BUILD_DIR)/huge/$*.pbm
$(BUILD_DIR)/%_cropped.pdf: $(BUILD_DIR) $(LATEX_DIR)/%.tex
sed 's/\\sicpsize}{\\fontsize{200}{220}/\\sicpsize}{\\fontsize{16}{18}/' < $(LATEX_DIR)/sicpstyle.sty > $(LATEX_DIR)/sicpstyle2.sty
mv $(LATEX_DIR)/sicpstyle2.sty $(LATEX_DIR)/sicpstyle.sty
cd $(LATEX_DIR) && pdflatex -output-dir ./build ./$*.tex
pdfcrop --clip $(BUILD_DIR)/$*.pdf $(BUILD_DIR)/$*_cropped.pdf
rm -f $(NORMAL_MARK)
$(IMAGES_DIR)/%.gif: $(BUILD_DIR)/%_cropped.pdf
convert $(BUILD_DIR)/$*_cropped.pdf $@
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/huge/:
mkdir -p $(BUILD_DIR)/huge/
svg: $(SVG_FILES)
gif: $(GIF_FILES)
clean:
rm -rf sicp.epub $(BUILD_DIR) $(SVG_FILES) $(GIF_FILES)