Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 3 | from waflib import Context, Logs, Utils |
| 4 | import os, subprocess |
| 5 | |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 6 | VERSION = '0.1.0' |
| 7 | APPNAME = 'ndns' |
| 8 | BUGREPORT = 'https://redmine.named-data.net/projects/ndns' |
| 9 | URL = 'http://named-data.net/doc/ndns/' |
| 10 | GIT_TAG_PREFIX = 'ndns-' |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 11 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 12 | def options(opt): |
| 13 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 14 | opt.load(['default-compiler-flags', |
| 15 | 'coverage', 'sanitizers', 'boost', 'sqlite3', |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 16 | 'doxygen', 'sphinx_build'], |
| 17 | tooldir=['.waf-tools']) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 18 | |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 19 | optgrp = opt.add_option_group('NDNS Options') |
| 20 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 21 | help='Build unit tests') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 22 | |
| 23 | def configure(conf): |
| 24 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 25 | 'default-compiler-flags', 'boost', 'sqlite3', |
| 26 | 'doxygen', 'sphinx_build']) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 27 | |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 28 | conf.env.WITH_TESTS = conf.options.with_tests |
| 29 | |
| 30 | conf.find_program('dot', var='DOT', mandatory=False) |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 31 | |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 32 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', |
| 33 | pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR)) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 34 | |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 35 | conf.check_sqlite3() |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 36 | |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 37 | boost_libs = ['system', 'program_options', 'filesystem', 'thread', 'log'] |
| 38 | if conf.env.WITH_TESTS: |
| 39 | boost_libs.append('unit_test_framework') |
| 40 | conf.check_boost(lib=boost_libs, mt=True) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 41 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 42 | conf.check_compiler_flags() |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 43 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 44 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 45 | conf.load('coverage') |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 46 | conf.load('sanitizers') |
| 47 | |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 48 | conf.define_cond('HAVE_TESTS', conf.env.WITH_TESTS) |
| 49 | conf.define('CONFDIR', '%s/ndn/ndns' % conf.env.SYSCONFDIR) |
| 50 | conf.define('DEFAULT_DBFILE', '%s/lib/ndn/ndns/ndns.db' % conf.env.LOCALSTATEDIR) |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 51 | conf.write_config_header('src/config.hpp', define_prefix='NDNS_') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 52 | |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 53 | def build(bld): |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 54 | version(bld) |
| 55 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 56 | bld(features='subst', |
| 57 | name='version.hpp', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 58 | source='src/version.hpp.in', |
| 59 | target='src/version.hpp', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 60 | VERSION_STRING=VERSION_BASE, |
| 61 | VERSION_BUILD=VERSION, |
| 62 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 63 | int(VERSION_SPLIT[1]) * 1000 + |
| 64 | int(VERSION_SPLIT[2]), |
| 65 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 66 | VERSION_MINOR=VERSION_SPLIT[1], |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 67 | VERSION_PATCH=VERSION_SPLIT[2]) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 68 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 69 | bld.objects( |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 70 | name='ndns-objects', |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 71 | source=bld.path.ant_glob('src/**/*.cpp'), |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 72 | use='version NDN_CXX BOOST', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 73 | includes='src', |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 74 | export_includes='src') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 75 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 76 | bld.recurse('tools') |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 77 | bld.recurse('tests') |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 78 | |
| 79 | bld(features='subst', |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 80 | name='conf-samples', |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 81 | source=['validator.conf.sample.in', 'ndns.conf.sample.in'], |
| 82 | target=['validator.conf.sample', 'ndns.conf.sample'], |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 83 | install_path='${SYSCONFDIR}/ndn/ndns', |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 84 | ANCHORPATH='anchors/root.cert', |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 85 | CONFDIR='%s/ndn/ndns' % bld.env.SYSCONFDIR, |
| 86 | DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env.LOCALSTATEDIR) |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 87 | |
| 88 | if Utils.unversioned_sys_platform() == 'linux': |
| 89 | bld(features='subst', |
| 90 | name='ndns.service', |
| 91 | source='systemd/ndns.service.in', |
| 92 | target='systemd/ndns.service') |
| 93 | |
| 94 | if bld.env.SPHINX_BUILD: |
| 95 | bld(features='sphinx', |
| 96 | name='manpages', |
| 97 | builder='man', |
| 98 | config='docs/conf.py', |
| 99 | outdir='docs/manpages', |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 100 | source=bld.path.ant_glob('docs/manpages/*.rst'), |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 101 | install_path='${MANDIR}', |
Alexander Afanasyev | 60514ec | 2020-06-03 14:18:53 -0400 | [diff] [blame] | 102 | version=VERSION_BASE, |
| 103 | release=VERSION) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 104 | |
| 105 | def docs(bld): |
| 106 | from waflib import Options |
| 107 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 108 | |
| 109 | def doxygen(bld): |
| 110 | version(bld) |
| 111 | |
| 112 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 113 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 114 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 115 | bld(features='subst', |
| 116 | name='doxygen.conf', |
| 117 | source=['docs/doxygen.conf.in', |
| 118 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 119 | target=['docs/doxygen.conf', |
| 120 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 121 | VERSION=VERSION, |
Davide Pesavento | 3d01fa3 | 2021-10-03 17:13:38 -0400 | [diff] [blame] | 122 | HAVE_DOT='YES' if bld.env.DOT else 'NO', |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 123 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 124 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 125 | else '../docs/named_data_theme/named_data_footer.html', |
| 126 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 127 | |
| 128 | bld(features='doxygen', |
| 129 | doxyfile='docs/doxygen.conf', |
| 130 | use='doxygen.conf') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 131 | |
| 132 | def sphinx(bld): |
| 133 | version(bld) |
| 134 | |
| 135 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 136 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 137 | |
| 138 | bld(features='sphinx', |
| 139 | config='docs/conf.py', |
| 140 | outdir='docs', |
| 141 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 142 | version=VERSION_BASE, |
| 143 | release=VERSION) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 144 | |
| 145 | def version(ctx): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 146 | # don't execute more than once |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 147 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 148 | return |
| 149 | |
| 150 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 151 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 152 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 153 | # first, try to get a version string from git |
| 154 | gotVersionFromGit = False |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 155 | try: |
| 156 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 157 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 158 | if out: |
| 159 | gotVersionFromGit = True |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 160 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 161 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 162 | else: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 163 | # no tags matched |
| 164 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 9003483 | 2018-05-30 10:10:31 -0400 | [diff] [blame] | 165 | except (OSError, subprocess.CalledProcessError): |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 166 | pass |
| 167 | |
Alexander Afanasyev | 2b1b5da | 2020-06-01 19:18:19 -0400 | [diff] [blame] | 168 | versionFile = ctx.path.find_node('VERSION.info') |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 169 | if not gotVersionFromGit and versionFile is not None: |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 170 | try: |
| 171 | Context.g_module.VERSION = versionFile.read() |
| 172 | return |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 173 | except EnvironmentError: |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 174 | pass |
| 175 | |
| 176 | # version was obtained from git, update VERSION file if necessary |
| 177 | if versionFile is not None: |
| 178 | try: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 179 | if versionFile.read() == Context.g_module.VERSION: |
| 180 | # already up-to-date |
| 181 | return |
| 182 | except EnvironmentError as e: |
| 183 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 184 | else: |
Alexander Afanasyev | 2b1b5da | 2020-06-01 19:18:19 -0400 | [diff] [blame] | 185 | versionFile = ctx.path.make_node('VERSION.info') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 186 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 187 | try: |
| 188 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 189 | except EnvironmentError as e: |
| 190 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 191 | |
| 192 | def dist(ctx): |
| 193 | version(ctx) |
| 194 | |
| 195 | def distcheck(ctx): |
| 196 | version(ctx) |