about summary refs log tree commit diff stats
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
parent2b9b1cf3867a63dda0a5ac92a5ad8c88fce6f0d1 (diff)
downloadmu-f0cf7af7d8e28ce957754873cc16c2ac42138466.tar.gz
4216 - include simpler alternative to build script
-rwxr-xr-xbuild053
-rwxr-xr-xbuild1 (renamed from build)20
-rwxr-xr-xbuild_and_test_until2
-rwxr-xr-xmu2
-rwxr-xr-xtest_layers6
5 files changed, 72 insertions, 11 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
diff --git a/build b/build1
index dda1c974..2da95706 100755
--- a/build
+++ b/build1
@@ -1,14 +1,27 @@
 #!/bin/sh
+# Alternative to build0 that tries to avoid redoing redundant work.
+# Also splits compilation into multiple .cc files (see 'cleave' below).
+# Faster than build0 for recompiling after small changes.
+#
 # For details on the basic form of this script, see https://notabug.org/akkartik/basic-build.
 
 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 -> .build/*.cc -> .build/*.o -> .build/mu_bin
 # (layers)   |        |              |             |
 #          tangle  cleave          $CXX          $CXX
 
 # can also be called with a layer to only build until
-#   $ ./build --until 050
+#   $ ./build1 --until 050
 UNTIL_LAYER=${2:-zzz}
 
 # there's two mechanisms for fast builds here:
@@ -19,11 +32,6 @@ UNTIL_LAYER=${2:-zzz}
 # otherwise you'll see spurious messages about files being updated
 # risk: a file may unnecessarily update without changes, causing unnecessary work downstream
 
-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"
-
 # return 1 if $1 is older than _any_ of the remaining args
 older_than() {
   local target=$1
diff --git a/build_and_test_until b/build_and_test_until
index 2220be17..a1cc7d51 100755
--- a/build_and_test_until
+++ b/build_and_test_until
@@ -2,4 +2,4 @@
 set -e
 
 ./clean top-level
-./build --until $1  &&  ./mu_bin test
+./build1 --until $1  &&  ./mu_bin test
diff --git a/mu b/mu
index 7e3d6be6..41c98ce8 100755
--- a/mu
+++ b/mu
@@ -2,7 +2,7 @@
 # Run interpreter, first compiling if necessary.
 set -e
 
-./build  &&  ./mu_bin "$@"
+./build1  &&  ./mu_bin "$@"
 
 # Scenarios considered:
 #   mu
diff --git a/test_layers b/test_layers
index e004b796..73c00597 100755
--- a/test_layers
+++ b/test_layers
@@ -17,7 +17,7 @@ set -e
 
 if [[ $1 == one-off ]]
 then
-  ./build
+  ./build1
   ./mu_bin test || exit 1
   exit 0
 fi
@@ -29,7 +29,7 @@ do
   if [[ $2 && $f > $2 ]]; then exit 0; fi
   echo "=== $f"
   rm -rf .build mu.cc mu_bin core.mu  # force full rebuild for top-level, but not subsidiary tools like tangle and cleave
-  ./build --until $f || exit 1
+  ./build1 --until $f || exit 1
   # valgrind requires Linux
   valgrind --leak-check=yes --num-callers=40 -q --error-exitcode=1 ./mu_bin test || exit 1
   # run on Mac OS without valgrind, and with a hacky fix for the coarser clock
@@ -39,7 +39,7 @@ done
 
 # Layers for Mu apps without Valgrind
 ./clean
-./build
+./build1
 
 if [[ ! $1 || $1 == chessboard ]]
 then