blob: 6beff79ae08a10325a33ca620dc8e426505f0217 [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"""
Davide Pesavento1e9faf12023-01-21 16:04:50 -05003Copyright (c) 2014-2023, 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
Davide Pesaventofa54ee92023-02-20 04:16:51 -050025VERSION = '0.6.0'
26APPNAME = 'nlsr'
27GIT_TAG_PREFIX = 'NLSR-'
akmhoque298385a2014-02-13 14:13:09 -060028
akmhoque298385a2014-02-13 14:13:09 -060029def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070030 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento7ae8b082021-10-12 21:45:47 -040031 opt.load(['default-compiler-flags',
32 'coverage', 'sanitizers', 'boost',
33 'doxygen', 'sphinx_build'],
Davide Pesaventoe5569912019-01-29 19:39:06 -050034 tooldir=['.waf-tools'])
akmhoque298385a2014-02-13 14:13:09 -060035
Davide Pesaventof75bfda2019-11-10 18:34:13 -050036 optgrp = opt.add_option_group('NLSR Options')
Varun Patil7d2d6892022-10-14 12:50:30 -070037
38 optgrp.add_option('--with-chronosync', dest='with_chronosync', action='store_true', default=False,
Davide Pesavento7ae8b082021-10-12 21:45:47 -040039 help='Build with ChronoSync support')
Varun Patil7d2d6892022-10-14 12:50:30 -070040 optgrp.add_option('--without-chronosync', dest='with_chronosync', action='store_false', default=False,
41 help='Build without ChronoSync support')
42
43 optgrp.add_option('--with-psync', dest='with_psync', action='store_true', default=True,
44 help='Build with PSync support')
45 optgrp.add_option('--without-psync', dest='with_psync', action='store_false', default=True,
46 help='Build without PSync support')
47
48 optgrp.add_option('--with-svs', dest='with_svs', action='store_true', default=False,
49 help='Build with State Vector Sync support')
50 optgrp.add_option('--without-svs', dest='with_svs', action='store_false', default=False,
51 help='Build without State Vector Sync support')
akmhoque05d5fcf2014-04-15 14:58:45 -050052
Davide Pesaventofcef0582022-12-06 15:00:02 -050053 optgrp.add_option('--with-tests', action='store_true', default=False,
54 help='Build unit tests')
55
akmhoque298385a2014-02-13 14:13:09 -060056def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050057 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040058 'default-compiler-flags', 'boost',
Vince Lehmanb722b102014-08-24 16:33:49 -050059 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060060
Davide Pesaventof75bfda2019-11-10 18:34:13 -050061 conf.env.WITH_TESTS = conf.options.with_tests
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070062
Davide Pesaventoede59632022-08-26 20:35:44 -040063 conf.find_program('dot', mandatory=False)
64
65 # Prefer pkgconf if it's installed, because it gives more correct results
66 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
67 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
68 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
Davide Pesavento7ae8b082021-10-12 21:45:47 -040069
Davide Pesaventod1f1df82022-03-12 16:40:37 -050070 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento1e9faf12023-01-21 16:04:50 -050071 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesaventod1f1df82022-03-12 16:40:37 -050072 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
akmhoque85d88332014-02-17 21:11:21 -060073
Davide Pesaventof75bfda2019-11-10 18:34:13 -050074 boost_libs = ['system', 'iostreams', 'filesystem', 'regex']
75 if conf.env.WITH_TESTS:
Davide Pesaventod1f1df82022-03-12 16:40:37 -050076 boost_libs.append('unit_test_framework')
akmhoque85d88332014-02-17 21:11:21 -060077
dmcoomescf8d0ed2017-02-21 11:39:01 -060078 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventod1f1df82022-03-12 16:40:37 -050079 if conf.env.BOOST_VERSION_NUMBER < 106501:
Davide Pesavento7ae8b082021-10-12 21:45:47 -040080 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
81 'Please upgrade your distribution or manually install a newer version of Boost.\n'
82 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
akmhoque05d5fcf2014-04-15 14:58:45 -050083
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070084 if conf.options.with_chronosync:
Davide Pesavento1e9faf12023-01-21 16:04:50 -050085 conf.check_cfg(package='ChronoSync', args=['ChronoSync >= 0.5.5', '--cflags', '--libs'],
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070086 uselib_store='CHRONOSYNC', pkg_config_path=pkg_config_path)
akmhoque05d5fcf2014-04-15 14:58:45 -050087
Varun Patil7d2d6892022-10-14 12:50:30 -070088 if conf.options.with_psync:
Davide Pesavento1e9faf12023-01-21 16:04:50 -050089 conf.check_cfg(package='PSync', args=['PSync >= 0.4.0', '--cflags', '--libs'],
Varun Patil7d2d6892022-10-14 12:50:30 -070090 uselib_store='PSYNC', pkg_config_path=pkg_config_path)
91
92 if conf.options.with_svs:
93 conf.check_cfg(package='libndn-svs', args=['libndn-svs >= 0.1.0', '--cflags', '--libs'],
94 uselib_store='SVS', pkg_config_path=pkg_config_path)
95
96 if not any((conf.options.with_chronosync, conf.options.with_psync, conf.options.with_svs)):
97 conf.fatal('Cannot compile without any Sync protocol. '
98 'Specify at least one of --with-psync or --with-svs or --with-chronosync')
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050099
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500100 conf.check_compiler_flags()
101
Davide Pesaventoe5569912019-01-29 19:39:06 -0500102 # Loading "late" to prevent tests from being compiled with profiling flags
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700103 conf.load('coverage')
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500104 conf.load('sanitizers')
105
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500106 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
Junxiao Shia3a63972022-01-24 02:03:41 +0000107 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env.SYSCONFDIR)
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500108 # The config header will contain all defines that were added using conf.define()
109 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
110 # will not appear in the config header, but will instead be passed directly to the
111 # compiler on the command line.
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700112 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -0500113
Vince Lehmanb722b102014-08-24 16:33:49 -0500114def build(bld):
115 version(bld)
116
Davide Pesaventoe5569912019-01-29 19:39:06 -0500117 bld(features='subst',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500118 name='version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -0500119 source='src/version.hpp.in',
120 target='src/version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -0500121 VERSION_STRING=VERSION_BASE,
122 VERSION_BUILD=VERSION,
123 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
124 int(VERSION_SPLIT[1]) * 1000 +
125 int(VERSION_SPLIT[2]),
126 VERSION_MAJOR=VERSION_SPLIT[0],
127 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500128 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -0500129
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500130 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700131 target='nlsr-objects',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500132 source=bld.path.ant_glob('src/**/*.cpp',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700133 excl=['src/main.cpp']),
Varun Patil7d2d6892022-10-14 12:50:30 -0700134 use='NDN_CXX BOOST CHRONOSYNC PSYNC SVS',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700135 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500136 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600137
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500138 bld.program(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700139 target='bin/nlsr',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500140 name='nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700141 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500142 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600143
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500144 bld.program(
Vince Lehmanc439d662015-04-27 10:56:00 -0500145 target='bin/nlsrc',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500146 name='nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500147 source='tools/nlsrc.cpp',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500148 use='nlsr-objects')
Vince Lehmanc439d662015-04-27 10:56:00 -0500149
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500150 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700151 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500152
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500153 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
154
155 if Utils.unversioned_sys_platform() == 'linux':
156 bld(features='subst',
157 name='nlsr.service',
158 source='systemd/nlsr.service.in',
159 target='systemd/nlsr.service')
160
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500161 if bld.env.SPHINX_BUILD:
162 bld(features='sphinx',
163 name='manpages',
164 builder='man',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500165 config='docs/conf.py',
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500166 outdir='docs/manpages',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500167 source=bld.path.ant_glob('docs/manpages/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500168 install_path='${MANDIR}',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500169 version=VERSION_BASE,
170 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500171
172def docs(bld):
173 from waflib import Options
174 Options.commands = ['doxygen', 'sphinx'] + Options.commands
175
176def doxygen(bld):
177 version(bld)
178
179 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500180 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500181
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500182 bld(features='subst',
183 name='doxygen.conf',
184 source=['docs/doxygen.conf.in',
185 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
186 target=['docs/doxygen.conf',
187 'docs/named_data_theme/named_data_footer-with-analytics.html'],
188 VERSION=VERSION,
Davide Pesavento7ae8b082021-10-12 21:45:47 -0400189 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500190 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
191 if os.getenv('GOOGLE_ANALYTICS', None) \
192 else '../docs/named_data_theme/named_data_footer.html',
193 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
194
195 bld(features='doxygen',
196 doxyfile='docs/doxygen.conf',
197 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500198
199def sphinx(bld):
200 version(bld)
201
202 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500203 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
204
205 bld(features='sphinx',
206 config='docs/conf.py',
207 outdir='docs',
208 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500209 version=VERSION_BASE,
210 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500211
212def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500213 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500214 if getattr(Context.g_module, 'VERSION_BASE', None):
215 return
216
217 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500218 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500219
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500220 # first, try to get a version string from git
221 gotVersionFromGit = False
Vince Lehmanb722b102014-08-24 16:33:49 -0500222 try:
223 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500224 out = subprocess.check_output(cmd, universal_newlines=True).strip()
225 if out:
226 gotVersionFromGit = True
Vince Lehmanb722b102014-08-24 16:33:49 -0500227 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500228 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Vince Lehmanb722b102014-08-24 16:33:49 -0500229 else:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500230 # no tags matched
231 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesaventoa08dc3f2018-05-24 00:40:28 -0400232 except (OSError, subprocess.CalledProcessError):
Vince Lehmanb722b102014-08-24 16:33:49 -0500233 pass
234
Alexander Afanasyev96ebd9b2020-06-01 19:16:52 -0400235 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500236 if not gotVersionFromGit and versionFile is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500237 try:
238 Context.g_module.VERSION = versionFile.read()
239 return
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500240 except EnvironmentError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500241 pass
242
243 # version was obtained from git, update VERSION file if necessary
244 if versionFile is not None:
245 try:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500246 if versionFile.read() == Context.g_module.VERSION:
247 # already up-to-date
248 return
249 except EnvironmentError as e:
250 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500251 else:
Alexander Afanasyev96ebd9b2020-06-01 19:16:52 -0400252 versionFile = ctx.path.make_node('VERSION.info')
Vince Lehmanb722b102014-08-24 16:33:49 -0500253
Vince Lehmanb722b102014-08-24 16:33:49 -0500254 try:
255 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500256 except EnvironmentError as e:
257 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500258
259def dist(ctx):
Davide Pesaventofa54ee92023-02-20 04:16:51 -0500260 ctx.algo = 'tar.xz'
Vince Lehmanb722b102014-08-24 16:33:49 -0500261 version(ctx)
262
263def distcheck(ctx):
Davide Pesaventofa54ee92023-02-20 04:16:51 -0500264 ctx.algo = 'tar.xz'
Vince Lehmanb722b102014-08-24 16:33:49 -0500265 version(ctx)