New waf/wscript and initial reorganization
diff --git a/waf-tools/ccnx.py b/waf-tools/ccnx.py
deleted file mode 100644
index 5338b5f..0000000
--- a/waf-tools/ccnx.py
+++ /dev/null
@@ -1,77 +0,0 @@
-#! /usr/bin/env python
-# encoding: utf-8
-
-'''
-
-When using this tool, the wscript will look like:
-
-	def options(opt):
-	        opt.tool_options('ccnx', tooldir=["waf-tools"])
-
-	def configure(conf):
-		conf.load('compiler_cxx ccnx')
-
-	def build(bld):
-		bld(source='main.cpp', target='app', use='CCNX')
-
-Options are generated, in order to specify the location of ccnx includes/libraries.
-
-
-'''
-import sys
-import re
-from waflib import Utils,Logs,Errors
-from waflib.Configure import conf
-CCNX_DIR=['/usr','/usr/local','/opt/local','/sw']
-CCNX_VERSION_FILE='ccn/ccn.h'
-CCNX_VERSION_CODE='''
-#include <iostream>
-#include <ccn/ccn.h>
-int main() { std::cout << ((CCN_API_VERSION/100000) % 100) << "." << ((CCN_API_VERSION/1000) % 100) << "." << (CCN_API_VERSION % 1000); }
-'''
-
-def options(opt):
-	opt.add_option('--ccnx',type='string',default='',dest='ccnx_dir',help='''path to where CCNx is installed, e.g. /usr/local''')
-@conf
-def __ccnx_get_version_file(self,dir):
-	# Logs.pprint ('CYAN', '  + %s/%s/%s' % (dir, 'include', CCNX_VERSION_FILE))
-	try:
-		return self.root.find_dir(dir).find_node('%s/%s' % ('include', CCNX_VERSION_FILE))
-	except:
-		return None
-@conf
-def ccnx_get_version(self,dir):
-	val=self.check_cxx(fragment=CCNX_VERSION_CODE,includes=['%s/%s' % (dir, 'include')],execute=True,define_ret = True, mandatory=True)
-	return val
-@conf
-def ccnx_get_root(self,*k,**kw):
-	root=k and k[0]or kw.get('path',None)
-	# Logs.pprint ('RED', '   %s' %root)
-	if root and self.__ccnx_get_version_file(root):
-		return root
-	for dir in CCNX_DIR:
-		if self.__ccnx_get_version_file(dir):
-			return dir
-	if root:
-		self.fatal('CCNx not found in %s'%root)
-	else:
-		self.fatal('CCNx not found, please provide a --ccnx argument (see help)')
-@conf
-def check_ccnx(self,*k,**kw):
-	if not self.env['CXX']:
-		self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
-
-	var=kw.get('uselib_store','CCNX')
-	self.start_msg('Checking CCNx')
-	root = self.ccnx_get_root(*k,**kw);
-	self.env.CCNX_VERSION=self.ccnx_get_version(root)
-
-	self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include");
-	self.env['LIB_%s'%var] = "ccn"
-	self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
-
-	self.end_msg(self.env.CCNX_VERSION)
-	if Logs.verbose:
-		Logs.pprint('CYAN','	ccnx include : %s'%self.env['INCLUDES_%s'%var])
-		Logs.pprint('CYAN','	ccnx lib     : %s'%self.env['LIB_%s'%var])
-		Logs.pprint('CYAN','	ccnx libpath : %s'%self.env['LIBPATH_%s'%var])
diff --git a/waf-tools/ndnx.py b/waf-tools/ndnx.py
new file mode 100644
index 0000000..eec23c5
--- /dev/null
+++ b/waf-tools/ndnx.py
@@ -0,0 +1,160 @@
+#! /usr/bin/env python
+# encoding: utf-8
+
+'''
+
+When using this tool, the wscript will look like:
+
+	def options(opt):
+	        opt.tool_options('ndnx')
+
+	def configure(conf):
+		conf.load('compiler_c ndnx')
+
+	def build(bld):
+		bld(source='main.cpp', target='app', use='NDNX')
+
+Options are generated, in order to specify the location of ndnx includes/libraries.
+
+
+'''
+import sys, re
+from waflib import Utils, Logs, Errors, Options, ConfigSet
+from waflib.Configure import conf
+
+NDNX_DIR=['/usr','/usr/local','/opt/local','/sw']
+NDNX_VERSION_FILE='ccn/ccn.h'
+NDNX_VERSION_CODE='''
+#include <ccn/ccn.h>
+#include <stdio.h>
+int main() { printf ("%d.%d.%d", ((CCN_API_VERSION/100000) % 100), ((CCN_API_VERSION/1000) % 100), (CCN_API_VERSION % 1000)); return 0; }
+'''
+
+@conf
+def __ndnx_get_version_file(self,dir):
+	# Logs.pprint ('CYAN', '  + %s/%s/%s' % (dir, 'include', NDNX_VERSION_FILE))
+	try:
+		return self.root.find_dir(dir).find_node('%s/%s' % ('include', NDNX_VERSION_FILE))
+	except:
+		return None
+@conf
+def ndnx_get_version(self,dir):
+	val=self.check_cc(fragment=NDNX_VERSION_CODE,includes=['%s/%s' % (dir, 'include')],execute=True,define_ret = True, mandatory=True)
+	return val
+@conf
+def ndnx_get_root(self,*k,**kw):
+	root=Options.options.ndnx_dir or (k and k[0]) or kw.get('path',None)
+        
+	if root:
+                if self.__ndnx_get_version_file(root):
+                        return root
+		self.fatal('NDNx not found in %s'%root)
+                
+	for dir in NDNX_DIR:
+		if self.__ndnx_get_version_file(dir):
+			return dir
+        self.fatal('NDNx not found, please provide a --ndnx argument (see help)')
+
+@conf
+def check_openssl(self,*k,**kw):
+        root = k and k[0] or kw.get('path',None) or Options.options.openssl
+        mandatory = kw.get('mandatory', True)
+        var = kw.get('var', 'SSL')
+
+        CODE = """
+#include <openssl/crypto.h>
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+	(void)argc;
+        printf ("%s", argv[0]);
+
+	return 0;
+}
+"""
+        if root:
+                testApp = self.check_cc (lib=['ssl', 'crypto'],
+                                         header_name='openssl/crypto.h',
+                                         define_name='HAVE_%s' % var,
+                                         uselib_store=var,
+                                         mandatory = mandatory,
+                                         cflags="-I%s/include" % root,
+                                         linkflags="-L%s/lib" % root,
+                                         execute = True, fragment = CODE, define_ret = True)
+        else:
+                testApp = libcrypto = self.check_cc (lib=['ssl', 'crypto'],
+                                                     header_name='openssl/crypto.h',
+                                                     define_name='HAVE_%s' % var,
+                                                     uselib_store=var,
+                                                     mandatory = mandatory,
+                                                     execute = True, fragment = CODE, define_ret = True)
+
+        if not testApp:
+                return
+
+        self.start_msg ('Checking if selected openssl matches NDNx')
+
+        ndn_var = kw.get('ndn_var', "NDNX")
+        if Utils.unversioned_sys_platform () == "darwin":
+                def otool (binary):
+                        p = Utils.subprocess.Popen (['/usr/bin/otool', '-L', binary], 
+                                                    stdout = Utils.subprocess.PIPE, )
+                        for line in p.communicate()[0].split ('\n'):
+                                if re.match ('.*/libcrypto\..*', line):
+                                        return line
+
+                selected_crypto = otool (testApp)
+                ccnd_crypto = otool ('%s/bin/ccnd' % self.env['%s_ROOT' % ndn_var])
+
+                if ccnd_crypto != selected_crypto:
+                        self.fatal ("Selected openssl does not match used to compile NDNx (%s != %s)" % 
+                                    (selected_crypto.strip (), ccnd_crypto.strip ()))
+                self.end_msg (True)
+
+        elif Utils.unversioned_sys_platform () == "linux" or  Utils.unversioned_sys_platform () == "freebsd":
+                def ldd (binary):
+                        p = Utils.subprocess.Popen (['/usr/bin/ldd', binary], 
+                                                        stdout = Utils.subprocess.PIPE, )
+                        for line in p.communicate()[0].split ('\n'):
+                                if re.match ('libcrypto\..*', line):
+                                        return line
+
+                selected_crypto = ldd (testApp)
+                ccnd_crypto = ldd ('%s/bin/ccnd' % self.env['%s_ROOT' % ndn_var])
+
+                if ccnd_crypto != selected_crypto:
+                        self.fatal ("Selected openssl does not match used to compile NDNx (%s != %s)" % 
+                                    (selected_crypto.strip (), ccnd_crypto.strip ()))
+                self.end_msg (True)
+        else:
+                self.end_msg ("Don't know how to check", 'YELLOW')
+
+@conf
+def check_ndnx(self,*k,**kw):
+	if not self.env['CC']:
+		self.fatal('load a c compiler first, conf.load("compiler_c")')
+
+	var=kw.get('uselib_store', 'NDNX')
+	self.start_msg('Checking for NDNx')
+	root = self.ndnx_get_root(*k,**kw);
+	self.env.NDNX_VERSION=self.ndnx_get_version(root)
+
+	self.env['INCLUDES_%s' % var]= '%s/%s' % (root, "include");
+	self.env['LIB_%s' % var] = "ccn"
+	self.env['LIBPATH_%s' % var] = '%s/%s' % (root, "lib")
+
+        self.env['%s_ROOT' % var] = root
+
+	self.end_msg("%s in %s " % (self.env.NDNX_VERSION, root))
+	if Logs.verbose:
+		Logs.pprint('CYAN','	NDNx include : %s'%self.env['INCLUDES_%s' % var])
+		Logs.pprint('CYAN','	NDNx lib     : %s'%self.env['LIB_%s' % var])
+		Logs.pprint('CYAN','	NDNx libpath : %s'%self.env['LIBPATH_%s' % var])
+
+def options(opt):
+        """
+        NDNx options
+        """
+        ndnopt = opt.add_option_group("NDNx Options")
+	ndnopt.add_option('--ndnx',type='string',default=None,dest='ndnx_dir',help='''path to where NDNx is installed, e.g. /usr/local''')
+        ndnopt.add_option('--openssl',type='string',default='',dest='openssl',help='''path to openssl, should be the same NDNx is compiled against''')
diff --git a/waf-tools/ns3.py b/waf-tools/ns3.py
deleted file mode 100644
index 8a1f33f..0000000
--- a/waf-tools/ns3.py
+++ /dev/null
@@ -1,71 +0,0 @@
-## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-
-import waflib
-from waflib.Configure import conf
-from waflib import Utils,Logs,Errors
-
-@conf
-def _print_optional_features(conf):
-    # Write a summary of optional features status
-    print "---- Summary of optional NS-3 features:"
-    Logs.pprint ('RED', "---- Summary of optional NS-3 features:")
-    # for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']:
-    #     if was_enabled:
-    #         status = 'enabled'
-    #     else:
-    #         status = 'not enabled (%s)' % reason_not_enabled
-    #     print "%-30s: %s" % (caption, status)
-
-@conf
-def _check_dependencies(conf, required, mandatory):
-    # Logs.pprint ('CYAN', '  + %s' % required)
-    found = []
-    
-    libversion = "optimized"
-    if conf.options.ns3_debug:
-        libversion = "debug"
-    
-    for module in required:
-        retval = conf.check_cfg(package = 'libns3-dev-%s-%s' % (module, libversion),
-                                args='--cflags --libs', mandatory=mandatory,
-                                msg="Checking for ns3-%s" % module,
-                                uselib_store='NS3_%s' % module.upper())
-        # Logs.pprint ('CYAN', 'NS3_%s' % module.upper())
-        if not retval is None:
-            found.append(module)
-    import copy
-    if not 'NS3_MODULES_FOUND' in conf.env:
-        conf.env['NS3_MODULES_FOUND'] = []
-    conf.env['NS3_MODULES_FOUND'] = conf.env['NS3_MODULES_FOUND'] + copy.copy(found)
-
-def modules_uselib(bld, names):
-    return ['NS3_%s' % name.upper() for name in names] + \
-        ['NS3_LIBRARY_%s' % name.upper() for name in names] + \
-        ['NS3_HEADERS_%s' % name.upper() for name in names]
-
-def modules_found(bld, needed):
-    for module in needed:
-        if not module in bld.env['NS3_MODULES_FOUND']:
-            return False
-    return True
-
-@conf
-def check_modules(conf, modules, mandatory = True):
-    import os
-
-    if not 'NS3_CHECK_MODULE_ONCE' in conf.env:
-        conf.env['NS3_CHECK_MODULE_ONCE'] = ''
-
-        conf.check_cfg(atleast_pkgconfig_version='0.0.0')
-
-        if conf.options.log4cxx:
-            conf.env.append_value('DEFINES', 'NS3_LOG_ENABLE')
-
-    conf._check_dependencies(modules, mandatory)
-    conf._print_optional_features
-
-@conf
-def print_ns3_feature_summary(conf):
-    Logs.pprint ('CYAN', "---- Summary of optional NS-3 features:")
-    conf._print_optional_features
-
diff --git a/waf-tools/protobuf.py b/waf-tools/protobuf.py
deleted file mode 100644
index 684a945..0000000
--- a/waf-tools/protobuf.py
+++ /dev/null
@@ -1,72 +0,0 @@
-# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
-
-#! /usr/bin/env python
-# encoding: utf-8
-
-'''
-
-When using this tool, the wscript will look like:
-
-def options(opt):
-   opt.tool_options("protobuf", tooldir=["waf-tools"])
-
-def configure(conf):
-   conf.load("compiler_cxx protobuf")
-
-def build(bld):
-   bld(source="main.cpp", target="app", use="PROTOBUF")
-
-Options are generated, in order to specify the location of protobuf includes/libraries.
-
-'''
-
-from waflib import Utils, TaskGen, Task, Logs
-
-from waflib import Utils,Logs,Errors
-from waflib.Configure import conf
-
-def options(opt):
-    pass
-
-def configure(conf):
-    """
-    """
-    conf.check_cfg(package='protobuf', args=['--cflags', '--libs'], uselib_store='PROTOBUF', mandatory=True)
-
-    conf.find_program ('protoc', var='PROTOC', path_list = conf.env['PATH'], mandatory = True)
-
-@TaskGen.extension('.proto')
-def add_proto(self, node):
-    """
-    Compile PROTOBUF protocol specifications
-    """
-    prototask = self.create_task ("protobuf", node, node.change_ext (".pb"))
-    try:
-        self.compiled_tasks.append (prototask)
-    except AttributeError:
-        self.compiled_tasks = [prototask]
-
-class protobuf(Task.Task):
-    """
-    Task for compiling PROTOBUF protocol specifications
-    """
-    run_str = '${PROTOC} --cpp_out ${TGT[0].parent.abspath()} --proto_path ${SRC[0].parent.abspath()} ${SRC[0].abspath()} -o${TGT[0].abspath()}'
-    color   = 'BLUE'
-
-@TaskGen.feature('cxxshlib')
-@TaskGen.before_method('process_source')
-def dynamic_post(self):
-    if not getattr(self, 'dynamic_source', None):
-        return
-    self.source = Utils.to_list(self.source)
-
-    src = self.bld.path.get_bld().ant_glob (Utils.to_list(self.dynamic_source))
-
-    for cc in src:
-        # Signature for the source
-        cc.sig = Utils.h_file (cc.abspath())
-        # Signature for the header
-        h = cc.change_ext (".h")
-        h.sig = Utils.h_file (h.abspath())
-
-    self.source.extend (src)