blob: 5338b5f16ca8f1394247510e158fec08ce307157 [file] [log] [blame]
Alexander Afanasyev250a4c42012-03-07 13:40:18 -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('ccnx', tooldir=["waf-tools"])
10
11 def configure(conf):
12 conf.load('compiler_cxx ccnx')
13
14 def build(bld):
15 bld(source='main.cpp', target='app', use='CCNX')
16
17Options are generated, in order to specify the location of ccnx includes/libraries.
18
19
20'''
21import sys
22import re
23from waflib import Utils,Logs,Errors
24from waflib.Configure import conf
25CCNX_DIR=['/usr','/usr/local','/opt/local','/sw']
26CCNX_VERSION_FILE='ccn/ccn.h'
27CCNX_VERSION_CODE='''
28#include <iostream>
29#include <ccn/ccn.h>
30int main() { std::cout << ((CCN_API_VERSION/100000) % 100) << "." << ((CCN_API_VERSION/1000) % 100) << "." << (CCN_API_VERSION % 1000); }
31'''
32
33def options(opt):
34 opt.add_option('--ccnx',type='string',default='',dest='ccnx_dir',help='''path to where CCNx is installed, e.g. /usr/local''')
35@conf
36def __ccnx_get_version_file(self,dir):
37 # Logs.pprint ('CYAN', ' + %s/%s/%s' % (dir, 'include', CCNX_VERSION_FILE))
38 try:
39 return self.root.find_dir(dir).find_node('%s/%s' % ('include', CCNX_VERSION_FILE))
40 except:
41 return None
42@conf
43def ccnx_get_version(self,dir):
44 val=self.check_cxx(fragment=CCNX_VERSION_CODE,includes=['%s/%s' % (dir, 'include')],execute=True,define_ret = True, mandatory=True)
45 return val
46@conf
47def ccnx_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.__ccnx_get_version_file(root):
51 return root
52 for dir in CCNX_DIR:
53 if self.__ccnx_get_version_file(dir):
54 return dir
55 if root:
56 self.fatal('CCNx not found in %s'%root)
57 else:
58 self.fatal('CCNx not found, please provide a --ccnx argument (see help)')
59@conf
60def check_ccnx(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','CCNX')
65 self.start_msg('Checking CCNx')
66 root = self.ccnx_get_root(*k,**kw);
67 self.env.CCNX_VERSION=self.ccnx_get_version(root)
68
69 self.env['INCLUDES_%s'%var]= '%s/%s' % (root, "include");
70 self.env['LIB_%s'%var] = "ccn"
71 self.env['LIBPATH_%s'%var] = '%s/%s' % (root, "lib")
72
73 self.end_msg(self.env.CCNX_VERSION)
74 if Logs.verbose:
75 Logs.pprint('CYAN',' ccnx include : %s'%self.env['INCLUDES_%s'%var])
76 Logs.pprint('CYAN',' ccnx lib : %s'%self.env['LIB_%s'%var])
77 Logs.pprint('CYAN',' ccnx libpath : %s'%self.env['LIBPATH_%s'%var])