blob: d0432abfd393db9ff1aecb98b136060ed46044f9 [file] [log] [blame]
Yingdi Yuce841ca2013-12-14 08:28:00 +08001#! /usr/bin/env python
2# encoding: utf-8
3
4'''
5
6When using this tool, the wscript will look like:
7
8 def options(opt):
9 opt.tool_options('ndn_cpp', tooldir=["waf-tools"])
10
11 def configure(conf):
12 conf.load('compiler_cxx ndn_cpp')
13
14 def build(bld):
15 bld(source='main.cpp', target='app', use='NDNCPP')
16
17Options are generated, in order to specify the location of ndn-cpp includes/libraries.
18
19
20'''
21
22import sys
23import re
24from waflib import Utils,Logs,Errors
25from waflib.Configure import conf
26NDNCPP_DIR=['/usr/local/ndn', '/usr', '/usr/local', '/opt/local','/sw']
27NDNCPP_VERSION_FILE='ndn-cpp-config.h'
28NDNCPP_VERSION_CODE='''
29#include <iostream>
30#include <ndn-cpp/ndn-cpp-config.h>
31int main() { std::cout << NDN_CPP_PACKAGE_VERSION; }
32'''
33
34def options(opt):
35 opt.add_option('--ndn-cpp',type='string',default='/usr/local/ndn',dest='ndn_cpp_dir',help='''path to where ndn-cpp is installed, e.g. /usr/local/ndn''')
36@conf
37def __ndncpp_get_version_file(self,dir):
38 try:
39 return self.root.find_dir(dir).find_node('%s/%s' % ('include/ndn-cpp', NDNCPP_VERSION_FILE))
40 except:
41 return None
42@conf
43def ndncpp_get_version(self,dir):
44 val=self.check_cxx(fragment=NDNCPP_VERSION_CODE,includes=['%s/%s' % (dir, 'include')], execute=True, define_ret = True, mandatory=True)
45 return val
46@conf
47def ndncpp_get_root(self,*k,**kw):
48 root=k and k[0]or kw.get('path',None)
49 # Logs.pprint ('RED', ' %s' %root)
50 if root and self.__ndncpp_get_version_file(root):
51 return root
52 for dir in NDNCPP_DIR:
53 if self.__ndncpp_get_version_file(dir):
54 return dir
55 if root:
56 self.fatal('NDNCPP not found in %s'%root)
57 else:
58 self.fatal('NDNCPP not found, please provide a --ndn-cpp argument (see help)')
59@conf
60def check_ndncpp(self,*k,**kw):
61 if not self.env['CXX']:
62 self.fatal('load a c++ compiler first, conf.load("compiler_cxx")')
63
64 var=kw.get('uselib_store','NDNCPP')
65 self.start_msg('Checking ndn-cpp')
66 root = self.ndncpp_get_root(*k,**kw)
67 self.env.NDNCPP_VERSION=self.ndncpp_get_version(root)
68
69 self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include")
70 self.env['LIB_%s'%var] = "ndn-cpp"
71 self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
72
73 self.end_msg(self.env.NDNCPP_VERSION)
74 if Logs.verbose:
75 Logs.pprint('CYAN',' NDNCPP include : %s'%self.env['INCLUDES_%s'%var])
76 Logs.pprint('CYAN',' NDNCPP lib : %s'%self.env['LIB_%s'%var])
77 Logs.pprint('CYAN',' NDNCPP libpath : %s'%self.env['LIBPATH_%s'%var])
78
79