-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.www.mk
290 lines (271 loc) · 9.54 KB
/
build.www.mk
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#
# Copyright (c) 2001-2020 Julien Nadeau Carriere <[email protected]>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistribution of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistribution in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Process a set of HTML source files (m4 + mlproc). ${HTML} targets can be
# .css, .html (single page) and .html.var (multiple languages / charsets).
#
M4?= m4
M4FLAGS?=
MLPROC?= mlproc
MLPROCFLAGS?=
PERL?= perl
ICONV?= iconv
BASEDIR?= ${TOP}/m4
TEMPLATE?= simple
LANGUAGES?= en fr
DEF_LANGUAGE?= en
MKDEPS= build.www.mk build.subdir.mk build.common.mk
CLEANFILES?=
HTMLDIR?= none
HTML?=
HTML_EXTRA?=
JS?=
CSS?=
CSS_TEMPLATE?=style
HTML_OVERWRITE?=No
HTML_INSTSOURCE?=Yes
MINIFIER?= cat
MINIFIERFLAGS?=
MINIFIERFLAGSCSS?=
#DTD?= <!DOCTYPE html>
#DTD?= <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" \
# "http://www.w3.org/TR/html4/loose.dtd">
all: ${HTML} ${CSS} all-subdir
clean: clean-www clean-subdir
cleandir: clean-www cleandir-www clean-subdir cleandir-subdir
install: all install-www install-subdir
deinstall: deinstall-www deinstall-subdir
regress: regress-subdir
depend: depend-www depend-subdir
.SUFFIXES: .html.var .html .htm .jpg .jpeg .png .gif .m4 .css .css-in
.css-in.css: ${BASEDIR}/${CSS_TEMPLATE}.m4
@cp -f $< ${BASEDIR}/base.css
@echo -n "$@:"
${M4} ${M4FLAGS} -D__BASE_DIR=${BASEDIR} -D__FILE=$@ \
${BASEDIR}/${CSS_TEMPLATE}.m4 | \
${MINIFIER} ${MINIFIERFLAGSCSS} > $@
@rm -f ${BASEDIR}/base.css
.htm.html: ${BASEDIR}/${TEMPLATE}.m4
@cp -f $< ${BASEDIR}/base.htm
@echo "${M4} $< | ${MLPROC} -H ${MLPROCFLAGS} -l ${DEF_LANGUAGE} > $@"
@export out="[email protected]"; \
${M4} ${M4FLAGS} -D__BASE_DIR=${BASEDIR} -D__FILE=$@ \
-D__TEMPLATE=${TEMPLATE} -D__LANG=${DEF_LANGUAGE} \
${BASEDIR}/${TEMPLATE}.m4 | \
${MINIFIER} ${MINIFIERFLAGS} > "$$out"; \
echo '' > $@; \
${MLPROC} -H ${MLPROCFLAGS} -l ${DEF_LANGUAGE} "$$out" \
|${MINIFIER} ${MINIFIERFLAGS} >> $@ 2>/dev/null; \
rm -f "$$out" ${BASEDIR}/base.htm
.htm.html.var: ${BASEDIR}/${TEMPLATE}.m4
@cp -f $< ${BASEDIR}/base.htm
@export base="`echo $@ | sed s/\.var//`"; \
echo -n "$$base:"; \
echo > $@; \
for L in ${LANGUAGES}; do \
export out=".$base.$$L.tmp"; \
echo -n " $$L"; \
${M4} ${M4FLAGS} -D__BASE_DIR=${BASEDIR} -D__FILE=$$base \
-D__TEMPLATE=${TEMPLATE} -D__LANG=$$L \
${BASEDIR}/${TEMPLATE}.m4 | ${MINIFIER} ${MINIFIERFLAGS} > $$out; \
echo '' > $$base.$$L; \
${MLPROC} -H ${MLPROCFLAGS} -l $$L $$out \
| ${MINIFIER} ${MINIFIERFLAGS} >> $$base.$$L; \
rm -f $$out; \
echo "Content-Type: text/html; charset=UTF-8" >> $@; \
echo "Content-Language: $$L" >> $@; \
echo "URI: $$base.$$L" >> $@; \
echo "" >> $@; \
done; \
rm -f ${BASEDIR}/base.htm; \
echo "."
clean-www:
@echo -n "Clean:"
@for F in ${HTML}; do \
if [ "`echo $$F | sed s/\.var//`" != "$$F" ]; then \
export base="`echo $$F | sed s/\.var//`"; \
echo -n " $$base"; \
for L in ${LANGUAGES}; do \
rm -f $$base.$$L; \
done; \
rm -f $$F; \
else \
echo -n " $$F"; \
fi; \
done
@if [ "${CLEANFILES}" != "" ]; then \
echo " ${CLEANFILES}"; \
rm -f ${CLEANFILES}; \
fi
@echo "."
cleandir-www:
echo -n >.depend
install-www-makefile:
@export out=.Makefile.out; \
echo "# Generated by <build.www.mk> install on `date`" > $$out; \
echo "TOP=." >> $$out; \
echo "HTMLDIR=none" >> $$out; \
echo "BASEDIR=m4" >> $$out; \
echo "HTML=${HTML}" >> $$out; \
echo "CSS=${CSS}" >> $$out; \
echo "MLPROC=${MLPROC}" >> $$out; \
echo "MLPROCFLAGS=${MLPROCFLAGS}" >> $$out; \
echo "M4=${M4}" >> $$out; \
echo "PERL=${PERL}" >> $$out; \
echo "ICONV=${ICONV}" >> $$out; \
echo "MINIFIER=${MINIFIER}" >> $$out; \
echo "MINIFIERFLAGS=${MINIFIERFLAGS}" >> $$out; \
echo "MINIFIERFLAGSCSS=${MINIFIERFLAGSCSS}" >> $$out; \
echo "TEMPLATE=${TEMPLATE}" >> $$out; \
echo "CSS_TEMPLATE=${CSS_TEMPLATE}" >> $$out; \
echo "LANGUAGES=${LANGUAGES}" >> $$out; \
echo "DEF_LANGUAGE=${DEF_LANGUAGE}" >> $$out; \
echo "include mk/build.www.mk" >> $$out; \
echo "${INSTALL_DATA} $$out ${HTMLDIR}/Makefile"; \
${SUDO} ${INSTALL_DATA} $$out ${DESTDIR}${HTMLDIR}/Makefile; \
rm -f $$out
install-www-source:
@if [ -e "${DESTDIR}${HTMLDIR}/$$SRCFILE" \
-a "${HTML_OVERWRITE}" = "" ]; then \
echo "${HTMLDIR}/$$SRCFILE exists; preserving"; \
else \
echo "${INSTALL_DATA} $$SRCFILE ${HTMLDIR}"; \
${SUDO} ${INSTALL_DATA} $$SRCFILE ${DESTDIR}${HTMLDIR}; \
fi
@if [ -e "${DESTDIR}${HTMLDIR}/Makefile" \
-a "${HTML_OVERWRITE}" = "" ]; then \
echo "${HTMLDIR}/Makefile exists; preserving"; \
else
${MAKE} install-www-makefile; \
fi
install-www-base:
@if [ ! -d "${DESTDIR}${HTMLDIR}/mk" ]; then \
echo "${INSTALL_DATA_DIR} ${HTMLDIR}/mk"; \
${SUDO} ${INSTALL_DATA_DIR} ${DESTDIR}${HTMLDIR}/mk; \
fi
@for MK in ${MKDEPS}; do \
echo "${INSTALL_DATA} ${TOP}/mk/$$MK ${HTMLDIR}/mk"; \
${SUDO} ${INSTALL_DATA} ${TOP}/mk/$$MK ${DESTDIR}${HTMLDIR}/mk; \
done
@if [ ! -d "${DESTDIR}${HTMLDIR}/m4" ]; then \
echo "${INSTALL_DATA_DIR} ${HTMLDIR}/m4"; \
${SUDO} ${INSTALL_DATA_DIR} ${DESTDIR}${HTMLDIR}/m4; \
fi
@(cd ${BASEDIR}; for M4IN in `ls -1 *.m4`; do \
if [ -e "${DESTDIR}${HTMLDIR}/m4/$$M4IN" \
-a "${HTML_OVERWRITE}" = "" ]; then \
echo "m4/$$M4IN: exists; preserving"; \
else \
echo "${INSTALL_DATA} $$M4IN ${HTMLDIR}/m4"; \
${SUDO} ${INSTALL_DATA} $$M4IN ${DESTDIR}${HTMLDIR}/m4; \
fi; \
done)
install-www:
@if [ "${HTMLDIR}" = "none" ]; then \
exit 0; \
fi
@if [ "${DESTDIR}" != "" ]; then \
echo "# Installing under DESTDIR=${DESTDIR}:"; \
if [ ! -e "${DESTDIR}" ]; then \
echo "${INSTALL_DESTDIR} ${DESTDIR}"; \
${SUDO} ${INSTALL_DESTDIR} ${DESTDIR}; \
fi; \
fi
@if [ ! -d "${DESTDIR}${HTMLDIR}" ]; then \
echo "${INSTALL_DATA_DIR} ${HTMLDIR}"; \
${SUDO} ${INSTALL_DATA_DIR} ${DESTDIR}${HTMLDIR}; \
fi
@if [ "${HTML_INSTSOURCE}" = "Yes" ]; then \
${MAKE} install-www-base; \
fi
@for F in ${HTML}; do \
export base="`echo $$F | sed s/\.var//`"; \
if [ "${HTML_INSTSOURCE}" = "Yes" ]; then \
${MAKE} install-www-source \
SRCFILE="`echo $$base |sed s,.html$$,.htm,`"; \
fi; \
if [ -e "${DESTDIR}${HTMLDIR}/$$F" \
-a "${HTML_OVERWRITE}" = "" ]; then \
echo "$$F exists; preserving"; \
else \
echo "${INSTALL_DATA} $$F ${HTMLDIR}"; \
${SUDO} ${INSTALL_DATA} $$F ${DESTDIR}${HTMLDIR}; \
fi; \
for L in ${LANGUAGES}; do \
if [ -e "${DESTDIR}${HTMLDIR}/$$base.$$L" \
-a "${HTML_OVERWRITE}" = "" ]; then \
echo "$$base.$$L exists; preserving"; \
else \
echo "${INSTALL_DATA} $$base.$$L ${HTMLDIR}"; \
${SUDO} ${INSTALL_DATA} $$base.$$L ${DESTDIR}${HTMLDIR}; \
fi; \
done; \
done
@for F in ${HTML_EXTRA}; do \
echo "${INSTALL_DATA} $$F ${HTMLDIR}"; \
${SUDO} ${INSTALL_DATA} $$F ${DESTDIR}${HTMLDIR}; \
done
@for F in ${JS}; do \
export base="`echo $$F | sed s/\.js//`"; \
echo "${MLPROC} ${MLPROCFLAGS} -l ${DEF_LANGUAGE} -o ${HTMLDIR}/$$F $$F"; \
${MLPROC} ${MLPROCFLAGS} -l ${DEF_LANGUAGE} -o ${HTMLDIR}/$$F $$F; \
for L in ${LANGUAGES}; do \
echo "${MLPROC} ${MLPROCFLAGS} -l $$L -o ${HTMLDIR}/$$base.$$L.js $$F"; \
${MLPROC} ${MLPROCFLAGS} -l $$L -o ${HTMLDIR}/$$base.$$L.js $$F; \
done; \
done
deinstall-www:
@for F in ${HTML}; do \
export base="`echo $$F | sed s/\.var//`"; \
echo "${DEINSTALL_DATA} ${HTMLDIR}/$$base"; \
${SUDO} ${DEINSTALL_DATA} ${DESTDIR}${HTMLDIR}/$$base; \
for L in ${LANGUAGES}; do \
echo "${DEINSTALL_DATA} ${HTMLDIR}/$$base.$$L"; \
${SUDO} ${DEINSTALL_DATA} ${DESTDIR}${HTMLDIR}/$$base.$$L; \
done; \
done
@for F in ${JS}; do \
export base="`echo $$F | sed s/\.js//`"; \
for L in ${LANGUAGES}; do \
echo "${DEINSTALL_DATA} ${DATADIR}/$$base.$$L.js"; \
${SUDO} ${DEINSTALL_DATA} ${DESTDIR}${HTMLDIR}/$$base.$$L.js; \
done; \
echo "${DEINSTALL_DATA} ${DATADIR}/$$F.js"; \
${SUDO} ${DEINSTALL_DATA} ${DESTDIR}${HTMLDIR}/$$F.js; \
done
@echo "${DEINSTALL_DATA_DIR} ${HTMLDIR}"; \
@${SUDO} ${DEINSTALL_DATA_DIR} ${DESTDIR}${HTMLDIR}; \
depend-www:
@files="${HTML}"; \
if [ "$$files" != "" -a "$$files" != "none" ]; then \
echo "${PERL} ${TOP}/mk/gen-wwwdepend.pl $$files"; \
env M4=${M4} BASEDIR=${BASEDIR} TEMPLATE=${TEMPLATE} \
CSS_TEMPLATE=${CSS_TEMPLATE} \
${PERL} ${TOP}/mk/gen-wwwdepend.pl $$files > .depend; \
fi
.PHONY: install deinstall clean cleandir regress depend depend-www clean-www
.PHONY: install-www install-www-makefile install-www-source install-www-base
.PHONY: cleandir-www deinstall-www
include ${TOP}/mk/build.common.mk
include ${TOP}/mk/build.subdir.mk
include .depend