#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" BUILD_SH="${ROOT_DIR}/build.sh" usage() { cat <<'EOF' Usage: ./build_arch.sh [--le|--be] [-- ] Examples: ./build_arch.sh mips ./build_arch.sh mips.le ./build_arch.sh mips --be ./build_arch.sh riscv64 ./build_arch.sh sparc.be -- --skip-fetch -d Notes: - If has no endian suffix, default is ".le" - Use "--le" or "--be" to force endianness - Everything after "--" is passed to build.sh EOF } if [[ $# -lt 1 ]]; then usage exit 1 fi arch="$1"; shift || true force_endian="" extra_args=() # Parse flags until optional "--" while [[ $# -gt 0 ]]; do case "$1" in --le|--be) force_endian="${1#--}" shift ;; -h|--help) usage exit 0 ;; --) shift extra_args+=("$@") break ;; *) # unknown flag -> treat as extra args (or enforce strict if you want) extra_args+=("$1") shift ;; esac done # Normalize arch -> ensure it matches CORES entries like "mips.le", "mips.be", "mips64.le", etc. if [[ "$arch" == *.* ]]; then # Already has suffix (e.g. mips.le) normalized="$arch" else # No suffix: apply forced endian or default to le if [[ -n "$force_endian" ]]; then normalized="${arch}.${force_endian}" else normalized="${arch}.le" fi fi # If user provided both "mips.le" and "--be", --be wins (optional behavior) if [[ -n "$force_endian" ]]; then base="${normalized%%.*}" normalized="${base}.${force_endian}" fi if [[ ! -x "$BUILD_SH" ]]; then echo "Error: build.sh not found or not executable at: $BUILD_SH" >&2 exit 1 fi exec "$BUILD_SH" --external-lib-arch "$normalized" "${extra_args[@]}"