blob: ddae7925e28349e23555e0ba431f46ffaff96756 [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 Pesavento1af6ccd2019-11-09 15:20:27 -05003from waflib import Context, Logs, Utils
4import os, subprocess
5
Davide Pesavento98026122022-03-14 22:00:03 -04006VERSION = '0.1'
Davide Pesaventod01c1a42019-01-21 21:42:45 -05007APPNAME = 'ndns'
Davide Pesaventod01c1a42019-01-21 21:42:45 -05008GIT_TAG_PREFIX = 'ndns-'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07009
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070010def options(opt):
11 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento3d01fa32021-10-03 17:13:38 -040012 opt.load(['default-compiler-flags',
13 'coverage', 'sanitizers', 'boost', 'sqlite3',
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050014 'doxygen', 'sphinx_build'],
15 tooldir=['.waf-tools'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070016
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050017 optgrp = opt.add_option_group('NDNS Options')
18 optgrp.add_option('--with-tests', action='store_true', default=False,
19 help='Build unit tests')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070020
21def configure(conf):
22 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050023 'default-compiler-flags', 'boost', 'sqlite3',
24 'doxygen', 'sphinx_build'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070025
Davide Pesavento3d01fa32021-10-03 17:13:38 -040026 conf.env.WITH_TESTS = conf.options.with_tests
27
28 conf.find_program('dot', var='DOT', mandatory=False)
Davide Pesaventod01c1a42019-01-21 21:42:45 -050029
Davide Pesavento98026122022-03-14 22:00:03 -040030 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
31 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'],
32 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070033
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050034 conf.check_sqlite3()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070035
Davide Pesavento98026122022-03-14 22:00:03 -040036 boost_libs = ['system', 'program_options', 'filesystem']
Davide Pesavento3d01fa32021-10-03 17:13:38 -040037 if conf.env.WITH_TESTS:
38 boost_libs.append('unit_test_framework')
39 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070040
Alexander Afanasyev08d18742018-03-15 16:31:28 -040041 conf.check_compiler_flags()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070042
Alexander Afanasyev08d18742018-03-15 16:31:28 -040043 # Loading "late" to prevent tests from being compiled with profiling flags
44 conf.load('coverage')
Alexander Afanasyev08d18742018-03-15 16:31:28 -040045 conf.load('sanitizers')
46
Davide Pesavento3d01fa32021-10-03 17:13:38 -040047 conf.define_cond('HAVE_TESTS', conf.env.WITH_TESTS)
48 conf.define('CONFDIR', '%s/ndn/ndns' % conf.env.SYSCONFDIR)
49 conf.define('DEFAULT_DBFILE', '%s/lib/ndn/ndns/ndns.db' % conf.env.LOCALSTATEDIR)
Davide Pesaventod01c1a42019-01-21 21:42:45 -050050 conf.write_config_header('src/config.hpp', define_prefix='NDNS_')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070051
Davide Pesavento3d01fa32021-10-03 17:13:38 -040052def build(bld):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070053 version(bld)
54
Davide Pesavento98026122022-03-14 22:00:03 -040055 vmajor = int(VERSION_SPLIT[0])
56 vminor = int(VERSION_SPLIT[1]) if len(VERSION_SPLIT) >= 2 else 0
57 vpatch = int(VERSION_SPLIT[2]) if len(VERSION_SPLIT) >= 3 else 0
58
Alexander Afanasyev08d18742018-03-15 16:31:28 -040059 bld(features='subst',
60 name='version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070061 source='src/version.hpp.in',
62 target='src/version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070063 VERSION_STRING=VERSION_BASE,
64 VERSION_BUILD=VERSION,
Davide Pesavento98026122022-03-14 22:00:03 -040065 VERSION=vmajor * 1000000 + vminor * 1000 + vpatch,
66 VERSION_MAJOR=str(vmajor),
67 VERSION_MINOR=str(vminor),
68 VERSION_PATCH=str(vpatch))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070069
Alexander Afanasyev08d18742018-03-15 16:31:28 -040070 bld.objects(
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070071 name='ndns-objects',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050072 source=bld.path.ant_glob('src/**/*.cpp'),
Davide Pesavento98026122022-03-14 22:00:03 -040073 use='version.hpp NDN_CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070074 includes='src',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040075 export_includes='src')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070076
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070077 bld.recurse('tools')
Davide Pesavento3d01fa32021-10-03 17:13:38 -040078 bld.recurse('tests')
Shock Jiang0b165f42014-10-24 09:08:09 -070079
80 bld(features='subst',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050081 name='conf-samples',
Shock Jiangcde28712014-10-19 21:17:20 -070082 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
83 target=['validator.conf.sample', 'ndns.conf.sample'],
Davide Pesaventod01c1a42019-01-21 21:42:45 -050084 install_path='${SYSCONFDIR}/ndn/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070085 ANCHORPATH='anchors/root.cert',
Davide Pesavento3d01fa32021-10-03 17:13:38 -040086 CONFDIR='%s/ndn/ndns' % bld.env.SYSCONFDIR,
87 DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env.LOCALSTATEDIR)
Davide Pesavento5704fdf2019-01-20 16:23:11 -050088
89 if Utils.unversioned_sys_platform() == 'linux':
90 bld(features='subst',
91 name='ndns.service',
92 source='systemd/ndns.service.in',
93 target='systemd/ndns.service')
94
95 if bld.env.SPHINX_BUILD:
96 bld(features='sphinx',
97 name='manpages',
98 builder='man',
99 config='docs/conf.py',
100 outdir='docs/manpages',
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400101 source=bld.path.ant_glob('docs/manpages/*.rst'),
Davide Pesavento5704fdf2019-01-20 16:23:11 -0500102 install_path='${MANDIR}',
Alexander Afanasyev60514ec2020-06-03 14:18:53 -0400103 version=VERSION_BASE,
104 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700105
106def docs(bld):
107 from waflib import Options
108 Options.commands = ['doxygen', 'sphinx'] + Options.commands
109
110def doxygen(bld):
111 version(bld)
112
113 if not bld.env.DOXYGEN:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400114 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700115
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400116 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,
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400123 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400124 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
125 if os.getenv('GOOGLE_ANALYTICS', None) \
126 else '../docs/named_data_theme/named_data_footer.html',
127 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
128
129 bld(features='doxygen',
130 doxyfile='docs/doxygen.conf',
131 use='doxygen.conf')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700132
133def sphinx(bld):
134 version(bld)
135
136 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400137 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
138
139 bld(features='sphinx',
140 config='docs/conf.py',
141 outdir='docs',
142 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento1af6ccd2019-11-09 15:20:27 -0500143 version=VERSION_BASE,
144 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700145
146def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400147 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700148 if getattr(Context.g_module, 'VERSION_BASE', None):
149 return
150
151 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400152 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700153
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400154 # first, try to get a version string from git
155 gotVersionFromGit = False
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700156 try:
157 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400158 out = subprocess.check_output(cmd, universal_newlines=True).strip()
159 if out:
160 gotVersionFromGit = True
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700161 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400162 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700163 else:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400164 # no tags matched
165 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento90034832018-05-30 10:10:31 -0400166 except (OSError, subprocess.CalledProcessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700167 pass
168
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400169 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400170 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700171 try:
172 Context.g_module.VERSION = versionFile.read()
173 return
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400174 except EnvironmentError:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700175 pass
176
177 # version was obtained from git, update VERSION file if necessary
178 if versionFile is not None:
179 try:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400180 if versionFile.read() == Context.g_module.VERSION:
181 # already up-to-date
182 return
183 except EnvironmentError as e:
184 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700185 else:
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400186 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700187
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700188 try:
189 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400190 except EnvironmentError as e:
191 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700192
193def dist(ctx):
194 version(ctx)
195
196def distcheck(ctx):
197 version(ctx)