build: Add coverage.py tool that introduces --with-coverage configure option

Change-Id: I1c6eeb71c734ef8b37e06cc5ac3d0b40aef492da
diff --git a/.waf-tools/coverage.py b/.waf-tools/coverage.py
new file mode 100644
index 0000000..eac7608
--- /dev/null
+++ b/.waf-tools/coverage.py
@@ -0,0 +1,20 @@
+# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
+
+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''')
+
+def configure(conf):
+    if conf.options.with_coverage:
+        conf.check_cxx(cxxflags=['-fprofile-arcs', '-ftest-coverage', '-fPIC'],
+                       linkflags=['-fprofile-arcs'], uselib_store='GCOV', mandatory=True)
+
+@TaskGen.feature('cxx','cc')
+@TaskGen.after('process_source')
+def add_coverage(self):
+    if getattr(self, 'use', ''):
+        self.use += ' GCOV'
+    else:
+        self.use = 'GCOV'
diff --git a/wscript b/wscript
index 7f33a8e..f0b04ac 100644
--- a/wscript
+++ b/wscript
@@ -5,7 +5,7 @@
 
 def options(opt):
     opt.load('compiler_cxx')
-    opt.load('boost doxygen', tooldir=['.waf-tools'])
+    opt.load('boost doxygen coverage', tooldir=['.waf-tools'])
 
     nfdopt = opt.add_option_group('NFD Options')
     nfdopt.add_option('--debug',action='store_true',default=False,dest='debug',help='''Compile library debugging mode without all optimizations (-O0)''')
@@ -58,6 +58,8 @@
     
     conf.check_cxx(lib='rt', uselib_store='RT', define_name='HAVE_RT', mandatory=False)
 
+    conf.load('coverage')
+
     conf.write_config_header('daemon/config.hpp')
 
 def build(bld):