From 8caa2d142f5125324e0f1130bfc36c9245f4ccc6 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Thu, 1 Jun 2023 04:56:30 +0300 Subject: [PATCH] scripts: sailfish: initial SailfishOS support --- engine/wscript | 2 +- filesystem/wscript | 2 +- game_launch/game.cpp | 13 +++ game_launch/wscript | 4 +- public/wscript | 1 - scripts/sailfish/build.sh | 79 +++++++++++++++++++ scripts/sailfish/deploy.sh | 21 +++++ scripts/sailfish/harbour-xash3d-fwgs.desktop | 17 ++++ scripts/sailfish/harbour-xash3d-fwgs.spec | 83 ++++++++++++++++++++ scripts/sailfish/run.sh | 31 ++++++++ scripts/waifulib/xcompile.py | 7 +- wscript | 21 ++++- 12 files changed, 273 insertions(+), 8 deletions(-) create mode 100755 scripts/sailfish/build.sh create mode 100755 scripts/sailfish/deploy.sh create mode 100644 scripts/sailfish/harbour-xash3d-fwgs.desktop create mode 100644 scripts/sailfish/harbour-xash3d-fwgs.spec create mode 100644 scripts/sailfish/run.sh diff --git a/engine/wscript b/engine/wscript index 911cde93..7876fcd0 100644 --- a/engine/wscript +++ b/engine/wscript @@ -263,5 +263,5 @@ def build(bld): use = libs, install_path = install_path, subsystem = bld.env.MSVC_SUBSYSTEM, - rpath = '$ORIGIN', + rpath = bld.env.DEFAULT_RPATH, ) diff --git a/filesystem/wscript b/filesystem/wscript index 73f1777e..a0b842e9 100644 --- a/filesystem/wscript +++ b/filesystem/wscript @@ -45,6 +45,6 @@ def build(bld): source = tests[i], target = 'test_%s' % i, use = libs + ['DL'], - rpath = '$ORIGIN', + rpath = bld.env.DEFAULT_RPATH, subsystem = bld.env.CONSOLE_SUBSYSTEM, install_path = None) diff --git a/game_launch/game.cpp b/game_launch/game.cpp index 704c9f16..b29dd600 100644 --- a/game_launch/game.cpp +++ b/game_launch/game.cpp @@ -153,6 +153,19 @@ _inline int Sys_Start( void ) pfnChangeGame changeGame = NULL; const char *game = getenv( E_GAME ); +#ifdef XASH_SAILFISH + const char *home = getenv( "HOME" ); + char buf[1024]; + + snprintf( buf, sizeof( buf ), "%s/xash", home ); + setenv( "XASH3D_BASEDIR", buf, true ); +#if XASH_SAILFISH == aurora + setenv( "XASH3D_RODIR", "/usr/share/su.xash.Engine/rodir", true ); +#else + setenv( "XASH3D_RODIR", "/usr/share/harbour-xash3d-fwgs/rodir", true ); +#endif +#endif // SAILFISH + if( !game ) game = XASH_GAMEDIR; diff --git a/game_launch/wscript b/game_launch/wscript index 138d6911..3034eb4c 100644 --- a/game_launch/wscript +++ b/game_launch/wscript @@ -23,6 +23,7 @@ def configure(conf): def build(bld): libs = ['sdk_includes'] source = ['game.cpp'] + defines = [] if bld.env.DEST_OS != 'win32': libs += [ 'DL' ] @@ -34,7 +35,8 @@ def build(bld): target = 'xash3d', # hl.exe features = 'c cxx cxxprogram', use = libs, - rpath = '$ORIGIN', + defines = defines, + rpath = bld.env.DEFAULT_RPATH, install_path = bld.env.BINDIR, subsystem = bld.env.MSVC_SUBSYSTEM ) diff --git a/public/wscript b/public/wscript index 1243fd20..c1002e78 100644 --- a/public/wscript +++ b/public/wscript @@ -35,6 +35,5 @@ def build(bld): source = tests[i], target = 'test_%s' % i, use = 'public', - rpath = '$ORIGIN', subsystem = bld.env.CONSOLE_SUBSYSTEM, install_path = None) diff --git a/scripts/sailfish/build.sh b/scripts/sailfish/build.sh new file mode 100755 index 00000000..a451a845 --- /dev/null +++ b/scripts/sailfish/build.sh @@ -0,0 +1,79 @@ +#!/bin/bash + +. scripts/lib.sh + +download_sign_key() +{ + echo -n "Downloading $1: " + curl https://community.omprussia.ru/documentation/files/doc/$1 -o $1 &> /dev/null || die "Can't download $1" && echo "OK" +} + +pack_sources() +{ + echo "Packing sources to $1..." + git ls-files --recurse-submodules | tar caf "$1" -T- +} + +dependencies="SDL2-devel ImageMagick" +build_dir="build_rpm" + +if [ "$1" == "aurora" ]; then + name="su.xash.Engine" + flavor="aurora" +else + name="harbour-xash3d-fwgs" + flavor="sailfish" +fi + +if [ $flavor == 'aurora' ]; then + download_sign_key regular_key.pem + download_sign_key regular_cert.pem +fi + +rm -fr ${build_dir}/{BUILD,SRPMS} +mkdir -p ${build_dir}/SOURCES +pack_sources ${build_dir}/SOURCES/${name}.tar +git clone https://github.com/FWGS/hlsdk-portable -b mobile_hacks +pushd hlsdk-portable +pack_sources ../${build_dir}/SOURCES/hlsdk-portable.tar +popd + +sfdk_targets=`sfdk engine exec sb2-config -l | grep default | grep -v i486` + +for each in $sfdk_targets; do + target_arch=${each##*-} + target_arch=${target_arch/.default/} + echo "Build for '$each' target with '$target_arch' architecture" + + # install deps for current target + sfdk engine exec sb2 -t $each -R -m sdk-install zypper in -y ${dependencies} + + # build RPM for current target + sfdk engine exec sb2 -t $each rpmbuild \ + --define "_topdir `pwd`/${build_dir}" \ + --define "_arch $target_arch" \ + --define "_packagename $name" \ + --define "_flavor $flavor" \ + -ba scripts/sailfish/harbour-xash3d-fwgs.spec || die "Build for ${each}: FAIL" + + # sign RPM packacge + if [ "$flavor" == "aurora" ]; then + echo -n "Signing RPMs: " + sfdk engine exec sb2 -t $each rpmsign-external sign --key `pwd`/regular_key.pem --cert `pwd`/regular_cert.pem `pwd`/${build_dir}/RPMS/${target_arch}/$name-0*.rpm || die "FAIL" && echo "OK" + fi + + echo -n "Validate RPM: " + if [ "$flavor" == "aurora" ]; then + validator_output=`sfdk engine exec rpm-validator -p regular $(pwd)/${build_dir}/RPMS/${target_arch}/$name-0* 2>&1` + else + sfdk config target=${each/.default/} + validator_output=`sfdk check $(pwd)/${build_dir}/RPMS/${target_arch}/$name-0* 2>&1` + fi + if [ $? -ne 0 ] ; then + echo "FAIL" + echo "${validator_output}" + break; + fi + echo "OK" +done +echo "All build done! All your packages in `pwd`/build_rpm/RPMS" diff --git a/scripts/sailfish/deploy.sh b/scripts/sailfish/deploy.sh new file mode 100755 index 00000000..90b95556 --- /dev/null +++ b/scripts/sailfish/deploy.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +PASSWORD="12345" +IP="192.168.1.10" + +if [ "$1" == "aurora" ]; then + name="su.xash.Engine" + arch="armv7hl" # lame! +else + name="harbour-xash3d-fwgs" + arch="aarch64" # absolutely lame... +fi +package=$(ls build_rpm/RPMS/$arch/$name-0*.rpm) + +sshpass -p $PASSWORD scp $package defaultuser@$IP:~/ + +# sandwich of programs: +# 1. Call sshpass to automatically fill password for ssh session +# 2. Call devel-su that reads password from stdin +# 3. devel-su calls pkcon install-local -y and installs the package +echo $PASSWORD | sshpass -p $PASSWORD ssh defaultuser@$IP devel-su pkcon install-local -y $(basename $package) diff --git a/scripts/sailfish/harbour-xash3d-fwgs.desktop b/scripts/sailfish/harbour-xash3d-fwgs.desktop new file mode 100644 index 00000000..cadf0b60 --- /dev/null +++ b/scripts/sailfish/harbour-xash3d-fwgs.desktop @@ -0,0 +1,17 @@ +[Desktop Entry] +Categories=Game;Shooter; +Comment=Half-Life compatible game engine +Exec=__REPLACE_EXEC__ +Icon=__REPLACE_ICON__ +Keywords=first;person;shooter;multiplayer;half-life;halflife;singleplayer; +Name=Xash3D FWGS +Name[en]=Xash3D FWGS +PrefersNonDefaultGPU=true +Terminal=false +Type=Application +X-Nemo-Application-Type=silica-qt5 + +[X-Sailjail] +Permissions=Audio;Internet;Microphone;PublicDir; +OrganizationName=su.xash +ApplicationName=Engine diff --git a/scripts/sailfish/harbour-xash3d-fwgs.spec b/scripts/sailfish/harbour-xash3d-fwgs.spec new file mode 100644 index 00000000..e0ca166f --- /dev/null +++ b/scripts/sailfish/harbour-xash3d-fwgs.spec @@ -0,0 +1,83 @@ +# Based on harbour-quake2 spec file + +Name: %{_packagename} +Summary: Xash3D FWGS +Release: 1 +Version: 0.20 +Group: Amusements/Games +License: GPLv2 +BuildArch: %{_arch} +URL: https://github.com/FWGS/xash3d-fwgs +Source0: %{name}.tar +Source1: hlsdk-portable.tar +BuildRequires: SDL2-devel ImageMagick + +%define __provides_exclude_from ^%{_datadir}/%{name}/lib/.*$ + +%description +Xash3D FWGS is a game engine compatible with Half-Life 1 and mods. + +%prep +tar -xf %{_topdir}/SOURCES/%{name}.tar +python3 waf configure \ + -T release \ + --sailfish=%{_flavor} \ + --enable-stbtt \ + --enable-bundled-deps \ + --enable-packaging \ + --disable-gl \ + --enable-gles2 \ + --enable-gl4es \ + --prefix=/usr \ + --libdir=%{_datadir}/%{name}/lib \ + --bindir=%{_bindir} + +mkdir -p hlsdk-portable +pushd hlsdk-portable +tar -xf %{_topdir}/SOURCES/hlsdk-portable.tar +python3 waf configure -T release +popd + +%build +python3 waf build -j$(($(nproc)+1)) +pushd hlsdk-portable +python3 waf build -j$(($(nproc)+1)) +popd + +%install +python3 waf install --destdir=%{buildroot} +pushd hlsdk-portable +python3 waf install --destdir=%{buildroot}%{_datadir}/%{name}/rodir +popd +# rename real binary +mv %{buildroot}/usr/bin/xash3d %{buildroot}/usr/bin/%{name} + +install -d %{buildroot}/%{_datadir}/applications +sed "s/__REPLACE_ICON__/su.xash.Engine/g;s/__REPLACE_EXEC__/su.xash.Engine/g;" scripts/sailfish/harbour-xash3d-fwgs.desktop > %{buildroot}/%{_datadir}/applications/%{name}.desktop +chmod 644 %{buildroot}/%{_datadir}/applications/%{name}.desktop + +install -d %{buildroot}/%{_datadir}/icons/hicolor/86x86/apps +install -d %{buildroot}/%{_datadir}/icons/hicolor/108x108/apps +install -d %{buildroot}/%{_datadir}/icons/hicolor/128x128/apps +install -d %{buildroot}/%{_datadir}/icons/hicolor/172x172/apps +convert game_launch/icon-xash-material.png -resize 86x86 %{buildroot}/%{_datadir}/icons/hicolor/86x86/apps/%{name}.png +convert game_launch/icon-xash-material.png -resize 108x108 %{buildroot}/%{_datadir}/icons/hicolor/108x108/apps/%{name}.png +convert game_launch/icon-xash-material.png -resize 128x128 %{buildroot}/%{_datadir}/icons/hicolor/128x128/apps/%{name}.png +convert game_launch/icon-xash-material.png -resize 172x172 %{buildroot}/%{_datadir}/icons/hicolor/172x172/apps/%{name}.png + +%files +%defattr(-,root,root,-) +%attr(755,root,root) %{_bindir}/%{name} +%attr(755,root,root) %{_datadir}/%{name}/lib/* +%attr(644,root,root) %{_datadir}/%{name}/rodir/valve/extras.pk3 +%attr(755,root,root) %{_datadir}/%{name}/rodir/valve/cl_dlls/* +%attr(755,root,root) %{_datadir}/%{name}/rodir/valve/dlls/* +%attr(644,root,root) %{_datadir}/icons/hicolor/86x86/apps/%{name}.png +%attr(644,root,root) %{_datadir}/icons/hicolor/108x108/apps/%{name}.png +%attr(644,root,root) %{_datadir}/icons/hicolor/128x128/apps/%{name}.png +%attr(644,root,root) %{_datadir}/icons/hicolor/172x172/apps/%{name}.png +%{_datadir}/applications/%{name}.desktop + +%changelog +* Thu Jun 1 2023 a1batross +- initial port diff --git a/scripts/sailfish/run.sh b/scripts/sailfish/run.sh new file mode 100644 index 00000000..cdd59e53 --- /dev/null +++ b/scripts/sailfish/run.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +die() +{ + echo "$@" + exit 1 +} + +echo "Xash3D FWGS installed as Sailfish RPM" + +# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html +# $XDG_DATA_HOME defines the base directory relative to which user-specific data files should be stored. +# If $XDG_DATA_HOME is either not set or empty, a default equal to $HOME/.local/share should be used. +if [ -z "$XDG_DATA_HOME" ]; then + export XDG_DATA_HOME="$HOME/.local/share" +fi + +if [ -z "$XASH3D_BASEDIR" ]; then + export XASH3D_BASEDIR="$XDG_DATA_HOME/xash3d-fwgs/" +fi + +mkdir -p "$XASH3D_BASEDIR" +cd "$XASH3D_BASEDIR" || die "Can't cd into $XASH3D_BASEDIR" +echo "XASH3D_BASEDIR is $XASH3D_BASEDIR" + +#if [ -z "$XASH3D_EXTRAS_PAK1" ]; then +# export XASH3D_EXTRAS_PAK1=/app/share/xash3d/valve/extras.pk3 +#fi +#echo "XASH3D_EXTRAS_PAK1 is $XASH3D_EXTRAS_PAK1" + +exec $DEBUGGER /app/lib32/xash3d/xash3d "$@" diff --git a/scripts/waifulib/xcompile.py b/scripts/waifulib/xcompile.py index 08e90228..18f190a0 100644 --- a/scripts/waifulib/xcompile.py +++ b/scripts/waifulib/xcompile.py @@ -507,9 +507,11 @@ def options(opt): xc.add_option('--enable-msvc-wine', action='store_true', dest='MSVC_WINE', default=False, help='enable building with MSVC using Wine [default: %default]') xc.add_option('--nswitch', action='store_true', dest='NSWITCH', default = False, - help ='enable building for Nintendo Switch [default: %default]') + help='enable building for Nintendo Switch [default: %default]') xc.add_option('--psvita', action='store_true', dest='PSVITA', default = False, - help ='enable building for PlayStation Vita [default: %default]') + help='enable building for PlayStation Vita [default: %default]') + xc.add_option('--sailfish', action='store', dest='SAILFISH', default = None, + help='enable building for Sailfish/Aurora') def configure(conf): if conf.options.ANDROID_OPTS: @@ -593,6 +595,7 @@ def configure(conf): conf.env.MAGX = conf.options.MAGX conf.env.MSVC_WINE = conf.options.MSVC_WINE + conf.env.SAILFISH = conf.options.SAILFISH MACRO_TO_DESTOS = OrderedDict({ '__ANDROID__' : 'android', '__SWITCH__' : 'nswitch', '__vita__' : 'psvita' }) for k in c_config.MACRO_TO_DESTOS: MACRO_TO_DESTOS[k] = c_config.MACRO_TO_DESTOS[k] # ordering is important diff --git a/wscript b/wscript index 338a99a1..8dcc0a73 100644 --- a/wscript +++ b/wscript @@ -261,6 +261,13 @@ def configure(conf): # check if we're in a sgug environment if 'sgug' in os.environ['LD_LIBRARYN32_PATH']: linkflags.append('-lc') + elif conf.env.SAILFISH != None: + # TODO: enable XASH_MOBILE_PLATFORM + conf.env.append_unique('DEFINES', 'XASH_SAILFISH=%s' % conf.env.SAILFISH) + + # Do not warn us about bug in SDL_Audio headers + conf.env.append_unique('CFLAGS', ['-Wno-attributes']) + conf.env.append_unique('CXXFLAGS', ['-Wno-attributes']) conf.check_cc(cflags=cflags, linkflags=linkflags, msg='Checking for required C flags') conf.check_cxx(cxxflags=cxxflags, linkflags=linkflags, msg='Checking for required C++ flags') @@ -335,6 +342,11 @@ def configure(conf): conf.env.DEDICATED = conf.options.DEDICATED conf.env.SINGLE_BINARY = conf.options.SINGLE_BINARY or conf.env.DEDICATED + if conf.env.SAILFISH == 'aurora': + conf.env.DEFAULT_RPATH = '/usr/share/su.xash.Engine/lib' + else: + conf.env.DEFAULT_RPATH = '$ORIGIN' + setattr(conf, 'refdlls', REFDLLS) for refdll in REFDLLS: @@ -432,8 +444,13 @@ int main(int argc, char **argv) { strchrnul(argv[1], 'x'); return 0; }''' conf.env.PACKAGING = conf.options.PACKAGING if conf.options.PACKAGING: conf.env.PREFIX = conf.options.prefix - conf.env.LIBDIR = conf.env.BINDIR = conf.env.LIBDIR + '/xash3d' - conf.env.SHAREDIR = '${PREFIX}/share/xash3d' + if conf.env.SAILFISH == "aurora": + conf.env.SHAREDIR = '${PREFIX}/share/su.xash.Engine/rodir' + elif conf.env.SAILFISH == "sailfish": + conf.env.SHAREDIR = '${PREFIX}/share/harbour-xash3d-fwgs/rodir' + else: + conf.env.SHAREDIR = '${PREFIX}/share/xash3d' + conf.env.LIBDIR += '/xash3d' else: conf.env.SHAREDIR = conf.env.LIBDIR = conf.env.BINDIR = conf.env.PREFIX