blob: fc1baaaef78c20d260c4cf9e519498362ff43fd0 (
plain)
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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
|
#!/bin/bash
SRCDIR=$(dirname "${BASH_SOURCE[0]}")
BUILD_DIR=$SRCDIR/build
if [[ "${BUILD_DIR:0:2}" == "./" ]]; then
BUILD_DIR=${BUILD_DIR:2}
fi
# DIST_DIR=$BUILD_DIR/fonts/
DIST_DIR_TOK='$(FONTDIR)/'
BUILD_TMP_DIR=$BUILD_DIR/tmp
VENV_DIR=$BUILD_DIR/venv
if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then
# sourced
if [[ -z $VIRTUAL_ENV ]] && [[ ! -f "$VENV_DIR/bin/activate" ]]; then
echo "Project not configured." >&2
echo "Execute this script instead of sourcing it to perform setup." >&2
else
source "$VENV_DIR/bin/activate"
pushd "$SRCDIR" >/dev/null
SRCDIR_ABS=$(pwd)
popd >/dev/null
export PYTHONPATH=$SRCDIR_ABS/misc/tools
fi
else
# Subshell
set -e
cd "$SRCDIR"
if [[ "$1" == "-h" ]] || [[ "$1" == "-help" ]] || [[ "$1" == "--help" ]]; then
echo "usage: $0 [options]" >&2
echo "options:" >&2
echo " -clean Start from scratch" >&2
exit 1
fi
clean=false
if [[ "$1" == "-clean" ]]; then
clean=true
fi
platform=osx
UNAME=$(uname)
if [[ "$UNAME" == *"inux"* ]]; then
platform=linux
elif [[ "$UNAME" != *"arwin"* ]]; then
echo "Unsupported platform $UNAME (only macOS and Linux are supported)" >&2
exit 1
fi
# ——————————————————————————————————————————————————————————————————
# virtualenv
mkdir -p "$VENV_DIR"
pushd "$(dirname "$VENV_DIR")" >/dev/null
VENV_DIR_ABS=$(pwd)/$(basename "$VENV_DIR")
popd >/dev/null
# must check and set VENV_ACTIVE before polluting local env
VENV_ACTIVE=false
if [[ "$VIRTUAL_ENV" == "$VENV_DIR_ABS" ]] && [[ "$1" != "-force" ]]; then
VENV_ACTIVE=true
fi
require_virtualenv() {
# find pip3 (Python 3)
export pip=$(which pip3)
if [ "$pip" = "" ]; then
export pip=$(which pip)
if [ "$pip" = "" ]; then
echo "pip not found in PATH -- please install Python 3" >&2
exit 1
fi
fi
echo "using $("$pip" --version)"
if [ "$pip" = "" ]; then
echo "Pip for Python 3 not found (tried pip and pip3 in PATH)" >&2
exit 1
elif ! ($pip --version 2>&1 | grep -q 'ython 3'); then
echo "Pip for Python 3 not found (found pip for different python version)" >&2
exit 1
fi
# find virtualenv
if ! ($pip show virtualenv >/dev/null); then
echo "$0: Can't find virtualenv -- install through '$pip install --user virtualenv'" >&2
exit 1
fi
virtualenv_pkgdir=$($pip show virtualenv | grep Location | cut -d ' ' -f 2)
export virtualenv="$(dirname "$(dirname "$(dirname "$virtualenv_pkgdir")")")/bin/virtualenv"
echo "using virtualenv: $virtualenv"
}
# TODO: allow setting a flag to recreate venv
if $clean; then
rm -rf "$VENV_DIR"
fi
if [[ ! -d "$VENV_DIR/bin" ]]; then
require_virtualenv
echo "Setting up virtualenv in '$VENV_DIR'"
rm -f "$VENV_DIR/lib/python"
$virtualenv "$VENV_DIR"
elif [[ ! -z $VIRTUAL_ENV ]] && [[ "$VIRTUAL_ENV" != "$VENV_DIR_ABS" ]]; then
echo "Looks like the repository has moved location -- updating virtualenv"
rm -f "$VENV_DIR/lib/python"
require_virtualenv
$virtualenv "$VENV_DIR"
fi
# symlink lib/python -> lib/python<version>
if [[ ! -d "$VENV_DIR/lib/python" ]]; then
for f in "$VENV_DIR/lib/"python*; do
if [[ -d "$f" ]]; then
ln -svf $(basename "$f") "$VENV_DIR/lib/python"
break
fi
done
fi
# ——————————————————————————————————————————————————————————————————
# python dependencies
# install if deps changed
REQUIREMENTS_FILE=$SRCDIR/requirements.txt
UPDATE_TIMESTAMP_FILE="$VENV_DIR/last-pip-run.mark"
if [ "$REQUIREMENTS_FILE" -nt "$UPDATE_TIMESTAMP_FILE" ]; then
echo "$VENV_DIR/bin/pip install -r $REQUIREMENTS_FILE"
"$VENV_DIR/bin/pip" install -r "$REQUIREMENTS_FILE"
date '+%s' > "$UPDATE_TIMESTAMP_FILE"
fi
# ——————————————————————————————————————————————————————————————————
# activate env (for rest of this script)
source "$VENV_DIR/bin/activate"
# ——————————————————————————————————————————————————————————————————
# other toolchain dependencies
DEPS_DIR=$BUILD_DIR/deps
PATCH_DIR=$(pwd)/misc/patches
mkdir -p "$DEPS_DIR"
function fetch() {
URL=$1
DSTFILE=$2
echo "Fetching $URL"
curl '-#' -o "$DSTFILE" -L "$URL"
}
function check_dep() {
NAME=$1
REPO_URL=$2
BRANCH=$3
TREE_REF=$4
set -e
REPODIR=$DEPS_DIR/$NAME
CHANGED=false
if [[ ! -d "$REPODIR/.git" ]]; then
rm -rf "$REPODIR"
echo "Fetching $NAME from $REPO_URL"
if ! (git clone --recursive --single-branch -b $BRANCH -- "$REPO_URL" "$REPODIR"); then
exit 1
fi
CHANGED=true
elif [[ "$(git -C "$REPODIR" rev-parse HEAD)" != "$TREE_REF" ]]; then
CHANGED=true
git -C "$REPODIR" fetch origin
fi
if $CHANGED; then
if [[ ! -z $TREE_REF ]]; then
git -C "$REPODIR" checkout "$TREE_REF"
git -C "$REPODIR" submodule update
fi
return 1
fi
return 0
}
# woff2
LINK=false
if ! (check_dep woff2 \
https://github.com/google/woff2.git master \
a0d0ed7da27b708c0a4e96ad7a998bddc933c06e )
then
echo "Building woff2"
make -C "$DEPS_DIR/woff2" -j8 clean
if !(make -C "$DEPS_DIR/woff2" -j8 all); then
rm -rf "$DEPS_DIR/woff2"
exit 1
fi
LINK=true
elif [[ ! -f "$VENV_DIR/bin/woff2_compress" ]]; then
LINK=true
fi
if $LINK; then
ln -vfs ../../deps/woff2/woff2_compress "$VENV_DIR/bin/woff2_compress"
fi
# # EOT (disabled)
# if ! (check_dep \
# ttf2eot https://github.com/rsms/ttf2eot.git master )
# then
# echo "Building ttf2eot"
# make -C "$DEPS_DIR/ttf2eot" clean all
# fi
# if [[ ! -f "$VENV_DIR/bin/ttf2eot" ]]; then
# ln -vfs ../../deps/ttf2eot/ttf2eot "$VENV_DIR/bin"
# fi
# # meson (internal requirement of ots)
# MESON_VERSION=0.47.2
# pushd "$DEPS_DIR" >/dev/null
# MESON_BIN=$PWD/meson-${MESON_VERSION}/meson.py
# popd >/dev/null
# if [[ ! -f "$MESON_BIN" ]]; then
# fetch \
# https://github.com/mesonbuild/meson/releases/download/${MESON_VERSION}/meson-${MESON_VERSION}.tar.gz \
# "$DEPS_DIR/meson.tar.gz"
# tar -C "$DEPS_DIR" -xzf "$DEPS_DIR/meson.tar.gz"
# rm "$DEPS_DIR/meson.tar.gz"
# fi
# # ninja
# NINJA_VERSION=1.8.2
# pushd "$DEPS_DIR" >/dev/null
# NINJA_BIN=$PWD/ninja-${NINJA_VERSION}
# if [[ ! -f "$NINJA_BIN" ]]; then
# fetch \
# https://github.com/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-mac.zip \
# ninja.zip
# rm -f ninja
# unzip -q -o ninja.zip
# rm ninja.zip
# mv ninja "$NINJA_BIN"
# fi
# popd >/dev/null
# # ots (from source)
# LINK=false
# if ! (check_dep ots \
# https://github.com/khaledhosny/ots.git master \
# cad0b4f9405d03ddf801f977f2f65892192ad047 )
# then
# echo "Building ots"
# pushd "$DEPS_DIR/ots" >/dev/null
# "$MESON_BIN" build
# "$NINJA_BIN" -C build
# popd >/dev/null
# fi
# ots (from dist)
OTS_VERSION=7.1.7
OTS_DIR=$DEPS_DIR/ots-${OTS_VERSION}
LINK=false
if [[ ! -f "$OTS_DIR/ots-sanitize" ]]; then
mkdir -p "$OTS_DIR"
fetch \
https://github.com/khaledhosny/ots/releases/download/v${OTS_VERSION}/ots-${OTS_VERSION}-${platform}.zip \
"$OTS_DIR/ots.zip"
pushd "$OTS_DIR" >/dev/null
unzip ots.zip
rm ots.zip
mv ots-* xx-ots
mv xx-ots/* .
rm -rf xx-ots
popd >/dev/null
LINK=true
fi
if $LINK || [[ ! -f "$VENV_DIR/bin/ots-sanitize" ]]; then
pushd "$OTS_DIR" >/dev/null
for f in ots-*; do
popd >/dev/null
ln -vfs ../../deps/ots-${OTS_VERSION}/$f "$VENV_DIR/bin/$f"
pushd "$OTS_DIR" >/dev/null
done
popd >/dev/null
fi
AUTOHINT_VERSION=1.8.2
AUTOHINT_SRC_VERSION=1.8.2.8
LINK=false
if [[ ! -f "$DEPS_DIR/ttfautohint-${AUTOHINT_VERSION}" ]]; then
if [[ "$platform" == "osx" ]]; then
fetch \
https://download.savannah.gnu.org/releases/freetype/ttfautohint-${AUTOHINT_VERSION}-tty-osx.tar.gz \
"$DEPS_DIR/ttfautohint.tar.gz"
tar -C "$DEPS_DIR" -xzf "$DEPS_DIR/ttfautohint.tar.gz"
rm "$DEPS_DIR/ttfautohint.tar.gz"
mv -f "$DEPS_DIR/ttfautohint" "$DEPS_DIR/ttfautohint-${AUTOHINT_VERSION}"
else
fetch \
https://github.com/source-foundry/ttfautohint-build/archive/v${AUTOHINT_SRC_VERSION}.tar.gz \
"$DEPS_DIR/ttfautohint-build.tar.gz"
pushd "$DEPS_DIR" >/dev/null
tar -xzf ttfautohint-build.tar.gz
rm ttfautohint-build.tar.gz
rm -rf ttfautohint-build
mv -f ttfautohint*/ ./ttfautohint-build
pushd ttfautohint-build >/dev/null
./ttfautohint-build.sh
popd >/dev/null
mv -f \
/root/ttfautohint-build/ttfautohint*/frontend/ttfautohint \
"ttfautohint-${AUTOHINT_VERSION}"
rm -rf /root/ttfautohint-build ttfautohint-build
popd >/dev/null
fi
LINK=true
elif [[ ! -f "$VENV_DIR/bin/ttfautohint" ]]; then
LINK=true
fi
if $LINK; then
ln -vfs ../../deps/ttfautohint-${AUTOHINT_VERSION} "$VENV_DIR/bin/ttfautohint"
fi
if [[ ! -f "$VENV_DIR/bin/ttf2woff" ]] || [[ ! -f "$SRCDIR/misc/ttf2woff/ttf2woff" ]]; then
echo "Building ttf2woff"
make -C "$SRCDIR/misc/ttf2woff" -j8
fi
if [[ ! -f "$VENV_DIR/bin/ttf2woff" ]]; then
ln -vfs ../../../misc/ttf2woff/ttf2woff "$VENV_DIR/bin"
fi
has_newer() {
DIR=$1
REF_FILE=$2
for f in $(find "$DIR" -type f -newer "$REF_FILE" -print -quit); do
return 0
done
return 1
}
# ————————————————————————————————————————————————————————————————————————————————————————————————
# $BUILD_DIR/etc/generated.make
master_styles=( \
Thin \
ThinItalic \
Regular \
Italic \
Black \
BlackItalic \
)
derived_styles=( \
"Light : Thin Regular" \
"LightItalic : ThinItalic Italic" \
"ExtraLight : Thin Regular" \
"ExtraLightItalic : ThinItalic Italic" \
"Medium : Regular Black" \
"MediumItalic : Italic BlackItalic" \
"SemiBold : Regular Black" \
"SemiBoldItalic : Italic BlackItalic" \
"Bold : Regular Black" \
"BoldItalic : Italic BlackItalic" \
"ExtraBold : Regular Black" \
"ExtraBoldItalic : Italic BlackItalic" \
)
web_formats=( woff woff2 ) # Disabled/unused: eot
mkdir -p "$BUILD_DIR/etc"
GEN_MAKE_FILE=$BUILD_DIR/etc/generated.make
# Only generate if there are changes to the font sources or init.sh
NEED_GENERATE=false
if $clean || [[ ! -f "$GEN_MAKE_FILE" ]] || [[ "$0" -nt "$GEN_MAKE_FILE" ]]; then
NEED_GENERATE=true
else
for style in "${master_styles[@]}"; do
if $NEED_GENERATE; then
break
fi
if has_newer "src/Inter-${style}.ufo" "$GEN_MAKE_FILE"; then
NEED_GENERATE=true
fi
done
fi
if $NEED_GENERATE; then
echo "Generating '$GEN_MAKE_FILE'"
echo "# Generated by init.sh -- do not modify manually" > "$GEN_MAKE_FILE"
all_styles=()
# add master styles to style array
for style in "${master_styles[@]}"; do
all_styles+=( $style )
echo -n "${style}_ufo_d := \$(wildcard" >> "$GEN_MAKE_FILE"
echo -n " src/Inter-${style}.ufo/*.plist" >> "$GEN_MAKE_FILE"
echo -n " src/Inter-${style}.ufo/*.fea" >> "$GEN_MAKE_FILE"
echo -n " src/Inter-${style}.ufo/glyphs/*.plist" >> "$GEN_MAKE_FILE"
echo -n " src/features/*" >> "$GEN_MAKE_FILE"
# echo -n " src/Inter-${style}.ufo/glyphs/*.glif" >> "$GEN_MAKE_FILE"
echo -n ")" >> "$GEN_MAKE_FILE"
echo " src/Inter.designspace" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# master OTF and TTF rules
for style in "${master_styles[@]}"; do
echo "${DIST_DIR_TOK}const/Inter-${style}.otf: \$(${style}_ufo_d) version.txt" >> "$GEN_MAKE_FILE"
echo -e "\tmisc/fontbuild compile -o \$@ \$(FONTBUILD_FLAGS) src/Inter-${style}.ufo" >> "$GEN_MAKE_FILE"
echo "${DIST_DIR_TOK}const/Inter-${style}.ttf: \$(${style}_ufo_d) version.txt" >> "$GEN_MAKE_FILE"
echo -e "\tmisc/fontbuild compile -o \$@ \$(FONTBUILD_FLAGS) src/Inter-${style}.ufo" >> "$GEN_MAKE_FILE"
echo "" >> "$GEN_MAKE_FILE"
done
# generate all_ufo: <master_ufos>
# echo -n "all_ufo:" >> "$GEN_MAKE_FILE"
# for style in "${master_styles[@]}"; do
# echo -n " \$(${style}_ufo_d)" >> "$GEN_MAKE_FILE"
# done
# echo "" >> "$GEN_MAKE_FILE"
# add derived styles to style array
for e in "${derived_styles[@]}"; do
style=$(echo "${e%%:*}" | xargs)
dependent_styles=$(echo "${e#*:}" | xargs)
all_styles+=( $style )
done
# STYLE and STYLE_ttf targets
for style in "${all_styles[@]}"; do
echo "${style}: ${style}_otf ${style}_ttf ${style}_ttf_hinted ${style}_web ${style}_web_hinted" >> "$GEN_MAKE_FILE"
echo "${style}_ttf_hinted: ${DIST_DIR_TOK}const-hinted/Inter-${style}.ttf" >> "$GEN_MAKE_FILE"
echo "${style}_ttf: ${DIST_DIR_TOK}const/Inter-${style}.ttf" >> "$GEN_MAKE_FILE"
echo "${style}_otf: ${DIST_DIR_TOK}const/Inter-${style}.otf" >> "$GEN_MAKE_FILE"
echo -n "${style}_web:" >> "$GEN_MAKE_FILE"
for format in "${web_formats[@]}"; do
echo -n " ${DIST_DIR_TOK}const/Inter-${style}.${format}" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
echo -n "${style}_web_hinted:" >> "$GEN_MAKE_FILE"
for format in "${web_formats[@]}"; do
echo -n " ${DIST_DIR_TOK}const-hinted/Inter-${style}.${format}" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
echo "${style}_check: ${DIST_DIR_TOK}const/Inter-${style}.otf ${DIST_DIR_TOK}const/Inter-${style}.ttf" >> "$GEN_MAKE_FILE"
echo -e "\tmisc/fontbuild checkfont $^" >> "$GEN_MAKE_FILE"
echo "" >> "$GEN_MAKE_FILE"
done
# all_otf target
echo -n "all_otf:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " ${style}_otf" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_ttf target
echo -n "all_ttf:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " ${style}_ttf" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_ttf_hinted target
echo -n "all_ttf_hinted:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " ${style}_ttf_hinted" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_web target
echo -n "all_web:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " ${style}_web" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_web_hinted target
echo -n "all_web_hinted:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " ${style}_web_hinted" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_check_const target
echo -n "all_check_const:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " ${style}_check" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_samples_pdf target
echo -n "all_samples_pdf:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " \$(FONTDIR)/samples/Inter-${style}.pdf" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_samples_png target
echo -n "all_samples_png:" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " \$(FONTDIR)/samples/Inter-${style}.png" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
# all_const_fonts target
# echo -n "all_const_fonts:" >> "$GEN_MAKE_FILE"
# for style in "${all_styles[@]}"; do
# echo -n " ${style}" >> "$GEN_MAKE_FILE"
# done
# echo "" >> "$GEN_MAKE_FILE"
echo -n ".PHONY: all_otf all_ttf_hinted all_ttf all_web all_web_hinted all_ufo all_check_const" >> "$GEN_MAKE_FILE"
for style in "${all_styles[@]}"; do
echo -n " ${style} ${style}_ttf ${style}_ttf_hinted ${style}_otf ${style}_check" >> "$GEN_MAKE_FILE"
done
echo "" >> "$GEN_MAKE_FILE"
fi
# # ————————————————————————————————————————————————————————————————
# # summary
# if ! $VENV_ACTIVE; then
# echo -n "You can activate virtualenv by running "
# if [ "$0" == "./init.sh" ]; then
# # pretty format for common case
# echo '`source init.sh`'
# else
# echo "\`source \"$0\"\`"
# fi
# fi
fi
|