build-native-tools.sh (2592B)
1 #!/bin/sh 2 ## build-native-tools.sh — compile mescc-tools M1 and hex2 natively for 3 ## dev-loop speed. These are NOT in the bootstrap chain; they are a fast 4 ## substitute for stage0 M0/hex2-0, used by m1pp/build.sh's default mode. 5 ## 6 ## Output is verified byte-exact with the bootstrap tools when the right 7 ## flags are passed (see m1pp/build.sh). Using them saves ~150× wall time 8 ## on P1 builds / tests by avoiding the per-byte syscall storm the 9 ## stage0 tools incur under Apple's linux/arm64 VM. 10 ## 11 ## Source lookup (first match wins): 12 ## 1. $MESCC_TOOLS_SRC (if set) 13 ## 2. ../live-bootstrap/seed/stage0-posix/mescc-tools 14 ## 3. ../mescc-tools (if M2libc is populated) 15 16 set -eu 17 18 REPO=$(cd "$(dirname "$0")/.." && pwd) 19 cd "$REPO" 20 21 OUT=build/native-tools 22 mkdir -p "$OUT" 23 24 find_src() { 25 if [ -n "${MESCC_TOOLS_SRC:-}" ]; then 26 if [ -f "$MESCC_TOOLS_SRC/M1-macro.c" ] && [ -f "$MESCC_TOOLS_SRC/M2libc/bootstrappable.c" ]; then 27 echo "$MESCC_TOOLS_SRC" 28 return 0 29 fi 30 echo "build-native-tools.sh: MESCC_TOOLS_SRC=$MESCC_TOOLS_SRC is not a complete mescc-tools tree" >&2 31 return 1 32 fi 33 for d in \ 34 "$REPO/../live-bootstrap/seed/stage0-posix/mescc-tools" \ 35 "$REPO/../mescc-tools" 36 do 37 if [ -f "$d/M1-macro.c" ] && [ -f "$d/M2libc/bootstrappable.c" ]; then 38 echo "$d" 39 return 0 40 fi 41 done 42 echo "build-native-tools.sh: no mescc-tools source found." >&2 43 echo " set MESCC_TOOLS_SRC to a directory containing M1-macro.c and M2libc/," >&2 44 echo " or fall back to the bootstrap path with M1PP_BOOTSTRAP_TOOLS=1." >&2 45 return 1 46 } 47 48 SRC=$(find_src) 49 50 : "${CC:=cc}" 51 CFLAGS="-O2 -std=c99 -D_GNU_SOURCE" 52 53 ## Only rebuild if sources are newer than the cached binary. 54 m1_fresh() { 55 [ -x "$OUT/M1" ] || return 1 56 for s in "$SRC/M1-macro.c" "$SRC/stringify.c" "$SRC/M2libc/bootstrappable.c"; do 57 [ "$OUT/M1" -nt "$s" ] || return 1 58 done 59 return 0 60 } 61 hex2_fresh() { 62 [ -x "$OUT/hex2" ] || return 1 63 for s in "$SRC/hex2.c" "$SRC/hex2_linker.c" "$SRC/hex2_word.c" "$SRC/M2libc/bootstrappable.c"; do 64 [ "$OUT/hex2" -nt "$s" ] || return 1 65 done 66 return 0 67 } 68 69 if ! m1_fresh; then 70 echo " compiling $OUT/M1 from $SRC" 71 $CC $CFLAGS \ 72 "$SRC/M1-macro.c" "$SRC/stringify.c" "$SRC/M2libc/bootstrappable.c" \ 73 -o "$OUT/M1" 74 fi 75 76 if ! hex2_fresh; then 77 echo " compiling $OUT/hex2 from $SRC" 78 $CC $CFLAGS \ 79 "$SRC/hex2.c" "$SRC/hex2_linker.c" "$SRC/hex2_word.c" "$SRC/M2libc/bootstrappable.c" \ 80 -o "$OUT/hex2" 81 fi