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: |
Mathias Gibbens | 16f24c5 | 2014-05-06 17:12:27 -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 | |
Alexander Afanasyev | fff47d6 | 2014-05-11 19:24:46 -0700 | [diff] [blame] | 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 | fff47d6 | 2014-05-11 19:24:46 -0700 | [diff] [blame] | 66 | use = kw.get('use', 'PTHREAD') |
| 67 | |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 68 | self.start_msg('Checking Crypto++ lib') |
| 69 | (root, file) = self.__cryptopp_find_root_and_version_file(*k, **kw) |
| 70 | |
| 71 | try: |
| 72 | txt = file.read() |
| 73 | re_version = re.compile('^#define\\s+CRYPTOPP_VERSION\\s+(.*)', re.M) |
| 74 | match = re_version.search(txt) |
| 75 | |
| 76 | if match: |
| 77 | self.env.CRYPTOPP_VERSION = match.group(1) |
| 78 | self.end_msg(self.env.CRYPTOPP_VERSION) |
| 79 | else: |
| 80 | self.fatal('CryptoPP files are present, but are not recognizable') |
| 81 | except: |
| 82 | self.fatal('CryptoPP not found or is not usable') |
| 83 | |
| 84 | val = self.check_cxx(msg='Checking if CryptoPP library works', |
| 85 | header_name='cryptopp/config.h', |
| 86 | lib='cryptopp', |
Alexander Afanasyev | ae80f10 | 2014-05-12 17:20:46 -0700 | [diff] [blame] | 87 | includes="%s/include" % root, |
| 88 | libpath="%s/lib" % root, |
Alexander Afanasyev | 1160baa | 2014-04-10 18:50:29 -0700 | [diff] [blame] | 89 | mandatory=mandatory, |
Alexander Afanasyev | fff47d6 | 2014-05-11 19:24:46 -0700 | [diff] [blame] | 90 | use=use, |
Alexander Afanasyev | 5e1288e | 2014-03-28 11:11:48 -0700 | [diff] [blame] | 91 | uselib_store=var) |