blob: 56ee0c3274df1d6e40b006240cbcac27d5a10cab [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 Pesavento679c42a2025-03-25 20:50:03 -040015 'doxygen', 'sphinx'],
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050016 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',
Davide Pesavento679c42a2025-03-25 20:50:03 -040025 'doxygen', 'sphinx'])
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)
Davide Pesavento679c42a2025-03-25 20:50:03 -040055 conf.define('CONFDIR', f'{conf.env.SYSCONFDIR}/ndn/ndns')
56 conf.define('DEFAULT_DBFILE', f'{conf.env.LOCALSTATEDIR}/lib/ndn/ndns/ndns.db')
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
Davide Pesavento3d01fa32021-10-03 17:13:38 -040084 bld.recurse('tests')
Davide Pesavento679c42a2025-03-25 20:50:03 -040085 bld.recurse('tools')
Shock Jiang0b165f42014-10-24 09:08:09 -070086
Davide Pesavento679c42a2025-03-25 20:50:03 -040087 # Install sample configs
Shock Jiang0b165f42014-10-24 09:08:09 -070088 bld(features='subst',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050089 name='conf-samples',
Shock Jiangcde28712014-10-19 21:17:20 -070090 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
91 target=['validator.conf.sample', 'ndns.conf.sample'],
Davide Pesaventod01c1a42019-01-21 21:42:45 -050092 install_path='${SYSCONFDIR}/ndn/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070093 ANCHORPATH='anchors/root.cert',
Davide Pesavento3d01fa32021-10-03 17:13:38 -040094 CONFDIR='%s/ndn/ndns' % bld.env.SYSCONFDIR,
95 DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env.LOCALSTATEDIR)
Davide Pesavento5704fdf2019-01-20 16:23:11 -050096
97 if Utils.unversioned_sys_platform() == 'linux':
98 bld(features='subst',
Davide Pesavento9a0d2132024-02-10 16:55:04 -050099 name='systemd-units',
Davide Pesavento5704fdf2019-01-20 16:23:11 -0500100 source='systemd/ndns.service.in',
101 target='systemd/ndns.service')
102
103 if bld.env.SPHINX_BUILD:
104 bld(features='sphinx',
105 name='manpages',
106 builder='man',
107 config='docs/conf.py',
108 outdir='docs/manpages',
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400109 source=bld.path.ant_glob('docs/manpages/*.rst'),
Davide Pesavento5704fdf2019-01-20 16:23:11 -0500110 install_path='${MANDIR}',
Alexander Afanasyev60514ec2020-06-03 14:18:53 -0400111 version=VERSION_BASE,
112 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700113
114def docs(bld):
115 from waflib import Options
116 Options.commands = ['doxygen', 'sphinx'] + Options.commands
117
118def doxygen(bld):
119 version(bld)
120
121 if not bld.env.DOXYGEN:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400122 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700123
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400124 bld(features='subst',
125 name='doxygen.conf',
126 source=['docs/doxygen.conf.in',
127 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
128 target=['docs/doxygen.conf',
129 'docs/named_data_theme/named_data_footer-with-analytics.html'],
130 VERSION=VERSION,
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400131 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400132 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
133 if os.getenv('GOOGLE_ANALYTICS', None) \
134 else '../docs/named_data_theme/named_data_footer.html',
135 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
136
137 bld(features='doxygen',
138 doxyfile='docs/doxygen.conf',
139 use='doxygen.conf')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700140
141def sphinx(bld):
142 version(bld)
143
144 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400145 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
146
147 bld(features='sphinx',
148 config='docs/conf.py',
149 outdir='docs',
150 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento1af6ccd2019-11-09 15:20:27 -0500151 version=VERSION_BASE,
152 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700153
154def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400155 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700156 if getattr(Context.g_module, 'VERSION_BASE', None):
157 return
158
159 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400160 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700161
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400162 # first, try to get a version string from git
Davide Pesavento679c42a2025-03-25 20:50:03 -0400163 version_from_git = ''
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700164 try:
Davide Pesavento679c42a2025-03-25 20:50:03 -0400165 cmd = ['git', 'describe', '--abbrev=8', '--always', '--match', f'{GIT_TAG_PREFIX}*']
166 version_from_git = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
167 if version_from_git:
168 if GIT_TAG_PREFIX and version_from_git.startswith(GIT_TAG_PREFIX):
169 Context.g_module.VERSION = version_from_git[len(GIT_TAG_PREFIX):]
170 elif not GIT_TAG_PREFIX and ('.' in version_from_git or '-' in version_from_git):
171 Context.g_module.VERSION = version_from_git
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700172 else:
Davide Pesavento679c42a2025-03-25 20:50:03 -0400173 # no tags matched (or we are in a shallow clone)
174 Context.g_module.VERSION = f'{VERSION_BASE}+git.{version_from_git}'
Davide Pesavento9a0d2132024-02-10 16:55:04 -0500175 except (OSError, subprocess.SubprocessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700176 pass
177
Davide Pesavento679c42a2025-03-25 20:50:03 -0400178 # fallback to the VERSION.info file, if it exists and is not empty
179 version_from_file = ''
180 version_file = ctx.path.find_node('VERSION.info')
181 if version_file is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700182 try:
Davide Pesavento679c42a2025-03-25 20:50:03 -0400183 version_from_file = version_file.read().strip()
184 except OSError as e:
185 Logs.warn(f'{e.filename} exists but is not readable ({e.strerror})')
186 if version_from_file and not version_from_git:
187 Context.g_module.VERSION = version_from_file
188 return
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700189
Davide Pesavento679c42a2025-03-25 20:50:03 -0400190 # update VERSION.info if necessary
191 if version_from_file == Context.g_module.VERSION:
192 # already up-to-date
193 return
194 if version_file is None:
195 version_file = ctx.path.make_node('VERSION.info')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700196 try:
Davide Pesavento679c42a2025-03-25 20:50:03 -0400197 version_file.write(Context.g_module.VERSION)
198 except OSError as e:
199 Logs.warn(f'{e.filename} is not writable ({e.strerror})')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700200
201def dist(ctx):
Davide Pesavento67272972023-03-16 17:20:22 -0400202 ctx.algo = 'tar.xz'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700203 version(ctx)
204
205def distcheck(ctx):
Davide Pesavento67272972023-03-16 17:20:22 -0400206 ctx.algo = 'tar.xz'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700207 version(ctx)