-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.package
224 lines (191 loc) · 6.38 KB
/
Makefile.package
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# This Makefile must be included at the end of the including file.
latex = $(COMMON:%=%.sty) $(LATEX)
plain = $(COMMON:%=%.tex) $(PLAIN)
context = $(COMMON:%=t-%.tex) $(CONTEXT)
TEX = $(latex) $(plain) $(context) $(GENERIC)
RUNTIME = $(TEX) $(SCRIPTS) $(MAN)
ALL = $(RUNTIME) $(SOURCE) $(DOC) \
$(README) $(INSTALL) $(CHANGELOG) $(LICENCE) $(MAKEFILE)
ctan/$(PACKAGE).zip: $(ALL)
CTAN-DIR = ctan/$(PACKAGE)
CTAN-DOC-DIR = ctan/$(PACKAGE)/doc
format-dir = $(subst context,context/third,$(FORMAT))
TDS-DIR = texmf/$(PACKAGE).tds
TDS-SCRIPTS-DIR = $(TDS-DIR)/scripts/$(PACKAGE)
TDS-DOC-DIR = $(TDS-DIR)/doc/$(format-dir)/$(PACKAGE)
TDS-SOURCE-DIR = $(TDS-DIR)/source/$(format-dir)/$(PACKAGE)
TDS-MAN-DIR = $(TDS-DIR)/doc/man/man
TDS-ALL-DIRS = $(TDS-SCRIPTS-DIR) $(TDS-SOURCE-DIR) $(TDS-DOC-DIR) \
$(TDS-DIR)/tex/{latex,plain,generic}/$(PACKAGE) \
$(TDS-DIR)/tex/context/third/$(PACKAGE) \
$(TDS-MAN-DIR){1,2,3,4,5,6,7,8,9}
readme?md = README$(findstring .md, $(suffix $(README)))
install?md = INSTALL$(findstring .md, $(suffix $(INSTALL)))
changelog?md = CHANGELOG$(findstring .md, $(suffix $(CHANGELOG)))
licence?md = LICENCE$(findstring .md, $(suffix $(LICENCE)))
man1 = $(filter %.1,$(MAN))
man2 = $(filter %.2,$(MAN))
man3 = $(filter %.3,$(MAN))
man4 = $(filter %.4,$(MAN))
man5 = $(filter %.5,$(MAN))
man6 = $(filter %.6,$(MAN))
man7 = $(filter %.7,$(MAN))
man8 = $(filter %.8,$(MAN))
man9 = $(filter %.9,$(MAN))
define MAKE-CTAN
$(CTAN-BEGIN)
$(CTAN-END)
endef
define CTAN-BEGIN
rm -rf $(CTAN-DIR) ctan/$(PACKAGE).zip
mkdir -p $(CTAN-DIR) $(CTAN-DOC-DIR)
$(call cp,$(SOURCE) $(SCRIPTS) $(CTAN),$(CTAN-DIR))
$(call cp,$(README),$(CTAN-DIR)/$(readme?md))
$(call cp,$(INSTALL),$(CTAN-DIR)/$(install?md))
$(call cp,$(CHANGELOG),$(CTAN-DIR)/$(changelog?md))
$(call cp,$(LICENCE),$(CTAN-DIR)/$(licence?md))
$(call cp,$(MAKEFILE),$(CTAN-DIR))
$(call cp,$(DOC),$(CTAN-DOC-DIR))
endef
define CTAN-END
if [[ -d $(TDS-DIR) ]] ; then \
cd $(TDS-DIR) && \
zip -r $(PACKAGE).tds.zip * ; \
fi
if [[ -a $(TDS-DIR)/$(PACKAGE).tds.zip ]] ; then \
mv $(TDS-DIR)/$(PACKAGE).tds.zip ctan ; \
fi
rmdir -p --ignore-fail-on-non-empty `find $(CTAN-DIR) -type d`
cd ctan && zip -r $(PACKAGE).zip $(PACKAGE) $(PACKAGE).tds.zip
cp ctan/$(PACKAGE).zip ctan/$(PACKAGE)-$(YEAR)-$(MONTH)-$(DAY)-v$(VERSION).zip
endef
define MAKE-TDS
$(TDS-BEGIN)
$(TDS-END)
endef
define TDS-BEGIN
rm -rf $(TDS-DIR)
$(TDS-MKDIR)
$(TDS-CP)
endef
define TDS-MKDIR
mkdir -p $(TDS-ALL-DIRS)
endef
define TDS-CP
$(call cp,$(latex),$(TDS-DIR)/tex/latex/$(PACKAGE))
$(call cp,$(plain),$(TDS-DIR)/tex/plain/$(PACKAGE))
$(call cp,$(context),$(TDS-DIR)/tex/context/third/$(PACKAGE))
$(call cp,$(GENERIC),$(TDS-DIR)/tex/generic/$(PACKAGE))
$(call cp,$(SCRIPTS),$(TDS-SCRIPTS-DIR))
$(call cp,$(SOURCE),$(TDS-SOURCE-DIR))
$(call cp,$(MAKEFILE),$(TDS-SOURCE-DIR))
$(call cp,$(DOC),$(TDS-DOC-DIR))
$(call cp,$(README),$(TDS-DOC-DIR)/$(readme?md))
$(call cp,$(INSTALL),$(TDS-DOC-DIR)/$(install?md))
$(call cp,$(CHANGELOG),$(TDS-DOC-DIR)/$(changelog?md))
$(call cp,$(LICENCE),$(TDS-DOC-DIR)/$(licence?md))
$(call cp,$(man1),$(TDS-MAN-DIR)1)
$(call cp,$(man2),$(TDS-MAN-DIR)2)
$(call cp,$(man3),$(TDS-MAN-DIR)3)
$(call cp,$(man4),$(TDS-MAN-DIR)4)
$(call cp,$(man5),$(TDS-MAN-DIR)5)
$(call cp,$(man6),$(TDS-MAN-DIR)6)
$(call cp,$(man7),$(TDS-MAN-DIR)7)
$(call cp,$(man8),$(TDS-MAN-DIR)8)
$(call cp,$(man9),$(TDS-MAN-DIR)9)
endef
define TDS-END
$(TDS-FILES)
$(TDS-PRUNE)
endef
define TDS-FILES
cd $(TDS-DIR) ; find . -type f | sed 's!^\./!!' \
> doc/$(format-dir)/$(PACKAGE)/FILES
endef
define TDS-PRUNE
rmdir -p --ignore-fail-on-non-empty `find $(TDS-DIR) -type d`
endef
%.1: %.1.md
pandoc $< -s -t man -o $@
%.2: %.2.md
pandoc $< -s -t man -o $@
%.3: %.3.md
pandoc $< -s -t man -o $@
%.4: %.4.md
pandoc $< -s -t man -o $@
%.5: %.5.md
pandoc $< -s -t man -o $@
%.6: %.6.md
pandoc $< -s -t man -o $@
%.7: %.7.md
pandoc $< -s -t man -o $@
%.8: %.8.md
pandoc $< -s -t man -o $@
%.9: %.9.md
pandoc $< -s -t man -o $@
.PHONY: runtimes link-runtimes install-runtimes uninstall-runtimes version
.IGNORE: uninstall-runtimes
cp=$(intcmp $(words $(1)),0,,,cp $(1) $(2))
runtimes: $(RUNTIME)
TEXMFHOME=$(shell kpsewhich -var-value TEXMFHOME)
link-runtimes:
$(eval TDS-DIR=$(TEXMFHOME))
$(eval cp=$$(intcmp $$(words $$(1)),0,,,ln -srf $$(1) $$(2)))
$(TDS-MKDIR)
$(TDS-CP)
$(TDS-PRUNE)
texconfig rehash
install-runtimes:
$(eval TDS-DIR=$(TEXMFHOME))
$(TDS-MKDIR)
$(TDS-CP)
$(TDS-PRUNE)
texconfig rehash
uninstall-runtimes:
$(eval TDS-DIR=$(TEXMFHOME))
$(eval cp=$$(intcmp $$(words $$(1)),0,,,\
if [[ -d $$(2) ]] ; then rm -f $$(foreach f,$$(1),$$(2)/$$(notdir $$(f))) ; \
else rm -f $$(2) ; fi \
))
$(TDS-CP)
$(TDS-PRUNE)
texconfig rehash
# $1 = source file, $2 = package name
VERSION-LATEX = $(YEAR)/$(MONTH)/$(DAY) v$(VERSION)
define EDIT-VERSION-LATEX
sed -Ei 's!\\ProvidesPackage\{$(2)\}\[[0-9]{4}/[0-9]{1,2}/[0-9]{1,2} v[-0-9.a-z]* !\\ProvidesPackage{$(2)}[$(VERSION-LATEX) !' $(1)
endef
# $1 = source file
# This assumes that all the \modules in the file have the same date and version.
VERSION-CONTEXT = $(VERSION)
DATE-CONTEXT = $(YEAR)-$(MONTH)-$(DAY)
define EDIT-VERSION-CONTEXT
sed -Ei 's!(%D *version=)[-0-9.a-z]*,!\1$(VERSION-CONTEXT),!;s!(%D *date=)[-0-9]*,!\1$(DATE-CONTEXT),!' $(1)
endef
# $1 = source .pl file, $2 = version
VERSION-PERL = $(YEAR)/$(MONTH)/$(DAY) v$(VERSION)
define EDIT-VERSION-PERL
sed -i "s!^my \$$VERSION = .*!my \$$VERSION = '$(VERSION-PERL)';!" $(1)
endef
# $1 = source .py file, $2 = version
VERSION-PYTHON = $(YEAR)/$(MONTH)/$(DAY) v$(VERSION)
define EDIT-VERSION-PYTHON
sed -i "s!^__version__ = .*!__version__ = '$(VERSION-PYTHON)'!" $(1)
endef
# $1 = source file
VERSION-MAN = $(VERSION)
DATE-MAN = $(shell LANG=en date -d '$(YEAR)-$(MONTH)-$(DAY)' +"%B %d, %Y")
# This assumes that the source filename is file.<N>.md, because it strips away two suffixes.
define EDIT-VERSION-MAN
sed -i '/^date:/c date: $(DATE-MAN)' $(1)
sed -i '/^footer:/c footer: $(basename $(basename $(notdir $(1)))) $(VERSION-MAN)' $(1)
endef
# $1 = source file, $2 = package name
VERSION-PLAIN = $(VERSION-LATEX)
define EDIT-VERSION-PLAIN
sed -Ei 's!^(%<[^\>]*>% Package $(2) ).*!\1$(VERSION-PLAIN)!' $(1)
endef
# Change the date of the latest release (identified by the version) of the package.
define EDIT-DATE-CHANGELOG
sed -Ei 's!^(#+|Manual: Memoize) [0-9]{4}/[0-9]{1,2}/[0-9]{1,2} +v$(VERSION)!\1 $(YEAR)/$(MONTH)/$(DAY) v$(VERSION)!' $(1)
endef