-
Notifications
You must be signed in to change notification settings - Fork 3
/
install
executable file
·278 lines (250 loc) · 9.51 KB
/
install
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
#!/bin/sh
# Copyright 2017-2019, 2023, 2024 Karl Landstrom <karl@miasap.se>
#
# This file is part of OBNC.
#
# OBNC is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OBNC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OBNC. If not, see <http://www.gnu.org/licenses/>.
set -o errexit -o nounset
readonly selfDirPath="$(cd "$(dirname "$0")"; pwd -P)"
readonly prefix="$(awk -F '=' '$1 == "prefix" { print $2; }' CONFIG)"
readonly libdir="$(awk -F '=' '$1 == "libdir" { print $2; }' CONFIG)"
destdir=
includeLibCSrc=false
readonly scripts="obncdoc-extract obncdoc-index obncdoc-markup"
readonly basicModules="Files In Input Input0 Math Out Strings XYplane"
readonly extModules="extArgs extConvert extEnv extErr extPipes extTrap"
readonly docFiles="oberon-report.html"
readonly man1Files="obnc.1 obnc-compile.1 obnc-path.1 obncdoc.1"
EchoAndRun()
{
echo "$@"
eval "$@"
}
Install()
{
#install core files
EchoAndRun mkdir -p "$destdir$prefix/bin"
EchoAndRun cp "bin/obnc" "$destdir$prefix/bin"
EchoAndRun cp "bin/obnc-compile" "$destdir$prefix/bin"
EchoAndRun cp "bin/obnc-path" "$destdir$prefix/bin"
EchoAndRun cp "bin/obncdoc" "$destdir$prefix/bin"
local file=
for file in $scripts; do
EchoAndRun sed -e '"s|^\(readonly defaultPrefix=\).*$|\1'"'$prefix'"'|"' \
-e '"s|^\(readonly defaultLibDir=\).*$|\1'"'$libdir'"'|"' \
'"bin/'$file'"' \> '"'$destdir$prefix/bin/$file'"'
EchoAndRun chmod +x "$destdir$prefix/bin/$file"
done
EchoAndRun mkdir -p "$destdir$prefix/include/obnc"
EchoAndRun cp "lib/obnc/OBNCConfig.h" "$destdir$prefix/include/obnc"
EchoAndRun cp "lib/obnc/OBNC.h" "$destdir$prefix/include/obnc"
EchoAndRun mkdir -p "$destdir$prefix/$libdir/obnc"
EchoAndRun cp "lib/obnc/OBNC.o" "$destdir$prefix/$libdir/obnc"
EchoAndRun cp "lib/obnc/OBNC.env" "$destdir$prefix/$libdir/obnc"
if "$includeLibCSrc"; then
EchoAndRun sed -e '"s|#include \"OBNC\.h\"|#include <obnc/OBNC.h>|"' lib/obnc/OBNC.c \> "'$destdir$prefix/$libdir/obnc/OBNC.c'"
fi
#install basic library
rm -rf "lib/obnc/.obnc"
local module=
for module in $basicModules; do
#allow installation to proceed even if some optional libraries (like SDL) are missing
if (cd "lib/obnc" && env OBNC_PREFIX="$destdir$prefix" CFLAGS="-I$destdir$prefix/include" "$destdir$prefix/bin/obnc" "${module}Test.obn"); then
EchoAndRun cp "lib/obnc/.obnc/$module.h" "$destdir$prefix/include/obnc"
EchoAndRun cp "lib/obnc/.obnc/$module.o" "$destdir$prefix/$libdir/obnc"
EchoAndRun cp "lib/obnc/.obnc/$module.sym" "$destdir$prefix/$libdir/obnc"
EchoAndRun cp "lib/obnc/.obnc/$module.imp" "$destdir$prefix/$libdir/obnc"
if [ -e "lib/obnc/$module.env" ]; then
EchoAndRun cp "lib/obnc/$module.env" "$destdir$prefix/$libdir/obnc"
fi
if "$includeLibCSrc"; then
local source="lib/obnc/$module.c"
if [ ! -e "$source" ]; then
source="lib/obnc/.obnc/$module.c"
fi
EchoAndRun sed -e "'s|#include \"\(\.obnc/\)\?\([^.]*\)\.h\"|#include <obnc/\2.h>|'" "'$source'" \> "'$destdir$prefix/$libdir/obnc/$module.c'"
fi
fi
done
rm -r "lib/obnc/.obnc"
#install extended library
EchoAndRun mkdir -p "$destdir$prefix/include/obnc/ext"
EchoAndRun mkdir -p "$destdir$prefix/$libdir/obnc/ext"
rm -rf "lib/obnc/ext/.obnc"
local module=
for module in $extModules; do
(cd "lib/obnc/ext" && env OBNC_PREFIX="$destdir$prefix" CFLAGS="-I$destdir$prefix/include" "$destdir$prefix/bin/obnc" "${module#ext}Test.obn")
EchoAndRun cp "lib/obnc/ext/.obnc/$module.h" "$destdir$prefix/include/obnc/ext"
EchoAndRun cp "lib/obnc/ext/.obnc/$module.o" "$destdir$prefix/$libdir/obnc/ext"
EchoAndRun cp "lib/obnc/ext/.obnc/$module.sym" "$destdir$prefix/$libdir/obnc/ext"
EchoAndRun cp "lib/obnc/ext/.obnc/$module.imp" "$destdir$prefix/$libdir/obnc/ext"
if [ -e "lib/obnc/ext/$module.env" ]; then
EchoAndRun cp "lib/obnc/ext/$module.env" "$destdir$prefix/$libdir/obnc/ext"
fi
if "$includeLibCSrc"; then
local source="lib/obnc/ext/$module.c"
if [ ! -e "$source" ]; then
source="lib/obnc/ext/.obnc/$module.c"
fi
EchoAndRun sed -e "'s|#include \"\(\.obnc/\)\?\([^.]*\)\.h\"|#include <obnc/ext/\2.h>|'" "'$source'" \> "'$destdir$prefix/$libdir/obnc/ext/$module.c'"
fi
done
rm -r "lib/obnc/ext/.obnc"
#install documentation
EchoAndRun mkdir -p "$destdir$prefix/share/doc/obnc"
for file in $docFiles; do
EchoAndRun cp "share/doc/obnc/$file" "$destdir$prefix/share/doc/obnc"
done
(cd "lib/obnc" && OBNC_PREFIX="$selfDirPath" ../../bin/obncdoc)
EchoAndRun mkdir -p "$destdir$prefix/share/doc/obnc/obncdoc/basic"
for file in "lib/obnc/obncdoc"/*; do
EchoAndRun cp "$file" "$destdir$prefix/share/doc/obnc/obncdoc/basic"
done
(cd "lib/obnc/ext" && OBNC_PREFIX="$selfDirPath" ../../../bin/obncdoc)
EchoAndRun mkdir -p "$destdir$prefix/share/doc/obnc/obncdoc/ext"
for file in "lib/obnc/ext/obncdoc"/*; do
EchoAndRun cp "$file" "$destdir$prefix/share/doc/obnc/obncdoc/ext"
done
EchoAndRun cd "$destdir$prefix/share/doc/obnc/obncdoc"
EchoAndRun "$selfDirPath/bin/obncdoc-index" \> index.html
EchoAndRun cp "$selfDirPath/share/obnc/style.css" .
cd - >/dev/null
rm -r lib/obnc/obncdoc
#install man pages
EchoAndRun mkdir -p "$destdir$prefix/share/man/man1"
for file in $man1Files; do
EchoAndRun cp "share/man/man1/$file" "$destdir$prefix/share/man/man1"
done
#install obncdoc style file
EchoAndRun mkdir -p "$destdir$prefix/share/obnc"
EchoAndRun cp "$selfDirPath/share/obnc/style.css" "$destdir$prefix/share/obnc"
}
Uninstall()
{
#delete executables
EchoAndRun rm -f "$destdir$prefix/bin/obnc"
EchoAndRun rm -f "$destdir$prefix/bin/obnc-compile"
EchoAndRun rm -f "$destdir$prefix/bin/obnc-path"
EchoAndRun rm -f "$destdir$prefix/bin/obncdoc"
local file=
for file in $scripts; do
EchoAndRun rm -f "$destdir$prefix/bin/$file"
done
#delete library files
local module=
for module in $basicModules; do
EchoAndRun rm -f "$destdir$prefix/include/obnc/$module.h"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/$module.o"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/$module.sym"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/$module.imp"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/$module.env"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/$module.c"
done
for module in $extModules; do
EchoAndRun rm -f "$destdir$prefix/include/obnc/ext/$module.h"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/ext/$module.o"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/ext/$module.sym"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/ext/$module.imp"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/ext/$module.env"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/ext/$module.c"
done
EchoAndRun rm -f "$destdir$prefix/include/obnc/OBNC.h"
EchoAndRun rm -f "$destdir$prefix/include/obnc/OBNCConfig.h"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/OBNC.o"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/OBNC.env"
EchoAndRun rm -f "$destdir$prefix/$libdir/obnc/OBNC.c"
#delete documentation
for file in $docFiles; do
EchoAndRun rm -f "$destdir$prefix/share/doc/obnc/$file"
done
EchoAndRun rm -f "$destdir$prefix/share/doc/obnc/obncdoc/basic/"*
EchoAndRun rm -f "$destdir$prefix/share/doc/obnc/obncdoc/ext/"*
EchoAndRun rm -f "$destdir$prefix/share/doc/obnc/obncdoc/index.html"
EchoAndRun rm -f "$destdir$prefix/share/doc/obnc/obncdoc/style.css"
#delete man pages
for file in $man1Files; do
EchoAndRun rm -f "$destdir$prefix/share/man/man1/$file"
done
#delete obncdoc style file
EchoAndRun rm -f "$destdir$prefix/share/obnc/style.css"
#delete obnc directories which have been emptied on files
if [ -z "$(find "$destdir$prefix/include/obnc" -type f 2>/dev/null)" ]; then
EchoAndRun rm -fr "$destdir$prefix/include/obnc"
fi
if [ -z "$(find "$destdir$prefix/$libdir/obnc" -type f 2>/dev/null)" ]; then
EchoAndRun rm -fr "$destdir$prefix/$libdir/obnc"
fi
if [ -z "$(find "$destdir$prefix/share/doc/obnc" -type f 2>/dev/null)" ]; then
EchoAndRun rm -fr "$destdir$prefix/share/doc/obnc"
fi
if [ -z "$(find "$destdir$prefix/share/obnc" -type f 2>/dev/null)" ]; then
EchoAndRun rm -fr "$destdir$prefix/share/obnc"
fi
}
PrintHelp()
{
echo "usage: "
printf "\tinstall [u] [--destdir=DESTDIR] [--include-lib-c-src]\n"
printf "\tinstall -h\n"
echo
printf "\tu\t\t\tuninstall\n"
printf "\t--destdir\t\tspecify directory for staged installation\n"
printf "\t--include-lib-c-src\tmake cross compilation possible\n"
printf "\t-h\t\t\tdisplay help and exit\n"
}
ExitInvalidCommand()
{
echo "invalid command. Try 'install -h' for more information." >&2
exit 1
}
Run()
{
local helpWanted=false
local uninstall=false
local arg=
for arg in "$@"; do
case "$arg" in
u)
uninstall=true;;
--destdir=*)
destdir="${arg#--destdir=}";;
--include-lib-c-src)
includeLibCSrc=true;;
-h)
helpWanted=true;;
*)
ExitInvalidCommand
esac
done
if "$helpWanted"; then
PrintHelp
else
if [ -e CONFIG ]; then
if [ "$prefix" != "${prefix#/}" ]; then
if "$uninstall"; then
Uninstall
else
Install
fi
else
printf "prefix must be an absolute path: %s\ninstallation aborted\n" "$prefix" >&2
exit 1
fi
else
printf "must first run build script\ninstallation aborted\n" >&2
exit 1
fi
fi
}
Run "$@"