1 LinuxAppImage
Itms edited this page 2024-03-28 20:41:11 +01:00

Linux AppImage

You can use these steps to create an AppImage:

Build 0ad. Using the 0ad stable distribution archives is recommended.

./clean-workspaces.sh
./update-workspaces.sh -j$(nproc) \
 && make config=release -C gcc -j$(nproc)

Copy the content in the code block below and save it to a text file (to be run as script). READ through the comments before running the script. It will require minor edits.

# install.sh: Installs files to prepare for building an AppImage
# Copyright 2022 The 0ad project
#
set -ev # exit on error, be verbose

# VERSION= Set the version of the appimage (e.g
# ARCH = probably not needed, usually auto-detected

# Some other variables can be used but I couldn't find the docs for them.
# They're shown in the code here:
# https://github.com/AppImage/AppImageKit/blob/master/src/appimagetool.c

# Get a copy of 'linuxdeploy' (you can use `wget` to get the desired release/arch).
# https://github.com/linuxdeploy/linuxdeploy/releases

# NOTE: Instead of using 'linuxdeploy', you might want to use 'appimagetool' which is a
# lower-level tool that provides other options, such as signing.
# https://github.com/AppImage/AppImageKit#appimagetool-usage

# In a docker container, you'll get an error if trying to run an appimage.
#
# dlopen(): error loading libfuse.so.2
# AppImages require FUSE to run.
#
# You can enter `./linuxdeploy-x86_64.AppImage --appimage-extract` to
# extract the image. It will extract to a directory named 'squashfs-root'.
# You can then execute linuxdeploy and all required arguments by using
# <path-to>/squashfs-root/AppRun [args]

if [ -z ${ARCH} ]; then
  echo "ARCH must be set"
  exit 1
fi

wget -c "https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-${ARCH}.AppImage"
chmod +x linuxdeploy-${ARCH}.AppImage

# The linuxdeploy gtk plugin is required for Atlas to work
wget -c "https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh"
chmod +x linuxdeploy-plugin-gtk.sh

# 'patchelf' is required
# '-e' is set so the script will exit with an error message if this fails
patchelf --version

#ABS_PATH_WORK_DIR=
#ABS_PATH_SRC_ROOT=/0ad

if [ ! -d "${ABS_PATH_WORK_DIR}" ]; then
  echo "The work dir must be an absolute path to an existing directory."
  exit 1
fi

if [ ! -r "${ABS_PATH_SRC_ROOT}/source/main.cpp" ]; then
  echo "set the source root!"
  exit 1
fi

APPDIR=${ABS_PATH_WORK_DIR}/AppDir

cd ${ABS_PATH_SRC_ROOT}

install -s binaries/system/pyrogenesis -Dt ${APPDIR}/usr/bin
install -s binaries/system/ActorEditor -Dt ${APPDIR}/usr/bin

cd ${APPDIR}/usr/bin
ln -s pyrogenesis 0ad

for lib in libmozjs78-ps-release.so \
        libnvcore.so    \
        libnvimage.so   \
        libnvmath.so    \
        libnvtt.so
do
  patchelf --set-rpath $lib:${ABS_PATH_SRC_ROOT}/binaries/system pyrogenesis
done
patchelf --set-rpath libthai.so.0:$APPDIR/usr/lib ActorEditor
patchelf --set-rpath libAtlasUI.so:${ABS_PATH_SRC_ROOT}/binaries/system ActorEditor

# Note that binaries/system{libmoz*.so, libnv*.so, libAtlasUI.so} will be copied into
# the ${APPDIR} folder automatically when linuxdeploy is run below.

cd ${ABS_PATH_SRC_ROOT}

install binaries/system/libCollada.so -Dt ${APPDIR}/usr/lib
install build/resources/0ad.appdata.xml -Dt ${APPDIR}/usr/share/appdata
install build/resources/0ad.desktop -Dt ${APPDIR}/usr/share/applications
install build/resources/0ad.png -Dt ${APPDIR}/usr/share/pixmaps

mkdir -p ${APPDIR}/usr/data/config
cp -a binaries/data/config/default.cfg ${APPDIR}/usr/data/config

cp -a binaries/data/l10n ${APPDIR}/usr/data
cp -a binaries/data/tools ${APPDIR}/usr/data # for Atlas

# IMPORTANT: If you're creating the image from a distribution archive, this should copy
# 'binaries/data/mods/mod/mod.zip', 'binaries/data/mods/public/public.zip', and
# 'binaries/data/mods/public/mod.json'
# If you're using the svn/git version, you'll need to use the pyrogenesis
# pyromod archive builder. It's recommended to create the two zip files
# in a directory outside of the ${APPDIR} folder (in case you need to remove
# the ${APPDIR} folder later) and then copy them to ${APPDIR}/usr/data
# see https://trac.wildfiregames.com/wiki/Modding_Guide#Distributingyourmods
#
cp -a binaries/data/mods ${APPDIR}/usr/data

# Remove any symlinks to mods that may be in binaries/data/mods (this will cause 0ad to crash
# when the appimage is run). If you're creating the image from a clean 0ad archive, then
# there won't be any symlinks of course

# Create the image
cd ${ABS_PATH_WORK_DIR}

DEPLOY_GTK_VERSION=3 # Variable used by gtk plugin
./linuxdeploy-${ARCH}.AppImage -d ${APPDIR}/usr/share/applications/0ad.desktop \
  --icon-file=${APPDIR}/usr/share/pixmaps/0ad.png \
  --icon-filename=0ad \
  --executable ${APPDIR}/usr/bin/pyrogenesis \
  --library=/usr/lib/x86_64-linux-gnu/libthai.so.0 \ # not installed Gentoo
  --appdir ${APPDIR} \
  --output appimage \
  --plugin gtk

Other Notes:

To test any changes you want to make to the appimage, or for debugging, you can make changes inside the '${APPDIR}' folder, then cd back to '${APPDIR}' and enter ./AppRun. When satisfied, repeat the "Create image" step above.

To use the --writableRoot option with the 0ad appimage, it must be extracted by providing the --appimage-extract option to the 0ad appimage. Then cd into squashfs-root, and type in ./AppRun --writableRoot.