blob: 728ec8aff0cf70499b149000d3301a60a155df00 [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 Pesaventod01c1a42019-01-21 21:42:45 -05003VERSION = '0.1.0'
4APPNAME = 'ndns'
5BUGREPORT = 'https://redmine.named-data.net/projects/ndns'
6URL = 'http://named-data.net/doc/ndns/'
7GIT_TAG_PREFIX = 'ndns-'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07008
9from waflib import Logs, Utils, Context
Alexander Afanasyev08d18742018-03-15 16:31:28 -040010import os, subprocess
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070011
12def options(opt):
13 opt.load(['compiler_cxx', 'gnu_dirs'])
14 opt.load(['boost', 'default-compiler-flags', 'doxygen', 'sphinx_build',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040015 'sqlite3', 'sanitizers', 'coverage'], tooldir=['.waf-tools'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070016
17 ropt = opt.add_option_group('NDNS Options')
Alexander Afanasyev08d18742018-03-15 16:31:28 -040018 ropt.add_option('--with-tests', action='store_true', default=False, help='build unit tests')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070019
20def configure(conf):
21 conf.load(['compiler_cxx', 'gnu_dirs',
22 'boost', 'default-compiler-flags', 'doxygen', 'sphinx_build',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040023 'sqlite3'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070024
Davide Pesaventod01c1a42019-01-21 21:42:45 -050025 conf.env['WITH_TESTS'] = conf.options.with_tests
26
Alexander Afanasyev6ba3ae02015-03-30 10:55:15 -070027 if 'PKG_CONFIG_PATH' not in os.environ:
28 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070029 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
30 uselib_store='NDN_CXX', mandatory=True)
31
32 conf.check_sqlite3(mandatory=True)
33
Alexander Afanasyev08d18742018-03-15 16:31:28 -040034 USED_BOOST_LIBS = ['system', 'filesystem', 'thread', 'log', 'log_setup']
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070035 if conf.env['WITH_TESTS']:
36 USED_BOOST_LIBS += ['unit_test_framework']
Alexander Afanasyev08d18742018-03-15 16:31:28 -040037 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, mt=True)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070038
Alexander Afanasyev08d18742018-03-15 16:31:28 -040039 conf.check_compiler_flags()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070040
Alexander Afanasyev08d18742018-03-15 16:31:28 -040041 # Loading "late" to prevent tests from being compiled with profiling flags
42 conf.load('coverage')
43
44 conf.load('sanitizers')
45
Davide Pesaventod01c1a42019-01-21 21:42:45 -050046 conf.define_cond('HAVE_TESTS', conf.env['WITH_TESTS'])
47 conf.define('CONFDIR', '%s/ndn/ndns' % conf.env['SYSCONFDIR'])
48 conf.define('DEFAULT_DBFILE', '%s/lib/ndn/ndns/ndns.db' % conf.env['LOCALSTATEDIR'])
49 conf.write_config_header('src/config.hpp', define_prefix='NDNS_')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070050
51def build (bld):
52 version(bld)
53
Alexander Afanasyev08d18742018-03-15 16:31:28 -040054 bld(features='subst',
55 name='version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070056 source='src/version.hpp.in',
57 target='src/version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070058 VERSION_STRING=VERSION_BASE,
59 VERSION_BUILD=VERSION,
60 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
61 int(VERSION_SPLIT[1]) * 1000 +
62 int(VERSION_SPLIT[2]),
63 VERSION_MAJOR=VERSION_SPLIT[0],
64 VERSION_MINOR=VERSION_SPLIT[1],
Alexander Afanasyev08d18742018-03-15 16:31:28 -040065 VERSION_PATCH=VERSION_SPLIT[2])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070066
Alexander Afanasyev08d18742018-03-15 16:31:28 -040067 bld.objects(
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070068 name='ndns-objects',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050069 source=bld.path.ant_glob('src/**/*.cpp'),
Alexander Afanasyev08d18742018-03-15 16:31:28 -040070 use='version NDN_CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070071 includes='src',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040072 export_includes='src')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070073
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070074 bld.recurse('tests')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070075 bld.recurse('tools')
Shock Jiang0b165f42014-10-24 09:08:09 -070076
77 bld(features='subst',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050078 name='conf-samples',
Shock Jiangcde28712014-10-19 21:17:20 -070079 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
80 target=['validator.conf.sample', 'ndns.conf.sample'],
Davide Pesaventod01c1a42019-01-21 21:42:45 -050081 install_path='${SYSCONFDIR}/ndn/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070082 ANCHORPATH='anchors/root.cert',
Davide Pesaventod01c1a42019-01-21 21:42:45 -050083 CONFDIR='%s/ndn/ndns' % bld.env['SYSCONFDIR'],
84 DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env['LOCALSTATEDIR'])
Davide Pesavento5704fdf2019-01-20 16:23:11 -050085
86 if Utils.unversioned_sys_platform() == 'linux':
87 bld(features='subst',
88 name='ndns.service',
89 source='systemd/ndns.service.in',
90 target='systemd/ndns.service')
91
92 if bld.env.SPHINX_BUILD:
93 bld(features='sphinx',
94 name='manpages',
95 builder='man',
96 config='docs/conf.py',
97 outdir='docs/manpages',
98 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
99 install_path='${MANDIR}',
100 VERSION=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700101
102def docs(bld):
103 from waflib import Options
104 Options.commands = ['doxygen', 'sphinx'] + Options.commands
105
106def doxygen(bld):
107 version(bld)
108
109 if not bld.env.DOXYGEN:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400110 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700111
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400112 bld(features='subst',
113 name='doxygen.conf',
114 source=['docs/doxygen.conf.in',
115 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
116 target=['docs/doxygen.conf',
117 'docs/named_data_theme/named_data_footer-with-analytics.html'],
118 VERSION=VERSION,
119 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
120 if os.getenv('GOOGLE_ANALYTICS', None) \
121 else '../docs/named_data_theme/named_data_footer.html',
122 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
123
124 bld(features='doxygen',
125 doxyfile='docs/doxygen.conf',
126 use='doxygen.conf')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700127
128def sphinx(bld):
129 version(bld)
130
131 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400132 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
133
134 bld(features='sphinx',
135 config='docs/conf.py',
136 outdir='docs',
137 source=bld.path.ant_glob('docs/**/*.rst'),
138 VERSION=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700139
140def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400141 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700142 if getattr(Context.g_module, 'VERSION_BASE', None):
143 return
144
145 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400146 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700147
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400148 # first, try to get a version string from git
149 gotVersionFromGit = False
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700150 try:
151 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400152 out = subprocess.check_output(cmd, universal_newlines=True).strip()
153 if out:
154 gotVersionFromGit = True
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700155 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400156 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700157 else:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400158 # no tags matched
159 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento90034832018-05-30 10:10:31 -0400160 except (OSError, subprocess.CalledProcessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700161 pass
162
163 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400164 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700165 try:
166 Context.g_module.VERSION = versionFile.read()
167 return
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400168 except EnvironmentError:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700169 pass
170
171 # version was obtained from git, update VERSION file if necessary
172 if versionFile is not None:
173 try:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400174 if versionFile.read() == Context.g_module.VERSION:
175 # already up-to-date
176 return
177 except EnvironmentError as e:
178 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700179 else:
180 versionFile = ctx.path.make_node('VERSION')
181
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700182 try:
183 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400184 except EnvironmentError as e:
185 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700186
187def dist(ctx):
188 version(ctx)
189
190def distcheck(ctx):
191 version(ctx)