blob: a9b38dac66aba61e51b064bba111773e7d299c24 [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 Pesavento1af6ccd2019-11-09 15:20:27 -050014 opt.load(['default-compiler-flags', 'coverage', 'sanitizers', 'boost', 'sqlite3',
15 'doxygen', 'sphinx_build'],
16 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',
25 'doxygen', 'sphinx_build'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070026
Davide Pesaventod01c1a42019-01-21 21:42:45 -050027 conf.env['WITH_TESTS'] = conf.options.with_tests
28
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050029 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
30 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070031
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050032 conf.check_sqlite3()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070033
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050034 USED_BOOST_LIBS = ['system', 'program_options', 'filesystem', 'thread', 'log']
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070035 if conf.env['WITH_TESTS']:
36 USED_BOOST_LIBS += ['unit_test_framework']
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050037 conf.check_boost(lib=USED_BOOST_LIBS, 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')
Alexander Afanasyev08d18742018-03-15 16:31:28 -040043 conf.load('sanitizers')
44
Davide Pesaventod01c1a42019-01-21 21:42:45 -050045 conf.define_cond('HAVE_TESTS', conf.env['WITH_TESTS'])
46 conf.define('CONFDIR', '%s/ndn/ndns' % conf.env['SYSCONFDIR'])
47 conf.define('DEFAULT_DBFILE', '%s/lib/ndn/ndns/ndns.db' % conf.env['LOCALSTATEDIR'])
48 conf.write_config_header('src/config.hpp', define_prefix='NDNS_')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070049
50def build (bld):
51 version(bld)
52
Alexander Afanasyev08d18742018-03-15 16:31:28 -040053 bld(features='subst',
54 name='version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070055 source='src/version.hpp.in',
56 target='src/version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070057 VERSION_STRING=VERSION_BASE,
58 VERSION_BUILD=VERSION,
59 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
60 int(VERSION_SPLIT[1]) * 1000 +
61 int(VERSION_SPLIT[2]),
62 VERSION_MAJOR=VERSION_SPLIT[0],
63 VERSION_MINOR=VERSION_SPLIT[1],
Alexander Afanasyev08d18742018-03-15 16:31:28 -040064 VERSION_PATCH=VERSION_SPLIT[2])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070065
Alexander Afanasyev08d18742018-03-15 16:31:28 -040066 bld.objects(
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070067 name='ndns-objects',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050068 source=bld.path.ant_glob('src/**/*.cpp'),
Alexander Afanasyev08d18742018-03-15 16:31:28 -040069 use='version NDN_CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070070 includes='src',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040071 export_includes='src')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070072
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070073 bld.recurse('tests')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070074 bld.recurse('tools')
Shock Jiang0b165f42014-10-24 09:08:09 -070075
76 bld(features='subst',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050077 name='conf-samples',
Shock Jiangcde28712014-10-19 21:17:20 -070078 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
79 target=['validator.conf.sample', 'ndns.conf.sample'],
Davide Pesaventod01c1a42019-01-21 21:42:45 -050080 install_path='${SYSCONFDIR}/ndn/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070081 ANCHORPATH='anchors/root.cert',
Davide Pesaventod01c1a42019-01-21 21:42:45 -050082 CONFDIR='%s/ndn/ndns' % bld.env['SYSCONFDIR'],
83 DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env['LOCALSTATEDIR'])
Davide Pesavento5704fdf2019-01-20 16:23:11 -050084
85 if Utils.unversioned_sys_platform() == 'linux':
86 bld(features='subst',
87 name='ndns.service',
88 source='systemd/ndns.service.in',
89 target='systemd/ndns.service')
90
91 if bld.env.SPHINX_BUILD:
92 bld(features='sphinx',
93 name='manpages',
94 builder='man',
95 config='docs/conf.py',
96 outdir='docs/manpages',
97 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
98 install_path='${MANDIR}',
99 VERSION=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700100
101def docs(bld):
102 from waflib import Options
103 Options.commands = ['doxygen', 'sphinx'] + Options.commands
104
105def doxygen(bld):
106 version(bld)
107
108 if not bld.env.DOXYGEN:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400109 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700110
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400111 bld(features='subst',
112 name='doxygen.conf',
113 source=['docs/doxygen.conf.in',
114 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
115 target=['docs/doxygen.conf',
116 'docs/named_data_theme/named_data_footer-with-analytics.html'],
117 VERSION=VERSION,
118 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
119 if os.getenv('GOOGLE_ANALYTICS', None) \
120 else '../docs/named_data_theme/named_data_footer.html',
121 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
122
123 bld(features='doxygen',
124 doxyfile='docs/doxygen.conf',
125 use='doxygen.conf')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700126
127def sphinx(bld):
128 version(bld)
129
130 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400131 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
132
133 bld(features='sphinx',
134 config='docs/conf.py',
135 outdir='docs',
136 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento1af6ccd2019-11-09 15:20:27 -0500137 version=VERSION_BASE,
138 release=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
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400163 versionFile = ctx.path.find_node('VERSION.info')
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:
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400180 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700181
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)