blob: 7683c0691c24465612ef158f615f1ddac55c178a [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 Pesaventod01c1a42019-01-21 21:42:45 -05006VERSION = '0.1.0'
7APPNAME = 'ndns'
8BUGREPORT = 'https://redmine.named-data.net/projects/ndns'
9URL = 'http://named-data.net/doc/ndns/'
10GIT_TAG_PREFIX = 'ndns-'
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070011
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070012def options(opt):
13 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento3d01fa32021-10-03 17:13:38 -040014 opt.load(['default-compiler-flags',
15 'coverage', 'sanitizers', 'boost', 'sqlite3',
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050016 'doxygen', 'sphinx_build'],
17 tooldir=['.waf-tools'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070018
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050019 optgrp = opt.add_option_group('NDNS Options')
20 optgrp.add_option('--with-tests', action='store_true', default=False,
21 help='Build unit tests')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070022
23def configure(conf):
24 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050025 'default-compiler-flags', 'boost', 'sqlite3',
26 'doxygen', 'sphinx_build'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070027
Davide Pesavento3d01fa32021-10-03 17:13:38 -040028 conf.env.WITH_TESTS = conf.options.with_tests
29
30 conf.find_program('dot', var='DOT', mandatory=False)
Davide Pesaventod01c1a42019-01-21 21:42:45 -050031
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050032 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
33 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070034
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050035 conf.check_sqlite3()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070036
Davide Pesavento3d01fa32021-10-03 17:13:38 -040037 boost_libs = ['system', 'program_options', 'filesystem', 'thread', 'log']
38 if conf.env.WITH_TESTS:
39 boost_libs.append('unit_test_framework')
40 conf.check_boost(lib=boost_libs, 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')
Alexander Afanasyev08d18742018-03-15 16:31:28 -040046 conf.load('sanitizers')
47
Davide Pesavento3d01fa32021-10-03 17:13:38 -040048 conf.define_cond('HAVE_TESTS', conf.env.WITH_TESTS)
49 conf.define('CONFDIR', '%s/ndn/ndns' % conf.env.SYSCONFDIR)
50 conf.define('DEFAULT_DBFILE', '%s/lib/ndn/ndns/ndns.db' % conf.env.LOCALSTATEDIR)
Davide Pesaventod01c1a42019-01-21 21:42:45 -050051 conf.write_config_header('src/config.hpp', define_prefix='NDNS_')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070052
Davide Pesavento3d01fa32021-10-03 17:13:38 -040053def build(bld):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070054 version(bld)
55
Alexander Afanasyev08d18742018-03-15 16:31:28 -040056 bld(features='subst',
57 name='version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070058 source='src/version.hpp.in',
59 target='src/version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070060 VERSION_STRING=VERSION_BASE,
61 VERSION_BUILD=VERSION,
62 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
63 int(VERSION_SPLIT[1]) * 1000 +
64 int(VERSION_SPLIT[2]),
65 VERSION_MAJOR=VERSION_SPLIT[0],
66 VERSION_MINOR=VERSION_SPLIT[1],
Alexander Afanasyev08d18742018-03-15 16:31:28 -040067 VERSION_PATCH=VERSION_SPLIT[2])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070068
Alexander Afanasyev08d18742018-03-15 16:31:28 -040069 bld.objects(
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070070 name='ndns-objects',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050071 source=bld.path.ant_glob('src/**/*.cpp'),
Alexander Afanasyev08d18742018-03-15 16:31:28 -040072 use='version NDN_CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070073 includes='src',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040074 export_includes='src')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070075
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070076 bld.recurse('tools')
Davide Pesavento3d01fa32021-10-03 17:13:38 -040077 bld.recurse('tests')
Shock Jiang0b165f42014-10-24 09:08:09 -070078
79 bld(features='subst',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050080 name='conf-samples',
Shock Jiangcde28712014-10-19 21:17:20 -070081 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
82 target=['validator.conf.sample', 'ndns.conf.sample'],
Davide Pesaventod01c1a42019-01-21 21:42:45 -050083 install_path='${SYSCONFDIR}/ndn/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070084 ANCHORPATH='anchors/root.cert',
Davide Pesavento3d01fa32021-10-03 17:13:38 -040085 CONFDIR='%s/ndn/ndns' % bld.env.SYSCONFDIR,
86 DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env.LOCALSTATEDIR)
Davide Pesavento5704fdf2019-01-20 16:23:11 -050087
88 if Utils.unversioned_sys_platform() == 'linux':
89 bld(features='subst',
90 name='ndns.service',
91 source='systemd/ndns.service.in',
92 target='systemd/ndns.service')
93
94 if bld.env.SPHINX_BUILD:
95 bld(features='sphinx',
96 name='manpages',
97 builder='man',
98 config='docs/conf.py',
99 outdir='docs/manpages',
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400100 source=bld.path.ant_glob('docs/manpages/*.rst'),
Davide Pesavento5704fdf2019-01-20 16:23:11 -0500101 install_path='${MANDIR}',
Alexander Afanasyev60514ec2020-06-03 14:18:53 -0400102 version=VERSION_BASE,
103 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700104
105def docs(bld):
106 from waflib import Options
107 Options.commands = ['doxygen', 'sphinx'] + Options.commands
108
109def doxygen(bld):
110 version(bld)
111
112 if not bld.env.DOXYGEN:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400113 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700114
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400115 bld(features='subst',
116 name='doxygen.conf',
117 source=['docs/doxygen.conf.in',
118 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
119 target=['docs/doxygen.conf',
120 'docs/named_data_theme/named_data_footer-with-analytics.html'],
121 VERSION=VERSION,
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400122 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400123 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'),
Davide Pesavento1af6ccd2019-11-09 15:20:27 -0500142 version=VERSION_BASE,
143 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700144
145def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400146 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700147 if getattr(Context.g_module, 'VERSION_BASE', None):
148 return
149
150 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400151 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700152
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400153 # first, try to get a version string from git
154 gotVersionFromGit = False
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700155 try:
156 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400157 out = subprocess.check_output(cmd, universal_newlines=True).strip()
158 if out:
159 gotVersionFromGit = True
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700160 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400161 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700162 else:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400163 # no tags matched
164 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento90034832018-05-30 10:10:31 -0400165 except (OSError, subprocess.CalledProcessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700166 pass
167
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400168 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400169 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700170 try:
171 Context.g_module.VERSION = versionFile.read()
172 return
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400173 except EnvironmentError:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700174 pass
175
176 # version was obtained from git, update VERSION file if necessary
177 if versionFile is not None:
178 try:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400179 if versionFile.read() == Context.g_module.VERSION:
180 # already up-to-date
181 return
182 except EnvironmentError as e:
183 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700184 else:
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400185 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700186
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700187 try:
188 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400189 except EnvironmentError as e:
190 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700191
192def dist(ctx):
193 version(ctx)
194
195def distcheck(ctx):
196 version(ctx)