/
compile.sh
executable file
·99 lines (80 loc) · 2.36 KB
/
compile.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
93
94
95
96
97
98
99
#!/usr/bin/env bash
# This script is meant for the EnterprisePharo book. You can use it for other projects
# Exit immediately if a command exits with a non-zero status
set -e
LATEX_COMPILER="pdflatex"
# LATEX_COMPILER="lualatex"
PILLAR_COMMAND="./pillar"
if hash "pillar" 2>/dev/null; then
PILLAR_COMMAND="pillar"
fi
function pillar_all() {
$PILLAR_COMMAND export --to='LaTeX whole book'
$PILLAR_COMMAND export --to='LaTeX by chapter'
$PILLAR_COMMAND export --to='HTML by chapter'
$PILLAR_COMMAND export --to='Markdown by chapter'
}
function pillar_one() {
input="$1"
$PILLAR_COMMAND export --to='LaTeX by chapter' "$input"
$PILLAR_COMMAND export --to='HTML by chapter' "$input"
$PILLAR_COMMAND export --to='Markdown by chapter' "$input"
}
function mypdflatex() {
pillar_file="$1"
echo "Compiling PDF from $pillar_file..."
${LATEX_COMPILER} -halt-on-error -file-line-error -interaction batchmode "$pillar_file" 2>&1 1>/dev/null
ret=$?
if [[ $ret -ne 0 ]]; then
cat $pillar_file.log
echo "Can't generate the PDF!"
exit 1
fi
}
function produce_pdf() {
dir="$1"
pillar_file="$2"
cd "$dir" # e.g., cd Zinc/
mypdflatex "$pillar_file" && mypdflatex "$pillar_file"
cd ..
}
function compile_chapters() {
chapters=$($PILLAR_COMMAND show inputFiles 2>/dev/null)
for chapter in $chapters; do
echo =========================================================
echo COMPILING $chapter
echo =========================================================
# e.g., chapter = Zinc/Zinc.pillar
pillar_file=$(basename $chapter) # e.g., Zinc.pillar
dir=$(dirname $chapter) # e.g., Zinc
produce_pdf "${dir}" "${pillar_file}"
done
}
function compile_latex_book() {
echo =========================================================
echo COMPILING Book
echo =========================================================
cd book-result
produce_pdf . Book
}
function latex_enabled() {
hash ${LATEX_COMPILER} 2>/dev/null
}
if [[ $# -eq 1 ]]; then
echo "Generating files based on $1"
dir=$(dirname "$1") # e.g., Zinc
pillar_file=$(basename "$1") # e.g., Zinc.pillar
pillar_one "$1"
if latex_enabled; then
produce_pdf "${dir}" "${pillar_file}"
fi
else
echo 'Generating files for all chapters'
mkdir -p book-result
pillar_all
if latex_enabled; then
compile_chapters
compile_latex_book
fi
fi
echo 'Done'