blob: 42635bb2abb8d24bf592ce4f13fc7db6e42b99c9 [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.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
77
78 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050079
Vince Lehmanb722b102014-08-24 16:33:49 -050080def build(bld):
81 version(bld)
82
Davide Pesaventoe5569912019-01-29 19:39:06 -050083 bld(features='subst',
Alexander Afanasyev67758b12018-03-06 18:36:44 -050084 name='version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050085 source='src/version.hpp.in',
86 target='src/version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050087 VERSION_STRING=VERSION_BASE,
88 VERSION_BUILD=VERSION,
89 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
90 int(VERSION_SPLIT[1]) * 1000 +
91 int(VERSION_SPLIT[2]),
92 VERSION_MAJOR=VERSION_SPLIT[0],
93 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050094 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -050095
Alexander Afanasyev67758b12018-03-06 18:36:44 -050096 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -070097 target='nlsr-objects',
Davide Pesaventoe5569912019-01-29 19:39:06 -050098 source=bld.path.ant_glob('src/**/*.cpp',
Yingdi Yu40cd1c32014-04-17 15:02:17 -070099 excl=['src/main.cpp']),
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500100 use='NDN_CXX BOOST SYNC PSYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700101 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500102 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600103
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500104 bld.program(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700105 target='bin/nlsr',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500106 name='nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700107 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500108 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600109
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500110 bld.program(
Vince Lehmanc439d662015-04-27 10:56:00 -0500111 target='bin/nlsrc',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500112 name='nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500113 source='tools/nlsrc.cpp',
Davide Pesaventoe5569912019-01-29 19:39:06 -0500114 use='nlsr-objects')
Vince Lehmanc439d662015-04-27 10:56:00 -0500115
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500116 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500117
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500118 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700119 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500120
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500121 if bld.env.SPHINX_BUILD:
122 bld(features='sphinx',
123 name='manpages',
124 builder='man',
125 outdir='docs/manpages',
126 config='docs/conf.py',
Vince Lehmanc439d662015-04-27 10:56:00 -0500127 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500128 install_path='${MANDIR}',
Vince Lehmanc439d662015-04-27 10:56:00 -0500129 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500130
131def docs(bld):
132 from waflib import Options
133 Options.commands = ['doxygen', 'sphinx'] + Options.commands
134
135def doxygen(bld):
136 version(bld)
137
138 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500139 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500140
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500141 bld(features='subst',
142 name='doxygen.conf',
143 source=['docs/doxygen.conf.in',
144 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
145 target=['docs/doxygen.conf',
146 'docs/named_data_theme/named_data_footer-with-analytics.html'],
147 VERSION=VERSION,
148 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
149 if os.getenv('GOOGLE_ANALYTICS', None) \
150 else '../docs/named_data_theme/named_data_footer.html',
151 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
152
153 bld(features='doxygen',
154 doxyfile='docs/doxygen.conf',
155 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500156
157def sphinx(bld):
158 version(bld)
159
160 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500161 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
162
163 bld(features='sphinx',
164 config='docs/conf.py',
165 outdir='docs',
166 source=bld.path.ant_glob('docs/**/*.rst'),
167 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500168
169def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500170 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500171 if getattr(Context.g_module, 'VERSION_BASE', None):
172 return
173
174 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500175 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500176
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500177 # first, try to get a version string from git
178 gotVersionFromGit = False
Vince Lehmanb722b102014-08-24 16:33:49 -0500179 try:
180 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500181 out = subprocess.check_output(cmd, universal_newlines=True).strip()
182 if out:
183 gotVersionFromGit = True
Vince Lehmanb722b102014-08-24 16:33:49 -0500184 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500185 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Vince Lehmanb722b102014-08-24 16:33:49 -0500186 else:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500187 # no tags matched
188 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesaventoa08dc3f2018-05-24 00:40:28 -0400189 except (OSError, subprocess.CalledProcessError):
Vince Lehmanb722b102014-08-24 16:33:49 -0500190 pass
191
192 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500193 if not gotVersionFromGit and versionFile is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500194 try:
195 Context.g_module.VERSION = versionFile.read()
196 return
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500197 except EnvironmentError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500198 pass
199
200 # version was obtained from git, update VERSION file if necessary
201 if versionFile is not None:
202 try:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500203 if versionFile.read() == Context.g_module.VERSION:
204 # already up-to-date
205 return
206 except EnvironmentError as e:
207 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500208 else:
209 versionFile = ctx.path.make_node('VERSION')
210
Vince Lehmanb722b102014-08-24 16:33:49 -0500211 try:
212 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500213 except EnvironmentError as e:
214 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500215
216def dist(ctx):
217 version(ctx)
218
219def distcheck(ctx):
220 version(ctx)