blob: b223288cea21c1fb2c2719d3400bc614fcc9bc3c [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 Pesaventoe28d8752022-03-19 03:55:25 -04003Copyright (c) 2014-2022, 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"
Vince Lehmanb722b102014-08-24 16:33:49 -050027GIT_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')
37 optgrp.add_option('--with-tests', action='store_true', default=False,
38 help='Build unit tests')
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070039 optgrp.add_option('--with-chronosync', action='store_true', default=False,
Davide Pesavento7ae8b082021-10-12 21:45:47 -040040 help='Build with ChronoSync support')
akmhoque05d5fcf2014-04-15 14:58:45 -050041
akmhoque298385a2014-02-13 14:13:09 -060042def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050043 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040044 'default-compiler-flags', 'boost',
Vince Lehmanb722b102014-08-24 16:33:49 -050045 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060046
Davide Pesaventof75bfda2019-11-10 18:34:13 -050047 conf.env.WITH_TESTS = conf.options.with_tests
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070048
Davide Pesavento7ae8b082021-10-12 21:45:47 -040049 conf.find_program('dot', var='DOT', mandatory=False)
50
Davide Pesaventod1f1df82022-03-12 16:40:37 -050051 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
52 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'],
53 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
akmhoque85d88332014-02-17 21:11:21 -060054
Davide Pesaventof75bfda2019-11-10 18:34:13 -050055 boost_libs = ['system', 'iostreams', 'filesystem', 'regex']
56 if conf.env.WITH_TESTS:
Davide Pesaventod1f1df82022-03-12 16:40:37 -050057 boost_libs.append('unit_test_framework')
akmhoque85d88332014-02-17 21:11:21 -060058
dmcoomescf8d0ed2017-02-21 11:39:01 -060059 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventod1f1df82022-03-12 16:40:37 -050060 if conf.env.BOOST_VERSION_NUMBER < 106501:
Davide Pesavento7ae8b082021-10-12 21:45:47 -040061 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
62 'Please upgrade your distribution or manually install a newer version of Boost.\n'
63 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
akmhoque05d5fcf2014-04-15 14:58:45 -050064
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070065 if conf.options.with_chronosync:
Davide Pesaventod1f1df82022-03-12 16:40:37 -050066 conf.check_cfg(package='ChronoSync', args=['ChronoSync >= 0.5.4', '--cflags', '--libs'],
Ashlesh Gawande30d96e42021-03-21 19:15:33 -070067 uselib_store='CHRONOSYNC', pkg_config_path=pkg_config_path)
akmhoque05d5fcf2014-04-15 14:58:45 -050068
Davide Pesaventod1f1df82022-03-12 16:40:37 -050069 conf.check_cfg(package='PSync', args=['PSync >= 0.3.0', '--cflags', '--libs'],
70 uselib_store='PSYNC', pkg_config_path=pkg_config_path)
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050071
Alexander Afanasyev67758b12018-03-06 18:36:44 -050072 conf.check_compiler_flags()
73
Davide Pesaventoe5569912019-01-29 19:39:06 -050074 # Loading "late" to prevent tests from being compiled with profiling flags
Yingdi Yu40cd1c32014-04-17 15:02:17 -070075 conf.load('coverage')
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050076 conf.load('sanitizers')
77
Davide Pesaventof75bfda2019-11-10 18:34:13 -050078 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
Junxiao Shia3a63972022-01-24 02:03:41 +000079 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env.SYSCONFDIR)
Davide Pesaventof75bfda2019-11-10 18:34:13 -050080 # The config header will contain all defines that were added using conf.define()
81 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
82 # will not appear in the config header, but will instead be passed directly to the
83 # compiler on the command line.
Yingdi Yu40cd1c32014-04-17 15:02:17 -070084 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050085
Vince Lehmanb722b102014-08-24 16:33:49 -050086def build(bld):
87 version(bld)
88
Davide Pesaventoe5569912019-01-29 19:39:06 -050089 bld(features='subst',
Alexander Afanasyev67758b12018-03-06 18:36:44 -050090 name='version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050091 source='src/version.hpp.in',
92 target='src/version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050093 VERSION_STRING=VERSION_BASE,
94 VERSION_BUILD=VERSION,
95 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
96 int(VERSION_SPLIT[1]) * 1000 +
97 int(VERSION_SPLIT[2]),
98 VERSION_MAJOR=VERSION_SPLIT[0],
99 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500100 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -0500101
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500102 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700103 target='nlsr-objects',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500104 source=bld.path.ant_glob('src/**/*.cpp',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700105 excl=['src/main.cpp']),
Ashlesh Gawande30d96e42021-03-21 19:15:33 -0700106 use='NDN_CXX BOOST CHRONOSYNC PSYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700107 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500108 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600109
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500110 bld.program(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700111 target='bin/nlsr',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500112 name='nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700113 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500114 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600115
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500116 bld.program(
Vince Lehmanc439d662015-04-27 10:56:00 -0500117 target='bin/nlsrc',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500118 name='nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500119 source='tools/nlsrc.cpp',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500120 use='nlsr-objects')
Vince Lehmanc439d662015-04-27 10:56:00 -0500121
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500122 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700123 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500124
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500125 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
126
127 if Utils.unversioned_sys_platform() == 'linux':
128 bld(features='subst',
129 name='nlsr.service',
130 source='systemd/nlsr.service.in',
131 target='systemd/nlsr.service')
132
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500133 if bld.env.SPHINX_BUILD:
134 bld(features='sphinx',
135 name='manpages',
136 builder='man',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500137 config='docs/conf.py',
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500138 outdir='docs/manpages',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500139 source=bld.path.ant_glob('docs/manpages/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500140 install_path='${MANDIR}',
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500141 version=VERSION_BASE,
142 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500143
144def docs(bld):
145 from waflib import Options
146 Options.commands = ['doxygen', 'sphinx'] + Options.commands
147
148def doxygen(bld):
149 version(bld)
150
151 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500152 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500153
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500154 bld(features='subst',
155 name='doxygen.conf',
156 source=['docs/doxygen.conf.in',
157 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
158 target=['docs/doxygen.conf',
159 'docs/named_data_theme/named_data_footer-with-analytics.html'],
160 VERSION=VERSION,
Davide Pesavento7ae8b082021-10-12 21:45:47 -0400161 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500162 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
163 if os.getenv('GOOGLE_ANALYTICS', None) \
164 else '../docs/named_data_theme/named_data_footer.html',
165 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
166
167 bld(features='doxygen',
168 doxyfile='docs/doxygen.conf',
169 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500170
171def sphinx(bld):
172 version(bld)
173
174 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500175 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
176
177 bld(features='sphinx',
178 config='docs/conf.py',
179 outdir='docs',
180 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesaventof75bfda2019-11-10 18:34:13 -0500181 version=VERSION_BASE,
182 release=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500183
184def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500185 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500186 if getattr(Context.g_module, 'VERSION_BASE', None):
187 return
188
189 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500190 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500191
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500192 # first, try to get a version string from git
193 gotVersionFromGit = False
Vince Lehmanb722b102014-08-24 16:33:49 -0500194 try:
195 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500196 out = subprocess.check_output(cmd, universal_newlines=True).strip()
197 if out:
198 gotVersionFromGit = True
Vince Lehmanb722b102014-08-24 16:33:49 -0500199 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500200 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Vince Lehmanb722b102014-08-24 16:33:49 -0500201 else:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500202 # no tags matched
203 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesaventoa08dc3f2018-05-24 00:40:28 -0400204 except (OSError, subprocess.CalledProcessError):
Vince Lehmanb722b102014-08-24 16:33:49 -0500205 pass
206
Alexander Afanasyev96ebd9b2020-06-01 19:16:52 -0400207 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500208 if not gotVersionFromGit and versionFile is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500209 try:
210 Context.g_module.VERSION = versionFile.read()
211 return
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500212 except EnvironmentError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500213 pass
214
215 # version was obtained from git, update VERSION file if necessary
216 if versionFile is not None:
217 try:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500218 if versionFile.read() == Context.g_module.VERSION:
219 # already up-to-date
220 return
221 except EnvironmentError as e:
222 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500223 else:
Alexander Afanasyev96ebd9b2020-06-01 19:16:52 -0400224 versionFile = ctx.path.make_node('VERSION.info')
Vince Lehmanb722b102014-08-24 16:33:49 -0500225
Vince Lehmanb722b102014-08-24 16:33:49 -0500226 try:
227 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500228 except EnvironmentError as e:
229 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500230
231def dist(ctx):
232 version(ctx)
233
234def distcheck(ctx):
235 version(ctx)