275 lines
9.7 KiB
Bash
Executable File
275 lines
9.7 KiB
Bash
Executable File
#!/bin/sh
|
|
# Cross-compile XLibre (X11Libre/xserver) + xf86-input-libinput + xf86-video-fbdev
|
|
# for Geminux aarch64 (MT6797X Cortex-A53/A72 + Mali-T880 Panfrost Glamor/DRI3/GLX)
|
|
set -eu
|
|
|
|
BASE_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
|
ROOTFS_DIR="${ROOTFS_DIR:-$BASE_DIR/rootfs}"
|
|
if [ -e "$ROOTFS_DIR" ]; then
|
|
ROOTFS_DIR="$(realpath "$ROOTFS_DIR")"
|
|
fi
|
|
|
|
exec docker run --rm --network=host \
|
|
-e HOST_UID="$(id -u)" \
|
|
-e HOST_GID="$(id -g)" \
|
|
-e FORCE_REBUILD="${FORCE_REBUILD:-0}" \
|
|
-v "$BASE_DIR:/geminux" \
|
|
-v "$ROOTFS_DIR:/target-rootfs" \
|
|
alpine:3.24 sh -eu -c '
|
|
cat > /etc/apk/repositories <<EOF
|
|
https://mirror.nura.eco/postmarketos/v26.06
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
|
EOF
|
|
cp /geminux/keys/*.rsa.pub /etc/apk/keys/
|
|
|
|
cleanup_perms() {
|
|
chown -R "$HOST_UID:$HOST_GID" \
|
|
/geminux/prebuilt/xlibre /geminux/build-cache \
|
|
/target-rootfs/usr/lib/xorg /target-rootfs/usr/bin/Xorg /target-rootfs/usr/bin/X 2>/dev/null || true
|
|
}
|
|
trap cleanup_perms EXIT
|
|
|
|
echo "[1/5] Installing host aarch64 cross-compilation toolchain and meson/ninja..."
|
|
apk add --no-cache \
|
|
build-base \
|
|
git \
|
|
ca-certificates \
|
|
patch \
|
|
gcc-aarch64 \
|
|
g++-aarch64 \
|
|
binutils-aarch64 \
|
|
meson \
|
|
ninja \
|
|
pkgconf \
|
|
python3 >/dev/null
|
|
|
|
XLIBRE_SRC="/geminux/build-cache/xlibre-xserver"
|
|
if [ ! -f "$XLIBRE_SRC/meson.build" ]; then
|
|
echo "[1b/5] Cloning X11Libre/xserver..."
|
|
rm -rf "$XLIBRE_SRC"
|
|
git clone --depth 1 https://github.com/X11Libre/xserver.git "$XLIBRE_SRC"
|
|
fi
|
|
XLIBRE_STAMP="$XLIBRE_SRC/.geminux-patches-sha"
|
|
XLIBRE_PATCH_SHA="$( { sha256sum /geminux/patches/xlibre/*.patch 2>/dev/null || echo "no-patches"; } | sha256sum | awk "{print \$1}" )"
|
|
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f "$XLIBRE_STAMP" ] || [ "$(cat "$XLIBRE_STAMP" 2>/dev/null || true)" != "$XLIBRE_PATCH_SHA" ]; then
|
|
echo "[1b-2/5] Applying XLibre patch series..."
|
|
if [ -d "$XLIBRE_SRC/.git" ]; then
|
|
git -c safe.directory="$XLIBRE_SRC" -C "$XLIBRE_SRC" checkout -- .
|
|
fi
|
|
for p in /geminux/patches/xlibre/*.patch; do
|
|
[ -f "$p" ] && patch -d "$XLIBRE_SRC" -p1 < "$p"
|
|
done
|
|
printf "%s\n" "$XLIBRE_PATCH_SHA" > "$XLIBRE_STAMP"
|
|
fi
|
|
|
|
XF86_LIBINPUT_SRC="/geminux/build-cache/xf86-input-libinput"
|
|
if [ ! -f "$XF86_LIBINPUT_SRC/meson.build" ]; then
|
|
echo "[1c/5] Cloning X11Libre/xf86-input-libinput..."
|
|
rm -rf "$XF86_LIBINPUT_SRC"
|
|
git clone --depth 1 https://github.com/X11Libre/xf86-input-libinput.git "$XF86_LIBINPUT_SRC"
|
|
fi
|
|
|
|
XF86_FBDEV_SRC="/geminux/build-cache/xf86-video-fbdev"
|
|
if [ ! -f "$XF86_FBDEV_SRC/src/fbdev.c" ]; then
|
|
echo "[1d/5] Cloning X11Libre/xf86-video-fbdev..."
|
|
rm -rf "$XF86_FBDEV_SRC"
|
|
git clone --depth 1 https://github.com/X11Libre/xf86-video-fbdev.git "$XF86_FBDEV_SRC"
|
|
fi
|
|
|
|
echo "[2/5] Preparing pure Alpine Edge aarch64 sysroot for XLibre + DDX drivers..."
|
|
SYSROOT="/tmp/aarch64-sysroot"
|
|
mkdir -p "$SYSROOT/etc/apk/keys"
|
|
cat > "$SYSROOT/etc/apk/repositories" <<EOF
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/main
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/community
|
|
https://dl-cdn.alpinelinux.org/alpine/edge/testing
|
|
EOF
|
|
cp /geminux/keys/alpine-devel@*.rsa.pub "$SYSROOT/etc/apk/keys/"
|
|
apk --root "$SYSROOT" --initdb --arch aarch64 add --no-scripts \
|
|
alpine-baselayout \
|
|
musl-dev \
|
|
linux-headers \
|
|
xorgproto \
|
|
xtrans \
|
|
font-util-dev \
|
|
pixman-dev \
|
|
libx11-dev \
|
|
libxext-dev \
|
|
libxfont2-dev \
|
|
libxkbfile-dev \
|
|
libxshmfence-dev \
|
|
libxdmcp-dev \
|
|
libxau-dev \
|
|
libxcvt-dev \
|
|
libdrm-dev \
|
|
libepoxy-dev \
|
|
mesa-dev \
|
|
eudev-dev \
|
|
dbus-dev \
|
|
libpciaccess-dev \
|
|
openssl-dev \
|
|
libinput-dev \
|
|
mtdev-dev >/dev/null
|
|
|
|
OPT_CFLAGS="-O2 -march=armv8-a+crc+crypto -mtune=cortex-a53 -fno-plt"
|
|
|
|
cat > /tmp/aarch64-cross.ini <<EOF
|
|
[binaries]
|
|
c = '\''aarch64-alpine-linux-musl-gcc'\''
|
|
cpp = '\''aarch64-alpine-linux-musl-g++'\''
|
|
ar = '\''aarch64-alpine-linux-musl-ar'\''
|
|
strip = '\''aarch64-alpine-linux-musl-strip'\''
|
|
pkg-config = '\''pkgconf'\''
|
|
|
|
[built-in options]
|
|
c_args = ['\''--sysroot=/tmp/aarch64-sysroot'\'', '\''-O2'\'', '\''-march=armv8-a+crc+crypto'\'', '\''-mtune=cortex-a53'\'', '\''-fno-plt'\'']
|
|
c_link_args = ['\''--sysroot=/tmp/aarch64-sysroot'\'', '\''-Wl,-O1,--as-needed'\'']
|
|
|
|
[properties]
|
|
sys_root = '\''/tmp/aarch64-sysroot'\''
|
|
pkg_config_libdir = '\''/tmp/aarch64-sysroot/usr/lib/pkgconfig:/tmp/aarch64-sysroot/usr/share/pkgconfig'\''
|
|
|
|
[host_machine]
|
|
system = '\''linux'\''
|
|
cpu_family = '\''aarch64'\''
|
|
cpu = '\''aarch64'\''
|
|
endian = '\''little'\''
|
|
EOF
|
|
|
|
# Detect ABI module directory from meson.build or default xlibre-25
|
|
ABI_MOD_DIR="/usr/lib/xorg/modules/xlibre-25"
|
|
if grep -q "xlibre-26" "$XLIBRE_SRC/meson.build" 2>/dev/null; then
|
|
ABI_MOD_DIR="/usr/lib/xorg/modules/xlibre-26"
|
|
fi
|
|
|
|
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f /geminux/prebuilt/xlibre/usr/bin/Xorg ]; then
|
|
echo "[3/5] Configuring and compiling XLibre (X11Libre/xserver) for aarch64..."
|
|
rm -rf /tmp/build-xlibre
|
|
meson setup /tmp/build-xlibre "$XLIBRE_SRC" \
|
|
--cross-file=/tmp/aarch64-cross.ini \
|
|
--prefix=/usr \
|
|
--libdir=lib \
|
|
--libexecdir=libexec \
|
|
--sysconfdir=/etc \
|
|
--localstatedir=/var \
|
|
--buildtype=release \
|
|
-Dxorg=true \
|
|
-Dxorg-sdk=true \
|
|
-Dglamor=true \
|
|
-Dglx=true \
|
|
-Ddri1=false \
|
|
-Ddri2=true \
|
|
-Ddri3=true \
|
|
-Ddrm=true \
|
|
-Dgbm=true \
|
|
-Dudev=true \
|
|
-Dudev_kms=true \
|
|
-Dsystemd_logind=false \
|
|
-Dseatd_libseat=false \
|
|
-Dsuid_wrapper=false \
|
|
-Dpciaccess=true \
|
|
-Dvgahw=false \
|
|
-Dint10=false \
|
|
-Ddga=false \
|
|
-Dxv=true \
|
|
-Dxvmc=false \
|
|
-Dxephyr=false \
|
|
-Dxnest=false \
|
|
-Dxvfb=false \
|
|
-Dxfake=false \
|
|
-Dxfbdev=false \
|
|
-Dxmodesetting=false \
|
|
-Dxf86-input-inputtest=false \
|
|
-Dxf86-input-null=false \
|
|
-Dlegacy_nvidia_340x=false \
|
|
-Dlegacy_nvidia_padding=false \
|
|
-Ddocs=false \
|
|
-Ddevel-docs=false \
|
|
-Dtests=false \
|
|
-Dlibunwind=false \
|
|
-Dsha1=libcrypto \
|
|
-Dinput_thread=true \
|
|
-Ddefault_font_path=/usr/share/fonts/misc,/usr/share/fonts/TTF,/usr/share/fonts/OTF \
|
|
-Dxkb_dir=/usr/share/X11/xkb \
|
|
-Dxkb_output_dir=/tmp \
|
|
-Dxkb_bin_dir=/usr/bin \
|
|
-Dlog_dir=/var/log
|
|
|
|
ninja -C /tmp/build-xlibre -j"$(nproc)"
|
|
rm -rf /geminux/prebuilt/xlibre
|
|
mkdir -p /geminux/prebuilt/xlibre
|
|
DESTDIR="/geminux/prebuilt/xlibre" ninja -C /tmp/build-xlibre install
|
|
else
|
|
echo "[3/5] Reusing compiled XLibre in /geminux/prebuilt/xlibre..."
|
|
fi
|
|
|
|
if [ -d /geminux/prebuilt/xlibre/tmp/aarch64-sysroot/usr ]; then
|
|
cp -a /geminux/prebuilt/xlibre/tmp/aarch64-sysroot/usr/. /geminux/prebuilt/xlibre/usr/
|
|
rm -rf /geminux/prebuilt/xlibre/tmp
|
|
fi
|
|
|
|
# Detect actual installed module ABI dir
|
|
REAL_MOD_DIR="$(find /geminux/prebuilt/xlibre/usr/lib/xorg/modules -maxdepth 1 -mindepth 1 -type d -name "xlibre-*" | head -n 1)"
|
|
if [ -n "$REAL_MOD_DIR" ]; then
|
|
ABI_MOD_DIR="/usr/lib/xorg/modules/$(basename "$REAL_MOD_DIR")"
|
|
fi
|
|
|
|
cp -a /geminux/prebuilt/xlibre/usr/. "$SYSROOT/usr/"
|
|
|
|
echo "[4/5] Compiling xf86-input-libinput and xf86-video-fbdev against XLibre SDK ($ABI_MOD_DIR)..."
|
|
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f "/geminux/prebuilt/xlibre$ABI_MOD_DIR/input/libinput_drv.so" ]; then
|
|
rm -rf /tmp/build-libinput
|
|
meson setup /tmp/build-libinput "$XF86_LIBINPUT_SRC" \
|
|
--cross-file=/tmp/aarch64-cross.ini \
|
|
--prefix=/usr \
|
|
--libdir=lib \
|
|
--sysconfdir=/etc \
|
|
--buildtype=release \
|
|
-Dxorg-module-dir="$ABI_MOD_DIR/input" \
|
|
-Dsdkdir=/usr/include/xorg \
|
|
-Dxorg-conf-dir=/usr/share/X11/xorg.conf.d
|
|
ninja -C /tmp/build-libinput -j"$(nproc)"
|
|
DESTDIR="/geminux/prebuilt/xlibre" ninja -C /tmp/build-libinput install
|
|
fi
|
|
|
|
if [ "${FORCE_REBUILD:-0}" = "1" ] || [ ! -f "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/fbdev_drv.so" ]; then
|
|
mkdir -p "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers" /tmp/fbdev-inc
|
|
cat > /tmp/fbdev-inc/config.h <<EOF
|
|
#include "xorg-server.h"
|
|
#define PACKAGE_VERSION_MAJOR 25
|
|
#define PACKAGE_VERSION_MINOR 0
|
|
#define PACKAGE_VERSION_PATCHLEVEL 0
|
|
#define PACKAGE_VERSION_SUFFIX ""
|
|
EOF
|
|
aarch64-alpine-linux-musl-gcc \
|
|
--sysroot="$SYSROOT" \
|
|
$OPT_CFLAGS -shared -fPIC \
|
|
-I/tmp/fbdev-inc \
|
|
-I"$SYSROOT/usr/include/xorg" \
|
|
-I"$XLIBRE_SRC/include" \
|
|
-I"$SYSROOT/usr/include/pixman-1" \
|
|
-I"$SYSROOT/usr/include/X11/dri" \
|
|
-I"$SYSROOT/usr/include/libdrm" \
|
|
"$XF86_FBDEV_SRC/src/fbdev.c" \
|
|
-o "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/fbdev_drv.so"
|
|
fi
|
|
|
|
echo "[5/5] Stripping XLibre binaries and cleaning headers..."
|
|
find /geminux/prebuilt/xlibre/usr/bin /geminux/prebuilt/xlibre/usr/lib -type f \( -name "Xorg" -o -name "gtf" -o -name "*.so" \) -exec aarch64-alpine-linux-musl-strip --strip-unneeded {} +
|
|
rm -rf /geminux/prebuilt/xlibre/usr/include \
|
|
/geminux/prebuilt/xlibre/usr/lib/pkgconfig \
|
|
/geminux/prebuilt/xlibre/usr/share/aclocal \
|
|
/geminux/prebuilt/xlibre/usr/share/man \
|
|
/geminux/prebuilt/xlibre/usr/share/X11/xorg.conf.d/10-nvidia*.conf \
|
|
/geminux/prebuilt/xlibre/etc/X11/xorg.conf.d/10-nvidia*
|
|
ln -sfn Xorg /geminux/prebuilt/xlibre/usr/bin/X
|
|
|
|
if [ -d /target-rootfs/usr ]; then
|
|
cp -a /geminux/prebuilt/xlibre/. /target-rootfs/
|
|
fi
|
|
chown -R "$HOST_UID:$HOST_GID" /geminux/prebuilt/xlibre /geminux/build-cache /target-rootfs/usr/lib/xorg /target-rootfs/usr/bin/Xorg /target-rootfs/usr/bin/X 2>/dev/null || true
|
|
ls -lh /geminux/prebuilt/xlibre/usr/bin/Xorg "/geminux/prebuilt/xlibre$ABI_MOD_DIR/drivers/"*.so "/geminux/prebuilt/xlibre$ABI_MOD_DIR/input/"*.so
|
|
'
|