build_m2.sh 1.0 KB

123456789101112131415161718192021222324252627282930
  1. #!/bin/sh
  2. # Builds M2make with the V3 M2 compiler itself.
  3. # Usage: ./build_m2.sh (from the tools/m2make directory)
  4. # Output: b_v3/M2make (a V3-built binary)
  5. #
  6. # Session: SysShim + FileIO (runtime/syslib) + M2makeOS + M2make,
  7. # then qbe + cc with the runtime shim and m2make_os.c.
  8. set -e
  9. cd "$(dirname "$0")"
  10. M2=../../compiler/M2
  11. SYS=../../runtime/syslib
  12. rm -rf b_v3
  13. mkdir -p b_v3
  14. cp M2make.mod M2makeOS.def m2make_os.c b_v3/
  15. cp M2makeOS_v3.mod b_v3/M2makeOS.mod
  16. cd b_v3
  17. mkdir -p gen_ssa
  18. echo "=== Compiling (M2 session) ==="
  19. # NB: M2 exits 0 even when it reports "Incorrect source", so gate on
  20. # the verdict text instead of the exit code.
  21. "../$M2" \
  22. "../$SYS/SysShim.def" "../$SYS/SysShim.mod" \
  23. "../$SYS/FileIO.def" "../$SYS/FileIO.mod" \
  24. M2makeOS.def M2makeOS.mod M2make.mod \
  25. 2>&1 | tee m2.log | grep -q Parsed || exit 1
  26. echo "=== Assembling and linking ==="
  27. qbe -o gen_ssa/M2make.s gen_ssa/M2make.ssa || exit 1
  28. cc gen_ssa/M2make.s "../$SYS/shim.c" m2make_os.c \
  29. -o M2make -lm || exit 1
  30. echo "=== b_v3/M2make built ==="