boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

build-native-tools.sh (2859B)


      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 (legacy oracle)
      9 ##   m1pp      — built from M1pp/M1pp.c (the C oracle for the new M1pp)
     10 ##   hex2pp    — built from hex2pp/hex2pp.c (the C oracle for hex2++)
     11 ##
     12 ## Source lookup for M1/hex2 (first match wins):
     13 ##   1. $MESCC_TOOLS_SRC (direct override)
     14 ##   2. $LIVE_BOOTSTRAP/seed/stage0-posix/mescc-tools
     15 ##
     16 ## No in-tree vendor copy — these tools are dev-loop helpers (the
     17 ## bootstrap path uses our seed/stage0 hex builds), so we keep the
     18 ## external dep explicit. Set LIVE_BOOTSTRAP=<path> the same way
     19 ## scripts/diag-livebootstrap-qemu.sh does.
     20 ##
     21 ## Usage: scripts/build-native-tools.sh <M1|hex2|m1pp|hex2pp>
     22 
     23 set -eu
     24 
     25 [ "$#" -eq 1 ] || { echo "usage: $0 <M1|hex2|m1pp|hex2pp>" >&2; exit 2; }
     26 
     27 TOOL=$1
     28 REPO=$(cd "$(dirname "$0")/.." && pwd)
     29 cd "$REPO"
     30 
     31 OUT=build/native-tools
     32 mkdir -p "$OUT"
     33 
     34 : "${CC:=cc}"
     35 CFLAGS="-O2 -std=c99 -D_GNU_SOURCE"
     36 
     37 find_mescc_src() {
     38     if [ -n "${MESCC_TOOLS_SRC:-}" ]; then
     39         if [ -f "$MESCC_TOOLS_SRC/M1-macro.c" ] && [ -f "$MESCC_TOOLS_SRC/M2libc/bootstrappable.c" ]; then
     40             echo "$MESCC_TOOLS_SRC"
     41             return 0
     42         fi
     43         echo "build-native-tools.sh: MESCC_TOOLS_SRC=$MESCC_TOOLS_SRC is not a complete mescc-tools tree" >&2
     44         return 1
     45     fi
     46     if [ -n "${LIVE_BOOTSTRAP:-}" ]; then
     47         d=$LIVE_BOOTSTRAP/seed/stage0-posix/mescc-tools
     48         if [ -f "$d/M1-macro.c" ] && [ -f "$d/M2libc/bootstrappable.c" ]; then
     49             echo "$d"
     50             return 0
     51         fi
     52         echo "build-native-tools.sh: LIVE_BOOTSTRAP=$LIVE_BOOTSTRAP has no mescc-tools at $d" >&2
     53         return 1
     54     fi
     55     echo "build-native-tools.sh: no mescc-tools source found." >&2
     56     echo "  set MESCC_TOOLS_SRC=<dir-with-M1-macro.c-and-M2libc/>," >&2
     57     echo "  or LIVE_BOOTSTRAP=<live-bootstrap-checkout>," >&2
     58     echo "  or fall back to the bootstrap path with M1PP_BOOTSTRAP_TOOLS=1." >&2
     59     return 1
     60 }
     61 
     62 case "$TOOL" in
     63     M1)
     64         SRC=$(find_mescc_src)
     65         $CC $CFLAGS \
     66             "$SRC/M1-macro.c" "$SRC/stringify.c" "$SRC/M2libc/bootstrappable.c" \
     67             -o "$OUT/M1"
     68         ;;
     69     hex2)
     70         SRC=$(find_mescc_src)
     71         $CC $CFLAGS \
     72             "$SRC/hex2.c" "$SRC/hex2_linker.c" "$SRC/hex2_word.c" "$SRC/M2libc/bootstrappable.c" \
     73             -o "$OUT/hex2"
     74         ;;
     75     m1pp)
     76         $CC -O2 -std=c99 M1pp/M1pp.c -o "$OUT/m1pp"
     77         ;;
     78     hex2pp)
     79         $CC -O2 -std=c99 hex2pp/hex2pp.c -o "$OUT/hex2pp"
     80         ;;
     81     *)
     82         echo "build-native-tools.sh: unknown tool '$TOOL'" >&2
     83         exit 2
     84         ;;
     85 esac