blob: ace234cdf8f24fc26b8c30604c87f256998ff3d2 [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}',
Alexander Afanasyev60514ec2020-06-03 14:18:53 -040099 version=VERSION_BASE,
100 release=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'),
Davide Pesavento1af6ccd2019-11-09 15:20:27 -0500138 version=VERSION_BASE,
139 release=VERSION)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700140
141def version(ctx):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400142 # don't execute more than once
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700143 if getattr(Context.g_module, 'VERSION_BASE', None):
144 return
145
146 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400147 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700148
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400149 # first, try to get a version string from git
150 gotVersionFromGit = False
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700151 try:
152 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400153 out = subprocess.check_output(cmd, universal_newlines=True).strip()
154 if out:
155 gotVersionFromGit = True
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700156 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400157 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700158 else:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400159 # no tags matched
160 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento90034832018-05-30 10:10:31 -0400161 except (OSError, subprocess.CalledProcessError):
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700162 pass
163
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400164 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400165 if not gotVersionFromGit and versionFile is not None:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700166 try:
167 Context.g_module.VERSION = versionFile.read()
168 return
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400169 except EnvironmentError:
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700170 pass
171
172 # version was obtained from git, update VERSION file if necessary
173 if versionFile is not None:
174 try:
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400175 if versionFile.read() == Context.g_module.VERSION:
176 # already up-to-date
177 return
178 except EnvironmentError as e:
179 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700180 else:
Alexander Afanasyev2b1b5da2020-06-01 19:18:19 -0400181 versionFile = ctx.path.make_node('VERSION.info')
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700182
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700183 try:
184 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev08d18742018-03-15 16:31:28 -0400185 except EnvironmentError as e:
186 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700187
188def dist(ctx):
189 version(ctx)
190
191def distcheck(ctx):
192 version(ctx)