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