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