blob: 5aa05c9d90c9fcfc7ad4f10844e5b60425eeb73c [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
Davide Pesavento423553e2022-08-19 20:46:06 -040028 conf.find_program('dot', mandatory=False)
29
30 # Prefer pkgconf if it's installed, because it gives more correct results
31 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
32 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
33 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
Davide Pesaventod01c1a42019-01-21 21:42:45 -050034
Davide Pesavento98026122022-03-14 22:00:03 -040035 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
36 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'],
37 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070038
Davide Pesavento1af6ccd2019-11-09 15:20:27 -050039 conf.check_sqlite3()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070040
Davide Pesavento98026122022-03-14 22:00:03 -040041 boost_libs = ['system', 'program_options', 'filesystem']
Davide Pesavento3d01fa32021-10-03 17:13:38 -040042 if conf.env.WITH_TESTS:
43 boost_libs.append('unit_test_framework')
Davide Pesavento423553e2022-08-19 20:46:06 -040044
Davide Pesavento3d01fa32021-10-03 17:13:38 -040045 conf.check_boost(lib=boost_libs, mt=True)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070046
Alexander Afanasyev08d18742018-03-15 16:31:28 -040047 conf.check_compiler_flags()
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070048
Alexander Afanasyev08d18742018-03-15 16:31:28 -040049 # Loading "late" to prevent tests from being compiled with profiling flags
50 conf.load('coverage')
Alexander Afanasyev08d18742018-03-15 16:31:28 -040051 conf.load('sanitizers')
52
Davide Pesavento3d01fa32021-10-03 17:13:38 -040053 conf.define_cond('HAVE_TESTS', conf.env.WITH_TESTS)
54 conf.define('CONFDIR', '%s/ndn/ndns' % conf.env.SYSCONFDIR)
55 conf.define('DEFAULT_DBFILE', '%s/lib/ndn/ndns/ndns.db' % conf.env.LOCALSTATEDIR)
Davide Pesaventod01c1a42019-01-21 21:42:45 -050056 conf.write_config_header('src/config.hpp', define_prefix='NDNS_')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070057
Davide Pesavento3d01fa32021-10-03 17:13:38 -040058def build(bld):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070059 version(bld)
60
Davide Pesavento98026122022-03-14 22:00:03 -040061 vmajor = int(VERSION_SPLIT[0])
62 vminor = int(VERSION_SPLIT[1]) if len(VERSION_SPLIT) >= 2 else 0
63 vpatch = int(VERSION_SPLIT[2]) if len(VERSION_SPLIT) >= 3 else 0
64
Alexander Afanasyev08d18742018-03-15 16:31:28 -040065 bld(features='subst',
66 name='version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070067 source='src/version.hpp.in',
68 target='src/version.hpp',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070069 VERSION_STRING=VERSION_BASE,
70 VERSION_BUILD=VERSION,
Davide Pesavento98026122022-03-14 22:00:03 -040071 VERSION=vmajor * 1000000 + vminor * 1000 + vpatch,
72 VERSION_MAJOR=str(vmajor),
73 VERSION_MINOR=str(vminor),
74 VERSION_PATCH=str(vpatch))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070075
Alexander Afanasyev08d18742018-03-15 16:31:28 -040076 bld.objects(
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070077 name='ndns-objects',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050078 source=bld.path.ant_glob('src/**/*.cpp'),
Davide Pesavento98026122022-03-14 22:00:03 -040079 use='version.hpp NDN_CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070080 includes='src',
Alexander Afanasyev08d18742018-03-15 16:31:28 -040081 export_includes='src')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070082
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070083 bld.recurse('tools')
Davide Pesavento3d01fa32021-10-03 17:13:38 -040084 bld.recurse('tests')
Shock Jiang0b165f42014-10-24 09:08:09 -070085
86 bld(features='subst',
Davide Pesavento5704fdf2019-01-20 16:23:11 -050087 name='conf-samples',
Shock Jiangcde28712014-10-19 21:17:20 -070088 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
89 target=['validator.conf.sample', 'ndns.conf.sample'],
Davide Pesaventod01c1a42019-01-21 21:42:45 -050090 install_path='${SYSCONFDIR}/ndn/ndns',
Shock Jiang0b165f42014-10-24 09:08:09 -070091 ANCHORPATH='anchors/root.cert',
Davide Pesavento3d01fa32021-10-03 17:13:38 -040092 CONFDIR='%s/ndn/ndns' % bld.env.SYSCONFDIR,
93 DEFAULT_DBFILE='%s/lib/ndn/ndns/ndns.db' % bld.env.LOCALSTATEDIR)
Davide Pesavento5704fdf2019-01-20 16:23:11 -050094
95 if Utils.unversioned_sys_platform() == 'linux':
96 bld(features='subst',
97 name='ndns.service',
98 source='systemd/ndns.service.in',
99 target='systemd/ndns.service')
100
101 if bld.env.SPHINX_BUILD:
102 bld(features='sphinx',
103 name='manpages',
104 builder='man',
105 config='docs/conf.py',
106 outdir='docs/manpages',
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400107 source=bld.path.ant_glob('docs/manpages/*.rst'),
Davide Pesavento5704fdf2019-01-20 16:23:11 -0500108 install_path='${MANDIR}',
Alexander Afanasyev60514ec2020-06-03 14:18:53 -0400109 version=VERSION_BASE,
110 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700111
112def docs(bld):
113 from waflib import Options
114 Options.commands = ['doxygen', 'sphinx'] + Options.commands
115
116def doxygen(bld):
117 version(bld)
118
119 if not bld.env.DOXYGEN:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400120 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700121
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400122 bld(features='subst',
123 name='doxygen.conf',
124 source=['docs/doxygen.conf.in',
125 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
126 target=['docs/doxygen.conf',
127 'docs/named_data_theme/named_data_footer-with-analytics.html'],
128 VERSION=VERSION,
Davide Pesavento3d01fa32021-10-03 17:13:38 -0400129 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400130 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
131 if os.getenv('GOOGLE_ANALYTICS', None) \
132 else '../docs/named_data_theme/named_data_footer.html',
133 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
134
135 bld(features='doxygen',
136 doxyfile='docs/doxygen.conf',
137 use='doxygen.conf')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700138
139def sphinx(bld):
140 version(bld)
141
142 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400143 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
144
145 bld(features='sphinx',
146 config='docs/conf.py',
147 outdir='docs',
148 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento1af6ccd2019-11-09 15:20:27 -0500149 version=VERSION_BASE,
150 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700151
152def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400153 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700154 if getattr(Context.g_module, 'VERSION_BASE', None):
155 return
156
157 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400158 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700159
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400160 # first, try to get a version string from git
161 gotVersionFromGit = False
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700162 try:
163 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400164 out = subprocess.check_output(cmd, universal_newlines=True).strip()
165 if out:
166 gotVersionFromGit = True
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700167 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400168 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700169 else:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400170 # no tags matched
171 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento90034832018-05-30 10:10:31 -0400172 except (OSError, subprocess.CalledProcessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700173 pass
174
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400175 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400176 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700177 try:
178 Context.g_module.VERSION = versionFile.read()
179 return
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400180 except EnvironmentError:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700181 pass
182
183 # version was obtained from git, update VERSION file if necessary
184 if versionFile is not None:
185 try:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400186 if versionFile.read() == Context.g_module.VERSION:
187 # already up-to-date
188 return
189 except EnvironmentError as e:
190 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700191 else:
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400192 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700193
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700194 try:
195 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400196 except EnvironmentError as e:
197 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700198
199def dist(ctx):
200 version(ctx)
201
202def distcheck(ctx):
203 version(ctx)