MangoHud/build.sh

215 lines
8.0 KiB
Bash
Raw Normal View History

2020-01-28 07:20:23 +00:00
#!/bin/bash
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}"
DATA_DIR="$XDG_DATA_HOME/MangoHud"
2020-02-12 09:56:29 +00:00
LAYER="build/release/usr/share/vulkan/implicit_layer.d/mangohud.json"
2020-03-10 12:39:52 +00:00
INSTALL_DIR="build/package/"
IMPLICIT_LAYER_DIR="$XDG_DATA_HOME/vulkan/implicit_layer.d"
2020-02-04 19:29:39 +00:00
VERSION=$(git describe --long --tags --always | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//')
2020-01-28 07:20:23 +00:00
# Correctly identify the os-release file.
for os_release in ${OS_RELEASE_FILES[@]} ; do
if [[ ! -e "${os_release}" ]]; then
continue
fi
DISTRO=$(sed 1q ${os_release} | sed 's/NAME=//g' | sed 's/"//g')
done
dependencies() {
if [[ ! -f build/release/usr/lib64/libMangoHud.so ]]; then
missing_deps() {
2020-02-12 09:56:29 +00:00
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
}
2020-02-02 05:29:49 +00:00
install() {
for i in $(eval echo $DEPS); do
2020-02-12 09:56:29 +00:00
$MANAGER_QUERY "$i" &> /dev/null
2020-02-02 05:29:49 +00:00
if [[ $? == 1 ]]; then
2020-02-12 09:56:29 +00:00
INSTALL="$INSTALL""$i "
2020-02-02 05:29:49 +00:00
fi
done
if [[ ! -z "$INSTALL" ]]; then
missing_deps
2020-02-12 09:56:29 +00:00
if [[ "$PERMISSION" == "Y" || "$PERMISSION" == "y" ]]; then
sudo $MANAGER_INSTALL $INSTALL
fi
2020-02-02 05:29:49 +00:00
fi
}
echo "# Checking Dependencies"
case $DISTRO in
"Arch Linux"|"Manjaro")
2020-02-02 05:29:49 +00:00
MANAGER_QUERY="pacman -Q"
MANAGER_INSTALL="pacman -S"
DEPS="{gcc,meson,pkgconf,python-mako,glslang,libglvnd,lib32-libglvnd}"
install
2020-02-03 10:09:24 +00:00
;;
"Fedora")
2020-02-02 05:29:49 +00:00
MANAGER_QUERY="dnf list installed"
MANAGER_INSTALL="dnf install"
2020-03-15 08:40:27 +00:00
DEPS="{meson,gcc,gcc-c++,libX11-devel,glslang,python3-mako,mesa-libGL-devel}"
2020-02-02 05:29:49 +00:00
install
2020-02-02 04:50:36 +00:00
unset INSTALL
2020-02-02 05:29:49 +00:00
DEPS="{glibc-devel.i686,libstdc++-devel.i686,libX11-devel.i686}"
install
2020-02-03 10:09:24 +00:00
;;
*"buntu"|"Linux Mint"|"Debian"|"Zorin OS"|"Pop!_OS"|"elementary OS")
MANAGER_QUERY="dpkg-query -s"
2020-02-02 05:29:49 +00:00
MANAGER_INSTALL="apt install"
DEPS="{gcc,g++,gcc-multilib,g++-multilib,ninja-build,python3-pip,python3-setuptools,python3-wheel,pkg-config,mesa-common-dev,libx11-dev:i386}"
install
if [[ $(sudo pip3 show meson; echo $?) == 1 || $(sudo pip3 show mako; echo $?) == 1 ]]; then
sudo pip3 install meson 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
sudo install -m755 bin/glslangValidator /usr/local/bin/
rm bin/glslangValidator glslang-master-linux-Release.zip
fi
2020-02-03 10:09:24 +00:00
;;
2020-03-16 21:10:34 +00:00
"openSUSE Leap"|"openSUSE Tumbleweed")
2020-03-16 19:14:31 +00:00
MANAGER_QUERY="zypper search"
MANAGER_INSTALL="zypper install"
DEPS="{gcc-c++,gcc-c++-31bit,meson,libpkgconf-devel,python3-Mako,libX11-devel,libX11-devel-32bit,glslang-devel,libglvnd-devel,libglvnd-devel-32bit,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel}"
install
2020-03-16 21:10:34 +00:00
;;
"Solus")
unset MANAGER_QUERY
unset DEPS
MANAGER_INSTALL="eopkg it"
local packages=("mesalib-32bit-devel" "glslang" "libstdc++-32bit" "glibc-32bit-devel" "mako")
# 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
install
;;
*)
echo "# Unable to find distro information!"
echo "# Attempting to build regardless"
esac
fi
}
2020-01-28 07:20:23 +00:00
configure() {
dependencies
git submodule update --init --depth 50
2020-02-12 09:56:29 +00:00
if [[ ! -f "build/meson64/build.ninja" ]]; then
2020-03-14 11:09:35 +00:00
meson build/meson64 --libdir lib/mangohud/lib64 --prefix /usr -Dappend_libdir_mangohud=false
fi
2020-02-12 09:56:29 +00:00
if [[ ! -f "build/meson32/build.ninja" ]]; then
2020-02-01 23:45:45 +00:00
export CC="gcc -m32"
export CXX="g++ -m32"
2020-02-02 04:50:36 +00:00
export PKG_CONFIG_PATH="/usr/lib32/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig:${PKG_CONFIG_PATH_32}"
2020-02-01 23:45:45 +00:00
export LLVM_CONFIG="/usr/bin/llvm-config32"
2020-03-14 11:09:35 +00:00
meson build/meson32 --libdir lib/mangohud/lib32 --prefix /usr -Dappend_libdir_mangohud=false
2020-01-28 07:20:23 +00:00
fi
}
build() {
2020-02-12 09:56:29 +00:00
if [[ ! -f "build/meson64/build.ninja" ]]; then
2020-02-03 10:09:24 +00:00
configure
fi
2020-03-11 16:04:10 +00:00
DESTDIR="$PWD/build/release" ninja -C build/meson32 install
DESTDIR="$PWD/build/release" ninja -C build/meson64 install
2020-01-28 07:20:23 +00:00
}
2020-02-02 22:40:06 +00:00
package() {
2020-03-11 16:04:10 +00:00
LIB="build/release/usr/lib/mangohud/lib64/libMangoHud.so"
LIB32="build/release/usr/lib/mangohud/lib32/libMangoHud.so"
2020-02-12 09:56:29 +00:00
if [[ ! -f "$LIB" || "$LIB" -ot "build/meson64/src/libMangoHud.so" ]]; then
2020-02-03 10:09:24 +00:00
build
fi
tar --numeric-owner --owner=0 --group=0 \
2020-03-11 16:04:10 +00:00
-C build/release -cvf "build/MangoHud-package.tar" .
2020-03-10 12:39:52 +00:00
}
release() {
rm build/MangoHud-package.tar
mkdir -p build/MangoHud
package
cp --preserve=mode bin/mangohud-setup.sh build/MangoHud/mangohud-setup.sh
2020-03-10 12:39:52 +00:00
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
2020-01-28 07:20:23 +00:00
}
2020-02-02 22:40:06 +00:00
install() {
rm -rf "$HOME/.local/share/MangoHud/"
rm -f "$HOME/.local/share/vulkan/implicit_layer.d/"{mangohud32.json,mangohud64.json}
if [[ ! -f build/MangoHud-package.tar ]]; then
echo No package found. Run \"$0 package\".
exit 1
fi
[ "$UID" -eq 0 ] || exec sudo bash "$0" install
tar -C / -xvf build/MangoHud-package.tar
2020-03-10 12:39:52 +00:00
ldconfig
echo "MangoHud Installed"
}
2020-01-28 07:20:23 +00:00
clean() {
2020-02-12 09:56:29 +00:00
rm -rf "build"
2020-01-28 07:20:23 +00:00
}
uninstall() {
[ "$UID" -eq 0 ] || exec sudo bash "$0" uninstall
2020-03-11 16:04:10 +00:00
rm -rfv "/usr/lib/mangohud"
rm -rfv "/usr/share/doc/mangohud"
2020-03-10 12:39:52 +00:00
rm -fv "/usr/share/vulkan/implicit_layer.d/mangohud.json"
rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.json"
2020-03-14 11:22:17 +00:00
rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.x86.json"
rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.x86_64.json"
2020-03-10 12:39:52 +00:00
rm -fv "/usr/bin/mangohud"
2020-03-14 11:09:35 +00:00
rm -fv "/usr/bin/mangohud.x86"
2020-01-28 07:20:23 +00:00
}
usage() {
if test -z $1; then
echo "Unrecognized command argument: $a"
else
echo "$0 requires one argument"
fi
echo 'Accepted arguments: "pull", "configure", "build", "package", "install", "clean", "uninstall".'
}
2020-02-03 10:09:24 +00:00
for a in $@; do
case $a in
"") build;;
2020-02-03 10:09:24 +00:00
"pull") git pull;;
"configure") configure;;
"build") build;;
2020-02-03 10:09:24 +00:00
"package") package;;
"install") install;;
2020-02-03 10:09:24 +00:00
"clean") clean;;
"uninstall") uninstall;;
2020-03-10 12:39:52 +00:00
"release") release;;
2020-02-03 10:09:24 +00:00
*)
usage
2020-02-03 10:09:24 +00:00
esac
done
if [[ -z $@ ]]; then
usage no-args
fi