Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 1 | #! /usr/bin/env python |
| 2 | # encoding: utf-8 |
| 3 | |
| 4 | ''' |
| 5 | |
| 6 | When using this tool, the wscript will look like: |
| 7 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 8 | def options(opt): |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 9 | opt.load('compiler_cxx cryptopp') |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 10 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 11 | def configure(conf): |
| 12 | conf.load('compiler_cxx cryptopp') |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 13 | conf.check_cryptopp() |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 14 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 15 | def build(bld): |
| 16 | bld(source='main.cpp', target='app', use='CRYPTOPP') |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 17 | |
| 18 | Options are generated, in order to specify the location of cryptopp includes/libraries. |
| 19 | |
| 20 | |
| 21 | ''' |
| 22 | import sys |
| 23 | import re |
| 24 | from waflib import Utils,Logs,Errors |
| 25 | from waflib.Configure import conf |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 26 | CRYPTOPP_DIR = ['/usr', '/usr/local', '/opt/local', '/sw', '/usr/local/ndn', '/opt/ndn'] |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 27 | CRYPTOPP_VERSION_FILE = 'config.h' |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 28 | |
| 29 | def options(opt): |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 30 | opt.add_option('--with-cryptopp', type='string', default=None, dest='cryptopp_dir', |
| 31 | help='''Path to where CryptoPP is installed, e.g., /usr/local''') |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 32 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 33 | @conf |
| 34 | def __cryptopp_get_version_file(self, dir): |
| 35 | try: |
| 36 | return self.root.find_dir(dir).find_node('%s/%s' % ('include/cryptopp', |
| 37 | CRYPTOPP_VERSION_FILE)) |
| 38 | except: |
| 39 | return None |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 40 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 41 | @conf |
| 42 | def __cryptopp_find_root_and_version_file(self, *k, **kw): |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 43 | root = k and k[0] or kw.get('path', self.options.cryptopp_dir) |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 44 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 45 | file = self.__cryptopp_get_version_file(root) |
| 46 | if root and file: |
| 47 | return (root, file) |
| 48 | for dir in CRYPTOPP_DIR: |
| 49 | file = self.__cryptopp_get_version_file(dir) |
| 50 | if file: |
| 51 | return (dir, file) |
Alexander Afanasyev | a1ae0a1 | 2014-01-28 15:21:02 -0800 | [diff] [blame] | 52 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 53 | if root: |
| 54 | self.fatal('CryptoPP not found in %s' % root) |
| 55 | else: |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 56 | self.fatal('CryptoPP not found, please provide a --with=cryptopp=PATH argument (see help)') |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 57 | |
| 58 | @conf |
| 59 | def check_cryptopp(self, *k, **kw): |
| 60 | if not self.env['CXX']: |
| 61 | self.fatal('Load a c++ compiler first, e.g., conf.load("compiler_cxx")') |
| 62 | |
| 63 | var = kw.get('uselib_store','CRYPTOPP') |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 64 | mandatory = kw.get('mandatory', True) |
| 65 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 66 | self.start_msg('Checking Crypto++ lib') |
| 67 | (root, file) = self.__cryptopp_find_root_and_version_file(*k, **kw) |
| 68 | |
| 69 | try: |
| 70 | txt = file.read() |
| 71 | re_version = re.compile('^#define\\s+CRYPTOPP_VERSION\\s+(.*)', re.M) |
| 72 | match = re_version.search(txt) |
| 73 | |
| 74 | if match: |
| 75 | self.env.CRYPTOPP_VERSION = match.group(1) |
| 76 | self.end_msg(self.env.CRYPTOPP_VERSION) |
| 77 | else: |
| 78 | self.fatal('CryptoPP files are present, but are not recognizable') |
| 79 | except: |
| 80 | self.fatal('CryptoPP not found or is not usable') |
| 81 | |
| 82 | val = self.check_cxx(msg='Checking if CryptoPP library works', |
| 83 | header_name='cryptopp/config.h', |
| 84 | lib='cryptopp', |
| 85 | cxxflags="-I%s/include" % root, |
| 86 | linkflags="-L%s/lib" % root, |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 87 | mandatory=mandatory, |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 88 | uselib_store=var) |