blob: 86973beb89cc98fa1ab24f044d93695d3e66cc70 [file] [log] [blame]
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Davide Pesavento9a0d2132024-02-10 16:55:04 -05003import os
4import subprocess
Davide Pesavento1af6ccd2019-11-09 15:20:27 -05005from waflib import Context, Logs, Utils
Davide Pesavento1af6ccd2019-11-09 15:20:27 -05006
Davide Pesavento98026122022-03-14 22:00:03 -04007VERSION = '0.1'
Davide Pesaventod01c1a42019-01-21 21:42:45 -05008APPNAME = 'ndns'
Davide Pesaventod01c1a42019-01-21 21:42:45 -05009GIT_TAG_PREFIX = 'ndns-'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070010
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070011def options(opt):
12 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento3d01fa32021-10-03 17:13:38 -040013 opt.load(['default-compiler-flags',
14 'coverage', 'sanitizers', 'boost', 'sqlite3',
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050015 'doxygen', 'sphinx_build'],
16 tooldir=['.waf-tools'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070017
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050018 optgrp = opt.add_option_group('NDNS Options')
19 optgrp.add_option('--with-tests', action='store_true', default=False,
20 help='Build unit tests')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070021
22def configure(conf):
23 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050024 'default-compiler-flags', 'boost', 'sqlite3',
25 'doxygen', 'sphinx_build'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070026
Davide Pesavento3d01fa32021-10-03 17:13:38 -040027 conf.env.WITH_TESTS = conf.options.with_tests
28
Davide Pesavento423553e2022-08-19 20:46:06 -040029 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 Pesaventod01c1a42019-01-21 21:42:45 -050035
Davide Pesavento98026122022-03-14 22:00:03 -040036 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento9a0d2132024-02-10 16:55:04 -050037 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento98026122022-03-14 22:00:03 -040038 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070039
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050040 conf.check_sqlite3()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070041
Davide Pesavento9a0d2132024-02-10 16:55:04 -050042 boost_libs = ['filesystem', 'program_options']
Davide Pesavento3d01fa32021-10-03 17:13:38 -040043 if conf.env.WITH_TESTS:
44 boost_libs.append('unit_test_framework')
Davide Pesavento423553e2022-08-19 20:46:06 -040045
Davide Pesavento3d01fa32021-10-03 17:13:38 -040046 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070047
Alexander Afanasyev08d18742018-03-15 16:31:28 -040048 conf.check_compiler_flags()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070049
Alexander Afanasyev08d18742018-03-15 16:31:28 -040050 # Loading "late" to prevent tests from being compiled with profiling flags
51 conf.load('coverage')
Alexander Afanasyev08d18742018-03-15 16:31:28 -040052 conf.load('sanitizers')
53
Davide Pesavento3d01fa32021-10-03 17:13:38 -040054 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 Pesaventod01c1a42019-01-21 21:42:45 -050057 conf.write_config_header('src/config.hpp', define_prefix='NDNS_')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070058
Davide Pesavento3d01fa32021-10-03 17:13:38 -040059def build(bld):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070060 version(bld)
61
Davide Pesavento98026122022-03-14 22:00:03 -040062 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 Afanasyev08d18742018-03-15 16:31:28 -040066 bld(features='subst',
67 name='version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070068 source='src/version.hpp.in',
69 target='src/version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070070 VERSION_STRING=VERSION_BASE,
71 VERSION_BUILD=VERSION,
Davide Pesavento98026122022-03-14 22:00:03 -040072 VERSION=vmajor * 1000000 + vminor * 1000 + vpatch,
73 VERSION_MAJOR=str(vmajor),
74 VERSION_MINOR=str(vminor),
75 VERSION_PATCH=str(vpatch))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070076
Alexander Afanasyev08d18742018-03-15 16:31:28 -040077 bld.objects(
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070078 name='ndns-objects',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050079 source=bld.path.ant_glob('src/**/*.cpp'),
Davide Pesavento98026122022-03-14 22:00:03 -040080 use='version.hpp NDN_CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070081 includes='src',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040082 export_includes='src')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070083
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070084 bld.recurse('tools')
Davide Pesavento3d01fa32021-10-03 17:13:38 -040085 bld.recurse('tests')
Shock Jiang0b165f42014-10-24 09:08:09 -070086
87 bld(features='subst',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050088 name='conf-samples',
Shock Jiangcde28712014-10-19 21:17:20 -070089 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
90 target=['validator.conf.sample', 'ndns.conf.sample'],
Davide Pesaventod01c1a42019-01-21 21:42:45 -050091 install_path='${SYSCONFDIR}/ndn/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070092 ANCHORPATH='anchors/root.cert',
Davide Pesavento3d01fa32021-10-03 17:13:38 -040093 CONFDIR='%s/ndn/ndns' % bld.env.SYSCONFDIR,
94 DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env.LOCALSTATEDIR)
Davide Pesavento5704fdf2019-01-20 16:23:11 -050095
96 if Utils.unversioned_sys_platform() == 'linux':
97 bld(features='subst',
Davide Pesavento9a0d2132024-02-10 16:55:04 -050098 name='systemd-units',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050099 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 Pesavento3d01fa32021-10-03 17:13:38 -0400108 source=bld.path.ant_glob('docs/manpages/*.rst'),
Davide Pesavento5704fdf2019-01-20 16:23:11 -0500109 install_path='${MANDIR}',
Alexander Afanasyev60514ec2020-06-03 14:18:53 -0400110 version=VERSION_BASE,
111 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700112
113def docs(bld):
114 from waflib import Options
115 Options.commands = ['doxygen', 'sphinx'] + Options.commands
116
117def doxygen(bld):
118 version(bld)
119
120 if not bld.env.DOXYGEN:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400121 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700122
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400123 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 Pesavento3d01fa32021-10-03 17:13:38 -0400130 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400131 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 Afanasyev4ffcff22014-09-02 15:39:20 -0700139
140def sphinx(bld):
141 version(bld)
142
143 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400144 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 Pesavento1af6ccd2019-11-09 15:20:27 -0500150 version=VERSION_BASE,
151 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700152
153def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400154 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700155 if getattr(Context.g_module, 'VERSION_BASE', None):
156 return
157
158 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400159 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700160
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400161 # first, try to get a version string from git
162 gotVersionFromGit = False
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700163 try:
Davide Pesavento9a0d2132024-02-10 16:55:04 -0500164 cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*']
165 out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400166 if out:
167 gotVersionFromGit = True
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700168 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400169 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700170 else:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400171 # no tags matched
Davide Pesavento9a0d2132024-02-10 16:55:04 -0500172 Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}'
173 except (OSError, subprocess.SubprocessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700174 pass
175
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400176 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400177 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700178 try:
179 Context.g_module.VERSION = versionFile.read()
180 return
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400181 except EnvironmentError:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700182 pass
183
184 # version was obtained from git, update VERSION file if necessary
185 if versionFile is not None:
186 try:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400187 if versionFile.read() == Context.g_module.VERSION:
188 # already up-to-date
189 return
190 except EnvironmentError as e:
Davide Pesavento9a0d2132024-02-10 16:55:04 -0500191 Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700192 else:
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400193 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700194
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700195 try:
196 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400197 except EnvironmentError as e:
Davide Pesavento9a0d2132024-02-10 16:55:04 -0500198 Logs.warn(f'{versionFile} is not writable ({e.strerror})')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700199
200def dist(ctx):
Davide Pesavento67272972023-03-16 17:20:22 -0400201 ctx.algo = 'tar.xz'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700202 version(ctx)
203
204def distcheck(ctx):
Davide Pesavento67272972023-03-16 17:20:22 -0400205 ctx.algo = 'tar.xz'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700206 version(ctx)