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 | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 3 | VERSION = '0.1.0' |
| 4 | APPNAME = 'ndns' |
| 5 | BUGREPORT = 'https://redmine.named-data.net/projects/ndns' |
| 6 | URL = 'http://named-data.net/doc/ndns/' |
| 7 | GIT_TAG_PREFIX = 'ndns-' |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 8 | |
| 9 | from waflib import Logs, Utils, Context |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 10 | import os, subprocess |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 11 | |
| 12 | def options(opt): |
| 13 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 14 | opt.load(['boost', 'default-compiler-flags', 'doxygen', 'sphinx_build', |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 15 | 'sqlite3', 'sanitizers', 'coverage'], tooldir=['.waf-tools']) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 16 | |
| 17 | ropt = opt.add_option_group('NDNS Options') |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 18 | ropt.add_option('--with-tests', action='store_true', default=False, help='build unit tests') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 19 | |
| 20 | def configure(conf): |
| 21 | conf.load(['compiler_cxx', 'gnu_dirs', |
| 22 | 'boost', 'default-compiler-flags', 'doxygen', 'sphinx_build', |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 23 | 'sqlite3']) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 24 | |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 25 | conf.env['WITH_TESTS'] = conf.options.with_tests |
| 26 | |
Alexander Afanasyev | 6ba3ae0 | 2015-03-30 10:55:15 -0700 | [diff] [blame] | 27 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 28 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 29 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 30 | uselib_store='NDN_CXX', mandatory=True) |
| 31 | |
| 32 | conf.check_sqlite3(mandatory=True) |
| 33 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 34 | USED_BOOST_LIBS = ['system', 'filesystem', 'thread', 'log', 'log_setup'] |
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'] |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 37 | conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, 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') |
| 43 | |
| 44 | conf.load('sanitizers') |
| 45 | |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 46 | conf.define_cond('HAVE_TESTS', conf.env['WITH_TESTS']) |
| 47 | conf.define('CONFDIR', '%s/ndn/ndns' % conf.env['SYSCONFDIR']) |
| 48 | conf.define('DEFAULT_DBFILE', '%s/lib/ndn/ndns/ndns.db' % conf.env['LOCALSTATEDIR']) |
| 49 | conf.write_config_header('src/config.hpp', define_prefix='NDNS_') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 50 | |
| 51 | def build (bld): |
| 52 | version(bld) |
| 53 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 54 | bld(features='subst', |
| 55 | name='version.hpp', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 56 | source='src/version.hpp.in', |
| 57 | target='src/version.hpp', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 58 | VERSION_STRING=VERSION_BASE, |
| 59 | VERSION_BUILD=VERSION, |
| 60 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 61 | int(VERSION_SPLIT[1]) * 1000 + |
| 62 | int(VERSION_SPLIT[2]), |
| 63 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 64 | VERSION_MINOR=VERSION_SPLIT[1], |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 65 | VERSION_PATCH=VERSION_SPLIT[2]) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 66 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 67 | bld.objects( |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 68 | name='ndns-objects', |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 69 | source=bld.path.ant_glob('src/**/*.cpp'), |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 70 | use='version NDN_CXX BOOST', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 71 | includes='src', |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 72 | export_includes='src') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 73 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 74 | bld.recurse('tests') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 75 | bld.recurse('tools') |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 76 | |
| 77 | bld(features='subst', |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 78 | name='conf-samples', |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 79 | source=['validator.conf.sample.in', 'ndns.conf.sample.in'], |
| 80 | target=['validator.conf.sample', 'ndns.conf.sample'], |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 81 | install_path='${SYSCONFDIR}/ndn/ndns', |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 82 | ANCHORPATH='anchors/root.cert', |
Davide Pesavento | d01c1a4 | 2019-01-21 21:42:45 -0500 | [diff] [blame] | 83 | CONFDIR='%s/ndn/ndns' % bld.env['SYSCONFDIR'], |
| 84 | DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env['LOCALSTATEDIR']) |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame] | 85 | |
| 86 | if Utils.unversioned_sys_platform() == 'linux': |
| 87 | bld(features='subst', |
| 88 | name='ndns.service', |
| 89 | source='systemd/ndns.service.in', |
| 90 | target='systemd/ndns.service') |
| 91 | |
| 92 | if bld.env.SPHINX_BUILD: |
| 93 | bld(features='sphinx', |
| 94 | name='manpages', |
| 95 | builder='man', |
| 96 | config='docs/conf.py', |
| 97 | outdir='docs/manpages', |
| 98 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
| 99 | install_path='${MANDIR}', |
| 100 | VERSION=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'), |
| 138 | VERSION=VERSION) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 139 | |
| 140 | def version(ctx): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 141 | # don't execute more than once |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 142 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 143 | return |
| 144 | |
| 145 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 146 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 147 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 148 | # first, try to get a version string from git |
| 149 | gotVersionFromGit = False |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 150 | try: |
| 151 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 152 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 153 | if out: |
| 154 | gotVersionFromGit = True |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 155 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 156 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 157 | else: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 158 | # no tags matched |
| 159 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 9003483 | 2018-05-30 10:10:31 -0400 | [diff] [blame] | 160 | except (OSError, subprocess.CalledProcessError): |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 161 | pass |
| 162 | |
| 163 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 164 | if not gotVersionFromGit and versionFile is not None: |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 165 | try: |
| 166 | Context.g_module.VERSION = versionFile.read() |
| 167 | return |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 168 | except EnvironmentError: |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 169 | pass |
| 170 | |
| 171 | # version was obtained from git, update VERSION file if necessary |
| 172 | if versionFile is not None: |
| 173 | try: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 174 | if versionFile.read() == Context.g_module.VERSION: |
| 175 | # already up-to-date |
| 176 | return |
| 177 | except EnvironmentError as e: |
| 178 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 179 | else: |
| 180 | versionFile = ctx.path.make_node('VERSION') |
| 181 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 182 | try: |
| 183 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 184 | except EnvironmentError as e: |
| 185 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 186 | |
| 187 | def dist(ctx): |
| 188 | version(ctx) |
| 189 | |
| 190 | def distcheck(ctx): |
| 191 | version(ctx) |