-
Notifications
You must be signed in to change notification settings - Fork 182
/
build.sh
executable file
·92 lines (72 loc) · 2.29 KB
/
build.sh
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
#!/bin/sh
# uses PREFIX and BUILD_MANPAGES from environment
: "${PREFIX:=/usr/local}"
: "${BUILD_MANPAGES:=1}"
set -e
PATH="$PWD/res:$PATH"
if [ -z "$SOURCE_DATE_EPOCH" ]; then
export SOURCE_DATE_EPOCH=$(git log --pretty='%ct' -1)
if [ -z "$SOURCE_DATE_EPOCH" -a "$BUILD_MANPAGES" = 1 ]; then
echo "git or SOURCE_DATE_EPOCH are needed to build man pages!"
exit 1
fi
fi
# Build HTML mdbook
echo "Building mdBook"
mdbook build
if [ "$BUILD_MANPAGES" = "1" ]; then
# Build mandoc version
echo "Building man pages"
cd src
find . -type d -exec mkdir -p "../mandoc/{}" \;
find . -type f -name "*.md" -exec sh -c \
'file="{}"; filew="${file%.md}"; \
man_date="$(git log --pretty=%cs -1 "$file" 2>/dev/null || date -d "@$SOURCE_DATE_EPOCH" +%F)";
lowdown -Tman \
${man_date:+-m "date: $man_date"} \
-m "title: ${filew##*/}" \
-m "section: 7" -m "source: Void Docs" -m "volume: Void Docs" \
-s -o "../mandoc/${filew}.7" "$file"' \;
cd -
fi
# Build script
echo "Building void-docs script and man page"
sed -e "s,@PREFIX@,$PREFIX," res/void-docs.in > res/void-docs
sed -e "s,@PREFIX@,$PREFIX," res/void-docs.1.in > res/void-docs.1
# Build PDF
echo "Building PDF"
## Temporarily add OpenType version of Latin Modern to font cache.
mkdir -p ~/.fonts
TMP_FONTDIR=$(mktemp -d -p ~/.fonts)
cp /usr/share/texmf-dist/fonts/opentype/public/lm/* $TMP_FONTDIR
fc-cache
## Create cover page using Latin Modern text.
rsvg-convert \
--dpi-x 300 \
--dpi-y 300 \
res/handbook-cover.svg > res/handbook-cover.png
## Letter version
pdflatex \
-output-directory=book/latex/ \
-jobname=handbook-letter \
book/latex/handbook.tex \
>/dev/null
pdflatex \
-output-directory=book/latex/ \
-jobname=handbook-letter \
book/latex/handbook.tex \
>/dev/null
## A4 version
sed -ie "s/\\documentclass\[letterpaper\]{article}/\\documentclass[a4paper]{article}/" \
book/latex/handbook.tex
pdflatex -output-directory=book/latex/ \
-jobname=handbook-a4 \
book/latex/handbook.tex \
>/dev/null
pdflatex -output-directory=book/latex/ \
-jobname=handbook-a4 \
book/latex/handbook.tex \
>/dev/null
## Remove temporary font directory
rm -rf $TMP_FONTDIR
fc-cache