enhance(scripts): termux_setup_xmake

This commit is contained in:
Jia Yuan Lo 2023-11-09 10:15:25 +08:00
parent 9af520da6e
commit 923d4e6e0f
2 changed files with 63 additions and 0 deletions

View File

@ -133,6 +133,10 @@ source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_rust.sh"
# shellcheck source=scripts/build/setup/termux_setup_swift.sh
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_swift.sh"
# Utility function to setup a current xmake build system.
# shellcheck source=scripts/build/setup/termux_setup_xmake.sh
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_xmake.sh"
# Utility function for zig-using packages to setup a zig toolchain.
# shellcheck source=scripts/build/setup/termux_setup_zig.sh
source "$TERMUX_SCRIPTDIR/scripts/build/setup/termux_setup_zig.sh"

View File

@ -0,0 +1,59 @@
# shellcheck shell=bash disable=SC2155
termux_setup_xmake() {
local XMAKE_VERSION=2.8.5
local XMAKE_TGZ_URL=https://github.com/xmake-io/xmake/releases/download/v${XMAKE_VERSION}/xmake-v${XMAKE_VERSION}.tar.gz
local XMAKE_TGZ_SHA256=19c67be3bcfcbda96ca87a18effac39bfccc443fbb3754c7bbc01511decd24af
local XMAKE_TGZ_FILE=${TERMUX_PKG_TMPDIR}/xmake-${XMAKE_VERSION}.tar.gz
local XMAKE_FOLDER=${TERMUX_COMMON_CACHEDIR}/xmake-${XMAKE_VERSION}
if [[ "${TERMUX_PACKAGES_OFFLINE-false}" == "true" ]]; then
XMAKE_FOLDER=${TERMUX_SCRIPTDIR}/build-tools/xmake-${XMAKE_VERSION}
fi
local XMAKE_PKG_VERSION=$(. "${TERMUX_SCRIPTDIR}/packages/xmake/build.sh"; echo ${TERMUX_PKG_VERSION})
if [[ "${TERMUX_ON_DEVICE_BUILD}" == "true" ]]; then
if [[ "$(cat "${TERMUX_BUILT_PACKAGES_DIRECTORY}/xmake" 2>/dev/null)" != "${XMAKE_PKG_VERSION}" && -z "$(command -v xmake)" ]]; then
cat <<- EOL >&2
Package 'xmake' is not installed.
You can install it with
pkg install xmake
or build it from source with
./build-package.sh xmake
EOL
exit 1
fi
return
fi
# always assume host build as xmake dont provide prebuilt binary
# dont use xmake-*.run as it uses single core to build and
# auto installs into ~/.local/{bin,share}
if [[ ! -x "${XMAKE_FOLDER}/bin/xmake" ]]; then
mkdir -p "${XMAKE_FOLDER}"
termux_download "${XMAKE_TGZ_URL}" "${XMAKE_TGZ_FILE}" "${XMAKE_TGZ_SHA256}"
tar -xf "${XMAKE_TGZ_FILE}" -C "${XMAKE_FOLDER}" --strip-components=1
# xmake injects -m64 and -m32 when it shouldnt
local files=$(grep -E "march = \"-m(32|64)" -nHR "${XMAKE_FOLDER}" | grep -E "gcc" | cut -d":" -f1 | sort)
for f in ${files}; do
echo "termux_setup_xmake: Patching ${f}"
sed -e "/.*march = \"-m.*/d" -i "${f}"
done
(
unset AR AS CC CFLAGS CPP CPPFLAGS CXX CXXFLAGS LD LDFLAGS PREFIX TERMUX_ARCH
pushd "${XMAKE_FOLDER}"
./configure --prefix="${XMAKE_FOLDER}"
make -j"$(nproc)" install
popd
)
fi
export PATH="${XMAKE_FOLDER}/bin:${PATH}"
if [[ -z "$(command -v xmake)" ]]; then
termux_error_exit "termux_setup_xmake: No xmake executable found!"
fi
}