build+ci: Update default build flags and CI scripts

This commit also fixes a few compilation errors.

Change-Id: I19bcbe360423dad2532b9caee4edcdc6356b0075
diff --git a/.jenkins.d/00-deps.sh b/.jenkins.d/00-deps.sh
new file mode 100755
index 0000000..36fcc7e
--- /dev/null
+++ b/.jenkins.d/00-deps.sh
@@ -0,0 +1,29 @@
+#!/usr/bin/env bash
+set -e
+
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
+if has OSX $NODE_LABELS; then
+    if has OSX-10.8 $NODE_LABELS; then
+        EXTRA_FLAGS=--c++11
+    fi
+
+    set -x
+    brew update
+    brew upgrade
+    brew install boost pkg-config cryptopp log4cxx $EXTRA_FLAGS
+    brew cleanup
+fi
+
+if has Ubuntu $NODE_LABELS; then
+    BOOST_PKG=libboost-all-dev
+    if has Ubuntu-12.04 $NODE_LABELS; then
+        BOOST_PKG=libboost1.48-all-dev
+    fi
+
+    set -x
+    sudo apt-get update -qq -y
+    sudo apt-get -qq -y install build-essential pkg-config $BOOST_PKG \
+                                libcrypto++-dev libsqlite3-dev liblog4cxx10-dev
+fi
diff --git a/.jenkins.d/10-ndn-cxx.sh b/.jenkins.d/10-ndn-cxx.sh
index 823b816..d22bfb6 100755
--- a/.jenkins.d/10-ndn-cxx.sh
+++ b/.jenkins.d/10-ndn-cxx.sh
@@ -2,38 +2,41 @@
 set -x
 set -e
 
-cd /tmp
-BUILD="no"
-if [ ! -d ndn-cxx ]; then
-    git clone --depth 1 git://github.com/named-data/ndn-cxx
-    cd ndn-cxx
-    BUILD="yes"
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
+pushd /tmp >/dev/null
+
+INSTALLED_VERSION=$((cd ndn-cxx && git rev-parse HEAD) 2>/dev/null || echo NONE)
+
+sudo rm -Rf ndn-cxx-latest
+
+git clone --depth 1 git://github.com/named-data/ndn-cxx ndn-cxx-latest
+
+LATEST_VERSION=$((cd ndn-cxx-latest && git rev-parse HEAD) 2>/dev/null || echo UNKNOWN)
+
+if [[ $INSTALLED_VERSION != $LATEST_VERSION ]]; then
+    sudo rm -Rf ndn-cxx
+    mv ndn-cxx-latest ndn-cxx
 else
-    cd ndn-cxx
-    INSTALLED_VERSION=`git rev-parse HEAD || echo NONE`
-    sudo rm -Rf latest-version
-    git clone --depth 1 git://github.com/named-data/ndn-cxx latest-version
-    cd latest-version
-    LATEST_VERSION=`git rev-parse HEAD || echo UNKNOWN`
-    cd ..
-    rm -Rf latest-version
-    if [ "$INSTALLED_VERSION" != "$LATEST_VERSION" ]; then
-        cd ..
-        sudo rm -Rf ndn-cxx
-        git clone --depth 1 git://github.com/named-data/ndn-cxx
-        cd ndn-cxx
-        BUILD="yes"
-    fi
+    sudo rm -Rf ndn-cxx-latest
 fi
 
 sudo rm -Rf /usr/local/include/ndn-cxx
 sudo rm -f /usr/local/lib/libndn-cxx*
 sudo rm -f /usr/local/lib/pkgconfig/libndn-cxx*
 
-if [ "$BUILD" = "yes" ]; then
-    ./waf distclean --color=yes
-fi
+pushd ndn-cxx >/dev/null
 
-./waf configure --color=yes --without-osx-keychain
+./waf configure -j1 --color=yes --enable-shared --disable-static --without-osx-keychain
 ./waf -j1 --color=yes
-sudo ./waf install --color=yes
+sudo ./waf install -j1 --color=yes
+
+popd >/dev/null
+popd >/dev/null
+
+if has Linux $NODE_LABELS; then
+    sudo ldconfig
+elif has FreeBSD $NODE_LABELS; then
+    sudo ldconfig -a
+fi
diff --git a/.jenkins.d/20-ndns.sh b/.jenkins.d/20-ndns.sh
index d2552e7..1d9ee2a 100755
--- a/.jenkins.d/20-ndns.sh
+++ b/.jenkins.d/20-ndns.sh
@@ -2,7 +2,8 @@
 set -x
 set -e
 
-COVERAGE=$( python -c "print '--with-coverage --debug' if 'code-coverage' in '$JOB_NAME' else ''" )
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
 
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
@@ -21,11 +22,20 @@
 # Cleanup
 sudo ./waf -j1 --color=yes distclean
 
-# Configure/build in optimized mode
-./waf -j1 --color=yes configure --with-tests $COVERAGE
+# Configure/build in debug mode
+if [[ "$JOB_NAME" == *"code-coverage" ]]; then
+    COVERAGE="--with-coverage"
+fi
+./waf -j1 --color=yes configure --debug --with-tests $COVERAGE
 ./waf -j1 --color=yes build
 
-# (tests will be run against optimized version)
+# (tests will be run against debug version)
 
 # Install
 sudo ./waf -j1 --color=yes install
+
+if has Linux $NODE_LABELS; then
+    sudo ldconfig
+elif has FreeBSD $NODE_LABELS; then
+    sudo ldconfig -a
+fi
diff --git a/.jenkins.d/30-unit-tests.sh b/.jenkins.d/30-unit-tests.sh
index 4f8248b..4d3a8b3 100755
--- a/.jenkins.d/30-unit-tests.sh
+++ b/.jenkins.d/30-unit-tests.sh
@@ -2,14 +2,15 @@
 set -x
 set -e
 
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
+
 # Prepare environment
-sudo rm -Rf ~/.ndn
+rm -Rf ~/.ndn
 
-IS_OSX=$( python -c "print 'yes' if 'OSX' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-IS_LINUX=$( python -c "print 'yes' if 'Linux' in '$NODE_LABELS'.strip().split(' ') else 'no'" )
-
-if [[ $IS_OSX == "yes" ]]; then
-    security unlock-keychain -p "named-data"
+if has OSX $NODE_LABELS; then
+  echo "Unlocking OSX Keychain"
+  security unlock-keychain -p "named-data"
 fi
 
 # Run unit tests
diff --git a/.jenkins.d/40-coverage.sh b/.jenkins.d/40-coverage.sh
index ccbb62e..e6ecdf3 100755
--- a/.jenkins.d/40-coverage.sh
+++ b/.jenkins.d/40-coverage.sh
@@ -2,9 +2,10 @@
 set -x
 set -e
 
-IS_COVR=$( python -c "print 'yes' if 'code-coverage' in '$JOB_NAME' else 'no'" )
+JDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
+source "$JDIR"/util.sh
 
-if [[ $IS_COVR == "yes" ]]; then
+if [[ "$JOB_NAME" == *"code-coverage" ]]; then
   BASE="`pwd | sed -e 's|/|\\\/|g'`\\"
   (cd build && gcovr -x -f $BASE/src -r ../ -o coverage.xml -b ./)
 fi
diff --git a/.jenkins.d/README.md b/.jenkins.d/README.md
new file mode 100644
index 0000000..956ae18
--- /dev/null
+++ b/.jenkins.d/README.md
@@ -0,0 +1,30 @@
+CONTINUOUS INTEGRATION SCRIPTS
+==============================
+
+Environment Variables Used in Build Scripts
+-------------------------------------------
+
+- `NODE_LABELS`: the variable defines a list of OS properties.  The set values are used by the
+  build scripts to select proper behavior for different OS.
+
+  The list should include at least `[OS_TYPE]`, `[DISTRO_TYPE]`, and `[DISTRO_VERSION]`.
+
+  Possible values for Linux OS:
+
+  * `[OS_TYPE]`: `Linux`
+  * `[DISTRO_TYPE]`: `Ubuntu`
+  * `[DISTRO_VERSION]`: `Ubuntu-12.04`, `Ubuntu-14.04`, `Ubuntu-15.04`
+
+  Possible values of OSX OS:
+
+  * `[OS_TYPE]`: `OSX`
+  * `[DISTRO_TYPE]`: `OSX` (can be absent)
+  * `[DISTRO_VERSION]`: `OSX-10.10`, `OSX-10.9`, `OSX-10.8`, `OSX-10.7`
+
+- `JOB_NAME`: optional variable to define type of the job.  Depending on the defined job type,
+  the build scripts can perform different tasks.
+
+  Possible values:
+
+  * empty: default build process
+  * `code-coverage` (Linux OS is assumed): build process with code coverage analysis
diff --git a/.jenkins.d/util.sh b/.jenkins.d/util.sh
new file mode 100644
index 0000000..81c8931
--- /dev/null
+++ b/.jenkins.d/util.sh
@@ -0,0 +1,9 @@
+has() {
+    local p=$1
+    shift
+    local x
+    for x in "$@"; do
+        [[ "${x}" == "${p}" ]] && return 0
+    done
+    return 1
+}
diff --git a/.travis.yml b/.travis.yml
index db6a8c6..7f40779 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,4 @@
-# For Ubuntu only
+sudo: true
 language: cpp
 os:
   - linux
@@ -8,9 +8,8 @@
   email:
     on_success: always
     on_failure: always
-before_install:
-  - travis_retry sudo apt-get update
-install:
-  - travis_retry sudo apt-get install -qq libssl-dev libpcap-dev libboost1.48-all-dev libcrypto++-dev libsqlite3-dev liblog4cxx10-dev protobuf-compiler libprotobuf-dev pkg-config
 script:
+  - if [[ $TRAVIS_OS_NAME == linux ]]; then export NODE_LABELS="Linux Ubuntu Ubuntu-12.04"; fi
+  - if [[ $TRAVIS_OS_NAME == osx ]]; then export NODE_LABELS="OSX OSX-10.10"; fi
+  - echo $NODE_LABELS
   - ./.jenkins
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index dd78c1c..f82fe10 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -14,22 +14,21 @@
         flags = ClangFlags()
     else:
         flags = CompilerFlags()
-        Logs.warn('The code has not been yet tested with %s compiler' % cxx)
+        Logs.warn('The code has not yet been tested with %s compiler' % cxx)
 
     areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
 
-    # General flags will alway be applied (e.g., selecting C++11 mode)
+    # General flags are always applied (e.g., selecting C++11 mode)
     generalFlags = flags.getGeneralFlags(conf)
     conf.add_supported_cxxflags(generalFlags['CXXFLAGS'])
     conf.add_supported_linkflags(generalFlags['LINKFLAGS'])
     conf.env.DEFINES += generalFlags['DEFINES']
 
-    # Debug or optimization CXXFLAGS and LINKFLAGS  will be applied only if the
+    # Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the
     # corresponding environment variables are not set.
-    # DEFINES will be always applied
+    # DEFINES are always applied.
     if conf.options.debug:
         extraFlags = flags.getDebugFlags(conf)
-
         if areCustomCxxflagsPresent:
             missingFlags = [x for x in extraFlags['CXXFLAGS'] if x not in conf.env.CXXFLAGS]
             if len(missingFlags) > 0:
@@ -96,20 +95,27 @@
         return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': ['NDEBUG']}
 
 class GccBasicFlags(CompilerFlags):
-    """This class defines base flags that work for gcc and clang compiler"""
+    """
+    This class defines basic flags that work for both gcc and clang compilers
+    """
     def getDebugFlags(self, conf):
         flags = super(GccBasicFlags, self).getDebugFlags(conf)
-        flags['CXXFLAGS'] += ['-Wall',
+        flags['CXXFLAGS'] += ['-pedantic',
+                              '-Wall',
                               '-O0',
                               '-g3',
                               '-Werror',
                               '-Wno-error=maybe-uninitialized', # Bug #1615
-                             ]
+                              ]
         return flags
 
     def getOptimizedFlags(self, conf):
         flags = super(GccBasicFlags, self).getOptimizedFlags(conf)
-        flags['CXXFLAGS'] += ['-Wall', '-O2', '-g']
+        flags['CXXFLAGS'] += ['-pedantic',
+                              '-Wall',
+                              '-O2',
+                              '-g',
+                              ]
         return flags
 
 class GccFlags(GccBasicFlags):
@@ -124,28 +130,44 @@
             flags['CXXFLAGS'] += ['-std=c++0x']
         else:
             flags['CXXFLAGS'] += ['-std=c++11']
+        if version < (4, 8, 0):
+            flags['DEFINES'] += ['_GLIBCXX_USE_NANOSLEEP'] # Bug #2499
         return flags
 
     def getDebugFlags(self, conf):
         flags = super(GccFlags, self).getDebugFlags(conf)
         flags['CXXFLAGS'] += ['-Og', # gcc >= 4.8
                               '-fdiagnostics-color', # gcc >= 4.9
-                             ]
+                              ]
+        return flags
+
+    def getOptimizedFlags(self, conf):
+        flags = super(GccFlags, self).getOptimizedFlags(conf)
+        flags['CXXFLAGS'] += ['-fdiagnostics-color'] # gcc >= 4.9
         return flags
 
 class ClangFlags(GccBasicFlags):
     def getGeneralFlags(self, conf):
         flags = super(ClangFlags, self).getGeneralFlags(conf)
-        flags['CXXFLAGS'] += ['-std=c++11',
-                              '-Wno-error=unneeded-internal-declaration', # Bug #1588
-                              '-Wno-error=deprecated-register',
-                              ]
-        if Utils.unversioned_sys_platform() == "darwin":
+        flags['CXXFLAGS'] += ['-std=c++11']
+        if Utils.unversioned_sys_platform() == 'darwin':
             flags['CXXFLAGS'] += ['-stdlib=libc++']
             flags['LINKFLAGS'] += ['-stdlib=libc++']
         return flags
 
     def getDebugFlags(self, conf):
         flags = super(ClangFlags, self).getDebugFlags(conf)
-        flags['CXXFLAGS'] += ['-fcolor-diagnostics']
+        flags['CXXFLAGS'] += ['-fcolor-diagnostics',
+                              '-Wno-unused-local-typedef', # Bugs #2657 and #3209
+                              '-Wno-error=unneeded-internal-declaration', # Bug #1588
+                              '-Wno-error=deprecated-register',
+                              '-Wno-error=keyword-macro', # Bug #3235
+                              ]
+        return flags
+
+    def getOptimizedFlags(self, conf):
+        flags = super(ClangFlags, self).getOptimizedFlags(conf)
+        flags['CXXFLAGS'] += ['-fcolor-diagnostics',
+                              '-Wno-unused-local-typedef', # Bugs #2657 and #3209
+                              ]
         return flags
diff --git a/src/daemon/config-file.cpp b/src/daemon/config-file.cpp
index 0522176..525287d 100644
--- a/src/daemon/config-file.cpp
+++ b/src/daemon/config-file.cpp
@@ -50,7 +50,7 @@
 namespace ndn {
 namespace ndns {
 
-NDNS_LOG_INIT("ConfigFile");
+NDNS_LOG_INIT("ConfigFile")
 
 void
 ConfigFile::throwErrorOnUnknownSection(const std::string& filename,
diff --git a/src/daemon/db-mgr.cpp b/src/daemon/db-mgr.cpp
index 53d3822..8f5fcb3 100644
--- a/src/daemon/db-mgr.cpp
+++ b/src/daemon/db-mgr.cpp
@@ -27,7 +27,7 @@
 namespace ndn {
 namespace ndns {
 
-NDNS_LOG_INIT("DbMgr");
+NDNS_LOG_INIT("DbMgr")
 
 static const std::string NDNS_SCHEMA = "\
 CREATE TABLE IF NOT EXISTS zones (      \n\
diff --git a/src/daemon/db-mgr.hpp b/src/daemon/db-mgr.hpp
index 336b330..5c4e179 100644
--- a/src/daemon/db-mgr.hpp
+++ b/src/daemon/db-mgr.hpp
@@ -39,7 +39,7 @@
     : Base(what)                                \
   {                                             \
   }                                             \
-};
+}
 
 
 
diff --git a/src/mgmt/management-tool.cpp b/src/mgmt/management-tool.cpp
index 75deeea..6fe2311 100644
--- a/src/mgmt/management-tool.cpp
+++ b/src/mgmt/management-tool.cpp
@@ -38,7 +38,7 @@
 namespace ndn {
 namespace ndns {
 
-NDNS_LOG_INIT("ManagementTool");
+NDNS_LOG_INIT("ManagementTool")
 
 ManagementTool::ManagementTool(const std::string& dbFile, KeyChain& keyChain)
   : m_keyChain(keyChain)
diff --git a/src/validator.cpp b/src/validator.cpp
index c3dff78..71c9680 100644
--- a/src/validator.cpp
+++ b/src/validator.cpp
@@ -27,7 +27,8 @@
 
 namespace ndn {
 namespace ndns {
-NDNS_LOG_INIT("validator");
+
+NDNS_LOG_INIT("validator")
 
 std::string Validator::VALIDATOR_CONF_FILE = DEFAULT_CONFIG_PATH "/" "validator.conf";
 
diff --git a/tests/main.cpp b/tests/main.cpp
index ac55966..7d4602b 100644
--- a/tests/main.cpp
+++ b/tests/main.cpp
@@ -20,7 +20,9 @@
 #define BOOST_TEST_MAIN 1
 #define BOOST_TEST_DYN_LINK 1
 
+#include <boost/version.hpp>
 #include <boost/test/unit_test.hpp>
+#include <boost/noncopyable.hpp>
 
 #include "logger.hpp"
 #include "config.hpp"
@@ -39,6 +41,9 @@
 };
 
 BOOST_GLOBAL_FIXTURE(UnitTestsLogging)
+#if (BOOST_VERSION >= 105900)
+;
+#endif // BOOST_VERSION >= 105900
 
 } // namespace tests
 } // namespace ndns
diff --git a/tests/unit/clients/iterative-query-controller.cpp b/tests/unit/clients/iterative-query-controller.cpp
index 116c6a1..254b4f3 100644
--- a/tests/unit/clients/iterative-query-controller.cpp
+++ b/tests/unit/clients/iterative-query-controller.cpp
@@ -30,7 +30,8 @@
 namespace ndn {
 namespace ndns {
 namespace tests {
-NDNS_LOG_INIT("IterativeQueryControllerTest");
+
+NDNS_LOG_INIT("IterativeQueryControllerTest")
 
 class QueryControllerFixture : public DbTestData
 {
diff --git a/tests/unit/daemon/name-server.cpp b/tests/unit/daemon/name-server.cpp
index f2b64bb..32f911c 100644
--- a/tests/unit/daemon/name-server.cpp
+++ b/tests/unit/daemon/name-server.cpp
@@ -34,7 +34,7 @@
 namespace ndns {
 namespace tests {
 
-NDNS_LOG_INIT("NameServerTest");
+NDNS_LOG_INIT("NameServerTest")
 
 class NameServerFixture : public DbTestData
 {
diff --git a/tests/unit/validator.cpp b/tests/unit/validator.cpp
index 09af09d..1ec16c6 100644
--- a/tests/unit/validator.cpp
+++ b/tests/unit/validator.cpp
@@ -26,7 +26,8 @@
 namespace ndn {
 namespace ndns {
 namespace tests {
-NDNS_LOG_INIT("ValidatorTest");
+
+NDNS_LOG_INIT("ValidatorTest")
 
 BOOST_AUTO_TEST_SUITE(Validator)
 
diff --git a/tools/ndns-daemon.cpp b/tools/ndns-daemon.cpp
index b40f6f0..af68abd 100644
--- a/tools/ndns-daemon.cpp
+++ b/tools/ndns-daemon.cpp
@@ -27,7 +27,7 @@
 namespace ndn {
 namespace ndns {
 
-NDNS_LOG_INIT("NdnsDaemon");
+NDNS_LOG_INIT("NdnsDaemon")
 
 /**
  * @brief Name Server Daemon
diff --git a/tools/ndns-dig.cpp b/tools/ndns-dig.cpp
index 36fea64..30afe88 100644
--- a/tools/ndns-dig.cpp
+++ b/tools/ndns-dig.cpp
@@ -35,7 +35,7 @@
 #include <memory>
 #include <string>
 
-NDNS_LOG_INIT("NdnsDig");
+NDNS_LOG_INIT("NdnsDig")
 
 namespace ndn {
 namespace ndns {
diff --git a/tools/ndns-update.cpp b/tools/ndns-update.cpp
index 25fda11..10bab42 100644
--- a/tools/ndns-update.cpp
+++ b/tools/ndns-update.cpp
@@ -42,7 +42,8 @@
 
 namespace ndn {
 namespace ndns {
-NDNS_LOG_INIT("NdnsUpdate");
+
+NDNS_LOG_INIT("NdnsUpdate")
 
 class NdnsUpdate : noncopyable
 {