blob: aa570efea3745f22f6479f7a0369219a7f0eef3e [file] [log] [blame]
akmhoque298385a2014-02-13 14:13:09 -06001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Yingdi Yu40cd1c32014-04-17 15:02:17 -07002"""
Ashlesh Gawande30d96e42021-03-21 19:15:33 -07003Copyright (c) 2014-2021, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06004 Regents of the University of California,
5 Arizona Board of Regents.
Yingdi Yu40cd1c32014-04-17 15:02:17 -07006
7This file is part of NLSR (Named-data Link State Routing).
8See AUTHORS.md for complete list of NLSR authors and contributors.
9
10NLSR is free software: you can redistribute it and/or modify it under the terms
11of the GNU General Public License as published by the Free Software Foundation,
12either version 3 of the License, or (at your option) any later version.
13
14NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along with
19NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20"""
21
Davide Pesaventof75bfda2019-11-10 18:34:13 -050022from waflib import Context, Logs, Utils
23import os, subprocess
24
Saurab Dulalcf064442020-12-14 11:04:57 -060025VERSION = "0.6.0"
sfayer93d9ec32014-12-04 23:34:41 +000026APPNAME = "nlsr"
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040027BUGREPORT = "https://redmine.named-data.net/projects/nlsr"
28URL = "https://named-data.net/doc/NLSR/"
Vince Lehmanb722b102014-08-24 16:33:49 -050029GIT_TAG_PREFIX = "NLSR-"
akmhoque298385a2014-02-13 14:13:09 -060030
akmhoque298385a2014-02-13 14:13:09 -060031def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070032 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento7ae8b082021-10-12 21:45:47 -040033 opt.load(['default-compiler-flags',
34 'coverage', 'sanitizers', 'boost',
35 'doxygen', 'sphinx_build'],
Davide Pesaventoe5569912019-01-29 19:39:06 -050036 tooldir=['.waf-tools'])
akmhoque298385a2014-02-13 14:13:09 -060037
Davide Pesaventof75bfda2019-11-10 18:34:13 -050038 optgrp = opt.add_option_group('NLSR Options')
39 optgrp.add_option('--with-tests', action='store_true', default=False,
40 help='Build unit tests')
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070041 optgrp.add_option('--with-chronosync', action='store_true', default=False,
Davide Pesavento7ae8b082021-10-12 21:45:47 -040042 help='Build with ChronoSync support')
akmhoque05d5fcf2014-04-15 14:58:45 -050043
akmhoque298385a2014-02-13 14:13:09 -060044def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050045 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040046 'default-compiler-flags', 'boost',
Vince Lehmanb722b102014-08-24 16:33:49 -050047 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060048
Davide Pesaventof75bfda2019-11-10 18:34:13 -050049 conf.env.WITH_TESTS = conf.options.with_tests
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070050
Davide Pesavento7ae8b082021-10-12 21:45:47 -040051 conf.find_program('dot', var='DOT', mandatory=False)
52
Davide Pesaventof75bfda2019-11-10 18:34:13 -050053 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR)
54 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
55 pkg_config_path=pkg_config_path)
akmhoque85d88332014-02-17 21:11:21 -060056
Davide Pesaventof75bfda2019-11-10 18:34:13 -050057 boost_libs = ['system', 'iostreams', 'filesystem', 'regex']
58 if conf.env.WITH_TESTS:
59 boost_libs += ['program_options', 'unit_test_framework']
akmhoque85d88332014-02-17 21:11:21 -060060
dmcoomescf8d0ed2017-02-21 11:39:01 -060061 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventoe5569912019-01-29 19:39:06 -050062 if conf.env.BOOST_VERSION_NUMBER < 105800:
Davide Pesavento7ae8b082021-10-12 21:45:47 -040063 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
64 'Please upgrade your distribution or manually install a newer version of Boost.\n'
65 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
66 elif conf.env.BOOST_VERSION_NUMBER < 106501:
67 Logs.warn('WARNING: Using a version of Boost older than 1.65.1 is not officially supported and may not work.\n'
68 'If you encounter any problems, please upgrade your distribution or manually install a newer version of Boost.\n'
69 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
akmhoque05d5fcf2014-04-15 14:58:45 -050070
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070071 if conf.options.with_chronosync:
72 conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'],
73 uselib_store='CHRONOSYNC', pkg_config_path=pkg_config_path)
akmhoque05d5fcf2014-04-15 14:58:45 -050074
Davide Pesaventof75bfda2019-11-10 18:34:13 -050075 conf.check_cfg(package='PSync', args=['--cflags', '--libs'], uselib_store='PSYNC',
76 pkg_config_path=pkg_config_path)
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050077
Alexander Afanasyev67758b12018-03-06 18:36:44 -050078 conf.check_compiler_flags()
79
Davide Pesaventoe5569912019-01-29 19:39:06 -050080 # Loading "late" to prevent tests from being compiled with profiling flags
Yingdi Yu40cd1c32014-04-17 15:02:17 -070081 conf.load('coverage')
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050082 conf.load('sanitizers')
83
Davide Pesaventof75bfda2019-11-10 18:34:13 -050084 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
Junxiao Shia3a63972022-01-24 02:03:41 +000085 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env.SYSCONFDIR)
Davide Pesaventof75bfda2019-11-10 18:34:13 -050086 # The config header will contain all defines that were added using conf.define()
87 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
88 # will not appear in the config header, but will instead be passed directly to the
89 # compiler on the command line.
Yingdi Yu40cd1c32014-04-17 15:02:17 -070090 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050091
Vince Lehmanb722b102014-08-24 16:33:49 -050092def build(bld):
93 version(bld)
94
Davide Pesaventoe5569912019-01-29 19:39:06 -050095 bld(features='subst',
Alexander Afanasyev67758b12018-03-06 18:36:44 -050096 name='version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050097 source='src/version.hpp.in',
98 target='src/version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050099 VERSION_STRING=VERSION_BASE,
100 VERSION_BUILD=VERSION,
101 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
102 int(VERSION_SPLIT[1]) * 1000 +
103 int(VERSION_SPLIT[2]),
104 VERSION_MAJOR=VERSION_SPLIT[0],
105 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500106 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -0500107
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500108 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700109 target='nlsr-objects',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500110 source=bld.path.ant_glob('src/**/*.cpp',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700111 excl=['src/main.cpp']),
Ashlesh Gawande30d96e42021-03-21 19:15:33 -0700112 use='NDN_CXX BOOST CHRONOSYNC PSYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700113 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500114 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600115
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500116 bld.program(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700117 target='bin/nlsr',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500118 name='nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700119 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500120 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600121
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500122 bld.program(
Vince Lehmanc439d662015-04-27 10:56:00 -0500123 target='bin/nlsrc',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500124 name='nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500125 source='tools/nlsrc.cpp',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500126 use='nlsr-objects')
Vince Lehmanc439d662015-04-27 10:56:00 -0500127
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500128 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700129 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500130
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500131 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
132
133 if Utils.unversioned_sys_platform() == 'linux':
134 bld(features='subst',
135 name='nlsr.service',
136 source='systemd/nlsr.service.in',
137 target='systemd/nlsr.service')
138
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500139 if bld.env.SPHINX_BUILD:
140 bld(features='sphinx',
141 name='manpages',
142 builder='man',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500143 config='docs/conf.py',
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500144 outdir='docs/manpages',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500145 source=bld.path.ant_glob('docs/manpages/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500146 install_path='${MANDIR}',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500147 version=VERSION_BASE,
148 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500149
150def docs(bld):
151 from waflib import Options
152 Options.commands = ['doxygen', 'sphinx'] + Options.commands
153
154def doxygen(bld):
155 version(bld)
156
157 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500158 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500159
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500160 bld(features='subst',
161 name='doxygen.conf',
162 source=['docs/doxygen.conf.in',
163 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
164 target=['docs/doxygen.conf',
165 'docs/named_data_theme/named_data_footer-with-analytics.html'],
166 VERSION=VERSION,
Davide Pesavento7ae8b082021-10-12 21:45:47 -0400167 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500168 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
169 if os.getenv('GOOGLE_ANALYTICS', None) \
170 else '../docs/named_data_theme/named_data_footer.html',
171 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
172
173 bld(features='doxygen',
174 doxyfile='docs/doxygen.conf',
175 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500176
177def sphinx(bld):
178 version(bld)
179
180 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500181 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
182
183 bld(features='sphinx',
184 config='docs/conf.py',
185 outdir='docs',
186 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500187 version=VERSION_BASE,
188 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500189
190def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500191 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500192 if getattr(Context.g_module, 'VERSION_BASE', None):
193 return
194
195 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500196 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500197
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500198 # first, try to get a version string from git
199 gotVersionFromGit = False
Vince Lehmanb722b102014-08-24 16:33:49 -0500200 try:
201 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500202 out = subprocess.check_output(cmd, universal_newlines=True).strip()
203 if out:
204 gotVersionFromGit = True
Vince Lehmanb722b102014-08-24 16:33:49 -0500205 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500206 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Vince Lehmanb722b102014-08-24 16:33:49 -0500207 else:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500208 # no tags matched
209 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesaventoa08dc3f2018-05-24 00:40:28 -0400210 except (OSError, subprocess.CalledProcessError):
Vince Lehmanb722b102014-08-24 16:33:49 -0500211 pass
212
Alexander Afanasyev96ebd9b2020-06-01 19:16:52 -0400213 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500214 if not gotVersionFromGit and versionFile is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500215 try:
216 Context.g_module.VERSION = versionFile.read()
217 return
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500218 except EnvironmentError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500219 pass
220
221 # version was obtained from git, update VERSION file if necessary
222 if versionFile is not None:
223 try:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500224 if versionFile.read() == Context.g_module.VERSION:
225 # already up-to-date
226 return
227 except EnvironmentError as e:
228 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500229 else:
Alexander Afanasyev96ebd9b2020-06-01 19:16:52 -0400230 versionFile = ctx.path.make_node('VERSION.info')
Vince Lehmanb722b102014-08-24 16:33:49 -0500231
Vince Lehmanb722b102014-08-24 16:33:49 -0500232 try:
233 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500234 except EnvironmentError as e:
235 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500236
237def dist(ctx):
238 version(ctx)
239
240def distcheck(ctx):
241 version(ctx)