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}', |
| 99 | VERSION=VERSION) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 100 | |
| 101 | def docs(bld): |
| 102 | from waflib import Options |
| 103 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 104 | |
| 105 | def doxygen(bld): |
| 106 | version(bld) |
| 107 | |
| 108 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 109 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 110 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 111 | bld(features='subst', |
| 112 | name='doxygen.conf', |
| 113 | source=['docs/doxygen.conf.in', |
| 114 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 115 | target=['docs/doxygen.conf', |
| 116 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 117 | VERSION=VERSION, |
| 118 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 119 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 120 | else '../docs/named_data_theme/named_data_footer.html', |
| 121 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 122 | |
| 123 | bld(features='doxygen', |
| 124 | doxyfile='docs/doxygen.conf', |
| 125 | use='doxygen.conf') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 126 | |
| 127 | def sphinx(bld): |
| 128 | version(bld) |
| 129 | |
| 130 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 131 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 132 | |
| 133 | bld(features='sphinx', |
| 134 | config='docs/conf.py', |
| 135 | outdir='docs', |
| 136 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | 1af6ccd | 2019-11-09 15:20:27 -0500 | [diff] [blame] | 137 | version=VERSION_BASE, |
| 138 | release=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) |