-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
170 lines (129 loc) · 5.19 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
PKG = commutative-diagrams
SHELL = bash
UTREE = $(shell kpsewhich --var-value TEXMFHOME)
YEAR = $(shell date +"%Y")
DATE = $(shell date +"%Y/%m/%d")
VERSION = UNRELEASED
SKIP_DOC = 0
INTERPOLATIONS = s@<<FILE>>@$(@F)@g;
INTERPOLATIONS += s@<<DATE>>@$(DATE)@g;
INTERPOLATIONS += s@<<YEAR>>@$(YEAR)@g;
INTERPOLATIONS += s/<<VERSION>>/$(VERSION)/g;
define safe-cp
mkdir -p $(@D)
cp $< $@
endef
##[ Default ]###################################################################
all: dist/$(PKG).zip
##[ hygiene ]###################################################################
clean:
rm -rf build
clobber: clean
rm -rf dist
##[ BUILD | Sourcecode ]########################################################
build/%.tex: src/HEADER src/%.tex
mkdir -p build
cat $^ | sed "$(INTERPOLATIONS)" > $@
build/%.sty: src/HEADER src/%.sty
mkdir -p build
cat $^ | sed "$(INTERPOLATIONS)" > $@
##[ BUILD | Documentation ]#####################################################
build/README: doc/README
$(safe-cp)
build/$(PKG)-doc.tex: doc/main.tex src/HEADER $(wildcard doc/*.tex)
mkdir -p build
cat src/HEADER $< \
| awk -F '[{}]' '/^\\input{.*}$$/{system("cat $(<D)/"$$2".tex"); next}1' \
| awk -F '[{}]' '/^\\input{.*}$$/{system("cat $(<D)/"$$2".tex"); next}1' \
| sed "$(INTERPOLATIONS)" \
> $@
# NOTE: the black magic above interpolates the `\input`s.
# It's the most portable solution I could come up with:
# ruby -pe '$$_.gsub!(/^\\input{(.*?)}$$/) { File.read("$(<D)/#{Regexp.last_match[1]}.tex")}'
# awk -F '[{}]' '/^\\include{.*}$/{system("cat "$2".tex"); next}1'
# sed 's@\\input{\(.*\)}@cat $(<D)/\1.tex@e' # NOTE: this requires GNU sed, so MacOS is cut off
build/latexmkrc: doc/latexmkrc
$(safe-cp)
build/$(PKG)-doc.pdf: build/$(PKG)-doc.tex build/latexmkrc \
build/tikzlibrary$(PKG).bapto.code.tex \
build/tikzlibrary$(PKG).code.tex \
build/tikzlibrary$(PKG).diorthono.code.tex \
build/tikzlibrary$(PKG).ektropi.code.tex \
build/tikzlibrary$(PKG).katharizo.code.tex \
build/tikzlibrary$(PKG).koinos.code.tex \
build/tikzlibrary$(PKG).mandyas.code.tex \
build/tikzlibrary$(PKG).mitra.code.tex \
build/tikzlibrary$(PKG).ozos.code.tex \
build/tikzlibrary$(PKG).ramma.code.tex \
build/tikzlibrary$(PKG).velos.code.tex \
build/$(PKG).sty
pushd $(<D); latexmk -gg $(<F)
##[ DIST | Tree file structure ]################################################
dist/tds/doc/generic/$(PKG)/$(PKG)-doc.pdf: build/$(PKG)-doc.pdf
$(safe-cp)
dist/tds/doc/generic/$(PKG)/$(PKG)-doc.tex: build/$(PKG)-doc.tex
$(safe-cp)
dist/tds/doc/generic/$(PKG)/README: build/README
$(safe-cp)
dist/tds/doc: \
dist/tds/doc/generic/$(PKG)/$(PKG)-doc.pdf \
dist/tds/doc/generic/$(PKG)/$(PKG)-doc.tex \
dist/tds/doc/generic/$(PKG)/README
dist/tds/tex/context/third/$(PKG)/t-$(PKG).tex: build/t-$(PKG).tex
$(safe-cp)
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).%.tex: build/tikzlibrary$(PKG).%.tex
$(safe-cp)
dist/tds/tex/latex/$(PKG)/$(PKG).sty: build/$(PKG).sty
$(safe-cp)
dist/tds/tex/latex/$(PKG)/kodi.sty: build/kodi.sty
$(safe-cp)
dist/tds/tex/plain/$(PKG)/$(PKG).tex: build/$(PKG).tex
$(safe-cp)
dist/tds/tex: \
dist/tds/tex/context/third/$(PKG)/t-$(PKG).tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).bapto.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).diorthono.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).ektropi.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).katharizo.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).koinos.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).mandyas.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).mitra.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).ozos.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).ramma.code.tex \
dist/tds/tex/generic/$(PKG)/tikzlibrary$(PKG).velos.code.tex \
dist/tds/tex/latex/$(PKG)/$(PKG).sty \
dist/tds/tex/latex/$(PKG)/kodi.sty \
dist/tds/tex/plain/$(PKG)/$(PKG).tex
ifeq ($(SKIP_DOC),1)
dist/tds: dist/tds/tex
else
dist/tds: dist/tds/tex dist/tds/doc
endif
##[ DIST | Tree file structure ZIP ]############################################
dist/$(PKG).tds.zip: dist/tds
pushd dist/tds; zip --recurse-paths ../$(PKG).tds.zip .
##[ DIST | Flat file structure ]################################################
dist/pkg/$(PKG): dist/$(PKG).tds.zip
mkdir -p $@
unzip -j $< -d $@
cp $< $(@D)
##[ DIST | Flat file structure ZIP ]############################################
dist/$(PKG).zip: dist/pkg/$(PKG)
pushd dist/pkg; zip --recurse-paths ../$(PKG).zip .
##[ Format ]####################################################################
build/$(PKG)-livedemo.fmt: $(PKG)-livedemo.tex install
mkdir -p $(@D)
cp $< $(@D)
pushd $(@D); pdftex -ini "&latex $<\dump"
dist/$(PKG)-livedemo.fmt: build/$(PKG)-livedemo.fmt
$(safe-cp)
##[ Local (un)installation ]####################################################
install: dist/tds
pushd $<; cp -vR . $(UTREE)/
uninstall:
find $(UTREE) -type d -name $(PKG) -prune -exec rm -vrf {} \;
##[ Development ]###############################################################
# NOTE: this is useful when writing the manual
watch:
ls doc/*.tex | entr -n -s 'make clean build/$(PKG)-doc.pdf'