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