forked from acidanthera/OpenCorePkg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildDocs.tool
executable file
·157 lines (127 loc) · 3.67 KB
/
BuildDocs.tool
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
#!/bin/bash
abort() {
echo "ERROR: $1!"
exit 1
}
prompt() {
echo "$1"
read -rp "Enter [Y]es to continue: " v
if [ "$v" != "Y" ] && [ "$v" != "y" ]; then
return 0
fi
return 1
}
latexbuild() {
# Perform file cleanup.
rm -f ./*.aux ./*.log ./*.out ./*.pdf ./*.toc
# Perform a first pass
pdflatex -draftmode "$1" "$2" || \
abort "Unable to create $1 draft"
# Perform a number of TOC passes.
while grep 'Rerun to get ' "${1}.log" ; do
pdflatex -draftmode "$1" "$2" || \
abort "Unable to create $1 draft with TOC"
done
# Create a real PDF.
pdflatex "$1" "$2" || \
abort "Unable to create $1 PDF"
# Perform a number of TOC passes for PDF (usually not needed).
while grep 'Rerun to get ' "${1}.log" ; do
pdflatex -draftmode "$1" "$2" || \
abort "Unable to create $1 PDF with TOC"
done
}
builddocs() {
latexbuild Configuration
cd Differences || abort "Unable to process annotations"
rm -f ./*.aux ./*.log ./*.out ./*.pdf ./*.toc
latexdiff --allow-spaces -s ONLYCHANGEDPAGE PreviousConfiguration.tex ../Configuration.tex \
> Differences.tex || \
abort "Unable to differentiate"
latexbuild Differences -interaction=nonstopmode
cd ../Errata || abort "Unable to process annotations"
latexbuild Errata
cd .. || abort "Unable to cd back to Docs directory"
}
updatedocshash() {
err=0
if [ "$(which md5)" != "" ]; then
HASH=$(md5 Configuration.tex | cut -f4 -d' ')
err=$?
elif [ "$(which openssl)" != "" ]; then
HASH=$(openssl md5 Configuration.tex | cut -f2 -d' ')
err=$?
else
abort "No md5 hasher found!"
fi
if [ $err -ne 0 ]; then
abort "Failed to calculate built configuration hash!"
fi
OLDHASH=""
if [ -f "Configuration.md5" ]; then
OLDHASH=$(cat "Configuration.md5")
fi
echo "$HASH" > "Configuration.md5"
}
checkdocs() {
if [ "$HASH" != "$OLDHASH" ]; then
echo "Configuration hash ${HASH} is different from ${OLDHASH}."
echo "You forgot to rebuild documentation (Configuration.pdf)!"
echo "Please run ./Docs/BuildDocs.tool."
exit 1
fi
}
checkver() {
ocver=$(grep OPEN_CORE_VERSION ../Include/Acidanthera/Library/OcMainLib.h | sed 's/.*"\(.*\)".*/\1/' | grep -E '^[0-9.]+$')
if [ "$ocver" = "" ]; then
abort "Invalid OpenCore version"
fi
docver=$(grep -w 'Reference Manual' ./Configuration.tex | sed -e 's/(//g' -e 's/)//g' | awk '{print $3}')
if [ "$docver" = "" ]; then
abort "Invalid document version"
fi
if [ "$ocver" = "$docver" ]; then
return 0
fi
return 1
}
bumpversion() {
echo "Bumping version from $docver to $ocver"
cd Differences || abort "Unable to enter Differences directory"
rm -f PreviousConfiguration.tex
cp ../Configuration.tex PreviousConfiguration.tex || abort "Failed to copy PreviousConfiguration.tex"
cd .. || abort "Unable to enter parent directory"
perl -pi -e "s/Reference Manual \($docver\)/Reference Manual \($ocver\)/g" ./Configuration.tex || abort "Failed to patch Configuration.tex"
}
main() {
if [ "$(which latexdiff)" = "" ]; then
abort "latexdiff is missing, check your TeX Live installation"
fi
if [ "$(which pdflatex)" = "" ]; then
abort "pdflatex is missing, check your TeX Live installation"
fi
cd "$(dirname "$0")" || abort "Wrong directory"
checkver
if [ $? = 1 ]; then
echo "Current Configuration.tex/pdf version: $docver"
echo "Current OC Header version: $ocver"
prompt "Bump version to $ocver?"
if [ $? = 0 ]; then
prompt "Still build docs?"
if [ $? = 0 ]; then
exit 1
fi
else
bumpversion
fi
fi
builddocs
updatedocshash
case "$1" in
-c|--check-docs )
checkdocs
;;
esac
}
main "$@"
exit 0