forked from pandoc/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
246 lines (224 loc) · 7.42 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
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
PANDOC_VERSION ?= edge
ifeq ($(PANDOC_VERSION),edge)
PANDOC_COMMIT ?= main
else
PANDOC_COMMIT ?= $(PANDOC_VERSION)
endif
# Use Alpine Linux as base stack by default.
STACK ?= alpine
# Used to specify the build context path for Docker. Note that we are
# specifying the repository root so that we can
#
# COPY common/latex/texlive.profile /root
#
# for example. If writing a COPY statement in *ANY* Dockerfile, just know that
# it is from the repository root.
makefile_dir := $(dir $(realpath Makefile))
# The freeze file fixes the versions of Haskell packages used to compile a
# specific version. This enables reproducible builds. The path is
# relative to a distributions base directory.
stack_freeze_file = freeze/pandoc-$(PANDOC_COMMIT).project.freeze
# List of Linux distributions which are supported as image bases.
image_stacks = alpine \
ubuntu \
static
# Keep this target first so that `make` with no arguments will print this rather
# than potentially engaging in expensive builds.
.PHONY: show-args
show-args:
@printf "# Pandoc version to build. Must be either a published version, or \n"
@printf "# the string 'edge' to build from the development version.\n"
@printf "PANDOC_VERSION=%s\n" $(PANDOC_VERSION)
@printf "\n# The pandoc commit used to build the image(s);\n"
@printf "# usually a tag or branch name.\n"
@printf "PANDOC_COMMIT=%s\n" $(PANDOC_COMMIT)
@printf "\n# Linux distribution used as base. List of supported base stacks:\n"
@printf "# %s\n" "$(image_stacks)"
@printf "# May be overwritten by using a stack-specific target.\n"
@printf "STACK=%s\n" $(STACK)
@printf "\n# Controls the number of threads to be used during the build\n"
@printf "process (use all cores when not set)\n"
@printf "CORES=%s\n" $(CORES)
# Calculate docker build options limiting the amount of CPU time that's
# being used.
ifdef CORES
docker_cpu_options=--cpu-period="100000" --cpu-quota="$$(( $(CORES) * 100000 ))"
else
docker_cpu_options=
endif
# Generates the targets for a given image stack.
# $1: base stack, one of the `supported_stacks`
define stack
# Define targets which have the stack in their names, then set the
# `STACK` variable based on the chosen target. This is an alternative to
# setting the `STACK` variable directly and allows for convenient tab
# completion.
.PHONY: $(1) $(1)-minimal $(1)-core $(1)-freeze-file
$(1) $(1)-minimal $(1)-freeze-file: STACK = $(1)
$(1): $(1)-minimal
$(1)-minimal: minimal
$(1)-freeze-file: $(1)/$(stack_freeze_file)
# Only alpine and ubuntu support core and latex images
ifeq ($(1),$(filter $(1),alpine ubuntu))
.PHONY: $(1)-core $(1)-latex $(1)-extra
$(1)-core: core
$(1)-latex: latex
$(1)-extra: extra
endif
# Do the same for test targets, again to allow for tab completion.
.PHONY: test-$(1) test-$(1)-minimal test-$(1)-core test-$(1)-latex test-$(1)-extra
test-$(1) test-$(1)-minimal test-$(1)-core test-$(1)-latex test-$(1)-extra: STACK = $(1)
test-$(1): test-minimal
test-$(1)-minimal: test-minimal
ifeq ($(1),$(filter $(1),alpine ubuntu))
test-$(1)-core: test-core
test-$(1)-latex: test-latex
test-$(1)-extra: test-extra
endif
# And for push targets
.PHONY: push-$(1) push-$(1)-minimal push-$(1)-core push-$(1)-latex push-$(1)-extra
push-$(1) push-$(1)-minimal push-$(1)-core push-$(1)-latex push-$(1)-extra: STACK = $(1)
push-$(1): push-minimal
push-$(1)-minimal: push-minimal
ifeq ($(1),$(filter $(1),alpine ubuntu))
push-$(1)-core: push-core
push-$(1)-latex: push-latex
push-$(1)-extra: push-extra
endif
endef
# Generate convenience targets for all supported stacks.
$(foreach img,$(image_stacks),$(eval $(call stack,$(img))))
export TEXLIVE_MIRROR_URL
# Freeze ################################################################
.PHONY: freeze-file
freeze-file: $(STACK)/$(stack_freeze_file)
%/$(stack_freeze_file): STACK = $*
%/$(stack_freeze_file):
./build.sh build -v \
-r "$(STACK)-builder-base" \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-builder-base" \
$(docker_cpu_options)
docker run --rm \
-v "$(makefile_dir):/app" \
--env WITHOUT_CROSSREF=$(WITHOUT_CROSSREF) \
pandoc/$(STACK)-builder-base:latest-$(STACK) \
sh /app/common/pandoc-freeze.sh \
-c $(PANDOC_COMMIT) \
-u "$(shell id -u):$(shell id -g)" \
-s "$(STACK)" \
-o /app/$@
# Minimal ###############################################################
.PHONY: minimal
minimal: $(STACK)/$(stack_freeze_file)
./build.sh build -v \
-r minimal \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-minimal" \
$(docker_cpu_options)
# Core ##################################################################
.PHONY: core
core: $(STACK)/$(stack_freeze_file)
./build.sh build -v \
-r core \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-core" \
$(docker_cpu_options)
# LaTeX #################################################################
.PHONY: latex
latex: $(STACK)/$(stack_freeze_file)
./build.sh build -v \
-r latex \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-latex" \
$(docker_cpu_options)
# Extra #################################################################
.PHONY: extra
extra: $(STACK)/$(stack_freeze_file)
./build.sh build -v \
-r extra \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-extra" \
$(docker_cpu_options)
# Test ##################################################################
.PHONY: test-core test-extra test-latex test-minimal
test-minimal: IMAGE ?= pandoc/minimal:$(PANDOC_VERSION)-$(STACK)
test-minimal:
IMAGE=$(IMAGE) make -C test test-minimal
test-core: IMAGE ?= pandoc/core:$(PANDOC_VERSION)-$(STACK)
test-core:
test -n "$(WITHOUT_CROSSREF)" || IMAGE=$(IMAGE) make -C test test-core
test-latex: IMAGE ?= pandoc/latex:$(PANDOC_VERSION)-$(STACK)
test-latex:
IMAGE=$(IMAGE) make -C test test-latex
test-extra: IMAGE ?= pandoc/extra:$(PANDOC_VERSION)-$(STACK)
test-extra:
IMAGE=$(IMAGE) make -C test test-extra
########################################################################
# Developer targets #
########################################################################
.PHONY: lint
lint:
shellcheck $(shell find . -name "*.sh")
.PHONY: push-minimal push-core push-latex push-extra
push-minimal: REPO ?= minimal
push-minimal:
./build.sh push -v \
-r $(REPO) \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-minimal"
push-core: REPO ?= core
push-core:
./build.sh push -v \
-r $(REPO) \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-core"
push-latex: REPO ?= latex
push-latex:
./build.sh push -v \
-r $(REPO) \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-latex"
push-extra: REPO ?= extra
push-extra:
./build.sh push -v \
-r $(REPO) \
-s "$(STACK)" \
-c "$(PANDOC_COMMIT)" \
-d "$(makefile_dir)" \
-t "$(STACK)-extra"
.PHONY: docs docs-minimal
docs:
@pandoc "docs/$(REPO).md" \
--lua-filter="docs/filters/transclude.lua" \
--lua-filter="docs/filters/supported-tags.lua" \
--lua-filter="docs/filters/texlive-versions.lua" \
--lua-filter="docs/filters/fix-run.lua" \
--to=commonmark
docs-minimal: REPO = minimal
docs-minimal: docs
docs-core: REPO = core
docs-core: docs
docs-latex: REPO = latex
docs-latex: docs
docs-extra: REPO = extra
docs-extra: docs
.PHONY: clean
clean:
IMAGE=none make -C test clean