blob: 52c98826cdcbf8a8a8862795ee722dfa3ffd26c6 [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 Pesaventoe5569912019-01-29 19:39:06 -05003Copyright (c) 2014-2019, 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
Saurab Dulal30122032018-05-07 23:20:59 +000022VERSION = "0.4.3"
sfayer93d9ec32014-12-04 23:34:41 +000023APPNAME = "nlsr"
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040024BUGREPORT = "https://redmine.named-data.net/projects/nlsr"
25URL = "https://named-data.net/doc/NLSR/"
Vince Lehmanb722b102014-08-24 16:33:49 -050026GIT_TAG_PREFIX = "NLSR-"
akmhoque298385a2014-02-13 14:13:09 -060027
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040028from waflib import Logs, Utils, Context
Alexander Afanasyev67758b12018-03-06 18:36:44 -050029import os, subprocess
akmhoque298385a2014-02-13 14:13:09 -060030
31def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070032 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050033 opt.load(['default-compiler-flags', 'coverage', 'sanitizers',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040034 'boost', 'doxygen', 'sphinx_build'],
Davide Pesaventoe5569912019-01-29 19:39:06 -050035 tooldir=['.waf-tools'])
akmhoque298385a2014-02-13 14:13:09 -060036
Yingdi Yu40cd1c32014-04-17 15:02:17 -070037 nlsropt = opt.add_option_group('NLSR Options')
Alexander Afanasyev67758b12018-03-06 18:36:44 -050038 nlsropt.add_option('--with-tests', action='store_true', default=False, help='build unit tests')
akmhoque05d5fcf2014-04-15 14:58:45 -050039
akmhoque298385a2014-02-13 14:13:09 -060040def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050041 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040042 'default-compiler-flags', 'boost',
Vince Lehmanb722b102014-08-24 16:33:49 -050043 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060044
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070045 if 'PKG_CONFIG_PATH' not in os.environ:
46 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
47
akmhoquec8a10f72014-04-25 18:42:55 -050048 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
Vince Lehmanb45eed22015-01-13 14:58:07 -060049 uselib_store='NDN_CXX', mandatory=True)
akmhoque85d88332014-02-17 21:11:21 -060050
dmcoomescf8d0ed2017-02-21 11:39:01 -060051 boost_libs = 'system chrono program_options iostreams thread regex filesystem log log_setup'
Yingdi Yu40cd1c32014-04-17 15:02:17 -070052 if conf.options.with_tests:
Alexander Afanasyev67758b12018-03-06 18:36:44 -050053 conf.env['WITH_TESTS'] = True
54 conf.define('WITH_TESTS', 1)
Yingdi Yu40cd1c32014-04-17 15:02:17 -070055 boost_libs += ' unit_test_framework'
akmhoque85d88332014-02-17 21:11:21 -060056
dmcoomescf8d0ed2017-02-21 11:39:01 -060057 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventoe5569912019-01-29 19:39:06 -050058 if conf.env.BOOST_VERSION_NUMBER < 105800:
59 conf.fatal('Minimum required Boost version is 1.58.0\n'
Alexander Afanasyev67758b12018-03-06 18:36:44 -050060 'Please upgrade your distribution or manually install a newer version of Boost'
61 ' (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)')
akmhoque05d5fcf2014-04-15 14:58:45 -050062
Ashlesh Gawande39cf81a2018-02-22 13:37:07 -060063 conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'],
Ashlesh Gawande415676b2016-12-22 00:26:23 -060064 uselib_store='SYNC', mandatory=True)
akmhoque05d5fcf2014-04-15 14:58:45 -050065
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050066 conf.check_cfg(package='PSync', args=['--cflags', '--libs'],
67 uselib_store='PSYNC', mandatory=True)
68
Alexander Afanasyev67758b12018-03-06 18:36:44 -050069 conf.check_compiler_flags()
70
Davide Pesaventoe5569912019-01-29 19:39:06 -050071 # Loading "late" to prevent tests from being compiled with profiling flags
Yingdi Yu40cd1c32014-04-17 15:02:17 -070072 conf.load('coverage')
73
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050074 conf.load('sanitizers')
75
Yingdi Yu40cd1c32014-04-17 15:02:17 -070076 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050077
Vince Lehmanb722b102014-08-24 16:33:49 -050078def build(bld):
79 version(bld)
80
Davide Pesaventoe5569912019-01-29 19:39:06 -050081 bld(features='subst',
Alexander Afanasyev67758b12018-03-06 18:36:44 -050082 name='version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050083 source='src/version.hpp.in',
84 target='src/version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050085 VERSION_STRING=VERSION_BASE,
86 VERSION_BUILD=VERSION,
87 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
88 int(VERSION_SPLIT[1]) * 1000 +
89 int(VERSION_SPLIT[2]),
90 VERSION_MAJOR=VERSION_SPLIT[0],
91 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050092 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -050093
Alexander Afanasyev67758b12018-03-06 18:36:44 -050094 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -070095 target='nlsr-objects',
Davide Pesaventoe5569912019-01-29 19:39:06 -050096 source=bld.path.ant_glob('src/**/*.cpp',
Yingdi Yu40cd1c32014-04-17 15:02:17 -070097 excl=['src/main.cpp']),
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050098 use='NDN_CXX BOOST SYNC PSYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -070099 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500100 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600101
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500102 bld.program(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700103 target='bin/nlsr',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500104 name='nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700105 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500106 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600107
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500108 bld.program(
Vince Lehmanc439d662015-04-27 10:56:00 -0500109 target='bin/nlsrc',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500110 name='nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500111 source='tools/nlsrc.cpp',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500112 use='nlsr-objects')
Vince Lehmanc439d662015-04-27 10:56:00 -0500113
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500114 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700115 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500116
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500117 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
118
119 if Utils.unversioned_sys_platform() == 'linux':
120 bld(features='subst',
121 name='nlsr.service',
122 source='systemd/nlsr.service.in',
123 target='systemd/nlsr.service')
124
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500125 if bld.env.SPHINX_BUILD:
126 bld(features='sphinx',
127 name='manpages',
128 builder='man',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500129 config='docs/conf.py',
Davide Pesavento0da3eab2019-01-31 01:10:00 -0500130 outdir='docs/manpages',
Vince Lehmanc439d662015-04-27 10:56:00 -0500131 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500132 install_path='${MANDIR}',
Vince Lehmanc439d662015-04-27 10:56:00 -0500133 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500134
135def docs(bld):
136 from waflib import Options
137 Options.commands = ['doxygen', 'sphinx'] + Options.commands
138
139def doxygen(bld):
140 version(bld)
141
142 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500143 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500144
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500145 bld(features='subst',
146 name='doxygen.conf',
147 source=['docs/doxygen.conf.in',
148 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
149 target=['docs/doxygen.conf',
150 'docs/named_data_theme/named_data_footer-with-analytics.html'],
151 VERSION=VERSION,
152 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
153 if os.getenv('GOOGLE_ANALYTICS', None) \
154 else '../docs/named_data_theme/named_data_footer.html',
155 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
156
157 bld(features='doxygen',
158 doxyfile='docs/doxygen.conf',
159 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500160
161def sphinx(bld):
162 version(bld)
163
164 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500165 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
166
167 bld(features='sphinx',
168 config='docs/conf.py',
169 outdir='docs',
170 source=bld.path.ant_glob('docs/**/*.rst'),
171 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500172
173def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500174 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500175 if getattr(Context.g_module, 'VERSION_BASE', None):
176 return
177
178 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500179 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500180
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500181 # first, try to get a version string from git
182 gotVersionFromGit = False
Vince Lehmanb722b102014-08-24 16:33:49 -0500183 try:
184 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500185 out = subprocess.check_output(cmd, universal_newlines=True).strip()
186 if out:
187 gotVersionFromGit = True
Vince Lehmanb722b102014-08-24 16:33:49 -0500188 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500189 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Vince Lehmanb722b102014-08-24 16:33:49 -0500190 else:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500191 # no tags matched
192 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesaventoa08dc3f2018-05-24 00:40:28 -0400193 except (OSError, subprocess.CalledProcessError):
Vince Lehmanb722b102014-08-24 16:33:49 -0500194 pass
195
196 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500197 if not gotVersionFromGit and versionFile is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500198 try:
199 Context.g_module.VERSION = versionFile.read()
200 return
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500201 except EnvironmentError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500202 pass
203
204 # version was obtained from git, update VERSION file if necessary
205 if versionFile is not None:
206 try:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500207 if versionFile.read() == Context.g_module.VERSION:
208 # already up-to-date
209 return
210 except EnvironmentError as e:
211 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500212 else:
213 versionFile = ctx.path.make_node('VERSION')
214
Vince Lehmanb722b102014-08-24 16:33:49 -0500215 try:
216 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500217 except EnvironmentError as e:
218 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500219
220def dist(ctx):
221 version(ctx)
222
223def distcheck(ctx):
224 version(ctx)