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 | |
| 3 | VERSION='0.1.0' |
| 4 | APPNAME="ndns" |
| 5 | BUGREPORT = "http://redmine.named-data.net/projects/ndns" |
| 6 | URL = "http://named-data.net/doc/ndns/" |
| 7 | GIT_TAG_PREFIX = "ndns-" |
| 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 | |
Alexander Afanasyev | 6ba3ae0 | 2015-03-30 10:55:15 -0700 | [diff] [blame] | 25 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 26 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Alexander Afanasyev | 83b7c2f | 2015-01-23 13:08:34 -0800 | [diff] [blame] | 27 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 28 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 29 | uselib_store='NDN_CXX', mandatory=True) |
| 30 | |
| 31 | conf.check_sqlite3(mandatory=True) |
| 32 | |
| 33 | if conf.options.with_tests: |
| 34 | conf.env['WITH_TESTS'] = True |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 35 | conf.define('NDNS_HAVE_TESTS', 1) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 37 | USED_BOOST_LIBS = ['system', 'filesystem', 'thread', 'log', 'log_setup'] |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 38 | if conf.env['WITH_TESTS']: |
| 39 | USED_BOOST_LIBS += ['unit_test_framework'] |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 40 | conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, 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') |
| 46 | |
| 47 | conf.load('sanitizers') |
| 48 | |
| 49 | conf.define('DEFAULT_CONFIG_PATH', '%s/ndns' % conf.env['SYSCONFDIR']) |
| 50 | conf.define('DEFAULT_DATABASE_PATH', '%s/ndns' % conf.env['LOCALSTATEDIR']) |
Shock Jiang | 3c72318 | 2014-09-10 16:41:18 -0700 | [diff] [blame] | 51 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 52 | conf.write_config_header('src/config.hpp') |
| 53 | |
| 54 | def build (bld): |
| 55 | version(bld) |
| 56 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 57 | bld(features='subst', |
| 58 | name='version.hpp', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 59 | source='src/version.hpp.in', |
| 60 | target='src/version.hpp', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 61 | VERSION_STRING=VERSION_BASE, |
| 62 | VERSION_BUILD=VERSION, |
| 63 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 64 | int(VERSION_SPLIT[1]) * 1000 + |
| 65 | int(VERSION_SPLIT[2]), |
| 66 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 67 | VERSION_MINOR=VERSION_SPLIT[1], |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 68 | VERSION_PATCH=VERSION_SPLIT[2]) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 69 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 70 | bld.objects( |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 71 | name='ndns-objects', |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame^] | 72 | source=bld.path.ant_glob('src/**/*.cpp'), |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 73 | use='version NDN_CXX BOOST', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 74 | includes='src', |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 75 | export_includes='src') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 76 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 77 | bld.recurse('tests') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 78 | bld.recurse('tools') |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 79 | |
| 80 | bld(features='subst', |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame^] | 81 | name='conf-samples', |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 82 | source=['validator.conf.sample.in', 'ndns.conf.sample.in'], |
| 83 | target=['validator.conf.sample', 'ndns.conf.sample'], |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 84 | install_path='${SYSCONFDIR}/ndns', |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 85 | ANCHORPATH='anchors/root.cert', |
| 86 | RELATION='is-prefix-of', |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 87 | DEFAULT_CONFIG_PATH='%s/ndns' % bld.env['SYSCONFDIR'], |
Davide Pesavento | 5704fdf | 2019-01-20 16:23:11 -0500 | [diff] [blame^] | 88 | DEFAULT_DATABASE_PATH='%s/ndns' % bld.env['LOCALSTATEDIR']) |
| 89 | |
| 90 | if Utils.unversioned_sys_platform() == 'linux': |
| 91 | bld(features='subst', |
| 92 | name='ndns.service', |
| 93 | source='systemd/ndns.service.in', |
| 94 | target='systemd/ndns.service') |
| 95 | |
| 96 | if bld.env.SPHINX_BUILD: |
| 97 | bld(features='sphinx', |
| 98 | name='manpages', |
| 99 | builder='man', |
| 100 | config='docs/conf.py', |
| 101 | outdir='docs/manpages', |
| 102 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
| 103 | install_path='${MANDIR}', |
| 104 | VERSION=VERSION) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 105 | |
| 106 | def docs(bld): |
| 107 | from waflib import Options |
| 108 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 109 | |
| 110 | def doxygen(bld): |
| 111 | version(bld) |
| 112 | |
| 113 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 114 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 115 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 116 | bld(features='subst', |
| 117 | name='doxygen.conf', |
| 118 | source=['docs/doxygen.conf.in', |
| 119 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 120 | target=['docs/doxygen.conf', |
| 121 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 122 | VERSION=VERSION, |
| 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'), |
| 142 | VERSION=VERSION) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 143 | |
| 144 | def version(ctx): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 145 | # don't execute more than once |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 146 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 147 | return |
| 148 | |
| 149 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 150 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 151 | |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 152 | # first, try to get a version string from git |
| 153 | gotVersionFromGit = False |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 154 | try: |
| 155 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 156 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 157 | if out: |
| 158 | gotVersionFromGit = True |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 159 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 160 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 161 | else: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 162 | # no tags matched |
| 163 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 9003483 | 2018-05-30 10:10:31 -0400 | [diff] [blame] | 164 | except (OSError, subprocess.CalledProcessError): |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 165 | pass |
| 166 | |
| 167 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 168 | if not gotVersionFromGit and versionFile is not None: |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 169 | try: |
| 170 | Context.g_module.VERSION = versionFile.read() |
| 171 | return |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 172 | except EnvironmentError: |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 173 | pass |
| 174 | |
| 175 | # version was obtained from git, update VERSION file if necessary |
| 176 | if versionFile is not None: |
| 177 | try: |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 178 | if versionFile.read() == Context.g_module.VERSION: |
| 179 | # already up-to-date |
| 180 | return |
| 181 | except EnvironmentError as e: |
| 182 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 183 | else: |
| 184 | versionFile = ctx.path.make_node('VERSION') |
| 185 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 186 | try: |
| 187 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 08d1874 | 2018-03-15 16:31:28 -0400 | [diff] [blame] | 188 | except EnvironmentError as e: |
| 189 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 190 | |
| 191 | def dist(ctx): |
| 192 | version(ctx) |
| 193 | |
| 194 | def distcheck(ctx): |
| 195 | version(ctx) |