build-native-tools.sh (2289B)
1 #!/bin/sh 2 ## build-native-tools.sh — host-compile one of the dev-loop tools. 3 ## 4 ## Pure transformation invoked by the Makefile per-target. Always rebuilds 5 ## the requested tool; Make handles staleness. 6 ## 7 ## Tools (NOT in the bootstrap chain — fast host substitutes): 8 ## M1, hex2 — built from upstream mescc-tools sources 9 ## m1pp — built from M1pp/M1pp.c (the C oracle) 10 ## 11 ## Source lookup for M1/hex2 (first match wins): 12 ## 1. $MESCC_TOOLS_SRC (if set) 13 ## 2. ../live-bootstrap/seed/stage0-posix/mescc-tools 14 ## 3. ../mescc-tools 15 ## 16 ## Usage: scripts/build-native-tools.sh <M1|hex2|m1pp> 17 18 set -eu 19 20 [ "$#" -eq 1 ] || { echo "usage: $0 <M1|hex2|m1pp>" >&2; exit 2; } 21 22 TOOL=$1 23 REPO=$(cd "$(dirname "$0")/.." && pwd) 24 cd "$REPO" 25 26 OUT=build/native-tools 27 mkdir -p "$OUT" 28 29 : "${CC:=cc}" 30 CFLAGS="-O2 -std=c99 -D_GNU_SOURCE" 31 32 find_mescc_src() { 33 if [ -n "${MESCC_TOOLS_SRC:-}" ]; then 34 if [ -f "$MESCC_TOOLS_SRC/M1-macro.c" ] && [ -f "$MESCC_TOOLS_SRC/M2libc/bootstrappable.c" ]; then 35 echo "$MESCC_TOOLS_SRC" 36 return 0 37 fi 38 echo "build-native-tools.sh: MESCC_TOOLS_SRC=$MESCC_TOOLS_SRC is not a complete mescc-tools tree" >&2 39 return 1 40 fi 41 for d in \ 42 "$REPO/../live-bootstrap/seed/stage0-posix/mescc-tools" \ 43 "$REPO/../mescc-tools" 44 do 45 if [ -f "$d/M1-macro.c" ] && [ -f "$d/M2libc/bootstrappable.c" ]; then 46 echo "$d" 47 return 0 48 fi 49 done 50 echo "build-native-tools.sh: no mescc-tools source found." >&2 51 echo " set MESCC_TOOLS_SRC to a directory containing M1-macro.c and M2libc/," >&2 52 echo " or fall back to the bootstrap path with M1PP_BOOTSTRAP_TOOLS=1." >&2 53 return 1 54 } 55 56 case "$TOOL" in 57 M1) 58 SRC=$(find_mescc_src) 59 $CC $CFLAGS \ 60 "$SRC/M1-macro.c" "$SRC/stringify.c" "$SRC/M2libc/bootstrappable.c" \ 61 -o "$OUT/M1" 62 ;; 63 hex2) 64 SRC=$(find_mescc_src) 65 $CC $CFLAGS \ 66 "$SRC/hex2.c" "$SRC/hex2_linker.c" "$SRC/hex2_word.c" "$SRC/M2libc/bootstrappable.c" \ 67 -o "$OUT/hex2" 68 ;; 69 m1pp) 70 $CC -O2 -std=c99 M1pp/M1pp.c -o "$OUT/m1pp" 71 ;; 72 *) 73 echo "build-native-tools.sh: unknown tool '$TOOL'" >&2 74 exit 2 75 ;; 76 esac