2020-03-23 10:59:09 +00:00
#!/usr/bin/env bash
set -e
2020-02-17 10:16:42 +00:00
OS_RELEASE_FILES = ( "/etc/os-release" "/usr/lib/os-release" )
2020-02-15 10:35:31 +00:00
XDG_DATA_HOME = " ${ XDG_DATA_HOME :- $HOME /.local/share } "
XDG_CONFIG_HOME = " ${ XDG_CONFIG_HOME :- $HOME /.config } "
DATA_DIR = " $XDG_DATA_HOME /MangoHud "
2020-03-15 17:26:02 +00:00
CONFIG_DIR = " $XDG_CONFIG_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/"
2020-02-15 10:35:31 +00:00
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//' )
2021-07-06 17:08:46 +00:00
SU_CMD = $( command -v sudo || command -v doas || echo )
2021-08-08 12:46:44 +00:00
MACHINE = $( uname -m || echo )
2020-04-12 09:51:14 +00:00
# doas requires a double dash if the command it runs will include any dashes,
# so append a double dash to the command
2020-04-12 10:12:28 +00:00
[ [ $SU_CMD = = *doas ] ] && SU_CMD = " $SU_CMD -- "
2020-01-28 07:20:23 +00:00
2020-02-17 10:16:42 +00:00
# Correctly identify the os-release file.
for os_release in ${ OS_RELEASE_FILES [@] } ; do
if [ [ ! -e " ${ os_release } " ] ] ; then
continue
fi
2021-08-08 18:25:08 +00:00
DISTRO = $( sed -rn 's/^ID(_LIKE)*=(.+)/\L\2/p' ${ os_release } | sed 's/"//g' )
2020-02-17 10:16:42 +00:00
done
2020-02-01 18:52:37 +00:00
dependencies( ) {
2020-07-08 20:43:09 +00:00
if [ [ ! -f build/release/usr/lib/libMangoHud.so ] ] ; then
2020-02-01 18:52:37 +00:00
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-01 18:52:37 +00:00
}
2020-05-26 14:55:59 +00:00
dep_install( ) {
2020-03-30 19:26:08 +00:00
set +e
2020-02-02 05:29:49 +00:00
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
2020-04-12 09:51:14 +00:00
$SU_CMD $MANAGER_INSTALL $INSTALL
2020-02-12 09:56:29 +00:00
fi
2020-02-02 05:29:49 +00:00
fi
2020-03-30 19:26:08 +00:00
set -e
2020-02-02 05:29:49 +00:00
}
2020-05-10 12:11:56 +00:00
2020-12-07 02:32:52 +00:00
for i in $DISTRO ; do
echo " # Checking dependencies for \" $i \" "
case $i in
*arch*| *manjaro*)
2020-02-02 05:29:49 +00:00
MANAGER_QUERY = "pacman -Q"
MANAGER_INSTALL = "pacman -S"
2021-07-06 17:08:46 +00:00
DEPS = "{gcc,meson,pkgconf,python-mako,glslang,libglvnd,lib32-libglvnd,libxnvctrl,libdrm}"
2020-05-26 14:55:59 +00:00
dep_install
2020-12-07 02:32:52 +00:00
break
2020-02-03 10:09:24 +00:00
; ;
2020-12-07 02:32:52 +00:00
*fedora*)
2020-02-02 05:29:49 +00:00
MANAGER_QUERY = "dnf list installed"
MANAGER_INSTALL = "dnf install"
2020-07-13 10:34:48 +00:00
DEPS = "{meson,gcc,gcc-c++,libX11-devel,glslang,python3-mako,mesa-libGL-devel,libXNVCtrl-devel,dbus-devel}"
2020-05-26 14:55:59 +00:00
dep_install
2020-02-02 05:29:49 +00:00
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}"
2020-05-26 14:55:59 +00:00
dep_install
2020-12-07 02:32:52 +00:00
break
2020-02-03 10:09:24 +00:00
; ;
2020-12-07 02:32:52 +00:00
2021-08-08 18:25:08 +00:00
*debian*| *ubuntu*| *deepin*)
2020-02-08 12:47:41 +00:00
MANAGER_QUERY = "dpkg-query -s"
2020-02-02 05:29:49 +00:00
MANAGER_INSTALL = "apt install"
2020-04-05 12:11:16 +00:00
DEPS = "{gcc,g++,gcc-multilib,g++-multilib,ninja-build,python3-pip,python3-setuptools,python3-wheel,pkg-config,mesa-common-dev,libx11-dev,libxnvctrl-dev,libdbus-1-dev}"
2020-05-26 14:55:59 +00:00
dep_install
2020-05-10 12:11:56 +00:00
2020-05-26 14:58:47 +00:00
if [ [ $( pip3 show meson; echo $? ) = = 1 || $( pip3 show mako; echo $? ) = = 1 ] ] ; then
2020-05-02 18:50:13 +00:00
$SU_CMD pip3 install 'meson>=0.54' mako
2020-02-01 18:52:37 +00:00
fi
2021-02-03 10:36:27 +00:00
if [ [ ! -f /usr/local/bin/glslangValidator ] ] ; then
2021-08-08 18:25:08 +00:00
wget https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip
2020-02-01 18:52:37 +00:00
unzip glslang-master-linux-Release.zip bin/glslangValidator
2021-07-06 17:08:46 +00:00
$SU_CMD /usr/bin/install -m755 bin/glslangValidator /usr/local/bin/
2020-02-01 18:52:37 +00:00
rm bin/glslangValidator glslang-master-linux-Release.zip
fi
2020-12-07 02:32:52 +00:00
break
2020-02-03 10:09:24 +00:00
; ;
2020-12-07 02:32:52 +00:00
*suse*)
2020-04-05 13:05:10 +00:00
PACKMAN_PKGS = "libXNVCtrl-devel"
2020-12-07 02:32:52 +00:00
echo " You may have to enable packman repository for some extra packages: ${ PACKMAN_PKGS } "
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"
2020-04-05 13:05:10 +00:00
2020-03-17 16:31:41 +00:00
MANAGER_QUERY = "rpm -q"
2020-03-16 19:14:31 +00:00
MANAGER_INSTALL = "zypper install"
2021-07-06 17:08:46 +00:00
DEPS = " {gcc-c++,gcc-c++-32bit,libpkgconf-devel,ninja,python3-pip,python3-Mako,libX11-devel,glslang-devel,glibc-devel,glibc-devel-32bit,libstdc++-devel,libstdc++-devel-32bit,Mesa-libGL-devel,dbus-1-devel,libdrm-devel, ${ PACKMAN_PKGS } } "
2020-05-26 14:55:59 +00:00
dep_install
2020-04-05 13:05:10 +00:00
2020-05-26 14:58:47 +00:00
if [ [ $( pip3 show meson; echo $? ) = = 1 ] ] ; then
$SU_CMD pip3 install 'meson>=0.54'
2020-04-05 13:05:10 +00:00
fi
2020-12-07 02:32:52 +00:00
break
2020-03-16 21:10:34 +00:00
; ;
2020-12-07 02:32:52 +00:00
*solus*)
2020-02-17 11:17:46 +00:00
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
2020-05-26 14:55:59 +00:00
dep_install
2020-12-07 02:32:52 +00:00
break
2020-02-17 11:17:46 +00:00
; ;
2020-02-01 18:52:37 +00:00
*)
echo "# Unable to find distro information!"
echo "# Attempting to build regardless"
esac
2020-12-07 02:32:52 +00:00
done
2020-02-01 18:52:37 +00:00
fi
}
2020-01-28 07:20:23 +00:00
configure( ) {
2020-02-01 18:52:37 +00:00
dependencies
git submodule update --init --depth 50
2020-02-12 09:56:29 +00:00
if [ [ ! -f "build/meson64/build.ninja" ] ] ; then
2021-08-08 12:46:44 +00:00
meson build/meson64 --libdir lib/mangohud/lib64 --prefix /usr -Dappend_libdir_mangohud= false -Dld_libdir_prefix= true -Dld_libdir_abs= true $@ ${ CONFIGURE_OPTS }
2020-02-05 20:01:28 +00:00
fi
2021-08-08 12:46:44 +00:00
if [ [ ! -f "build/meson32/build.ninja" && " $MACHINE " = "x86_64" ] ] ; 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-11-27 15:43:44 +00:00
meson build/meson32 --libdir lib/mangohud/lib32 --prefix /usr -Dappend_libdir_mangohud= false -Dld_libdir_prefix= true -Dld_libdir_abs= true $@ ${ CONFIGURE_OPTS }
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-07-20 12:30:16 +00:00
configure $@
2020-02-03 10:09:24 +00:00
fi
2020-03-11 16:04:10 +00:00
DESTDIR = " $PWD /build/release " ninja -C build/meson64 install
2021-08-08 12:46:44 +00:00
if [ " $MACHINE " = "x86_64" ] ; then
DESTDIR = " $PWD /build/release " ninja -C build/meson32 install
fi
2020-01-28 07:20:23 +00:00
}
2020-02-02 22:40:06 +00:00
package( ) {
2021-08-08 12:46:44 +00:00
LIB = "build/release/usr/lib/mangohud/lib64/libMangoHud.so"
2020-03-11 16:04:10 +00:00
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
2020-03-10 21:38:27 +00:00
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
2020-03-10 21:38:27 +00:00
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
2020-03-10 21:38:27 +00:00
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-07-08 20:43:09 +00:00
uninstall( ) {
[ " $UID " -eq 0 ] || exec $SU_CMD bash " $0 " uninstall
rm -rfv "/usr/lib/mangohud"
2020-08-13 15:28:16 +00:00
rm -rfv "/usr/share/doc/mangohud"
rm -fv "/usr/share/man/man1/mangohud.1"
2020-07-08 20:43:09 +00:00
rm -fv "/usr/share/vulkan/implicit_layer.d/mangohud.json"
2020-08-13 15:28:16 +00:00
rm -fv "/usr/share/vulkan/implicit_layer.d/MangoHud.json"
2020-07-08 20:43:09 +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-08-13 15:28:16 +00:00
rm -fv "/usr/bin/mangohud"
2020-07-08 20:43:09 +00:00
rm -fv "/usr/bin/mangohud.x86"
}
2020-02-02 22:40:06 +00:00
install( ) {
2020-03-13 16:51:32 +00:00
rm -rf " $HOME /.local/share/MangoHud/ "
2020-03-11 09:01:46 +00:00
rm -f " $HOME /.local/share/vulkan/implicit_layer.d/ " { mangohud32.json,mangohud64.json}
2020-03-21 12:56:39 +00:00
2020-03-15 17:26:02 +00:00
[ " $UID " -eq 0 ] || mkdir -pv " ${ CONFIG_DIR } "
2020-08-05 08:52:58 +00:00
[ " $UID " -eq 0 ] || build
2020-04-12 09:51:14 +00:00
[ " $UID " -eq 0 ] || exec $SU_CMD bash " $0 " install
2020-03-21 12:56:39 +00:00
2020-08-13 15:28:16 +00:00
uninstall
2021-08-08 12:46:44 +00:00
DEFAULTLIB = lib32
for i in $DISTRO ; do
case $i in
*arch*)
DEFAULTLIB = lib64
; ;
esac
done
2021-08-08 22:46:31 +00:00
if [ " $MACHINE " != "x86_64" ] ; then
2021-08-08 12:46:44 +00:00
# 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
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
fi
2020-08-13 15:37:06 +00:00
/usr/bin/install -Dvm644 ./build/release/usr/share/vulkan/implicit_layer.d/MangoHud.json /usr/share/vulkan/implicit_layer.d/MangoHud.json
/usr/bin/install -Dvm644 ./build/release/usr/share/vulkan/implicit_layer.d/MangoHud.json /usr/share/vulkan/implicit_layer.d/MangoHud.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
2020-03-21 12:56:39 +00:00
2021-08-08 12:46:44 +00:00
ln -sv $DEFAULTLIB /usr/lib/mangohud/lib
2020-07-08 20:43:09 +00:00
# FIXME get the triplet somehow
2021-08-08 12:46:44 +00:00
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
2020-09-11 07:47:26 +00:00
mkdir -p /usr/lib/mangohud/tls
2021-08-08 12:46:44 +00:00
ln -sv ../lib64 /usr/lib/mangohud/tls/x86_64
2020-09-11 07:47:26 +00:00
ln -sv ../lib32 /usr/lib/mangohud/tls/i686
2021-08-08 12:46:44 +00:00
2020-10-22 16:22:54 +00:00
# Some distros search in $prefix/x86_64-linux-gnu/tls/x86_64 etc instead
2021-08-08 12:46:44 +00:00
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
2020-09-11 07:47:26 +00:00
# $LIB can be "lib/tls/x86_64"?
ln -sv ../tls /usr/lib/mangohud/lib/tls
2020-11-10 07:04:13 +00:00
2021-08-08 12:46:44 +00:00
#ln -sv lib64 /usr/lib/mangohud/aarch64-linux-gnu
#ln -sv lib64 /usr/lib/mangohud/arm-linux-gnueabihf
2020-03-21 12:56:39 +00:00
2020-03-10 12:39:52 +00:00
echo "MangoHud Installed"
2020-01-29 10:35:42 +00:00
}
2020-05-05 19:37:15 +00:00
reinstall( ) {
build
package
install
}
2020-01-28 07:20:23 +00:00
clean( ) {
2020-02-12 09:56:29 +00:00
rm -rf "build"
2021-02-03 10:36:27 +00:00
rm -rf subprojects/*/
2020-01-28 07:20:23 +00:00
}
2020-03-15 08:16:53 +00:00
usage( ) {
if test -z $1 ; then
2021-03-09 01:41:30 +00:00
echo " Unrecognized command argument: $arg "
2020-03-15 08:16:53 +00:00
else
2020-03-15 08:27:19 +00:00
echo " $0 requires one argument "
2020-03-15 08:16:53 +00:00
fi
2020-03-21 14:17:34 +00:00
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"
2020-06-25 10:55:27 +00:00
echo -e "\treinstall\tRuns build, then package, and finally install"
2020-03-21 14:17:34 +00:00
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"
2020-03-15 08:16:53 +00:00
}
2020-07-20 12:30:16 +00:00
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 [@] } ; ;
2021-07-06 17:08:46 +00:00
"build_dbg" ) build --buildtype= debug -Dglibcxx_asserts= true ${ OPTS [@] } ; ;
2020-02-03 10:09:24 +00:00
"package" ) package; ;
2020-02-03 22:03:21 +00:00
"install" ) install; ;
2020-05-05 19:37:15 +00:00
"reinstall" ) reinstall; ;
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
*)
2020-03-15 08:16:53 +00:00
usage
2020-02-03 10:09:24 +00:00
esac
done