Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
| 3 | from waflib import Context, Logs, Utils |
| 4 | import os, subprocess |
| 5 | |
| 6 | VERSION = '0.1.0' |
| 7 | APPNAME = 'ndn-nac' |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 8 | PACKAGE_BUGREPORT = 'https://redmine.named-data.net/projects/nac' |
| 9 | GIT_TAG_PREFIX = 'nac-' |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 10 | |
| 11 | def options(opt): |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 12 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 13 | opt.load(['default-compiler-flags', 'boost', |
| 14 | 'coverage', 'sanitizers', |
| 15 | 'doxygen', 'sphinx_build'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 16 | tooldir=['.waf-tools']) |
| 17 | |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 18 | opt = opt.add_option_group('NDN-NAC Options') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 19 | |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 20 | opt.add_option('--with-tests', action='store_true', default=False, |
| 21 | help='Build unit tests') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 22 | |
| 23 | def configure(conf): |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 24 | conf.load(['compiler_cxx', 'gnu_dirs', |
| 25 | 'default-compiler-flags', 'boost', |
| 26 | 'doxygen', 'sphinx_build']) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 27 | |
| 28 | conf.env['WITH_TESTS'] = conf.options.with_tests |
| 29 | |
| 30 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 31 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
| 32 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 33 | uselib_store='NDN_CXX', mandatory=True) |
| 34 | |
| 35 | USED_BOOST_LIBS = ['system', 'thread', 'log', 'log_setup'] |
Alexander Afanasyev | c993428 | 2018-07-17 18:41:36 -0400 | [diff] [blame] | 36 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 37 | if conf.env['WITH_TESTS']: |
| 38 | USED_BOOST_LIBS += ['unit_test_framework'] |
Alexander Afanasyev | c993428 | 2018-07-17 18:41:36 -0400 | [diff] [blame] | 39 | conf.define('NDN_NAC_HAVE_TESTS', 1) |
| 40 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 41 | conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, mt=True) |
| 42 | |
| 43 | conf.check_compiler_flags() |
| 44 | |
| 45 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 46 | conf.load('coverage') |
| 47 | |
| 48 | conf.load('sanitizers') |
| 49 | |
| 50 | conf.define('SYSCONFDIR', conf.env['SYSCONFDIR']) |
| 51 | |
| 52 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 53 | # before dynamic library flags. This can result in compilation failure when the |
| 54 | # system has a different version of the ChronoSync library installed. |
| 55 | conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH'] |
| 56 | |
| 57 | conf.write_config_header('config.hpp') |
| 58 | |
| 59 | def build(bld): |
| 60 | version(bld) |
| 61 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 62 | bld(features='subst', |
| 63 | name='version.hpp', |
| 64 | source='src/version.hpp.in', |
| 65 | target='src/version.hpp', |
| 66 | install_path=None, |
| 67 | VERSION_STRING=VERSION_BASE, |
| 68 | VERSION_BUILD=VERSION, |
| 69 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 70 | int(VERSION_SPLIT[1]) * 1000 + |
| 71 | int(VERSION_SPLIT[2]), |
| 72 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 73 | VERSION_MINOR=VERSION_SPLIT[1], |
| 74 | VERSION_PATCH=VERSION_SPLIT[2]) |
| 75 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 76 | bld.shlib( |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 77 | target='ndn-nac', |
| 78 | name='libndn-nac', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 79 | vnum=VERSION_BASE, |
| 80 | cnum=VERSION_BASE, |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 81 | source=bld.path.ant_glob('src/**/*.cpp'), |
| 82 | use='BOOST NDN_CXX', |
| 83 | includes=['src', '.'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 84 | export_includes=['src', '.']) |
| 85 | |
Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 86 | # Unit tests |
| 87 | if bld.env['WITH_TESTS']: |
| 88 | bld.recurse('tests') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 89 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 90 | bld.recurse('tools') |
Alexander Afanasyev | c3d2990 | 2018-06-29 18:20:55 -0400 | [diff] [blame] | 91 | bld.recurse('examples') |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 92 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 93 | bld.install_files( |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 94 | dest = '%s/ndn-nac' % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 95 | files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']), |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 96 | cwd = bld.path.find_dir('src'), |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 97 | relative_trick = True) |
| 98 | |
| 99 | bld.install_files( |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 100 | dest = '%s/ndn-nac' % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 101 | files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']), |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 102 | cwd = bld.path.get_bld().find_dir('src'), |
| 103 | relative_trick = False) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 104 | |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 105 | bld(features='subst', |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 106 | source='libndn-nac.pc.in', |
| 107 | target='libndn-nac.pc', |
| 108 | install_path = '${LIBDIR}/pkgconfig', |
| 109 | PREFIX = bld.env['PREFIX'], |
Davide Pesavento | 8f9d062 | 2018-11-27 01:23:37 -0500 | [diff] [blame] | 110 | INCLUDEDIR = '%s/ndn-nac' % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 111 | VERSION = VERSION) |
| 112 | |
| 113 | def docs(bld): |
| 114 | from waflib import Options |
| 115 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 116 | |
| 117 | def doxygen(bld): |
| 118 | version(bld) |
| 119 | |
| 120 | if not bld.env.DOXYGEN: |
| 121 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 122 | |
| 123 | bld(features='subst', |
| 124 | name='doxygen.conf', |
| 125 | source=['docs/doxygen.conf.in', |
| 126 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 127 | target=['docs/doxygen.conf', |
| 128 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 129 | VERSION=VERSION, |
| 130 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 131 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 132 | else '../docs/named_data_theme/named_data_footer.html', |
| 133 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 134 | |
| 135 | bld(features='doxygen', |
| 136 | doxyfile='docs/doxygen.conf', |
| 137 | use='doxygen.conf') |
| 138 | |
| 139 | def sphinx(bld): |
| 140 | version(bld) |
| 141 | |
| 142 | if not bld.env.SPHINX_BUILD: |
| 143 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 144 | |
| 145 | bld(features='sphinx', |
| 146 | config='docs/conf.py', |
| 147 | outdir='docs', |
| 148 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 149 | VERSION=VERSION) |
| 150 | |
| 151 | def version(ctx): |
| 152 | # don't execute more than once |
| 153 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 154 | return |
| 155 | |
| 156 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 157 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 158 | |
| 159 | # first, try to get a version string from git |
| 160 | gotVersionFromGit = False |
| 161 | try: |
| 162 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 163 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 164 | if out: |
| 165 | gotVersionFromGit = True |
| 166 | if out.startswith(GIT_TAG_PREFIX): |
| 167 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
| 168 | else: |
| 169 | # no tags matched |
| 170 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
| 171 | except (OSError, subprocess.CalledProcessError): |
| 172 | pass |
| 173 | |
| 174 | versionFile = ctx.path.find_node('VERSION') |
| 175 | if not gotVersionFromGit and versionFile is not None: |
| 176 | try: |
| 177 | Context.g_module.VERSION = versionFile.read() |
| 178 | return |
| 179 | except EnvironmentError: |
| 180 | pass |
| 181 | |
| 182 | # version was obtained from git, update VERSION file if necessary |
| 183 | if versionFile is not None: |
| 184 | try: |
| 185 | if versionFile.read() == Context.g_module.VERSION: |
| 186 | # already up-to-date |
| 187 | return |
| 188 | except EnvironmentError as e: |
| 189 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
| 190 | else: |
| 191 | versionFile = ctx.path.make_node('VERSION') |
| 192 | |
| 193 | try: |
| 194 | versionFile.write(Context.g_module.VERSION) |
| 195 | except EnvironmentError as e: |
| 196 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 197 | |
| 198 | def dist(ctx): |
| 199 | version(ctx) |
| 200 | |
| 201 | def distcheck(ctx): |
| 202 | version(ctx) |