Add build script for BusyBox with ARM toolchain support
This commit is contained in:
78
build.sh
Executable file
78
build.sh
Executable file
@@ -0,0 +1,78 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# Build BusyBox with ARM toolchain from env.sh and optional sysroot.
|
||||
#
|
||||
# Usage:
|
||||
# ./build.sh [SYSROOT]
|
||||
#
|
||||
# Examples:
|
||||
# ./build.sh
|
||||
# ./build.sh /home/stargazer/arm-uclinuxfdpiceabi/sysroot
|
||||
|
||||
TOOLCHAIN_PREFIX="${TOOLCHAIN_PREFIX:-arm-uclinuxfdpiceabi}"
|
||||
CC_BIN="${CC_BIN:-${TOOLCHAIN_PREFIX}-gcc}"
|
||||
STRIP_BIN="${STRIP_BIN:-${TOOLCHAIN_PREFIX}-strip}"
|
||||
JOBS="${JOBS:-$(nproc)}"
|
||||
INSTALL_DIR_NAME="${INSTALL_DIR_NAME:-_install}"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
BUSYBOX_DIR="${SCRIPT_DIR}/busybox"
|
||||
SYSROOT_DEFAULT="/home/stargazer/arm-uclinuxfdpiceabi/sysroot"
|
||||
SYSROOT="${1:-${SYSROOT:-$SYSROOT_DEFAULT}}"
|
||||
ENV_FILE="${ENV_FILE:-${SCRIPT_DIR}/env.sh}"
|
||||
|
||||
die() {
|
||||
echo "ERROR: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
if [ -f "${ENV_FILE}" ]; then
|
||||
# shellcheck disable=SC1090
|
||||
. "${ENV_FILE}"
|
||||
fi
|
||||
|
||||
if ! command -v "${CC_BIN}" >/dev/null 2>&1; then
|
||||
die "Compiler not found in PATH: ${CC_BIN}"
|
||||
fi
|
||||
if ! command -v "${STRIP_BIN}" >/dev/null 2>&1; then
|
||||
die "Strip tool not found in PATH: ${STRIP_BIN}"
|
||||
fi
|
||||
if [ ! -d "${BUSYBOX_DIR}" ]; then
|
||||
die "busybox directory not found: ${BUSYBOX_DIR}"
|
||||
fi
|
||||
if [ ! -d "${SYSROOT}" ]; then
|
||||
die "SYSROOT not found: ${SYSROOT}"
|
||||
fi
|
||||
|
||||
INSTALL_DIR="${SCRIPT_DIR}/${INSTALL_DIR_NAME}"
|
||||
if [ "${INSTALL_DIR}" = "/" ]; then
|
||||
die "Refusing to install into /"
|
||||
fi
|
||||
|
||||
echo "Compiler: ${CC_BIN}"
|
||||
echo "Strip: ${STRIP_BIN}"
|
||||
echo "SYSROOT: ${SYSROOT}"
|
||||
echo "Source dir: ${BUSYBOX_DIR}"
|
||||
echo "Install dir: ${INSTALL_DIR}"
|
||||
|
||||
cd "${BUSYBOX_DIR}"
|
||||
|
||||
if [ ! -f ".config" ]; then
|
||||
make defconfig
|
||||
fi
|
||||
|
||||
make oldconfig
|
||||
make -j"${JOBS}" \
|
||||
CROSS_COMPILE="${TOOLCHAIN_PREFIX}-" \
|
||||
CC="${CC_BIN}" \
|
||||
STRIP="${STRIP_BIN}" \
|
||||
EXTRA_CFLAGS="--sysroot=${SYSROOT}" \
|
||||
EXTRA_LDFLAGS="--sysroot=${SYSROOT}"
|
||||
|
||||
make CONFIG_PREFIX="${INSTALL_DIR}" install
|
||||
"${STRIP_BIN}" busybox
|
||||
|
||||
echo "Build completed successfully."
|
||||
echo "Binary: ${BUSYBOX_DIR}/busybox"
|
||||
echo "Installed to: ${INSTALL_DIR}"
|
||||
Reference in New Issue
Block a user