build_m2.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. # Builds M2make with the V3 M2 compiler.
  3. # Usage: ./build_m2.sh (from the tools/m2make directory)
  4. # Output: b_v3/M2make (a V3-built binary)
  5. #
  6. # Two paths:
  7. # * If a V3-built M2make already exists (b_v3/M2make, e.g. from a
  8. # previous run), it drives the build -- M2make resolves the
  9. # SysShim/FileIO modules via -I runtime/syslib and orders the
  10. # session itself (the dogfooding path; same shape as
  11. # bootstrap/fixpoint.sh).
  12. # * Otherwise the session is spelled out by hand (bootstrap path).
  13. set -e
  14. cd "$(dirname "$0")"
  15. M2=../../compiler/M2
  16. SYS=../../runtime/syslib
  17. # keep the old driver (if any) aside so it can drive this build
  18. rm -rf b_v3.old
  19. if [ -x b_v3/M2make ]; then mv b_v3 b_v3.old; fi
  20. mkdir -p b_v3
  21. cp M2make.mod M2makeOS.def m2make_os.c b_v3/
  22. cp M2makeOS_v3.mod b_v3/M2makeOS.mod
  23. cd b_v3
  24. mkdir -p gen_ssa
  25. if [ -x ../b_v3.old/M2make ]; then
  26. echo "=== Building with the previous b_v3/M2make (dogfood) ==="
  27. ../b_v3.old/M2make -c m2 --m2bin "../$M2" --shim "../$SYS/shim.c" \
  28. --extra m2make_os.c -I "../$SYS" -o M2make M2make.mod || exit 1
  29. else
  30. echo "=== Compiling (M2 session; bootstrap path) ==="
  31. # NB: M2 exits 0 even when it reports "Incorrect source", so gate on
  32. # the verdict text instead of the exit code.
  33. "../$M2" \
  34. "../$SYS/SysShim.def" "../$SYS/SysShim.mod" \
  35. "../$SYS/FileIO.def" "../$SYS/FileIO.mod" \
  36. M2makeOS.def M2makeOS.mod M2make.mod \
  37. 2>&1 | tee m2.log | grep -q "Parsed correctly" || exit 1
  38. echo "=== Assembling and linking ==="
  39. qbe -o gen_ssa/M2make.s gen_ssa/M2make.ssa || exit 1
  40. cc gen_ssa/M2make.s "../$SYS/shim.c" m2make_os.c \
  41. -o M2make -lm || exit 1
  42. fi
  43. cd ..
  44. rm -rf b_v3.old
  45. echo "=== b_v3/M2make built ==="