build-cc.sh (2260B)
1 #!/bin/sh 2 ## tests/build-cc.sh — in-container .c -> .P1pp via scheme1 + cc.scm. 3 ## 4 ## Pure transformation. Caller (the Makefile) ensures every fixed-path 5 ## input below already exists: the per-arch scheme1 ELF and the catm'd 6 ## cc.scm source. Mirrors tests/build-p1pp.sh's contract: env-driven, 7 ## one thing only, no host work. 8 ## 9 ## Env: ARCH=aarch64|amd64|riscv64 10 ## CC_DEBUG=1 (optional) — pass --cc-debug to cc.scm so it prints 11 ## per-phase heap usage on stderr. 12 ## CC_TRACE_EMIT=1 (optional) — pass --cc-trace-emit so cc.scm 13 ## wraps every emitted function with a `%trace(<mangled>)` 14 ## call at entry. Pair with libp1pp's %trace macro and 15 ## libp1pp__trace runtime helper (in P1/P1pp.P1pp) to 16 ## produce a stderr line per function entry at runtime. 17 ## CC_LIB=PFX (optional) — compile in library mode (cc.scm 18 ## --lib=PFX). Skips cc.scm's auto-emitted entry 19 ## stub and trailing :ELF_end so the output catm's 20 ## into a larger link, and namespaces anonymous 21 ## string labels as PFX+"cc__str_N" to avoid 22 ## collisions with other cc.scm outputs in the 23 ## same chain. The catm caller then prepends 24 ## P1/entry-{plain,libc}.P1pp and appends 25 ## P1/elf-end.P1pp exactly once each. 26 ## Usage: tests/build-cc.sh <src.c> <out.P1pp> 27 28 set -eu 29 30 : "${ARCH:?ARCH must be set}" 31 [ "$#" -eq 2 ] || { echo "usage: ARCH=<arch> $0 <src> <out>" >&2; exit 2; } 32 33 SRC=$1 34 OUT=$2 35 36 SCHEME1_BIN=build/$ARCH/podman/boot2/scheme1 37 CC_SRC=build/cc.scm 38 39 [ -x "$SCHEME1_BIN" ] || { echo "missing $SCHEME1_BIN" >&2; exit 1; } 40 [ -e "$CC_SRC" ] || { echo "missing $CC_SRC" >&2; exit 1; } 41 [ -e "$SRC" ] || { echo "missing $SRC" >&2; exit 1; } 42 43 mkdir -p "$(dirname "$OUT")" 44 45 # Build cc-flag list once. Order doesn't matter to cc-main but 46 # stays stable for log readability. 47 set -- 48 [ "${CC_DEBUG:-0}" = "1" ] && set -- "$@" --cc-debug 49 [ "${CC_TRACE_EMIT:-0}" = "1" ] && set -- "$@" --cc-trace-emit 50 [ -n "${CC_LIB:-}" ] && set -- "$@" "--lib=$CC_LIB" 51 52 "$SCHEME1_BIN" "$CC_SRC" "$@" "$SRC" "$OUT"