-
Notifications
You must be signed in to change notification settings - Fork 291
/
build.sh
executable file
·345 lines (301 loc) · 12.8 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
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/usr/bin/env bash
set -e
# Import the variables for dependencies
source ./build_deps.sh
OS_RELEASE_FILES=("/etc/os-release" "/usr/lib/os-release")
XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
CONFIG_DIR="$XDG_CONFIG_HOME/MangoHud"
VERSION=$(git describe --long --tags --always | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//')
SU_CMD=$(command -v sudo || command -v doas || echo)
MACHINE=$(uname -m || echo)
# doas requires a double dash if the command it runs will include any dashes,
# so append a double dash to the command
[[ $SU_CMD == *doas ]] && SU_CMD="$SU_CMD -- "
# Correctly identify the os-release file.
for os_release in ${OS_RELEASE_FILES[@]} ; do
if [[ ! -e "${os_release}" ]]; then
continue
fi
DISTRO=$(sed -rn 's/^ID(_LIKE)*=(.+)/\L\2/p' ${os_release} | sed 's/"//g')
done
dependencies() {
if [[ ! -f build/release/usr/lib/libMangoHud.so ]]; then
missing_deps() {
echo "# Missing dependencies:$INSTALL"
read -rp "Do you wish the script to install these packages? [y/N]" PERMISSION
case "$PERMISSION" in
"y"|"Y") echo "Attempting to install missing packages"; sleep 0.5;;
*) echo "Continuing with missing dependencies"; sleep 1;;
esac
}
dep_install() {
set +e
for i in $(eval echo $DEPS); do
$MANAGER_QUERY "$i" &> /dev/null
if [[ $? == 1 ]]; then
INSTALL="$INSTALL""$i "
fi
done
if [[ ! -z "$INSTALL" ]]; then
missing_deps
if [[ "$PERMISSION" == "Y" || "$PERMISSION" == "y" ]]; then
$SU_CMD $MANAGER_INSTALL $INSTALL
fi
fi
set -e
}
for i in $DISTRO; do
echo "# Checking dependencies for \"$i\""
case $i in
*arch*|*manjaro*|*artix*|*SteamOS*)
MANAGER_QUERY="pacman -Q"
MANAGER_INSTALL="pacman -S"
DEPS="{${DEPS_ARCH}}"
dep_install
break
;;
*fedora*|*nobara*)
MANAGER_QUERY="dnf list installed"
MANAGER_INSTALL="dnf install"
DEPS="{${DEPS_FEDORA}}"
dep_install
unset INSTALL
DEPS="{glibc-devel.i686,libstdc++-devel.i686,libX11-devel.i686,wayland-devel.i686,libxkbcommon-devel.i686}"
dep_install
break
;;
*debian*|*ubuntu*|*deepin*|*pop*)
MANAGER_QUERY="dpkg-query -s"
MANAGER_INSTALL="apt install"
DEPS="{${DEPS_DEBIAN}}"
dep_install
if [[ $(pip3 show meson; echo $?) == 1 || $(pip3 show mako; echo $?) == 1 ]]; then
$SU_CMD pip3 install 'meson>=0.54' mako
fi
if [[ ! -f /usr/local/bin/glslangValidator ]]; then
wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip
unzip glslang-master-linux-Release.zip bin/glslangValidator
$SU_CMD /usr/bin/install -m755 bin/glslangValidator /usr/local/bin/
rm bin/glslangValidator glslang-master-linux-Release.zip
fi
break
;;
*suse*)
echo "You may have to enable packman repository for some extra packages: ${DEPS_SUSE_EXTRA}"
echo "Leap: zypper ar -cfp 90 https://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Leap_15.1/ packman"
echo "Tumbleweed: zypper ar -cfp 90 http://ftp.gwdg.de/pub/linux/misc/packman/suse/openSUSE_Tumbleweed/ packman"
MANAGER_QUERY="rpm -q"
MANAGER_INSTALL="zypper install"
DEPS="{${DEPS_SUSE},${DEPS_SUSE_EXTRA}}"
dep_install
if [[ $(pip3 show meson; echo $?) == 1 ]]; then
$SU_CMD pip3 install 'meson>=0.54'
fi
break
;;
*solus*)
unset MANAGER_QUERY
unset DEPS
MANAGER_INSTALL="eopkg it"
local packages=(${DEPS_SOLUS//,/ })
# eopkg doesn't emit exit codes properly, so use the python API to find if a package is installed.
for package in ${packages[@]}; do
python -c "import pisi.db; import sys; idb = pisi.db.installdb.InstallDB(); sys.exit(0 if idb.has_package(\"${package}\") else 1)"
if [[ $? -ne 0 ]]; then
INSTALL="${INSTALL}""${package} "
fi
done
# likewise, ensure the whole system.devel component is satisfied
python -c "import pisi.db; import sys; idb = pisi.db.installdb.InstallDB(); cdb = pisi.db.componentdb.ComponentDB(); mpkgs = [x for x in cdb.get_packages('system.devel') if not idb.has_package(x)]; sys.exit(0 if len(mpkgs) == 0 else 1)"
if [[ $? -ne 0 ]]; then
INSTALL="${INSTALL}""-c system.devel "
fi
dep_install
break
;;
*)
echo "# Unable to find distro information!"
echo "# Attempting to build regardless"
esac
done
fi
}
configure() {
dependencies
git submodule update --init --depth 50
CONFIGURE_OPTS="-Dwerror=true"
if [[ ! -f "build/meson64/build.ninja" ]]; then
meson build/meson64 --libdir lib/mangohud/lib64 --prefix /usr -Dappend_libdir_mangohud=false $@ ${CONFIGURE_OPTS}
fi
if [[ ! -f "build/meson32/build.ninja" && "$MACHINE" = "x86_64" ]]; then
export CC="gcc -m32"
export CXX="g++ -m32"
export PKG_CONFIG_PATH="/usr/lib32/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:${PKG_CONFIG_PATH_32}"
meson build/meson32 --libdir lib/mangohud/lib32 --prefix /usr -Dappend_libdir_mangohud=false $@ ${CONFIGURE_OPTS}
fi
}
build() {
if [[ ! -f "build/meson64/build.ninja" ]]; then
configure $@
fi
DESTDIR="$PWD/build/release" ninja -C build/meson64 install
if [ "$MACHINE" = "x86_64" ]; then
DESTDIR="$PWD/build/release" ninja -C build/meson32 install
fi
sed -i 's:/usr/\\$LIB:/usr/lib/mangohud/\\$LIB:g' "$PWD/build/release/usr/bin/mangohud"
}
package() {
LIB="build/release/usr/lib/mangohud/lib64/libMangoHud.so"
LIB32="build/release/usr/lib/mangohud/lib32/libMangoHud.so"
if [[ ! -f "$LIB" || "$LIB" -ot "build/meson64/src/libMangoHud.so" ]]; then
build
fi
tar --numeric-owner --owner=0 --group=0 \
-C build/release -cvf "build/MangoHud-package.tar" .
}
release() {
rm build/MangoHud-package.tar
mkdir -p build/MangoHud
package
cp --preserve=mode bin/mangohud-setup.sh build/MangoHud/mangohud-setup.sh
cp build/MangoHud-package.tar build/MangoHud/MangoHud-package.tar
tar --numeric-owner --owner=0 --group=0 \
-C build -czvf build/MangoHud-$VERSION.tar.gz MangoHud
}
uninstall() {
[ "$UID" -eq 0 ] || exec $SU_CMD bash "$0" uninstall
rm -rfv "/usr/lib/mangohud"
rm -rfv "/usr/share/doc/mangohud"
rm -fv "/usr/share/man/man1/mangohud.1"
rm -fv "/usr/share/vulkan/implicit_layer.d/mangohud.json"
rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.json"
rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.x86.json"
rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.x86_64.json"
rm -fv "/usr/bin/mangohud"
rm -fv "/usr/bin/mangoplot"
rm -fv "/usr/bin/mangohud.x86"
}
install() {
rm -rf "$HOME/.local/share/MangoHud/"
rm -f "$HOME/.local/share/vulkan/implicit_layer.d/"{mangohud32.json,mangohud64.json}
[ "$UID" -eq 0 ] || mkdir -pv "${CONFIG_DIR}"
[ "$UID" -eq 0 ] || build
[ "$UID" -eq 0 ] || exec $SU_CMD bash "$0" install
uninstall
DEFAULTLIB=lib32
for i in $DISTRO; do
case $i in
*arch*)
DEFAULTLIB=lib64
;;
esac
done
if [ "$MACHINE" != "x86_64" ]; then
# Native libs
DEFAULTLIB=lib64
fi
echo DEFAULTLIB: $DEFAULTLIB
/usr/bin/install -Dvm644 ./build/release/usr/lib/mangohud/lib64/libMangoHud.so /usr/lib/mangohud/lib64/libMangoHud.so
/usr/bin/install -Dvm644 ./build/release/usr/lib/mangohud/lib64/libMangoHud_dlsym.so /usr/lib/mangohud/lib64/libMangoHud_dlsym.so
/usr/bin/install -Dvm644 ./build/release/usr/lib/mangohud/lib64/libMangoHud_opengl.so /usr/lib/mangohud/lib64/libMangoHud_opengl.so
if [ "$MACHINE" = "x86_64" ]; then
/usr/bin/install -Dvm644 ./build/release/usr/lib/mangohud/lib32/libMangoHud.so /usr/lib/mangohud/lib32/libMangoHud.so
/usr/bin/install -Dvm644 ./build/release/usr/lib/mangohud/lib32/libMangoHud_dlsym.so /usr/lib/mangohud/lib32/libMangoHud_dlsym.so
/usr/bin/install -Dvm644 ./build/release/usr/lib/mangohud/lib32/libMangoHud_opengl.so /usr/lib/mangohud/lib32/libMangoHud_opengl.so
fi
/usr/bin/install -Dvm644 ./build/release/usr/share/vulkan/implicit_layer.d/MangoHud.x86_64.json /usr/share/vulkan/implicit_layer.d/MangoHud.x86_64.json
/usr/bin/install -Dvm644 ./build/release/usr/share/vulkan/implicit_layer.d/MangoHud.x86.json /usr/share/vulkan/implicit_layer.d/MangoHud.x86.json
/usr/bin/install -Dvm644 ./build/release/usr/share/man/man1/mangohud.1 /usr/share/man/man1/mangohud.1
/usr/bin/install -Dvm644 ./build/release/usr/share/doc/mangohud/MangoHud.conf.example /usr/share/doc/mangohud/MangoHud.conf.example
/usr/bin/install -vm755 ./build/release/usr/bin/mangohud /usr/bin/mangohud
/usr/bin/install -vm755 ./build/release/usr/bin/mangoplot /usr/bin/mangoplot
ln -sv $DEFAULTLIB /usr/lib/mangohud/lib
# FIXME get the triplet somehow
ln -sv lib64 /usr/lib/mangohud/x86_64
ln -sv lib64 /usr/lib/mangohud/x86_64-linux-gnu
ln -sv . /usr/lib/mangohud/lib64/x86_64
ln -sv . /usr/lib/mangohud/lib64/x86_64-linux-gnu
ln -sv lib32 /usr/lib/mangohud/i686
ln -sv lib32 /usr/lib/mangohud/i386-linux-gnu
ln -sv lib32 /usr/lib/mangohud/i686-linux-gnu
mkdir -p /usr/lib/mangohud/tls
ln -sv ../lib64 /usr/lib/mangohud/tls/x86_64
ln -sv ../lib32 /usr/lib/mangohud/tls/i686
# Some distros search in $prefix/x86_64-linux-gnu/tls/x86_64 etc instead
if [ ! -e /usr/lib/mangohud/lib/i386-linux-gnu ]; then
ln -sv ../lib32 /usr/lib/mangohud/lib/i386-linux-gnu
fi
if [ ! -e /usr/lib/mangohud/lib/i686-linux-gnu ]; then
ln -sv ../lib32 /usr/lib/mangohud/lib/i686-linux-gnu
fi
if [ ! -e /usr/lib/mangohud/lib/x86_64-linux-gnu ]; then
ln -sv ../lib64 /usr/lib/mangohud/lib/x86_64-linux-gnu
fi
# $LIB can be "lib/tls/x86_64"?
ln -sv ../tls /usr/lib/mangohud/lib/tls
#ln -sv lib64 /usr/lib/mangohud/aarch64-linux-gnu
#ln -sv lib64 /usr/lib/mangohud/arm-linux-gnueabihf
echo "MangoHud Installed"
}
reinstall() {
build
package
install
}
clean() {
rm -rf "build"
rm -rf subprojects/*/
}
usage() {
if test -z $1; then
echo "Unrecognized command argument: $arg"
else
echo "$0 requires one argument"
fi
echo -e "\nUsage: $0 <command>\n"
echo "Available commands:"
echo -e "\tpull\t\tPull latest commits (code) from Git"
echo -e "\tconfigure\tEnsures that dependencies are installed, updates git submodules, and generates files needed for building MangoHud. This is automatically run by the build command"
echo -e "\tbuild\t\tIf needed runs configure and then builds (compiles) MangoHud"
echo -e "\tpackage\t\tRuns build if needed and then builds a tar package from MangoHud"
echo -e "\tinstall\t\tInstall MangoHud onto your system"
echo -e "\treinstall\tRuns build, then package, and finally install"
echo -e "\tclean\t\tRemoves build directory"
echo -e "\tuninstall\tRemoves installed MangoHud files from your system"
echo -e "\trelease\t\tBuilds a MangoHud release tar package"
}
if [[ -z $@ ]]; then
usage no-args
fi
while [ $# -gt 0 ]; do
OPTS=()
arg="$1"
shift
while [ $# -gt 0 ] ; do
case $1 in
-*)
OPTS+=("$1")
shift
;;
*)
break
;;
esac;
done
echo -e "\e[1mCommand:\e[92m" $arg "\e[94m"${OPTS[@]}"\e[39m\e[0m"
case $arg in
"pull") git pull ${OPTS[@]};;
"configure") configure ${OPTS[@]};;
"build") build ${OPTS[@]};;
"build_dbg") build --buildtype=debug -Dglibcxx_asserts=true ${OPTS[@]};;
"package") package;;
"install") install;;
"reinstall") reinstall;;
"clean") clean;;
"uninstall") uninstall;;
"release") release;;
*)
usage
esac
done