build: Allow customization of paths for libpcap, librt, and libresolv
Change-Id: Id54955f33f0df728b8fad2a22de9592ce783adf1
diff --git a/.waf-tools/dependency-checker.py b/.waf-tools/dependency-checker.py
new file mode 100644
index 0000000..5751c62
--- /dev/null
+++ b/.waf-tools/dependency-checker.py
@@ -0,0 +1,28 @@
+# encoding: utf-8
+
+from waflib import Options, Logs
+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,
+ help='Path to %s, e.g., /usr/local %s' % (name, extraHelp))
+setattr(Options.OptionsContext, "addDependencyOptions", addDependencyOptions)
+
+@conf
+def checkDependency(self, name, **kw):
+ root = kw.get('path', getattr(Options.options, 'with_%s' % name))
+ kw['msg'] = kw.get('msg', 'Checking for %s library' % name)
+ kw['uselib_store'] = kw.get('uselib_store', name.upper())
+ kw['define_name'] = kw.get('define_name', 'HAVE_%s' % kw['uselib_store'])
+ kw['mandatory'] = kw.get('mandatory', True)
+
+ if root:
+ isOk = self.check_cxx(cxxflags="-I%s/include" % root,
+ linkflags="-L%s/lib" % root,
+ **kw)
+ else:
+ isOk = self.check_cxx(**kw)
+
+ if isOk:
+ self.env[kw['define_name']] = True
diff --git a/wscript b/wscript
index 9681089..ef4eade 100644
--- a/wscript
+++ b/wscript
@@ -32,11 +32,17 @@
import os
def options(opt):
- opt.load('compiler_cxx gnu_dirs')
- opt.load('boost doxygen coverage unix-socket default-compiler-flags sphinx_build',
+ opt.load(['compiler_cxx', 'gnu_dirs'])
+ opt.load(['boost', 'unix-socket', 'dependency-checker',
+ 'default-compiler-flags', 'coverage',
+ 'doxygen', 'sphinx_build'],
tooldir=['.waf-tools'])
nfdopt = opt.add_option_group('NFD Options')
+ opt.addDependencyOptions(nfdopt, 'libpcap', '(optional)')
+ opt.addDependencyOptions(nfdopt, 'librt', '(optional)')
+ opt.addDependencyOptions(nfdopt, 'libresolv', '(optional)')
+
nfdopt.add_option('--with-c++11', action='store_true', default=False, dest='use_cxx11',
help='''Enable C++11 mode (experimental, may not work)''')
nfdopt.add_option('--with-tests', action='store_true', default=False,
@@ -77,14 +83,9 @@
conf.load('unix-socket')
- conf.check_cxx(lib='rt', uselib_store='RT',
- define_name='HAVE_RT', mandatory=False)
-
- if conf.check_cxx(lib='pcap', uselib_store='PCAP',
- define_name='HAVE_PCAP', mandatory=False):
- conf.env['HAVE_PCAP'] = True
-
- conf.check_cxx(lib='resolv', uselib_store='RESOLV', mandatory=False)
+ conf.checkDependency(name='librt', lib='rt', mandatory=False)
+ conf.checkDependency(name='libpcap', lib='pcap', mandatory=False)
+ conf.checkDependency(name='libresolv', lib='resolv', mandatory=False)
conf.load('coverage')
@@ -101,13 +102,13 @@
excl=['daemon/face/ethernet-*.cpp',
'daemon/face/unix-*.cpp',
'daemon/main.cpp']),
- use='BOOST NDN_CPP RT',
+ use='BOOST NDN_CPP LIBRT',
includes='. daemon',
)
if bld.env['HAVE_PCAP']:
nfd_objects.source += bld.path.ant_glob('daemon/face/ethernet-*.cpp')
- nfd_objects.use += ' PCAP'
+ nfd_objects.use += ' LIBPCAP'
if bld.env['HAVE_UNIX_SOCKETS']:
nfd_objects.source += bld.path.ant_glob('daemon/face/unix-*.cpp')
@@ -124,7 +125,7 @@
target='bin/%s' % (str(app.change_ext(''))),
source=['tools/%s' % (str(app))],
includes='. daemon',
- use='nfd-objects RESOLV',
+ use='nfd-objects LIBRESOLV',
)
# Unit tests