Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 3 | from waflib import Context, Logs, Utils |
| 4 | import os, subprocess |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 5 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 6 | VERSION = '0.1.0' |
| 7 | APPNAME = 'ndn-nac' |
| 8 | PACKAGE_BUGREPORT = "http://redmine.named-data.net/projects/nac" |
| 9 | GIT_TAG_PREFIX = "ndn-nac-" |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 10 | |
| 11 | def options(opt): |
| 12 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 13 | opt.load(['boost', 'default-compiler-flags', 'sanitizers', 'coverage', 'doxygen'], |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 14 | tooldir=['.waf-tools']) |
| 15 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 16 | opt = opt.add_option_group ("NDN-NAC Options") |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 17 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 18 | opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests', |
| 19 | help='''Build unit tests''') |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 20 | |
| 21 | def configure(conf): |
Alexander Afanasyev | 867228e | 2016-10-17 16:54:55 -0700 | [diff] [blame] | 22 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'boost', 'default-compiler-flags', 'sanitizers', 'doxygen']) |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 24 | conf.env['WITH_TESTS'] = conf.options.with_tests |
| 25 | |
Yingdi Yu | da495a9 | 2015-05-05 13:57:59 -0700 | [diff] [blame] | 26 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 27 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 28 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 29 | uselib_store='NDN_CXX', mandatory=True) |
| 30 | |
| 31 | boost_libs = 'system iostreams' |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 32 | if conf.env['WITH_TESTS']: |
| 33 | conf.define('NDN_NAC_HAVE_TESTS', 1); |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 34 | boost_libs += ' unit_test_framework' |
| 35 | |
| 36 | conf.check_boost(lib=boost_libs) |
| 37 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 38 | conf.check_compiler_flags() |
| 39 | |
| 40 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 41 | conf.load('coverage') |
| 42 | |
| 43 | conf.load('sanitizers') |
| 44 | |
| 45 | conf.define('SYSCONFDIR', conf.env['SYSCONFDIR']) |
| 46 | |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 47 | conf.write_config_header('config.hpp') |
| 48 | |
| 49 | def build(bld): |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 50 | version(bld) |
| 51 | |
| 52 | bld.shlib( |
| 53 | target="libndn-nac", |
| 54 | vnum=VERSION_BASE, |
| 55 | cnum=VERSION_BASE, |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 56 | source = bld.path.ant_glob(['src/**/*.cpp']), |
Zhiyi Zhang | 19a11d2 | 2018-04-12 22:58:20 -0700 | [diff] [blame] | 57 | use = 'BOOST NDN_CXX CRYPTOPP', |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 58 | includes = ['src', '.'], |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 59 | export_includes=['src', '.']) |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 60 | |
| 61 | # Unit tests |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 62 | if bld.env['WITH_TESTS']: |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 63 | bld.recurse('tests') |
| 64 | |
| 65 | bld.install_files( |
| 66 | dest = "%s/ndn-group-encrypt" % bld.env['INCLUDEDIR'], |
Yingdi Yu | 0a6663a | 2016-03-20 18:55:46 -0700 | [diff] [blame] | 67 | files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']), |
| 68 | cwd = bld.path.find_dir("src"), |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 69 | relative_trick = True) |
Yingdi Yu | 0a6663a | 2016-03-20 18:55:46 -0700 | [diff] [blame] | 70 | |
| 71 | bld.install_files( |
| 72 | dest = "%s/ndn-group-encrypt" % bld.env['INCLUDEDIR'], |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 73 | files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']), |
| 74 | cwd = bld.path.get_bld().find_dir("src"), |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 75 | relative_trick = False ) |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 76 | |
Yingdi Yu | da495a9 | 2015-05-05 13:57:59 -0700 | [diff] [blame] | 77 | bld(features = "subst", |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 78 | source='libndn-nac.pc.in', |
| 79 | target='libndn-nac.pc', |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 80 | install_path = '${LIBDIR}/pkgconfig', |
| 81 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 82 | INCLUDEDIR = "%s/ndn-nac" % bld.env['INCLUDEDIR'], |
| 83 | VERSION = VERSION) |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 84 | |
| 85 | def docs(bld): |
| 86 | from waflib import Options |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 87 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 88 | |
| 89 | def doxygen(bld): |
| 90 | version(bld) |
| 91 | |
| 92 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 93 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 94 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 95 | bld(features='subst', |
| 96 | name='doxygen.conf', |
| 97 | source=['docs/doxygen.conf.in', |
| 98 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 99 | target=['docs/doxygen.conf', |
| 100 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 101 | VERSION=VERSION, |
| 102 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 103 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 104 | else '../docs/named_data_theme/named_data_footer.html', |
| 105 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 106 | |
| 107 | bld(features='doxygen', |
| 108 | doxyfile='docs/doxygen.conf', |
| 109 | use='doxygen.conf') |
| 110 | |
| 111 | def sphinx(bld): |
| 112 | version(bld) |
| 113 | |
| 114 | if not bld.env.SPHINX_BUILD: |
| 115 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 116 | |
| 117 | bld(features='sphinx', |
| 118 | config='docs/conf.py', |
| 119 | outdir='docs', |
| 120 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 121 | VERSION=VERSION) |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 122 | |
| 123 | def version(ctx): |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 124 | # don't execute more than once |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 125 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 126 | return |
| 127 | |
| 128 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 129 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 130 | |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 131 | # first, try to get a version string from git |
| 132 | gotVersionFromGit = False |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 133 | try: |
| 134 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 135 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 136 | if out: |
| 137 | gotVersionFromGit = True |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 138 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 139 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 140 | else: |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 141 | # no tags matched |
| 142 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
| 143 | except subprocess.CalledProcessError: |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 144 | pass |
| 145 | |
| 146 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 147 | if not gotVersionFromGit and versionFile is not None: |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 148 | try: |
| 149 | Context.g_module.VERSION = versionFile.read() |
| 150 | return |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 151 | except EnvironmentError: |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 152 | pass |
| 153 | |
| 154 | # version was obtained from git, update VERSION file if necessary |
| 155 | if versionFile is not None: |
| 156 | try: |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 157 | if versionFile.read() == Context.g_module.VERSION: |
| 158 | # already up-to-date |
| 159 | return |
| 160 | except EnvironmentError as e: |
| 161 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 162 | else: |
| 163 | versionFile = ctx.path.make_node('VERSION') |
| 164 | |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 165 | try: |
| 166 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 9091d83 | 2018-04-18 17:21:08 -0400 | [diff] [blame^] | 167 | except EnvironmentError as e: |
| 168 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 169 | |
| 170 | def dist(ctx): |
| 171 | version(ctx) |
| 172 | |
| 173 | def distcheck(ctx): |
| 174 | version(ctx) |