blob: f070b7400528ef7e0611c86d21d61b6151548ed1 [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 Pesavento5a1d77a2024-03-13 19:24:11 -04003Copyright (c) 2014-2024, 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 Pesavento5849ee72023-11-12 20:00:21 -050022import os
23import subprocess
Davide Pesaventof75bfda2019-11-10 18:34:13 -050024from waflib import Context, Logs, Utils
Davide Pesaventof75bfda2019-11-10 18:34:13 -050025
Saurab Dulalecb0b712023-08-18 01:48:54 +000026VERSION = '0.7.0'
Davide Pesaventofa54ee92023-02-20 04:16:51 -050027APPNAME = 'nlsr'
28GIT_TAG_PREFIX = 'NLSR-'
akmhoque298385a2014-02-13 14:13:09 -060029
akmhoque298385a2014-02-13 14:13:09 -060030def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070031 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento7ae8b082021-10-12 21:45:47 -040032 opt.load(['default-compiler-flags',
33 'coverage', 'sanitizers', 'boost',
Davide Pesavento5a1d77a2024-03-13 19:24:11 -040034 'doxygen', 'sphinx'],
Davide Pesaventoe5569912019-01-29 19:39:06 -050035 tooldir=['.waf-tools'])
akmhoque298385a2014-02-13 14:13:09 -060036
Davide Pesaventof75bfda2019-11-10 18:34:13 -050037 optgrp = opt.add_option_group('NLSR Options')
Varun Patil7d2d6892022-10-14 12:50:30 -070038
39 optgrp.add_option('--with-chronosync', dest='with_chronosync', action='store_true', default=False,
Davide Pesavento7ae8b082021-10-12 21:45:47 -040040 help='Build with ChronoSync support')
Varun Patil7d2d6892022-10-14 12:50:30 -070041 optgrp.add_option('--without-chronosync', dest='with_chronosync', action='store_false', default=False,
42 help='Build without ChronoSync support')
43
44 optgrp.add_option('--with-psync', dest='with_psync', action='store_true', default=True,
45 help='Build with PSync support')
46 optgrp.add_option('--without-psync', dest='with_psync', action='store_false', default=True,
47 help='Build without PSync support')
48
49 optgrp.add_option('--with-svs', dest='with_svs', action='store_true', default=False,
50 help='Build with State Vector Sync support')
51 optgrp.add_option('--without-svs', dest='with_svs', action='store_false', default=False,
52 help='Build without State Vector Sync support')
akmhoque05d5fcf2014-04-15 14:58:45 -050053
Davide Pesaventofcef0582022-12-06 15:00:02 -050054 optgrp.add_option('--with-tests', action='store_true', default=False,
55 help='Build unit tests')
56
akmhoque298385a2014-02-13 14:13:09 -060057def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050058 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040059 'default-compiler-flags', 'boost',
Davide Pesavento5a1d77a2024-03-13 19:24:11 -040060 'doxygen', 'sphinx'])
akmhoque298385a2014-02-13 14:13:09 -060061
Davide Pesaventof75bfda2019-11-10 18:34:13 -050062 conf.env.WITH_TESTS = conf.options.with_tests
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070063
Davide Pesaventoede59632022-08-26 20:35:44 -040064 conf.find_program('dot', mandatory=False)
65
66 # Prefer pkgconf if it's installed, because it gives more correct results
67 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
68 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
69 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
Davide Pesavento7ae8b082021-10-12 21:45:47 -040070
Davide Pesaventod1f1df82022-03-12 16:40:37 -050071 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento1e9faf12023-01-21 16:04:50 -050072 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesaventod1f1df82022-03-12 16:40:37 -050073 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
akmhoque85d88332014-02-17 21:11:21 -060074
Davide Pesavento5849ee72023-11-12 20:00:21 -050075 conf.check_boost(lib='filesystem', mt=True)
76 if conf.env.BOOST_VERSION_NUMBER < 107100:
77 conf.fatal('The minimum supported version of Boost is 1.71.0.\n'
Davide Pesavento7ae8b082021-10-12 21:45:47 -040078 'Please upgrade your distribution or manually install a newer version of Boost.\n'
79 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
akmhoque05d5fcf2014-04-15 14:58:45 -050080
Davide Pesavento5849ee72023-11-12 20:00:21 -050081 if conf.env.WITH_TESTS:
82 conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS')
83
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)):
Davide Pesaventob6adfe12024-07-05 13:03:15 -040097 conf.fatal('Cannot compile without any Sync protocol.\n'
Varun Patil7d2d6892022-10-14 12:50:30 -070098 'Specify at least one of --with-psync or --with-svs or --with-chronosync')
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050099
Davide Pesaventob6adfe12024-07-05 13:03:15 -0400100 if conf.env.WITH_TESTS and not conf.options.with_psync:
101 conf.fatal('--with-tests requires --with-psync')
102
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500103 conf.check_compiler_flags()
104
Davide Pesaventoe5569912019-01-29 19:39:06 -0500105 # Loading "late" to prevent tests from being compiled with profiling flags
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700106 conf.load('coverage')
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500107 conf.load('sanitizers')
108
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500109 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
Davide Pesavento5849ee72023-11-12 20:00:21 -0500110 conf.define('DEFAULT_CONFIG_FILE', f'{conf.env.SYSCONFDIR}/ndn/nlsr.conf')
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500111 # The config header will contain all defines that were added using conf.define()
112 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
113 # will not appear in the config header, but will instead be passed directly to the
114 # compiler on the command line.
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700115 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -0500116
Vince Lehmanb722b102014-08-24 16:33:49 -0500117def build(bld):
118 version(bld)
119
Davide Pesaventoe5569912019-01-29 19:39:06 -0500120 bld(features='subst',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500121 name='version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -0500122 source='src/version.hpp.in',
123 target='src/version.hpp',
Davide Pesavento5849ee72023-11-12 20:00:21 -0500124 install_path=None,
Vince Lehmanb722b102014-08-24 16:33:49 -0500125 VERSION_STRING=VERSION_BASE,
126 VERSION_BUILD=VERSION,
127 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
128 int(VERSION_SPLIT[1]) * 1000 +
129 int(VERSION_SPLIT[2]),
130 VERSION_MAJOR=VERSION_SPLIT[0],
131 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500132 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -0500133
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500134 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700135 target='nlsr-objects',
Davide Pesavento5849ee72023-11-12 20:00:21 -0500136 source=bld.path.ant_glob('src/**/*.cpp', excl=['src/main.cpp']),
137 use='BOOST NDN_CXX CHRONOSYNC PSYNC SVS',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700138 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500139 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600140
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500141 bld.program(
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500142 name='nlsr',
Davide Pesavento5849ee72023-11-12 20:00:21 -0500143 target='bin/nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700144 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500145 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600146
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500147 bld.program(
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500148 name='nlsrc',
Davide Pesavento5849ee72023-11-12 20:00:21 -0500149 target='bin/nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500150 source='tools/nlsrc.cpp',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500151 use='nlsr-objects')
Vince Lehmanc439d662015-04-27 10:56:00 -0500152
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500153 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700154 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500155
Davide Pesavento5849ee72023-11-12 20:00:21 -0500156 # Install sample config
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500157 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
158
159 if Utils.unversioned_sys_platform() == 'linux':
160 bld(features='subst',
Davide Pesavento5849ee72023-11-12 20:00:21 -0500161 name='systemd-units',
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500162 source='systemd/nlsr.service.in',
163 target='systemd/nlsr.service')
164
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500165 if bld.env.SPHINX_BUILD:
166 bld(features='sphinx',
167 name='manpages',
168 builder='man',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500169 config='docs/conf.py',
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500170 outdir='docs/manpages',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500171 source=bld.path.ant_glob('docs/manpages/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500172 install_path='${MANDIR}',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500173 version=VERSION_BASE,
174 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500175
176def docs(bld):
177 from waflib import Options
178 Options.commands = ['doxygen', 'sphinx'] + Options.commands
179
180def doxygen(bld):
181 version(bld)
182
183 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500184 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500185
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500186 bld(features='subst',
187 name='doxygen.conf',
188 source=['docs/doxygen.conf.in',
189 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
190 target=['docs/doxygen.conf',
191 'docs/named_data_theme/named_data_footer-with-analytics.html'],
192 VERSION=VERSION,
Davide Pesavento7ae8b082021-10-12 21:45:47 -0400193 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500194 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
195 if os.getenv('GOOGLE_ANALYTICS', None) \
196 else '../docs/named_data_theme/named_data_footer.html',
197 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
198
199 bld(features='doxygen',
200 doxyfile='docs/doxygen.conf',
201 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500202
203def sphinx(bld):
204 version(bld)
205
206 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500207 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
208
209 bld(features='sphinx',
210 config='docs/conf.py',
211 outdir='docs',
212 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500213 version=VERSION_BASE,
214 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500215
216def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500217 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500218 if getattr(Context.g_module, 'VERSION_BASE', None):
219 return
220
221 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500222 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500223
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500224 # first, try to get a version string from git
Davide Pesavento50213142024-04-22 03:44:05 -0400225 version_from_git = ''
Vince Lehmanb722b102014-08-24 16:33:49 -0500226 try:
Davide Pesavento50213142024-04-22 03:44:05 -0400227 cmd = ['git', 'describe', '--abbrev=8', '--always', '--match', f'{GIT_TAG_PREFIX}*']
228 version_from_git = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
229 if version_from_git:
230 if GIT_TAG_PREFIX and version_from_git.startswith(GIT_TAG_PREFIX):
231 Context.g_module.VERSION = version_from_git[len(GIT_TAG_PREFIX):]
232 elif not GIT_TAG_PREFIX and ('.' in version_from_git or '-' in version_from_git):
233 Context.g_module.VERSION = version_from_git
Vince Lehmanb722b102014-08-24 16:33:49 -0500234 else:
Davide Pesavento50213142024-04-22 03:44:05 -0400235 # no tags matched (or we are in a shallow clone)
236 Context.g_module.VERSION = f'{VERSION_BASE}+git.{version_from_git}'
Davide Pesavento5849ee72023-11-12 20:00:21 -0500237 except (OSError, subprocess.SubprocessError):
Vince Lehmanb722b102014-08-24 16:33:49 -0500238 pass
239
Davide Pesavento50213142024-04-22 03:44:05 -0400240 # fallback to the VERSION.info file, if it exists and is not empty
241 version_from_file = ''
242 version_file = ctx.path.find_node('VERSION.info')
243 if version_file is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500244 try:
Davide Pesavento50213142024-04-22 03:44:05 -0400245 version_from_file = version_file.read().strip()
246 except OSError as e:
247 Logs.warn(f'{e.filename} exists but is not readable ({e.strerror})')
248 if version_from_file and not version_from_git:
249 Context.g_module.VERSION = version_from_file
250 return
Vince Lehmanb722b102014-08-24 16:33:49 -0500251
Davide Pesavento50213142024-04-22 03:44:05 -0400252 # update VERSION.info if necessary
253 if version_from_file == Context.g_module.VERSION:
254 # already up-to-date
255 return
256 if version_file is None:
257 version_file = ctx.path.make_node('VERSION.info')
Vince Lehmanb722b102014-08-24 16:33:49 -0500258 try:
Davide Pesavento50213142024-04-22 03:44:05 -0400259 version_file.write(Context.g_module.VERSION)
260 except OSError as e:
261 Logs.warn(f'{e.filename} is not writable ({e.strerror})')
Vince Lehmanb722b102014-08-24 16:33:49 -0500262
263def dist(ctx):
Davide Pesaventofa54ee92023-02-20 04:16:51 -0500264 ctx.algo = 'tar.xz'
Vince Lehmanb722b102014-08-24 16:33:49 -0500265 version(ctx)
266
267def distcheck(ctx):
Davide Pesaventofa54ee92023-02-20 04:16:51 -0500268 ctx.algo = 'tar.xz'
Vince Lehmanb722b102014-08-24 16:33:49 -0500269 version(ctx)