build+ci: Upgrade build scripts, enable coverage and sanitizer flags

Change-Id: I825ea4fdf4f40c4af06b5667af432f1c0eab368d
diff --git a/.jenkins.d/20-build.sh b/.jenkins.d/20-build.sh
index 8220c31..e281a7d 100755
--- a/.jenkins.d/20-build.sh
+++ b/.jenkins.d/20-build.sh
@@ -1,32 +1,50 @@
 #!/usr/bin/env bash
-set -x
 set -e
 
-sudo rm -Rf /usr/local/include/ChronoSync
-sudo rm -f /usr/local/lib/libChronoSync*
-sudo rm -f /usr/local/lib/pkgconfig/ChronoSync*
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
+set -x
+
+git submodule init
+git submodule sync
+git submodule update
 
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
-# Configure/build in debug mode
-./waf -j1 --color=yes configure --with-tests --debug
+if [[ "$JOB_NAME" != *"limited-build" ]]; then
+  # Configure/build in optimized mode with tests
+  ./waf -j1 --color=yes configure --with-tests
+  ./waf -j1 --color=yes build
+
+  # Cleanup
+  sudo ./waf -j1 --color=yes distclean
+
+  # Configure/build in optimized mode without tests
+  ./waf -j1 --color=yes configure
+  ./waf -j1 --color=yes build
+
+  # Cleanup
+  sudo ./waf -j1 --color=yes distclean
+fi
+
+# Configure/build in debug mode with tests and without precompiled headers
+if [[ "$JOB_NAME" == *"code-coverage" ]]; then
+    COVERAGE="--with-coverage"
+elif ! has OSX-10.9 $NODE_LABELS && ! has OSX-10.11 $NODE_LABELS; then
+    ASAN="--with-sanitizer=address"
+fi
+./waf -j1 --color=yes configure --debug --with-tests --without-pch $COVERAGE $ASAN
 ./waf -j1 --color=yes build
 
-# Cleanup
-sudo ./waf -j1 --color=yes distclean
-
-# Configure/build in optimized mode without tests
-./waf -j1 --color=yes configure
-./waf -j1 --color=yes build
-
-# Cleanup
-sudo ./waf -j1 --color=yes distclean
-
-# Configure/build in optimized mode with tests
-./waf -j1 --color=yes configure --with-tests
-./waf -j1 --color=yes build
+# (tests will be run against debug version)
 
 # Install
-sudo ./waf install -j1 --color=yes
-sudo ldconfig || true
+sudo ./waf -j1 --color=yes install
+
+if has Linux $NODE_LABELS; then
+    sudo ldconfig
+elif has FreeBSD $NODE_LABELS; then
+    sudo ldconfig -a
+fi