| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #!/bin/sh
- # Builds M2make with the V3 M2 compiler.
- # Usage: ./build_m2.sh (from the tools/m2make directory)
- # Output: b_v3/M2make (a V3-built binary)
- #
- # Two paths:
- # * If a V3-built M2make already exists (b_v3/M2make, e.g. from a
- # previous run), it drives the build -- M2make resolves the
- # SysShim/FileIO modules via -I runtime/syslib and orders the
- # session itself (the dogfooding path; same shape as
- # bootstrap/fixpoint.sh).
- # * Otherwise the session is spelled out by hand (bootstrap path).
- set -e
- cd "$(dirname "$0")"
- M2=../../compiler/M2
- SYS=../../runtime/syslib
- # keep the old driver (if any) aside so it can drive this build
- rm -rf b_v3.old
- if [ -x b_v3/M2make ]; then mv b_v3 b_v3.old; fi
- mkdir -p b_v3
- cp M2make.mod M2makeOS.def m2make_os.c b_v3/
- cp M2makeOS_v3.mod b_v3/M2makeOS.mod
- cd b_v3
- mkdir -p gen_ssa
- if [ -x ../b_v3.old/M2make ]; then
- echo "=== Building with the previous b_v3/M2make (dogfood) ==="
- ../b_v3.old/M2make -c m2 --m2bin "../$M2" --shim "../$SYS/shim.c" \
- --extra m2make_os.c -I "../$SYS" -o M2make M2make.mod || exit 1
- else
- echo "=== Compiling (M2 session; bootstrap path) ==="
- # NB: M2 exits 0 even when it reports "Incorrect source", so gate on
- # the verdict text instead of the exit code.
- "../$M2" \
- "../$SYS/SysShim.def" "../$SYS/SysShim.mod" \
- "../$SYS/FileIO.def" "../$SYS/FileIO.mod" \
- M2makeOS.def M2makeOS.mod M2make.mod \
- 2>&1 | tee m2.log | grep -q Parsed || exit 1
- echo "=== Assembling and linking ==="
- qbe -o gen_ssa/M2make.s gen_ssa/M2make.ssa || exit 1
- cc gen_ssa/M2make.s "../$SYS/shim.c" m2make_os.c \
- -o M2make -lm || exit 1
- fi
- cd ..
- rm -rf b_v3.old
- echo "=== b_v3/M2make built ==="
|