Files
ipxe/build.sh
T
oxmc 9f6794ea97
Build / BIOS / i386 (push) Has been cancelled
Build / BIOS / x86_64 (push) Has been cancelled
Build / SBI / riscv32 (push) Has been cancelled
Build / SBI / riscv64 (push) Has been cancelled
Build / UEFI / arm32 (push) Has been cancelled
Build / UEFI / arm64 (push) Has been cancelled
Build / UEFI / i386 (push) Has been cancelled
Build / UEFI / loong64 (push) Has been cancelled
Build / UEFI / riscv32 (push) Has been cancelled
Build / UEFI / riscv64 (push) Has been cancelled
Build / UEFI / x86_64 (push) Has been cancelled
Build / UEFI SB / arm64 (push) Has been cancelled
Build / UEFI SB / x86_64 (push) Has been cancelled
Build / SB Sign / arm64 (push) Has been cancelled
Build / SB Sign / x86_64 (push) Has been cancelled
Build / Linux / arm32 (push) Has been cancelled
Build / Linux / arm64 (push) Has been cancelled
Build / Linux / i386 (push) Has been cancelled
Build / Linux / loong64 (push) Has been cancelled
Build / Linux / riscv32 (push) Has been cancelled
Build / Linux / riscv64 (push) Has been cancelled
Build / Linux / x86_64 (push) Has been cancelled
Build / UEFI shim (push) Has been cancelled
Build / Combine (push) Has been cancelled
Build / Version (push) Has been cancelled
Build / Publish (push) Has been cancelled
Build / Release (push) Has been cancelled
Change defaults, add boot.ipxe for mac testing
2026-05-25 05:19:41 -07:00

122 lines
5.2 KiB
Bash

#!/usr/bin/env bash
# =============================================================================
# iPXE build script
#
# Usage:
# ./build.sh [OPTIONS]
#
# Options:
# -p, --platform <name> Platform to build (default: efi-x64)
# -e, --embed <file> iPXE script to embed (default: none)
# -o, --output <dir> Output directory (default: ./build)
# -j, --jobs <n> Parallel jobs (default: nproc)
# -h, --help Show this help
#
# Platforms:
# efi-x64 x86-64 UEFI EFI application [bin-x86_64-efi/ipxe.efi]
# efi-ia32 32-bit UEFI EFI application [bin-i386-efi/ipxe.efi]
# efi-arm64 AArch64 UEFI EFI application [bin-arm64-efi/ipxe.efi]
# snp-x64 x86-64 SNP-only EFI binary [bin-x86_64-efi/snponly.efi]
# bios x86 legacy BIOS PXE [bin/undionly.kpxe]
#
# Examples:
# ./build.sh
# ./build.sh -p efi-x64 -e boot.ipxe
# ./build.sh -p bios -o ./out
# ./build.sh -p efi-x64 -e boot.ipxe -j 8
# =============================================================================
set -euo pipefail
# ── Defaults ─────────────────────────────────────────────────────────────────
PLATFORM="efi-x64"
EMBED=""
OUTPUT_DIR="$(dirname "$0")/build"
JOBS="$(nproc 2>/dev/null || sysctl -n hw.ncpu 2>/dev/null || echo 4)"
SRC_DIR="$(dirname "$0")/src"
# ── Colour helpers ────────────────────────────────────────────────────────────
if [ -t 1 ]; then
C_BOLD='\033[1m'; C_GREEN='\033[0;32m'; C_CYAN='\033[0;36m'
C_YELLOW='\033[0;33m'; C_RED='\033[0;31m'; C_RESET='\033[0m'
else
C_BOLD=''; C_GREEN=''; C_CYAN=''; C_YELLOW=''; C_RED=''; C_RESET=''
fi
info() { echo -e "${C_CYAN}${C_RESET} $*"; }
ok() { echo -e "${C_GREEN}${C_RESET} $*"; }
warn() { echo -e "${C_YELLOW}${C_RESET} $*"; }
die() { echo -e "${C_RED}${C_RESET} $*" >&2; exit 1; }
# ── Argument parsing ──────────────────────────────────────────────────────────
usage() {
sed -n '3,20p' "$0" | sed 's/^# \{0,1\}//'
exit 0
}
while [[ $# -gt 0 ]]; do
case $1 in
-p|--platform) PLATFORM="$2"; shift 2 ;;
-e|--embed) EMBED="$2"; shift 2 ;;
-o|--output) OUTPUT_DIR="$2"; shift 2 ;;
-j|--jobs) JOBS="$2"; shift 2 ;;
-h|--help) usage ;;
*) die "Unknown option: $1" ;;
esac
done
# ── Platform → make target ────────────────────────────────────────────────────
case "$PLATFORM" in
efi-x64) MAKE_TARGET="bin-x86_64-efi/ipxe.efi"; OUTPUT_NAME="ipxe-x64.efi" ;;
efi-ia32) MAKE_TARGET="bin-i386-efi/ipxe.efi"; OUTPUT_NAME="ipxe-ia32.efi" ;;
efi-arm64) MAKE_TARGET="bin-arm64-efi/ipxe.efi"; OUTPUT_NAME="ipxe-arm64.efi" ;;
snp-x64) MAKE_TARGET="bin-x86_64-efi/snponly.efi"; OUTPUT_NAME="snponly-x64.efi";;
bios) MAKE_TARGET="bin/undionly.kpxe"; OUTPUT_NAME="undionly.kpxe" ;;
*) die "Unknown platform: '$PLATFORM'. Run with --help for valid platforms." ;;
esac
# ── Validate inputs ───────────────────────────────────────────────────────────
[[ -d "$SRC_DIR" ]] || die "src/ directory not found at $SRC_DIR"
EMBED_ARG=""
if [[ -n "$EMBED" ]]; then
# Resolve relative to repo root, not src/
EMBED_ABS="$(realpath "$EMBED" 2>/dev/null)" || die "Embed script not found: $EMBED"
[[ -f "$EMBED_ABS" ]] || die "Embed script not found: $EMBED"
EMBED_ARG="EMBED=$EMBED_ABS"
info "Embed script: $EMBED_ABS"
fi
# ── Build ─────────────────────────────────────────────────────────────────────
mkdir -p "$OUTPUT_DIR"
echo -e "${C_BOLD}Platform:${C_RESET} $PLATFORM$MAKE_TARGET"
echo -e "${C_BOLD}Jobs:${C_RESET} $JOBS"
echo -e "${C_BOLD}Output:${C_RESET} $OUTPUT_DIR/$OUTPUT_NAME"
echo ""
info "Starting build…"
make -C "$SRC_DIR" \
"$MAKE_TARGET" \
$EMBED_ARG \
-j "$JOBS"
# ── Copy output ───────────────────────────────────────────────────────────────
BUILT_BIN="$SRC_DIR/$MAKE_TARGET"
[[ -f "$BUILT_BIN" ]] || die "Build succeeded but output not found: $BUILT_BIN"
cp "$BUILT_BIN" "$OUTPUT_DIR/$OUTPUT_NAME"
# Also write a sidecar with build info
cat > "$OUTPUT_DIR/$OUTPUT_NAME.info" <<EOF
platform=$PLATFORM
target=$MAKE_TARGET
embed=${EMBED:-none}
built=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
git=$(git -C "$(dirname "$0")" describe --always --dirty 2>/dev/null || echo unknown)
EOF
echo ""
ok "Built: $OUTPUT_DIR/$OUTPUT_NAME"
ok "Info: $OUTPUT_DIR/$OUTPUT_NAME.info"