86 lines
3.7 KiB
Bash
Executable File
86 lines
3.7 KiB
Bash
Executable File
#!/bin/bash
|
|
# Builds libm3ui.so against an upstream Fcitx5 source tree of the same version
|
|
# as the Fcitx5 installed on this system. The addon needs Fcitx5's internal
|
|
# Wayland protocol wrappers, which are not part of fcitx5-devel, so it is built
|
|
# inside the upstream tree.
|
|
set -euo pipefail
|
|
|
|
root=$(cd "$(dirname "$0")/.." && pwd)
|
|
work=${WORK_DIR:-$root/build}
|
|
version=${FCITX_VERSION:-$(pkg-config --modversion Fcitx5Core)}
|
|
|
|
die() { echo "build.sh: $*" >&2; exit 1; }
|
|
command -v git >/dev/null || die "git is needed to fetch the sources"
|
|
|
|
# The sources are fetched by commit hash and the hash is checked afterwards. A
|
|
# tag can be moved and a downloaded archive can be swapped, a commit hash cannot
|
|
# be faked, Git verifies the content against it. This plugin runs inside the
|
|
# input method and sees everything that is typed, so what it is built from
|
|
# matters.
|
|
#
|
|
# Commit the Fcitx5 release tag points to, check it yourself when adding one:
|
|
# git ls-remote https://github.com/fcitx/fcitx5 "refs/tags/<version>^{}"
|
|
declare -A known_commits=(
|
|
["5.1.23"]="27cca6e0239938b2d53937061d0980c087856b22"
|
|
)
|
|
commit=${FCITX_COMMIT:-${known_commits[$version]:-}}
|
|
[ -n "$commit" ] || die "no pinned commit for Fcitx5 $version. Look up the commit of its tag and pass it as FCITX_COMMIT=<sha>"
|
|
# Commit of the yoga submodule pinned by Fcitx5 (third_party/yoga).
|
|
yoga_commit=${YOGA_COMMIT:-042f5013152eb81c1552dec945b88f7b95ca350f}
|
|
# libmonet (header-only) supplies the colours derived from the desktop accent.
|
|
monet_commit=${MONET_COMMIT:-b97a55ac75ae82435628dc585cccadb45e4d2feb}
|
|
|
|
# fetch_commit <url> <dir> <commit>, leaves <dir> checked out at exactly <commit>
|
|
fetch_commit() {
|
|
local url=$1 dir=$2 want=$3
|
|
if [ -d "$dir/.git" ] && [ "$(git -C "$dir" rev-parse HEAD 2>/dev/null)" = "$want" ]; then
|
|
return 0
|
|
fi
|
|
rm -rf "$dir"
|
|
mkdir -p "$dir"
|
|
git -C "$dir" init -q
|
|
git -C "$dir" fetch -q --depth 1 "$url" "$want" || die "could not fetch $want from $url"
|
|
git -C "$dir" checkout -q FETCH_HEAD
|
|
[ "$(git -C "$dir" rev-parse HEAD)" = "$want" ] || die "$url gave a different commit than $want"
|
|
}
|
|
|
|
srcdir=$work/fcitx5-$version
|
|
mkdir -p "$work"
|
|
echo ">> fetching Fcitx5 $version ($commit)"
|
|
fetch_commit https://github.com/fcitx/fcitx5 "$srcdir" "$commit"
|
|
echo ">> fetching yoga ($yoga_commit)"
|
|
fetch_commit https://github.com/facebook/yoga "$srcdir/third_party/yoga" "$yoga_commit"
|
|
echo ">> fetching libmonet ($monet_commit)"
|
|
fetch_commit https://git.oeo.one/justme/libmonet.git "$work/libmonet" "$monet_commit"
|
|
[ -z "${FETCH_ONLY:-}" ] || { echo ">> sources are in place"; exit 0; }
|
|
|
|
echo ">> overlaying m3ui"
|
|
echo ">> applying icon cache hardening"
|
|
cache_patch="$root/patches/fcitx5-icon-cache.patch"
|
|
if git -C "$srcdir" apply --check "$cache_patch"; then
|
|
git -C "$srcdir" apply "$cache_patch"
|
|
elif git -C "$srcdir" apply --reverse --check "$cache_patch"; then
|
|
echo ">> icon cache hardening already applied"
|
|
else
|
|
die "icon cache patch does not match Fcitx5 $version; refusing a partial build"
|
|
fi
|
|
rm -rf "$srcdir/src/ui/m3ui"
|
|
cp -r "$root/src" "$srcdir/src/ui/m3ui"
|
|
if ! grep -q 'add_subdirectory(m3ui)' "$srcdir/src/ui/CMakeLists.txt"; then
|
|
sed -i 's/^add_subdirectory(classic)$/add_subdirectory(classic)\nadd_subdirectory(m3ui)/' \
|
|
"$srcdir/src/ui/CMakeLists.txt"
|
|
fi
|
|
|
|
echo ">> configuring"
|
|
cmake -S "$srcdir" -B "$work/cmake" -G Ninja \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DMONET_INCLUDE_DIR="$work/libmonet/include" \
|
|
-DCMAKE_INSTALL_PREFIX="${PREFIX:-$HOME/.local/m3ui}" \
|
|
-DENABLE_X11=On -DENABLE_WAYLAND=On \
|
|
-DENABLE_TEST=Off -DENABLE_TESTING_ADDONS=Off -DENABLE_ENCHANT=Off \
|
|
-DENABLE_DOC=Off -DENABLE_XDGAUTOSTART=Off -DENABLE_EMOJI=Off
|
|
|
|
echo ">> building"
|
|
ninja -C "$work/cmake" m3ui src/ui/m3ui/m3ui.conf
|
|
echo ">> done, run scripts/install.sh"
|