blob: 31fa6a74b0e8f8b41831a8f6bcb2f15a2642d108 [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
3VERSION='0.1.0'
4APPNAME="ndns"
5BUGREPORT = "http://redmine.named-data.net/projects/ndns"
6URL = "http://named-data.net/doc/ndns/"
7GIT_TAG_PREFIX = "ndns-"
8
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
Alexander Afanasyev6ba3ae02015-03-30 10:55:15 -070025 if 'PKG_CONFIG_PATH' not in os.environ:
26 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Alexander Afanasyev83b7c2f2015-01-23 13:08:34 -080027
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070028 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
29 uselib_store='NDN_CXX', mandatory=True)
30
31 conf.check_sqlite3(mandatory=True)
32
33 if conf.options.with_tests:
34 conf.env['WITH_TESTS'] = True
Shock Jiang0b165f42014-10-24 09:08:09 -070035 conf.define('NDNS_HAVE_TESTS', 1)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070036
Alexander Afanasyev08d18742018-03-15 16:31:28 -040037 USED_BOOST_LIBS = ['system', 'filesystem', 'thread', 'log', 'log_setup']
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070038 if conf.env['WITH_TESTS']:
39 USED_BOOST_LIBS += ['unit_test_framework']
Alexander Afanasyev08d18742018-03-15 16:31:28 -040040 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, mt=True)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070041
Alexander Afanasyev08d18742018-03-15 16:31:28 -040042 conf.check_compiler_flags()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070043
Alexander Afanasyev08d18742018-03-15 16:31:28 -040044 # Loading "late" to prevent tests from being compiled with profiling flags
45 conf.load('coverage')
46
47 conf.load('sanitizers')
48
49 conf.define('DEFAULT_CONFIG_PATH', '%s/ndns' % conf.env['SYSCONFDIR'])
50 conf.define('DEFAULT_DATABASE_PATH', '%s/ndns' % conf.env['LOCALSTATEDIR'])
Shock Jiang3c723182014-09-10 16:41:18 -070051
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070052 conf.write_config_header('src/config.hpp')
53
54def build (bld):
55 version(bld)
56
Alexander Afanasyev08d18742018-03-15 16:31:28 -040057 bld(features='subst',
58 name='version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070059 source='src/version.hpp.in',
60 target='src/version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070061 VERSION_STRING=VERSION_BASE,
62 VERSION_BUILD=VERSION,
63 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
64 int(VERSION_SPLIT[1]) * 1000 +
65 int(VERSION_SPLIT[2]),
66 VERSION_MAJOR=VERSION_SPLIT[0],
67 VERSION_MINOR=VERSION_SPLIT[1],
Alexander Afanasyev08d18742018-03-15 16:31:28 -040068 VERSION_PATCH=VERSION_SPLIT[2])
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'),
Alexander Afanasyev08d18742018-03-15 16:31:28 -040073 use='version 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('tests')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070078 bld.recurse('tools')
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'],
Shock Jiang0b165f42014-10-24 09:08:09 -070084 install_path='${SYSCONFDIR}/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070085 ANCHORPATH='anchors/root.cert',
86 RELATION='is-prefix-of',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040087 DEFAULT_CONFIG_PATH='%s/ndns' % bld.env['SYSCONFDIR'],
Davide Pesavento5704fdf2019-01-20 16:23:11 -050088 DEFAULT_DATABASE_PATH='%s/ndns' % bld.env['LOCALSTATEDIR'])
89
90 if Utils.unversioned_sys_platform() == 'linux':
91 bld(features='subst',
92 name='ndns.service',
93 source='systemd/ndns.service.in',
94 target='systemd/ndns.service')
95
96 if bld.env.SPHINX_BUILD:
97 bld(features='sphinx',
98 name='manpages',
99 builder='man',
100 config='docs/conf.py',
101 outdir='docs/manpages',
102 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
103 install_path='${MANDIR}',
104 VERSION=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,
123 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
124 if os.getenv('GOOGLE_ANALYTICS', None) \
125 else '../docs/named_data_theme/named_data_footer.html',
126 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
127
128 bld(features='doxygen',
129 doxyfile='docs/doxygen.conf',
130 use='doxygen.conf')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700131
132def sphinx(bld):
133 version(bld)
134
135 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400136 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
137
138 bld(features='sphinx',
139 config='docs/conf.py',
140 outdir='docs',
141 source=bld.path.ant_glob('docs/**/*.rst'),
142 VERSION=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700143
144def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400145 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700146 if getattr(Context.g_module, 'VERSION_BASE', None):
147 return
148
149 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400150 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700151
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400152 # first, try to get a version string from git
153 gotVersionFromGit = False
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700154 try:
155 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400156 out = subprocess.check_output(cmd, universal_newlines=True).strip()
157 if out:
158 gotVersionFromGit = True
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700159 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400160 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700161 else:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400162 # no tags matched
163 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento90034832018-05-30 10:10:31 -0400164 except (OSError, subprocess.CalledProcessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700165 pass
166
167 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400168 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700169 try:
170 Context.g_module.VERSION = versionFile.read()
171 return
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400172 except EnvironmentError:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700173 pass
174
175 # version was obtained from git, update VERSION file if necessary
176 if versionFile is not None:
177 try:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400178 if versionFile.read() == Context.g_module.VERSION:
179 # already up-to-date
180 return
181 except EnvironmentError as e:
182 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700183 else:
184 versionFile = ctx.path.make_node('VERSION')
185
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700186 try:
187 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400188 except EnvironmentError as e:
189 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700190
191def dist(ctx):
192 version(ctx)
193
194def distcheck(ctx):
195 version(ctx)