2025-02-16 12:24:13 +01:00
|
|
|
#!/bin/bash
|
2025-02-16 12:24:54 +01:00
|
|
|
set -e
|
2025-02-16 12:24:13 +01:00
|
|
|
|
|
|
|
usage() {
|
|
|
|
echo "Usage: build.sh [-b [release|debug]] "
|
|
|
|
echo " [-c [gcc|clang]]"
|
|
|
|
echo " [-m [meson|muon]"
|
|
|
|
echo " [config]"
|
|
|
|
echo ""
|
|
|
|
echo "CI build script."
|
|
|
|
echo ""
|
|
|
|
echo " -b [release]|debug build type"
|
|
|
|
echo " -c [gcc]|clang compiler to use"
|
|
|
|
echo " -m [meson]|muon use meson or muon"
|
|
|
|
echo " -t [arm]|ppc64le|s390x cross compile target"
|
|
|
|
echo ""
|
|
|
|
echo "configs with meson:"
|
|
|
|
echo " [default] default settings"
|
|
|
|
echo " fallback download all dependencies"
|
2025-02-16 12:25:41 +01:00
|
|
|
echo " and build them as shared libraries"
|
2025-02-16 12:24:13 +01:00
|
|
|
echo " cross use cross toolchain to build"
|
2025-02-16 12:24:54 +01:00
|
|
|
echo " coverage build coverage report"
|
|
|
|
echo " appimage build AppImage target"
|
2025-02-16 12:24:13 +01:00
|
|
|
echo ""
|
|
|
|
echo "configs with muon:"
|
|
|
|
echo " [default] minimal static build"
|
|
|
|
}
|
|
|
|
|
|
|
|
BUILDTOOL=meson
|
|
|
|
MESON=meson
|
|
|
|
BUILDTYPE=release
|
|
|
|
CROSS_TARGET=arm
|
|
|
|
CC=${CC:-"gcc"}
|
|
|
|
|
|
|
|
while getopts "b:c:m:t:" o; do
|
|
|
|
case "${o}" in
|
|
|
|
b)
|
|
|
|
BUILDTYPE="${OPTARG}"
|
|
|
|
;;
|
|
|
|
c)
|
|
|
|
CC="${OPTARG}"
|
|
|
|
;;
|
|
|
|
m)
|
|
|
|
BUILDTOOL="${OPTARG}"
|
|
|
|
;;
|
|
|
|
t)
|
|
|
|
CROSS_TARGET="${OPTARG}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
|
|
|
CONFIG=${1:-"default"}
|
|
|
|
|
|
|
|
cd "$(git rev-parse --show-toplevel)" || exit 1
|
|
|
|
|
|
|
|
BUILDDIR="$(pwd)/.build-ci"
|
2025-02-16 12:25:41 +01:00
|
|
|
TOOLDIR="$(pwd)/.build-tools"
|
2025-02-16 12:24:13 +01:00
|
|
|
|
2025-02-16 12:24:54 +01:00
|
|
|
fn_exists() { declare -F "$1" > /dev/null; }
|
|
|
|
|
2025-02-16 12:24:13 +01:00
|
|
|
config_meson_default() {
|
|
|
|
CC="${CC}" "${MESON}" setup \
|
|
|
|
--werror \
|
|
|
|
--buildtype="${BUILDTYPE}" \
|
|
|
|
--force-fallback-for=libnvme \
|
|
|
|
-Dlibnvme:werror=false \
|
|
|
|
"${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
config_meson_fallback() {
|
|
|
|
CC="${CC}" "${MESON}" setup \
|
|
|
|
--werror \
|
|
|
|
--buildtype="${BUILDTYPE}" \
|
|
|
|
--wrap-mode=forcefallback \
|
|
|
|
--default-library=both \
|
|
|
|
-Dlibnvme:werror=false \
|
|
|
|
-Dopenssl:werror=false \
|
|
|
|
"${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
config_meson_cross() {
|
|
|
|
CC="${CC}" "${MESON}" setup \
|
|
|
|
--werror \
|
|
|
|
--buildtype="${BUILDTYPE}" \
|
|
|
|
--cross-file=.github/cross/ubuntu-cross-${CROSS_TARGET}.txt \
|
|
|
|
--force-fallback-for=libnvme \
|
|
|
|
-Dlibnvme:werror=false \
|
|
|
|
-Dlibnvme:python=disabled \
|
|
|
|
-Dlibnvme:openssl=disabled \
|
|
|
|
"${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
2025-02-16 12:24:54 +01:00
|
|
|
config_meson_coverage() {
|
|
|
|
CC="${CC}" "${MESON}" setup \
|
|
|
|
--werror \
|
|
|
|
--buildtype="${BUILDTYPE}" \
|
|
|
|
--force-fallback-for=libnvme \
|
|
|
|
-Dlibnvme:werror=false \
|
|
|
|
-Db_coverage=true \
|
|
|
|
"${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
config_meson_appimage() {
|
|
|
|
CC="${CC}" "${MESON}" setup \
|
|
|
|
--werror \
|
|
|
|
--buildtype="${BUILDTYPE}" \
|
|
|
|
--force-fallback-for=libnvme \
|
|
|
|
--prefix=/usr \
|
|
|
|
-Dlibnvme:werror=false \
|
|
|
|
"${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
2025-02-16 12:24:13 +01:00
|
|
|
build_meson() {
|
|
|
|
"${MESON}" compile \
|
|
|
|
-C "${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_meson() {
|
|
|
|
"${MESON}" test \
|
|
|
|
-C "${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
2025-02-16 12:24:54 +01:00
|
|
|
test_meson_coverage() {
|
|
|
|
"${MESON}" test \
|
|
|
|
-C "${BUILDDIR}"
|
|
|
|
ninja -C "${BUILDDIR}" coverage --verbose
|
|
|
|
}
|
|
|
|
|
|
|
|
install_meson_appimage() {
|
|
|
|
"${MESON}" install \
|
|
|
|
-C "${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
2025-02-16 12:24:13 +01:00
|
|
|
tools_build_samurai() {
|
2025-02-16 12:25:41 +01:00
|
|
|
if [ ! -d "${TOOLDIR}"/samurai ]; then
|
|
|
|
git clone --depth 1 https://github.com/michaelforney/samurai.git \
|
|
|
|
"${TOOLDIR}/samurai"
|
|
|
|
fi
|
2025-02-16 12:24:13 +01:00
|
|
|
|
2025-02-16 12:25:41 +01:00
|
|
|
if [[ -f "${TOOLDIR}/samurai/samu" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
2025-02-16 12:24:13 +01:00
|
|
|
|
2025-02-16 12:25:41 +01:00
|
|
|
pushd "${TOOLDIR}/samurai" || exit 1
|
|
|
|
CC="${CC}" make
|
2025-02-16 12:24:13 +01:00
|
|
|
popd || exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
tools_build_muon() {
|
2025-02-16 12:25:41 +01:00
|
|
|
if [ ! -d "${TOOLDIR}/muon" ]; then
|
|
|
|
git clone --depth 1 https://git.sr.ht/~lattis/muon \
|
|
|
|
"${TOOLDIR}/muon"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -f "${TOOLDIR}/build-muon/muon" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
2025-02-16 12:24:13 +01:00
|
|
|
|
2025-02-16 12:25:41 +01:00
|
|
|
pushd "${TOOLDIR}/muon" || exit 1
|
|
|
|
|
|
|
|
CC="${CC}" CFLAGS="${CFLAGS} -std=c99" ninja="${SAMU}" ./bootstrap.sh stage1
|
2025-02-16 12:24:13 +01:00
|
|
|
|
|
|
|
CC="${CC}" ninja="${SAMU}" stage1/muon setup \
|
2025-02-16 12:25:41 +01:00
|
|
|
-Dprefix="${TOOLDIR}" \
|
2025-02-16 12:24:13 +01:00
|
|
|
-Ddocs=disabled \
|
|
|
|
-Dsamurai=disabled \
|
2025-02-16 12:25:41 +01:00
|
|
|
-Dbestline=disabled \
|
|
|
|
"${TOOLDIR}/build-muon"
|
|
|
|
"${SAMU}" -C "${TOOLDIR}/build-muon"
|
2025-02-16 12:24:13 +01:00
|
|
|
MUON="${BUILDDIR}/build-tools/.build-muon/muon"
|
|
|
|
|
2025-02-16 12:25:41 +01:00
|
|
|
# "${TOOLDIR}/build-muon/muon" \
|
|
|
|
# -C "${TOOLDIR}/build-muon" test
|
2025-02-16 12:24:13 +01:00
|
|
|
|
|
|
|
popd || exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
config_muon_default() {
|
2025-02-16 12:25:41 +01:00
|
|
|
# wrap_mode=forcefallback depends on git being available
|
|
|
|
|
|
|
|
CC="${CC}" CFLAGS="${CFLAGS}" ninja="${SAMU}" \
|
|
|
|
"${MUON}" setup \
|
|
|
|
-Ddefault_library=static \
|
|
|
|
-Dc_link_args="-static" \
|
2025-02-16 12:24:13 +01:00
|
|
|
-Dwrap_mode=forcefallback \
|
|
|
|
-Dlibnvme:json-c=disabled \
|
|
|
|
-Dlibnvme:python=disabled \
|
|
|
|
-Dlibnvme:openssl=disabled \
|
|
|
|
-Dlibnvme:keyutils=disabled \
|
|
|
|
-Djson-c=disabled \
|
|
|
|
"${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
build_muon() {
|
|
|
|
"${SAMU}" -C "${BUILDDIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_muon() {
|
|
|
|
ninja="${SAMU}" "${MUON}" -C "${BUILDDIR}" test
|
|
|
|
ldd "${BUILDDIR}/nvme" 2>&1 | grep 'not a dynamic executable' || exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if [[ "${BUILDTOOL}" == "muon" ]]; then
|
2025-02-16 12:25:41 +01:00
|
|
|
SAMU="$(which samu 2> /dev/null)" || true
|
|
|
|
if [[ -z "${SAMU}" ]]; then
|
2025-02-16 12:24:13 +01:00
|
|
|
tools_build_samurai
|
2025-02-16 12:25:41 +01:00
|
|
|
SAMU="${TOOLDIR}/samurai/samu"
|
2025-02-16 12:24:13 +01:00
|
|
|
fi
|
|
|
|
|
2025-02-16 12:25:41 +01:00
|
|
|
MUON="$(which muon 2> /dev/null)" || true
|
|
|
|
if [[ -z "${MUON}" ]]; then
|
2025-02-16 12:24:13 +01:00
|
|
|
tools_build_muon
|
2025-02-16 12:25:41 +01:00
|
|
|
MUON="${TOOLDIR}/build-muon/muon"
|
2025-02-16 12:24:13 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2025-02-16 12:25:41 +01:00
|
|
|
echo "samu: ${SAMU}"
|
|
|
|
echo "muon: ${MUON}"
|
|
|
|
|
|
|
|
rm -rf "${BUILDDIR}"
|
|
|
|
|
2025-02-16 12:24:13 +01:00
|
|
|
config_"${BUILDTOOL}"_"${CONFIG}"
|
2025-02-16 12:24:54 +01:00
|
|
|
fn_exists "build_${BUILDTOOL}_${CONFIG}" && "build_${BUILDTOOL}_${CONFIG}" || build_"${BUILDTOOL}"
|
|
|
|
fn_exists "test_${BUILDTOOL}_${CONFIG}" && "test_${BUILDTOOL}_${CONFIG}" || test_"${BUILDTOOL}"
|
|
|
|
fn_exists "install_${BUILDTOOL}_${CONFIG}" && "install_${BUILDTOOL}_${CONFIG}" || true;
|