about summary refs log tree commit diff stats
path: root/build
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2016-10-20 22:01:33 -0700
committerKartik K. Agaram <vc@akkartik.com>2016-10-20 22:19:37 -0700
commit9397c4c26bd2b57bd40bc0a7be22d687dbc96376 (patch)
tree65070136ec7b2b2f1e7ce9a579a3a3417d25c26a /build
parenteef0251c591a25e0405568869cb3542daae8b6f5 (diff)
downloadmu-9397c4c26bd2b57bd40bc0a7be22d687dbc96376.tar.gz
3533
Don't update autogenerated *_list files unless necessary.
Diffstat (limited to 'build')
-rwxr-xr-xbuild48
1 files changed, 35 insertions, 13 deletions
diff --git a/build b/build
index 11a328a2..d3dc4b0a 100755
--- a/build
+++ b/build
@@ -38,6 +38,27 @@ older_than() {
   return 1  # failure
 }
 
+# redirect to $1, unless it's already identical
+update() {
+  if [ ! -e $1 ]
+  then
+    cat > $1
+  else
+    cat > $1.tmp
+    diff -q $1 $1.tmp >/dev/null && rm $1.tmp || mv $1.tmp $1
+  fi
+}
+
+update_cp() {
+  if [ ! -e $2/$1 ]
+  then
+    cp $1 $2
+  elif [ $1 -nt $2/$1 ]
+  then
+    cp $1 $2
+  fi
+}
+
 noisy_cd() {
   cd $1
   echo "-- `pwd`" >&2
@@ -51,20 +72,20 @@ older_than enumerate/enumerate enumerate/enumerate.cc && {
   older_than tangle/tangle tangle/*.cc && {
     noisy_cd tangle
       older_than type_list [0-9]*.cc && {
-        grep -h "^struct .* {" [0-9]*.cc |sed 's/\(struct *[^ ]*\).*/\1;/' > type_list
-        grep -h "^typedef " [0-9]*.cc >> type_list
-      }
+        grep -h "^struct .* {" [0-9]*.cc |sed 's/\(struct *[^ ]*\).*/\1;/'
+        grep -h "^typedef " [0-9]*.cc
+      } |update type_list
       older_than function_list [0-9]*.cc && {
-        grep -h "^[^ #].*) {" [0-9]*.cc |sed 's/ {.*/;/' > function_list
+        grep -h "^[^ #].*) {" [0-9]*.cc |sed 's/ {.*/;/' |update function_list
       }
       older_than file_list [0-9]*.cc && {
-        ls [0-9]*.cc |grep -v "\.test\.cc$" |sed 's/.*/#include "&"/' > file_list
+        ls [0-9]*.cc |grep -v "\.test\.cc$" |sed 's/.*/#include "&"/' |update file_list
       }
       older_than test_file_list [0-9]*.test.cc && {
-        ls [0-9]*.test.cc |sed 's/.*/#include "&"/' > test_file_list
+        ls [0-9]*.test.cc |sed 's/.*/#include "&"/' |update test_file_list
       }
       older_than test_list [0-9]*.cc && {
-        grep -h "^[[:space:]]*void test_" [0-9]*.cc |sed 's/^\s*void \(.*\)() {$/\1,/' > test_list
+        grep -h "^[[:space:]]*void test_" [0-9]*.cc |sed 's/^\s*void \(.*\)() {$/\1,/' |update test_list
       }
       $CXX $CFLAGS boot.cc -o tangle
     noisy_cd ..  # no effect; just to show us returning to the parent directory
@@ -74,13 +95,13 @@ older_than enumerate/enumerate enumerate/enumerate.cc && {
 
 LAYERS=$(./enumerate/enumerate --until $UNTIL_LAYER |grep -v '.mu$')
 older_than mu.cc $LAYERS enumerate/enumerate tangle/tangle && {
-  ./tangle/tangle $LAYERS > mu.cc
+  ./tangle/tangle $LAYERS |update mu.cc
 }
 older_than function_list mu.cc && {
-  grep -h "^[^[:space:]#].*) {$" mu.cc |grep -v ":.*(" |sed 's/ {.*/;/' > function_list
+  grep -h "^[^[:space:]#].*) {$" mu.cc |grep -v ":.*(" |sed 's/ {.*/;/' |update function_list
 }
 older_than test_list mu.cc && {
-  grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/\1,/' > test_list
+  grep -h "^\s*void test_" mu.cc |sed 's/^\s*void \(.*\)() {.*/\1,/' |update test_list
 }
 
 older_than cleave/cleave cleave/cleave.cc && {
@@ -90,13 +111,14 @@ older_than cleave/cleave cleave/cleave.cc && {
 
 older_than mu_bin mu.cc *_list cleave/cleave termbox/* && {
   mkdir -p .build
-  cp function_list test_list .build
+  update_cp function_list .build
+  update_cp test_list .build
   mkdir -p .build/termbox
   cp termbox/termbox.h .build/termbox
   ./cleave/cleave mu.cc .build
   noisy_cd .build
     older_than global_declarations_list global_definitions_list && {
-      grep ';' global_definitions_list |sed 's/[=(].*/;/' |sed 's/^[^\/# ]/extern &/' |sed 's/^extern extern /extern /' > global_declarations_list
+      grep ';' global_definitions_list |sed 's/[=(].*/;/' |sed 's/^[^\/# ]/extern &/' |sed 's/^extern extern /extern /' |update global_declarations_list
     }
     for f in mu_*.cc
     do
@@ -123,7 +145,7 @@ older_than mu_bin mu.cc *_list cleave/cleave termbox/* && {
 
 MU_LAYERS=$(./enumerate/enumerate --until $UNTIL_LAYER |grep '.mu$') || exit 0  # ok if no .mu files
 older_than core.mu $MU_LAYERS enumerate/enumerate && {
-  cat $MU_LAYERS > core.mu
+  cat $MU_LAYERS |update core.mu
 }
 
 exit 0