-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·185 lines (154 loc) · 4.31 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
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
#!/bin/bash
ORIGINAL_WORKDIR=$(pwd)
# change directory to location of script
BASE_DIR=$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )
cd $BASE_DIR
TEXMFHOME=$(kpsewhich -var-value TEXMFHOME)
TEXMFMAIN=$(kpsewhich -var-value TEXMFMAIN)
SOURCE_DIR=$BASE_DIR/src
DOCS_SOURCE_DIR=$BASE_DIR/docs
BUILD_DIR=$BASE_DIR/build
BUILD_DOCS_DIR=$BUILD_DIR/docs
CLASS_NAME=elite
DOCS_SOURCE=$CLASS_NAME-docs-en.tex
function clean_build_dir {
# try to remove and redirect error messages to /dev/null
rm -r ./build/ 2> /dev/null
}
function assemble {
mkdir -p $BUILD_DIR/
echo -n "" > $BUILD_DIR/$CLASS_NAME.cls
if [ $GITHUB_SHA ]
then
echo "% Auto-built by GitHub Actions" >> $BUILD_DIR/$CLASS_NAME.cls
echo "% Latest Commit-Hash: $GITHUB_SHA" >> $BUILD_DIR/$CLASS_NAME.cls
fi
cd $SOURCE_DIR/
for STYFILE in *.sty
do
STYCONTENT=$(cat ${STYFILE})
echo_safe_filecontents $STYFILE "$STYCONTENT"
done
cd $BASE_DIR
echo "" >> $BUILD_DIR/$CLASS_NAME.cls
echo $CLASS_NAME
cat $SOURCE_DIR/$CLASS_NAME.cls >> $BUILD_DIR/$CLASS_NAME.cls
}
function echo_safe_filecontents {
FILENAME=$1
FILECONTENTS=$2
# echo "%
#% External File: $FILENAME
#%
#\begingroup\newif\ifmy
#\IfFileExists{$FILENAME}{}{\mytrue}
#\ifmy
#\begin{filecontents}{$FILENAME}
#$FILECONTENTS
#\end{filecontents}
#\fi\endgroup
#" >> $BUILD_DIR/${CLASS_NAME}.cls
echo "%
% External File: $FILENAME
%
\begin{filecontents}[overwrite]{$FILENAME}
$FILECONTENTS
\end{filecontents}
" >> $BUILD_DIR/$CLASS_NAME.cls
}
function build_docs {
mkdir -p $BUILD_DOCS_DIR/
cd $DOCS_SOURCE_DIR
# pdflatex -halt-on-error -output-directory $BUILD_DOCS_DIR -jobname $CLASS_NAME $DOCS_SOURCE_DIR/$DOCS_SOURCE
latexmk -pdf -halt-on-error --jobname=$CLASS_NAME --output-directory=$BUILD_DOCS_DIR $DOCS_SOURCE_DIR/$DOCS_SOURCE
cd $BUILD_DOCS_DIR
_temp=$(makeindex *.idx)
cd $BASE_DIR
}
function install_local {
mkdir -p ${TEXMFHOME}/tex/latex/$CLASS_NAME
install -m 0644 ${BASE_DIR}/build/$CLASS_NAME.cls $TEXMFHOME/tex/latex/$CLASS_NAME/$CLASS_NAME.cls
}
function install_docs_local {
mkdir -p ${TEXMFHOME}/doc/latex/$CLASS_NAME
install -m 0644 ${BASE_DIR}/build/docs/$CLASS_NAME.pdf ${TEXMFHOME}/doc/latex/$CLASS_NAME/$CLASS_NAME.pdf
}
function install_global {
mkdir -p ${TEXMFMAIN}/tex/latex/$CLASS_NAME
install -m 0644 ${BASE_DIR}/build/$CLASS_NAME.cls ${TEXMFMAIN}/tex/latex/$CLASS_NAME/$CLASS_NAME.cls
}
function install_docs_global {
mkdir -p ${TEXMFMAIN}/doc/latex/$CLASS_NAME
install -m 0644 ${BASE_DIR}/build/docs/$CLASS_NAME.pdf ${TEXMFMAIN}/doc/latex/$CLASS_NAME/$CLASS_NAME.pdf
}
#
# available procedures
#
function buildprocedure_clean {
echo "> clean"
clean_build_dir
}
function buildprocedure_build {
echo "> build"
assemble
}
function buildprocedure_docs {
echo "> docs"
# perform twice to create correct index
build_docs
build_docs
}
function buildprocedure_local {
buildprocedure_build
echo "> local"
install_local
buildprocedure_docs
install_docs_local
}
function buildprocedure_global {
buildprocedure_build
echo "> global"
install_global
buildprocedure_docs
install_docs_global
}
function echo_help {
echo "Usage: $BASENAME <procedure> [options]"
echo ""
echo "Available procedures:"
echo " clean delete old build files"
echo " build assemble the document class into a single file"
echo " docs build the documentation PDF"
echo " local run the build and docs procedures and install"
echo " the LaTeX files locally"
echo " global run the build and docs procedures and install"
echo " the LaTeX files globally"
echo ""
}
#
# build script
#
BASENAME=$(basename $0)
NO_COMMAND=1
for SUBCOMMAND in "${@:1}"
do
NO_COMMAND=0
case $SUBCOMMAND in
"" | "-h" | "--help")
echo_help
;;
*)
buildprocedure_$SUBCOMMAND
if [ $? = 127 ]; then
echo "Error: '$SUBCOMMAND' is not a known build procedure." >&2
echo " Run '$BASENAME --help' for a list of known subcommands." >&2
exit 1
fi
;;
esac
done
if [ $NO_COMMAND = 1 ]
then
echo_help
fi
cd $ORIGINAL_WORKDIR