build: Upgrade waf to version 2.0.6

This commit also includes:
- cleanup of build scripts
- replacing log4cxx with ndn-cxx logging facility

Change-Id: I96fd673a3cd2e06061e9efc1a7891e41cf97ea4f
diff --git a/.waf-tools/coverage.py b/.waf-tools/coverage.py
index ce92883..cc58165 100644
--- a/.waf-tools/coverage.py
+++ b/.waf-tools/coverage.py
@@ -1,15 +1,15 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
 
-from waflib import TaskGen, Logs
+from waflib import TaskGen
 
 def options(opt):
-    opt.add_option('--with-coverage', action='store_true', default=False, dest='with_coverage',
-                   help='''Set compiler flags for gcc to enable code coverage information''')
+    opt.add_option('--with-coverage', action='store_true', default=False,
+                   help='Add compiler flags to enable code coverage information')
 
 def configure(conf):
     if conf.options.with_coverage:
         if not conf.options.debug:
-            conf.fatal("Code coverage flags require debug mode compilation (add --debug)")
+            conf.fatal('Code coverage flags require debug mode compilation (add --debug)')
         conf.check_cxx(cxxflags=['-fprofile-arcs', '-ftest-coverage', '-fPIC'],
                        linkflags=['-fprofile-arcs'], uselib_store='GCOV', mandatory=True)
 
diff --git a/.waf-tools/default-compiler-flags.py b/.waf-tools/default-compiler-flags.py
index 2999e8f..54db7ea 100644
--- a/.waf-tools/default-compiler-flags.py
+++ b/.waf-tools/default-compiler-flags.py
@@ -1,44 +1,67 @@
 # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
 
-from waflib import Logs, Configure, Utils
+from waflib import Configure, Logs, Utils
 
 def options(opt):
-    opt.add_option('--debug', '--with-debug', action='store_true', default=False, dest='debug',
-                   help='''Compile in debugging mode without optimizations (-O0 or -Og)''')
+    opt.add_option('--debug', '--with-debug', action='store_true', default=False,
+                   help='Compile in debugging mode with minimal optimizations (-O0 or -Og)')
 
 def configure(conf):
-    cxx = conf.env['CXX_NAME'] # CXX_NAME represents generic name of the compiler
-    if cxx == 'gcc':
-        flags = GccFlags()
-    elif cxx == 'clang':
-        flags = ClangFlags()
-    else:
-        flags = CompilerFlags()
-        Logs.warn('The code has not yet been tested with %s compiler' % cxx)
+    conf.start_msg('Checking C++ compiler version')
 
-    areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
+    cxx = conf.env.CXX_NAME # generic name of the compiler
+    ccver = tuple(int(i) for i in conf.env.CC_VERSION)
+    ccverstr = '.'.join(conf.env.CC_VERSION)
+    errmsg = ''
+    warnmsg = ''
+    if cxx == 'gcc':
+        if ccver < (4, 8, 2):
+            errmsg = ('The version of gcc you are using is too old.\n'
+                      'The minimum supported gcc version is 4.8.2.')
+        conf.flags = GccFlags()
+    elif cxx == 'clang':
+        if ccver < (3, 4, 0):
+            errmsg = ('The version of clang you are using is too old.\n'
+                      'The minimum supported clang version is 3.4.0.')
+        conf.flags = ClangFlags()
+    else:
+        warnmsg = 'Note: %s compiler is unsupported' % cxx
+        conf.flags = CompilerFlags()
+
+    if errmsg:
+        conf.end_msg(ccverstr, color='RED')
+        conf.fatal(errmsg)
+    elif warnmsg:
+        conf.end_msg(ccverstr, color='YELLOW')
+        Logs.warn(warnmsg)
+    else:
+        conf.end_msg(ccverstr)
+
+    conf.areCustomCxxflagsPresent = (len(conf.env.CXXFLAGS) > 0)
 
     # General flags are always applied (e.g., selecting C++11 mode)
-    generalFlags = flags.getGeneralFlags(conf)
+    generalFlags = conf.flags.getGeneralFlags(conf)
     conf.add_supported_cxxflags(generalFlags['CXXFLAGS'])
     conf.add_supported_linkflags(generalFlags['LINKFLAGS'])
     conf.env.DEFINES += generalFlags['DEFINES']
 
+@Configure.conf
+def check_compiler_flags(conf):
     # Debug or optimized CXXFLAGS and LINKFLAGS are applied only if the
     # corresponding environment variables are not set.
     # DEFINES are always applied.
     if conf.options.debug:
-        extraFlags = flags.getDebugFlags(conf)
-        if areCustomCxxflagsPresent:
+        extraFlags = conf.flags.getDebugFlags(conf)
+        if conf.areCustomCxxflagsPresent:
             missingFlags = [x for x in extraFlags['CXXFLAGS'] if x not in conf.env.CXXFLAGS]
-            if len(missingFlags) > 0:
-                Logs.warn("Selected debug mode, but CXXFLAGS is set to a custom value '%s'"
-                          % " ".join(conf.env.CXXFLAGS))
-                Logs.warn("Default flags '%s' are not activated" % " ".join(missingFlags))
+            if missingFlags:
+                Logs.warn('Selected debug mode, but CXXFLAGS is set to a custom value "%s"'
+                          % ' '.join(conf.env.CXXFLAGS))
+                Logs.warn('Default flags "%s" will not be used' % ' '.join(missingFlags))
     else:
-        extraFlags = flags.getOptimizedFlags(conf)
+        extraFlags = conf.flags.getOptimizedFlags(conf)
 
-    if not areCustomCxxflagsPresent:
+    if not conf.areCustomCxxflagsPresent:
         conf.add_supported_cxxflags(extraFlags['CXXFLAGS'])
         conf.add_supported_linkflags(extraFlags['LINKFLAGS'])
 
@@ -55,9 +78,10 @@
     self.start_msg('Checking supported CXXFLAGS')
 
     supportedFlags = []
-    for flag in cxxflags:
-        if self.check_cxx(cxxflags=['-Werror', flag], mandatory=False):
-            supportedFlags += [flag]
+    for flags in cxxflags:
+        flags = Utils.to_list(flags)
+        if self.check_cxx(cxxflags=['-Werror'] + flags, mandatory=False):
+            supportedFlags += flags
 
     self.end_msg(' '.join(supportedFlags))
     self.env.prepend_value('CXXFLAGS', supportedFlags)
@@ -73,15 +97,19 @@
     self.start_msg('Checking supported LINKFLAGS')
 
     supportedFlags = []
-    for flag in linkflags:
-        if self.check_cxx(linkflags=['-Werror', flag], mandatory=False):
-            supportedFlags += [flag]
+    for flags in linkflags:
+        flags = Utils.to_list(flags)
+        if self.check_cxx(linkflags=['-Werror'] + flags, mandatory=False):
+            supportedFlags += flags
 
     self.end_msg(' '.join(supportedFlags))
     self.env.prepend_value('LINKFLAGS', supportedFlags)
 
 
 class CompilerFlags(object):
+    def getCompilerVersion(self, conf):
+        return tuple(int(i) for i in conf.env.CC_VERSION)
+
     def getGeneralFlags(self, conf):
         """Get dict of CXXFLAGS, LINKFLAGS, and DEFINES that are always needed"""
         return {'CXXFLAGS': [], 'LINKFLAGS': [], 'DEFINES': []}
@@ -98,18 +126,26 @@
     """
     This class defines basic flags that work for both gcc and clang compilers
     """
+    def getGeneralFlags(self, conf):
+        flags = super(GccBasicFlags, self).getGeneralFlags(conf)
+        flags['CXXFLAGS'] += ['-std=c++11']
+        return flags
+
     def getDebugFlags(self, conf):
         flags = super(GccBasicFlags, self).getDebugFlags(conf)
         flags['CXXFLAGS'] += ['-O0',
+                              '-Og', # gcc >= 4.8, clang >= 4.0
                               '-g3',
                               '-pedantic',
                               '-Wall',
                               '-Wextra',
                               '-Werror',
-                              '-Wno-unused-parameter',
-                              '-Wno-error=maybe-uninitialized', # Bug #1615
+                              '-Wnon-virtual-dtor',
                               '-Wno-error=deprecated-declarations', # Bug #3795
+                              '-Wno-error=maybe-uninitialized', # Bug #1615
+                              '-Wno-unused-parameter',
                               ]
+        flags['LINKFLAGS'] += ['-fuse-ld=gold', '-Wl,-O1']
         return flags
 
     def getOptimizedFlags(self, conf):
@@ -119,36 +155,23 @@
                               '-pedantic',
                               '-Wall',
                               '-Wextra',
+                              '-Wnon-virtual-dtor',
                               '-Wno-unused-parameter',
                               ]
+        flags['LINKFLAGS'] += ['-fuse-ld=gold', '-Wl,-O1']
         return flags
 
 class GccFlags(GccBasicFlags):
-    def getGeneralFlags(self, conf):
-        flags = super(GccFlags, self).getGeneralFlags(conf)
-        version = tuple(int(i) for i in conf.env['CC_VERSION'])
-        if version < (4, 8, 2):
-            conf.fatal('The version of gcc you are using (%s) is too old.\n' %
-                       '.'.join(conf.env['CC_VERSION']) +
-                       'The minimum supported gcc version is 4.8.2.')
-        else:
-            flags['CXXFLAGS'] += ['-std=c++11']
-        return flags
-
     def getDebugFlags(self, conf):
         flags = super(GccFlags, self).getDebugFlags(conf)
-        version = tuple(int(i) for i in conf.env['CC_VERSION'])
-        if version < (5, 1, 0):
+        if self.getCompilerVersion(conf) < (5, 1, 0):
             flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
-        flags['CXXFLAGS'] += ['-Og', # gcc >= 4.8
-                              '-fdiagnostics-color', # gcc >= 4.9
-                              ]
+        flags['CXXFLAGS'] += ['-fdiagnostics-color'] # gcc >= 4.9
         return flags
 
     def getOptimizedFlags(self, conf):
         flags = super(GccFlags, self).getOptimizedFlags(conf)
-        version = tuple(int(i) for i in conf.env['CC_VERSION'])
-        if version < (5, 1, 0):
+        if self.getCompilerVersion(conf) < (5, 1, 0):
             flags['CXXFLAGS'] += ['-Wno-missing-field-initializers']
         flags['CXXFLAGS'] += ['-fdiagnostics-color'] # gcc >= 4.9
         return flags
@@ -156,26 +179,36 @@
 class ClangFlags(GccBasicFlags):
     def getGeneralFlags(self, conf):
         flags = super(ClangFlags, self).getGeneralFlags(conf)
-        flags['CXXFLAGS'] += ['-std=c++11']
-        if Utils.unversioned_sys_platform() == 'darwin':
-            flags['CXXFLAGS'] += ['-stdlib=libc++']
-            flags['LINKFLAGS'] += ['-stdlib=libc++']
+        if Utils.unversioned_sys_platform() == 'darwin' and self.getCompilerVersion(conf) >= (9, 0, 0):
+            # Bug #4296
+            flags['CXXFLAGS'] += [['-isystem', '/usr/local/include'], # for Homebrew
+                                  ['-isystem', '/opt/local/include']] # for MacPorts
         return flags
 
     def getDebugFlags(self, conf):
         flags = super(ClangFlags, self).getDebugFlags(conf)
         flags['CXXFLAGS'] += ['-fcolor-diagnostics',
-                              '-Wno-unused-local-typedef', # Bugs #2657 and #3209
-                              '-Wno-error=unneeded-internal-declaration', # Bug #1588
+                              '-Wextra-semi',
+                              '-Wundefined-func-template',
                               '-Wno-error=deprecated-register',
-                              '-Wno-error=keyword-macro', # Bug #3235
                               '-Wno-error=infinite-recursion', # Bug #3358
+                              '-Wno-error=keyword-macro', # Bug #3235
+                              '-Wno-error=unneeded-internal-declaration', # Bug #1588
+                              '-Wno-unused-local-typedef', # Bugs #2657 and #3209
                               ]
+        version = self.getCompilerVersion(conf)
+        if version < (3, 9, 0) or (Utils.unversioned_sys_platform() == 'darwin' and version < (8, 1, 0)):
+            flags['CXXFLAGS'] += ['-Wno-unknown-pragmas']
         return flags
 
     def getOptimizedFlags(self, conf):
         flags = super(ClangFlags, self).getOptimizedFlags(conf)
         flags['CXXFLAGS'] += ['-fcolor-diagnostics',
+                              '-Wextra-semi',
+                              '-Wundefined-func-template',
                               '-Wno-unused-local-typedef', # Bugs #2657 and #3209
                               ]
+        version = self.getCompilerVersion(conf)
+        if version < (3, 9, 0) or (Utils.unversioned_sys_platform() == 'darwin' and version < (8, 1, 0)):
+            flags['CXXFLAGS'] += ['-Wno-unknown-pragmas']
         return flags
diff --git a/.waf-tools/dependency-checker.py b/.waf-tools/dependency-checker.py
index 629fbfd..63199a5 100644
--- a/.waf-tools/dependency-checker.py
+++ b/.waf-tools/dependency-checker.py
@@ -4,10 +4,10 @@
 from waflib.Configure import conf
 
 def addDependencyOptions(self, opt, name, extraHelp=''):
-    opt.add_option('--with-%s' % name, type='string', default=None,
-                   dest='with_%s' % name,
+    opt.add_option('--with-%s' % name, metavar='PATH',
                    help='Path to %s, e.g., /usr/local %s' % (name, extraHelp))
-setattr(Options.OptionsContext, "addDependencyOptions", addDependencyOptions)
+
+setattr(Options.OptionsContext, 'addDependencyOptions', addDependencyOptions)
 
 @conf
 def checkDependency(self, name, **kw):
@@ -18,8 +18,8 @@
     kw['mandatory'] = kw.get('mandatory', True)
 
     if root:
-        isOk = self.check_cxx(includes="%s/include" % root,
-                              libpath="%s/lib" % root,
+        isOk = self.check_cxx(includes='%s/include' % root,
+                              libpath='%s/lib' % root,
                               **kw)
     else:
         isOk = self.check_cxx(**kw)
diff --git a/.waf-tools/pch.py b/.waf-tools/pch.py
deleted file mode 100644
index 08cc5de..0000000
--- a/.waf-tools/pch.py
+++ /dev/null
@@ -1,148 +0,0 @@
-#! /usr/bin/env python
-# encoding: utf-8
-# Alexander Afanasyev (UCLA), 2014
-
-"""
-Enable precompiled C++ header support (currently only clang++ and g++ are supported)
-
-To use this tool, wscript should look like:
-
-	def options(opt):
-		opt.load('pch')
-		# This will add `--with-pch` configure option.
-		# Unless --with-pch during configure stage specified, the precompiled header support is disabled
-
-	def configure(conf):
-		conf.load('pch')
-		# this will set conf.env.WITH_PCH if --with-pch is specified and the supported compiler is used
-		# Unless conf.env.WITH_PCH is set, the precompiled header support is disabled
-
-	def build(bld):
-		bld(features='cxx pch',
-			target='precompiled-headers',
-			name='precompiled-headers',
-			headers='a.h b.h c.h', # headers to pre-compile into `precompiled-headers`
-
-			# Other parameters to compile precompiled headers
-			# includes=...,
-			# export_includes=...,
-			# use=...,
-			# ...
-
-			# Exported parameters will be propagated even if precompiled headers are disabled
-		)
-
-		bld(
-			target='test',
-			features='cxx cxxprogram',
-			source='a.cpp b.cpp d.cpp main.cpp',
-			use='precompiled-headers',
-		)
-
-		# or
-
-		bld(
-			target='test',
-			features='pch cxx cxxprogram',
-			source='a.cpp b.cpp d.cpp main.cpp',
-			headers='a.h b.h c.h',
-		)
-
-Note that precompiled header must have multiple inclusion guards.  If the guards are missing, any benefit of precompiled header will be voided and compilation may fail in some cases.
-"""
-
-import os
-from waflib import Task, TaskGen, Logs, Utils
-from waflib.Tools import c_preproc, cxx
-
-
-PCH_COMPILER_OPTIONS = {
-	'clang++': [['-include'], '.pch', ['-x', 'c++-header']],
-	'g++':     [['-include'], '.gch', ['-x', 'c++-header']],
-}
-
-
-def options(opt):
-	opt.add_option('--without-pch', action='store_false', default=True, dest='with_pch', help='''Try to use precompiled header to speed up compilation (only g++ and clang++)''')
-
-def configure(conf):
-	if (conf.options.with_pch and conf.env['COMPILER_CXX'] in PCH_COMPILER_OPTIONS.keys()):
-		conf.env.WITH_PCH = True
-		flags = PCH_COMPILER_OPTIONS[conf.env['COMPILER_CXX']]
-		conf.env.CXXPCH_F = flags[0]
-		conf.env.CXXPCH_EXT = flags[1]
-		conf.env.CXXPCH_FLAGS = flags[2]
-
-
-@TaskGen.feature('pch')
-@TaskGen.before('process_source')
-def apply_pch(self):
-	if not self.env.WITH_PCH:
-		return
-
-	if getattr(self.bld, 'pch_tasks', None) is None:
-		self.bld.pch_tasks = {}
-
-	if getattr(self, 'headers', None) is None:
-		return
-
-	self.headers = self.to_nodes(self.headers)
-
-	if getattr(self, 'name', None):
-		try:
-			task = self.bld.pch_tasks[self.name]
-			self.bld.fatal("Duplicated 'pch' task with name %r" % self.name)
-		except KeyError:
-			pass
-
-	out = '%s.%d%s' % (self.target, self.idx, self.env['CXXPCH_EXT'])
-	out = self.path.find_or_declare(out)
-	task = self.create_task('gchx', self.headers, out)
-
-	# target should be an absolute path of `out`, but without precompiled header extension
-	task.target = out.abspath()[:-len(out.suffix())]
-
-	self.pch_task = task
-	if getattr(self, 'name', None):
-		self.bld.pch_tasks[self.name] = task
-
-@TaskGen.feature('cxx')
-@TaskGen.after_method('process_source', 'propagate_uselib_vars')
-def add_pch(self):
-	if not (self.env['WITH_PCH'] and getattr(self, 'use', None) and getattr(self, 'compiled_tasks', None) and getattr(self.bld, 'pch_tasks', None)):
-		return
-
-	pch = None
-	# find pch task, if any
-
-	if getattr(self, 'pch_task', None):
-		pch = self.pch_task
-	else:
-		for use in Utils.to_list(self.use):
-			try:
-				pch = self.bld.pch_tasks[use]
-			except KeyError:
-				pass
-
-	if pch:
-		for x in self.compiled_tasks:
-			x.env.append_value('CXXFLAGS', self.env['CXXPCH_F'] + [pch.target])
-
-class gchx(Task.Task):
-	run_str = '${CXX} ${ARCH_ST:ARCH} ${CXXFLAGS} ${CPPFLAGS} ${CXXPCH_FLAGS} ${FRAMEWORKPATH_ST:FRAMEWORKPATH} ${CPPPATH_ST:INCPATHS} ${DEFINES_ST:DEFINES} ${CXXPCH_F:SRC} ${CXX_SRC_F}${SRC[0].abspath()} ${CXX_TGT_F}${TGT[0].abspath()}'
-	scan    = c_preproc.scan
-	color   = 'BLUE'
-	ext_out=['.h']
-
-	def runnable_status(self):
-		try:
-			node_deps = self.generator.bld.node_deps[self.uid()]
-		except KeyError:
-			node_deps = []
-		ret = Task.Task.runnable_status(self)
-		if ret == Task.SKIP_ME and self.env.CXX_NAME == 'clang':
-			t = os.stat(self.outputs[0].abspath()).st_mtime
-			for n in self.inputs + node_deps:
-				if os.stat(n.abspath()).st_mtime > t:
-					return Task.RUN_ME
-		return ret
diff --git a/.waf-tools/sqlite3.py b/.waf-tools/sqlite3.py
index 28dd57c..7ddbf0f 100644
--- a/.waf-tools/sqlite3.py
+++ b/.waf-tools/sqlite3.py
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # encoding: utf-8
 
-from waflib import Options
+from waflib import Options, Logs
 from waflib.Configure import conf
 
 def options(opt):
@@ -19,6 +19,9 @@
     mandatory = kw.get('mandatory', True)
     var = kw.get('uselib_store', 'SQLITE3')
 
+    if not self.options.with_sqlite_locking:
+        conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
+
     if root:
         self.check_cxx(lib='sqlite3',
                        msg='Checking for SQLite3 library',
@@ -31,6 +34,8 @@
         try:
             self.check_cfg(package='sqlite3',
                            args=['--cflags', '--libs'],
+                           global_define=True,
+                           define_name='HAVE_%s' % var,
                            uselib_store='SQLITE3',
                            mandatory=True)
         except: