-
Notifications
You must be signed in to change notification settings - Fork 21
/
Makefile
174 lines (149 loc) · 5.9 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
# you can override on command line
lang = en
# `make` reminders:
# `make -C <dir>` == change directory to <dir> before `make`-ing
# $@ == the file name of the target of the rule
# $< == the name of the first prerequisite
# $^ == the name of all the prerequisites, with a space between each one
# /linbit-documentation is the WORKDIR in the Dockerfile
# so, `./` in the `define` block below == `linbit-documentation`
# also creates a symbolic link to the `/fonts` directory, where RUN actions
# specified in the Dockerfile will download Japanese and Chinese fonts, when the
# `linbit-documentation` Docker image is built. `ln -s` used rather than `ln -sf`,
# in case a `fonts` dir exists already in someone's local `linbit-documentation` dir.
define run-in-docker =
docker run \
--rm \
--user $$(id -u):$$(id -g) \
--volume $$(pwd):/linbit-documentation \
linbit-documentation \
/bin/sh -c \
'ln -s /fonts ./ && \
make $(patsubst %-docker,%,$@) lang=$(lang); \
unlink ./fonts'
endef
# generate README.html from README.adoc
.PHONY: README.html-docker
README.html: README.adoc
asciidoctor -n -o $@ $<
README.html-docker: dockerimage
$(run-in-docker)
# needed for `make dockerimage` target
define dockerfile=
FROM asciidoctor/docker-asciidoctor:1.77
LABEL maintainers="Roland Kammerer <[email protected]>, Michael Troutman <[email protected]>"
# po4a and related packages needed for documentation translation commands
# zip needed for extracting LINBIT fonts package below
# font-noto-cjk needed for Japanese and Chinese EPUB rendering (one day)
# lftp and openssh-client needed for some GitLab pipeline preview actions
# shadow needed for useradd command
RUN apk update && \
apk add --no-cache \
po4a po4a-lang perl-yaml-tiny perl-unicode-linebreak perl-mime-charset \
make \
patch \
zip \
openssh-client \
lftp \
shadow \
curl \
font-noto-cjk
RUN mkdir -p /fonts/genshingothic-fonts
RUN mkdir -p /fonts/noto-cn
# download and extract LINBIT fonts collection for Japanese translations
RUN curl https://packages.linbit.com/public/genshingothic-20150607.zip --output /tmp/ja.zip && \
unzip /tmp/ja.zip -d /fonts/genshingothic-fonts && rm /tmp/ja.zip
# download Noto Sans CJK fonts for Chinese translations
RUN curl -L https://github.com/googlefonts/noto-cjk/raw/main/Sans/Variable/TTF/NotoSansCJKsc-VF.ttf --output /fonts/noto-cn/NotoSansCJKsc-VF.ttf
RUN curl -L https://github.com/googlefonts/noto-cjk/raw/main/Sans/Variable/TTF/Mono/NotoSansMonoCJKsc-VF.ttf --output /fonts/noto-cn/NotoSansMonoCJKsc-VF.ttf
WORKDIR /linbit-documentation
COPY /GNUmakefile ./
# the `makedoc` user actions below are necessary for docs website staging actions in a GitLab pipeline
RUN useradd -m makedoc
USER makedoc
RUN mkdir /home/makedoc/.ssh && \
chmod 700 /home/makedoc/.ssh && \
ssh-keygen -f /home/makedoc/.ssh/id_rsa -t rsa -N '' && \
cat /home/makedoc/.ssh/id_rsa.pub
endef
export dockerfile
Dockerfile:
@echo "$$dockerfile" > $@
# Quietly check for the existence of a linbit-documentation:latest Docker image and
# build the image if one does not exist already
# Also create a GNUmakefile if it does not exist already
.PHONY: dockerimage
dockerimage: Dockerfile
if ! docker images --format={{.Repository}}:{{.Tag}} | grep -q '^linbit-documentation:latest'; then \
test -f GNUmakefile || echo 'include Makefile' > GNUmakefile ; \
DOCKER_BUILDKIT=1 docker build -t linbit-documentation . ; \
fi
# Create UG 9 (PDF version)
.PHONY: UG9-pdf-finalize UG9-pdf-finalize-docker UG9-html-finalize UG9-html-finalize-docker
UG9-pdf-finalize: UG9-translate
make -C UG9 pdf-finalize lang=$(lang)
UG9-pdf-finalize-docker: UG9-translate-docker
$(run-in-docker)
# Create UG 9 (HTML version)
UG9-html-finalize: UG9-translate
make -C UG9 html-finalize lang=$(lang)
UG9-html-finalize-docker: UG9-translate-docker
$(run-in-docker)
# Create UG 9 translation `pot` and update (or create them if they don't exist) `po` files
# `--force` flag used because some of the `.adoc` files have `include` files (see `po4a --help`)
.PHONY: UG9-pot UG9-pot-docker
UG9-pot:
ifeq (${lang},en)
@echo "Generating .pot and .po files. lang=en, so generating .po files for all languages."
po4a --force --no-translations po4a.cfg
else
@echo Language specified: $(lang)
sed 's/\$$lang/\$$\(lang\)/g' po4a.cfg > /tmp/po4a-tmp.cfg
po4a --force --no-translations --variable lang=$(lang) /tmp/po4a-tmp.cfg
rm /tmp/po4a-tmp.cfg
endif
UG9-pot-docker: dockerimage
$(run-in-docker)
.PHONY: UG9-translate UG9-translate-docker
UG9-translate:
ifeq (${lang},en)
@echo "lang=en, nothing to do."
@echo "HINT: You can use this target to translate English adoc files by specifying lang=xx."
else
@echo Language specified: $(lang)
sed 's/\$$lang/\$$\(lang\)/g' po4a.cfg > /tmp/po4a-tmp.cfg
po4a --force --variable lang=$(lang) /tmp/po4a-tmp.cfg
rm /tmp/po4a-tmp.cfg
make -C UG9/$(lang) patch-drbd-ug
endif
UG9-translate-docker: dockerimage
$(run-in-docker)
# Create UG 8.4 (PDF version)
.PHONY: UG8.4-pdf-finalize UG8.4-pdf-finalize-docker UG8.4-html-finalize UG8.4-html-finalize-docker UG8.4-pot UG8.4-pot-docker
UG8.4-pdf-finalize:
make -C UG8.4 pdf-finalize lang=$(lang)
UG8.4-pdf-finalize-docker: dockerimage
$(run-in-docker)
# Create UG 8.4 (HTML version)
UG8.4-html-finalize:
make -C UG8.4 html-finalize lang=$(lang)
UG8.4-html-finalize-docker: dockerimage
$(run-in-docker)
# Create UG 8.4 translation `pot` files
UG8.4-pot:
make -C UG8.4 pot lang=en
UG8.4-pot-docker: dockerimage
$(run-in-docker)
## targets you can only use if you cloned the *private* `tech-guides` project
# create PDF tech guides
.PHONY: tech-guides-pdf-finalize tech-guides-pdf-finalize-docker
tech-guides-pdf-finalize:
make -C tech-guides pdf-finalize
tech-guides-pdf-finalize-docker: dockerimage
$(run-in-docker)
.PHONY: clean clean-all
clean:
$(warning this target is reserved, maybe you're looking for clean-all)
clean-all:
make -C UG8.4 clean-all
make -C UG9 clean-all