about summary refs log tree commit diff stats
path: root/build0
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2018-03-12 23:24:53 -0700
committerKartik K. Agaram <vc@akkartik.com>2018-03-12 23:26:10 -0700
commitf0cf7af7d8e28ce957754873cc16c2ac42138466 (patch)
tree4876ae0d642124c9d397ee23aca64f184c1a9368 /build0
parent2b9b1cf3867a63dda0a5ac92a5ad8c88fce6f0d1 (diff)
downloadmu-f0cf7af7d8e28ce957754873cc16c2ac42138466.tar.gz
4216 - include simpler alternative to build script
Diffstat (limited to 'build0')
-rwxr-xr-xbuild053
1 files changed, 53 insertions, 0 deletions
diff --git a/build0 b/build0
new file mode 100755
index 00000000..4eda5e8c
--- /dev/null
+++ b/build0
@@ -0,0 +1,53 @@
+#!/bin/sh
+# Compile mu from scratch.
+
+set -v
+set -e  # stop immediately on error
+
+# Some environment variables that can be passed in. For example, to turn off
+# optimization:
+#   $ CFLAGS=-g ./build0
+test "$CXX" || export CXX=c++
+test "$CC" || export CC=cc
+test "$CFLAGS" || export CFLAGS="-g -O3"
+export CFLAGS="$CFLAGS -Wall -Wextra -ftrapv -fno-strict-aliasing"
+
+# Outline:
+# [0-9]*.cc -> mu.cc -> mu_bin
+# (layers)   |        |
+#          tangle   $CXX
+
+# can also be called with a layer to only build until
+#   $ ./build0 --until 050
+UNTIL_LAYER=${2:-zzz}
+
+$CXX $CFLAGS enumerate/enumerate.cc -o enumerate/enumerate
+
+cd tangle
+  {
+    grep -h "^struct .* {" [0-9]*.cc  |sed 's/\(struct *[^ ]*\).*/\1;/'
+    grep -h "^typedef " [0-9]*.cc
+  }  > type_list
+  grep -h "^[^ #].*) {" [0-9]*.cc  |sed 's/ {.*/;/'  > function_list
+  ls [0-9]*.cc  |grep -v "\.test\.cc$"  |sed 's/.*/#include "&"/'  > file_list
+  ls [0-9]*.test.cc  |sed 's/.*/#include "&"/'  > test_file_list
+  grep -h "^[[:space:]]*void test_" [0-9]*.cc  |sed 's/^\s*void \(.*\)() {$/\1,/'  > test_list
+  $CXX $CFLAGS boot.cc -o tangle
+cd ..
+
+cd termbox
+  $CC $CFLAGS -c termbox.c
+  $CC $CFLAGS -c utf8.c
+  ar rcs libtermbox.a *.o
+cd ..
+
+LAYERS=$(./enumerate/enumerate --until $UNTIL_LAYER  |grep '\.cc$')
+./tangle/tangle $LAYERS  > mu.cc
+grep -h "^[^[:space:]#].*) {$" mu.cc  |grep -v ":.*("  |sed 's/ {.*/;/'  > function_list
+grep -h "^\s*void test_" mu.cc  |sed 's/^\s*void \(.*\)() {.*/\1,/'  > test_list
+$CXX $CFLAGS mu.cc termbox/libtermbox.a -o mu_bin
+
+## [0-9]*.mu -> core.mu
+
+MU_LAYERS=$(./enumerate/enumerate --until $UNTIL_LAYER  |grep '\.mu$') || exit 0  # ok if no .mu files
+cat $MU_LAYERS  > core.mu