110 lines
5.6 KiB
Shell
110 lines
5.6 KiB
Shell
|
|
#!/bin/sh
|
||
|
|
# SPDX-License-Identifier: GPL-3.0-only
|
||
|
|
# SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
# build-flatpak.sh — the aarch64 flatpak of imsd-messages, into an OSTree
|
||
|
|
# repository. crafter-build cross-compiles the executable against the
|
||
|
|
# sysroot of packaging/make-flatpak-sysroot.sh (run that first), and
|
||
|
|
# flatpak's build commands assemble it on org.freedesktop.Platform 26.08,
|
||
|
|
# with the libc++ it was linked against in /app/lib.
|
||
|
|
#
|
||
|
|
# packaging/build-flatpak.sh <repo> [branch] # branch: master by default
|
||
|
|
#
|
||
|
|
# The repository is created when it does not exist; `flatpak build-bundle`
|
||
|
|
# makes a single-file bundle out of it. The cache and $CRAFTER_REF are
|
||
|
|
# make-flatpak-sysroot.sh's. Needs flatpak, flock, readelf and
|
||
|
|
# appstreamcli.
|
||
|
|
set -eu
|
||
|
|
|
||
|
|
REPO=${1:?usage: build-flatpak.sh <repo> [branch]}
|
||
|
|
BRANCH=${2:-master}
|
||
|
|
APP_ID=net.catcrafts.ImsdMessages
|
||
|
|
ARCH=aarch64
|
||
|
|
TRIPLE=aarch64-unknown-linux-gnu
|
||
|
|
MULTIARCH=aarch64-linux-gnu
|
||
|
|
RUNTIME_VERSION=26.08
|
||
|
|
CRAFTER_REF=${CRAFTER_REF:-net.catcrafts.CrafterBuild//stable}
|
||
|
|
CACHE=${IMSD_MESSAGES_FLATPAK_CACHE:-${XDG_CACHE_HOME:-$HOME/.cache}/imsd-messages/flatpak}
|
||
|
|
INSTALLATION="$CACHE/installation"
|
||
|
|
SYSROOT="$CACHE/sysroot-$ARCH"
|
||
|
|
LIBCXX="$CACHE/libcxx-$ARCH"
|
||
|
|
SRC=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
||
|
|
# flatpak commands that need the aarch64 Sdk and Platform see their
|
||
|
|
# installation; crafter-build runs from wherever it is installed.
|
||
|
|
withsdk() { FLATPAK_USER_DIR="$INSTALLATION" "$@"; }
|
||
|
|
|
||
|
|
command -v readelf >/dev/null 2>&1 || { echo "readelf (binutils) is needed: the NEEDED checks below run on it" >&2; exit 1; }
|
||
|
|
# One build at a time on this cache: the build directory is removed and
|
||
|
|
# made again by every run.
|
||
|
|
mkdir -p "$CACHE"
|
||
|
|
exec 9>"$CACHE/lock"; flock 9
|
||
|
|
[ -f "$SYSROOT/.made-from" ] || { echo "no sysroot at $SYSROOT: run packaging/make-flatpak-sysroot.sh first" >&2; exit 1; } # under the lock: a sysroot being made is not missing
|
||
|
|
|
||
|
|
echo ">> the executable for $TRIPLE"
|
||
|
|
# Generic armv8-a: a flatpak is for any aarch64 machine, not one SoC. The
|
||
|
|
# output directory's name ends in a hash of the configuration (the sysroot,
|
||
|
|
# --debug, --local), and an older variant left in bin/ would be a second
|
||
|
|
# match below: this run's is the only one.
|
||
|
|
rm -rf "$SRC/bin/imsd-messages-$TRIPLE-armv8-a-generic-"*
|
||
|
|
(cd "$SRC" && flatpak run "$CRAFTER_REF" --march=armv8-a --mtune=generic -- --target="$TRIPLE" --sysroot="$SYSROOT")
|
||
|
|
set -- "$SRC/bin/imsd-messages-$TRIPLE-armv8-a-generic-"*/
|
||
|
|
[ $# = 1 ] && [ -x "$1/imsd-messages" ] || { echo "expected one output directory with an executable under $SRC/bin for $TRIPLE, found: $*" >&2; exit 1; }
|
||
|
|
bin=$1
|
||
|
|
|
||
|
|
echo ">> $APP_ID from $bin"
|
||
|
|
build="$CACHE/build-$ARCH"
|
||
|
|
rm -rf "$build"
|
||
|
|
withsdk flatpak build-init --arch="$ARCH" "$build" "$APP_ID" org.freedesktop.Sdk org.freedesktop.Platform "$RUNTIME_VERSION"
|
||
|
|
files="$build/files"
|
||
|
|
# The executable finds its shaders and font beside its real path.
|
||
|
|
mkdir -p "$files/bin" "$files/lib/imsd-messages"
|
||
|
|
cp -a "$bin". "$files/lib/imsd-messages/"
|
||
|
|
ln -s ../lib/imsd-messages/imsd-messages "$files/bin/imsd-messages"
|
||
|
|
cp -a "$LIBCXX/usr/lib/"libc++.so.1* "$LIBCXX/usr/lib/"libc++abi.so.1* "$LIBCXX/usr/lib/"libunwind.so.1* "$files/lib/"
|
||
|
|
install -Dm644 "$SRC/packaging/$APP_ID.desktop" "$files/share/applications/$APP_ID.desktop"
|
||
|
|
install -Dm644 "$SRC/packaging/icons/$APP_ID.svg" "$files/share/icons/hicolor/scalable/apps/$APP_ID.svg"
|
||
|
|
install -Dm644 "$SRC/packaging/$APP_ID.metainfo.xml" "$files/share/metainfo/$APP_ID.metainfo.xml"
|
||
|
|
# The licences of what the flatpak carries; packaging/licenses/NOTICE names
|
||
|
|
# what each text covers.
|
||
|
|
licenses="$files/share/licenses/$APP_ID"
|
||
|
|
install -Dm644 "$SRC/LICENSE" "$licenses/LICENSE"
|
||
|
|
install -Dm644 "$SRC/assets/OFL.txt" "$licenses/OFL.txt"
|
||
|
|
install -Dm644 -t "$licenses" "$SRC"/packaging/licenses/* "$LIBCXX"/licenses/*
|
||
|
|
|
||
|
|
# Every library the executable and the bundled ones need is in the Platform
|
||
|
|
# or in /app/lib, or the first start would fail on the phone.
|
||
|
|
platform=$(withsdk flatpak --user info --show-location --arch="$ARCH" "org.freedesktop.Platform//$RUNTIME_VERSION")/files
|
||
|
|
missing=0
|
||
|
|
for elf in "$files/lib/imsd-messages/imsd-messages" "$files/lib/"lib*.so.1; do
|
||
|
|
for lib in $(readelf -d "$elf" | sed -n 's/.*(NEEDED).*\[\(.*\)\]/\1/p'); do
|
||
|
|
if [ ! -e "$platform/lib/$MULTIARCH/$lib" ] && [ ! -e "$platform/lib/$lib" ] && [ ! -e "$files/lib/$lib" ]; then
|
||
|
|
echo "$(basename "$elf") needs $lib, which neither the Platform nor /app/lib has" >&2
|
||
|
|
missing=1
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
done
|
||
|
|
# One unwinder: LLVM's libunwind, which the bundled libc++abi uses, never
|
||
|
|
# the Platform's libunwind 8 beside it.
|
||
|
|
for elf in "$files/lib/imsd-messages/imsd-messages" "$files/lib/"lib*.so.1; do
|
||
|
|
if readelf -d "$elf" | grep -q 'NEEDED.*\[libunwind\.so\.8\]'; then
|
||
|
|
echo "$(basename "$elf") links libunwind 8, not LLVM's libunwind" >&2
|
||
|
|
missing=1
|
||
|
|
fi
|
||
|
|
done
|
||
|
|
[ "$missing" = 0 ] || exit 1
|
||
|
|
|
||
|
|
# The AppStream catalogue entry software centres list the app by, with PNG
|
||
|
|
# icons: appstreamcli's default, JPEG XL, is not read by older clients.
|
||
|
|
appstreamcli compose --prefix=/ --origin="$APP_ID" --image-format=png \
|
||
|
|
--result-root="$files" --data-dir="$files/share/app-info/xmls" \
|
||
|
|
--icons-dir="$files/share/app-info/icons/flatpak" "$files"
|
||
|
|
|
||
|
|
# The phone's compositor, its GPU, imsd on the system bus and the desktop's
|
||
|
|
# notifications; the portals need no permission.
|
||
|
|
withsdk flatpak build-finish "$build" --command=imsd-messages \
|
||
|
|
--socket=wayland --device=dri \
|
||
|
|
--system-talk-name=net.catcrafts.IMS1 \
|
||
|
|
--talk-name=org.freedesktop.Notifications
|
||
|
|
mkdir -p "$(dirname "$REPO")"
|
||
|
|
withsdk flatpak build-export --arch="$ARCH" "$REPO" "$build" "$BRANCH"
|
||
|
|
echo ">> done: app/$APP_ID/$ARCH/$BRANCH in $REPO"
|