2020-04-26 19:43:40 +00:00
#!/usr/bin/env bash
# Specialized build script for Steam Runtime SDK docker
2020-11-10 16:09:45 +00:00
set -e
2020-04-26 19:43:40 +00:00
2020-11-10 16:09:45 +00:00
IFS = " " read -ra debian_chroot < /etc/debian_chroot
LOCAL_CC = ${ CC :- gcc -5 }
LOCAL_CXX = ${ CXX :- g ++-5 }
RUNTIME = ${ RUNTIME :- ${ debian_chroot [1] } }
SRT_VERSION = ${ SRT_VERSION :- ${ debian_chroot [2] } }
2020-04-26 19:43:40 +00:00
VERSION = $( git describe --long --tags --always | sed 's/\([^-]*-g\)/r\1/;s/-/./g;s/^v//' )
dependencies( ) {
2020-11-10 16:09:45 +00:00
if [ [ ! -f build-srt/release/usr/lib/libMangoHud.so ] ] ; then
2020-04-26 19:43:40 +00:00
install( ) {
set +e
2020-11-10 16:09:45 +00:00
for i in ${ DEPS [@] } ; do
2020-04-26 19:43:40 +00:00
dpkg-query -s " $i " & > /dev/null
if [ [ $? = = 1 ] ] ; then
INSTALL = " $INSTALL " " $i "
fi
done
if [ [ ! -z " $INSTALL " ] ] ; then
apt-get update
apt-get -y install $INSTALL
fi
set -e
}
echo "# Checking Dependencies"
2022-03-05 20:12:30 +00:00
DEPS = ( ${ LOCAL_CC } -multilib ${ LOCAL_CXX } -multilib unzip)
2020-04-26 19:43:40 +00:00
install
2020-11-10 16:09:45 +00:00
# use py3.5 with scout, otherwise hope python is new enough
set +e
which python3.5 >/dev/null
if [ $? -eq 0 ] ; then
# py3.2 is weird
ln -sf python3.5 /usr/bin/python3
fi
set -e
2020-04-26 19:43:40 +00:00
if [ [ ! -f ./bin/get-pip.py ] ] ; then
2021-07-06 17:08:46 +00:00
curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o bin/get-pip.py
2021-07-02 16:42:05 +00:00
python3 ./bin/get-pip.py
2020-04-26 19:43:40 +00:00
fi
2021-07-02 16:42:05 +00:00
pip3 install 'meson>=0.54' mako
2020-04-26 19:43:40 +00:00
if [ [ ! -f /usr/include/NVCtrl/NVCtrl.h ] ] ; then
curl -LO http://mirrors.kernel.org/ubuntu/pool/main/n/nvidia-settings/libxnvctrl0_440.64-0ubuntu1_amd64.deb
curl -LO http://mirrors.kernel.org/ubuntu/pool/main/n/nvidia-settings/libxnvctrl-dev_440.64-0ubuntu1_amd64.deb
dpkg -i libxnvctrl0_440.64-0ubuntu1_amd64.deb libxnvctrl-dev_440.64-0ubuntu1_amd64.deb
fi
# preinstalled 7.10.xxxx
#if [[ ! -f /usr/local/bin/glslangValidator ]]; then
# curl -LO https://github.com/KhronosGroup/glslang/releases/download/master-tot/glslang-master-linux-Release.zip
# unzip glslang-master-linux-Release.zip bin/glslangValidator
# /usr/bin/install -m755 bin/glslangValidator /usr/local/bin/
# rm bin/glslangValidator glslang-master-linux-Release.zip
#fi
fi
}
configure( ) {
dependencies
git submodule update --init
2020-11-10 16:09:45 +00:00
if [ [ ! -f "build-srt/meson64/build.ninja" ] ] ; then
export CC = " ${ LOCAL_CC } "
export CXX = " ${ LOCAL_CXX } "
meson build-srt/meson64 --libdir lib/mangohud/lib --prefix /usr -Dappend_libdir_mangohud= false -Dld_libdir_prefix= true $@ ${ CONFIGURE_OPTS }
2020-04-26 19:43:40 +00:00
fi
2020-11-10 16:09:45 +00:00
if [ [ ! -f "build-srt/meson32/build.ninja" ] ] ; then
export CC = " ${ LOCAL_CC } -m32 "
export CXX = " ${ LOCAL_CXX } -m32 "
2020-04-26 19:43:40 +00:00
export PKG_CONFIG_PATH = " /usr/lib32/pkgconfig:/usr/lib/i386-linux-gnu/pkgconfig:/usr/lib/pkgconfig: ${ PKG_CONFIG_PATH_32 } "
2020-11-10 16:09:45 +00:00
meson build-srt/meson32 --libdir lib/mangohud/lib32 --prefix /usr -Dappend_libdir_mangohud= false -Dld_libdir_prefix= true $@ ${ CONFIGURE_OPTS }
2020-04-26 19:43:40 +00:00
fi
}
build( ) {
2020-11-10 16:09:45 +00:00
if [ [ ! -f "build-srt/meson64/build.ninja" || ! -f "build-srt/meson32/build.ninja" ] ] ; then
2021-07-06 17:08:46 +00:00
configure $@
2020-04-26 19:43:40 +00:00
fi
2020-11-10 16:09:45 +00:00
DESTDIR = " $PWD /build-srt/release " ninja -C build-srt/meson32 install
DESTDIR = " $PWD /build-srt/release " ninja -C build-srt/meson64 install
2020-04-26 19:43:40 +00:00
}
package( ) {
2020-11-10 16:09:45 +00:00
LIB = "build-srt/release/usr/lib/mangohud/lib/libMangoHud.so"
LIB32 = "build-srt/release/usr/lib/mangohud/lib32/libMangoHud.so"
if [ [ ! -f " $LIB " || " $LIB " -ot "build-srt/meson64/src/libMangoHud.so" ] ] ; then
2020-04-26 19:43:40 +00:00
build
fi
tar --numeric-owner --owner= 0 --group= 0 \
2020-11-10 16:09:45 +00:00
-C build-srt/release -cvf "build-srt/MangoHud-package.tar" .
2020-04-26 19:43:40 +00:00
}
release( ) {
2020-11-10 16:09:45 +00:00
rm build-srt/MangoHud-package.tar
mkdir -p build-srt/MangoHud
2020-04-26 19:43:40 +00:00
package
2020-11-10 16:09:45 +00:00
cp --preserve= mode bin/mangohud-setup.sh build-srt/MangoHud/mangohud-setup.sh
cp build-srt/MangoHud-package.tar build-srt/MangoHud/MangoHud-package.tar
2020-04-26 19:43:40 +00:00
tar --numeric-owner --owner= 0 --group= 0 \
2020-11-10 16:09:45 +00:00
-C build-srt -czvf build-srt/MangoHud-${ VERSION } _${ RUNTIME } -${ SRT_VERSION } .tar.gz MangoHud
2020-04-26 19:43:40 +00:00
}
clean( ) {
2020-11-10 16:09:45 +00:00
rm -rf "build-srt/"
2020-04-26 19:43:40 +00:00
}
usage( ) {
if test -z $1 ; then
echo " Unrecognized command argument: $a "
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 "\tclean\t\tRemoves build directory"
echo -e "\trelease\t\tBuilds a MangoHud release tar package"
}
2020-11-10 16:09:45 +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
"configure" ) configure ${ OPTS [@] } ; ;
"build" ) build ${ OPTS [@] } ; ;
2020-04-26 19:43:40 +00:00
"package" ) package; ;
"clean" ) clean; ;
"release" ) release; ;
*)
usage
esac
done