blob: 82252a64209be95010fe6f2861f3fe6ff7505542 [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
3"""
Ashlesh Gawande39cf81a2018-02-22 13:37:07 -06004Copyright (c) 2014-2018, The University of Memphis,
Vince Lehmanc2e51f62015-01-20 15:03:11 -06005 Regents of the University of California,
6 Arizona Board of Regents.
Yingdi Yu40cd1c32014-04-17 15:02:17 -07007
8This file is part of NLSR (Named-data Link State Routing).
9See AUTHORS.md for complete list of NLSR authors and contributors.
10
11NLSR is free software: you can redistribute it and/or modify it under the terms
12of the GNU General Public License as published by the Free Software Foundation,
13either version 3 of the License, or (at your option) any later version.
14
15NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
16without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17PURPOSE. See the GNU General Public License for more details.
18
19You should have received a copy of the GNU General Public License along with
20NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
21"""
22
Saurab Dulal30122032018-05-07 23:20:59 +000023VERSION = "0.4.3"
sfayer93d9ec32014-12-04 23:34:41 +000024APPNAME = "nlsr"
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040025BUGREPORT = "https://redmine.named-data.net/projects/nlsr"
26URL = "https://named-data.net/doc/NLSR/"
Vince Lehmanb722b102014-08-24 16:33:49 -050027GIT_TAG_PREFIX = "NLSR-"
akmhoque298385a2014-02-13 14:13:09 -060028
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040029from waflib import Logs, Utils, Context
Alexander Afanasyev67758b12018-03-06 18:36:44 -050030import os, subprocess
akmhoque298385a2014-02-13 14:13:09 -060031
32def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070033 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050034 opt.load(['default-compiler-flags', 'coverage', 'sanitizers',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040035 'boost', 'doxygen', 'sphinx_build'],
Yingdi Yu40cd1c32014-04-17 15:02:17 -070036 tooldir=['.waf-tools'])
akmhoque298385a2014-02-13 14:13:09 -060037
Yingdi Yu40cd1c32014-04-17 15:02:17 -070038 nlsropt = opt.add_option_group('NLSR Options')
Alexander Afanasyev67758b12018-03-06 18:36:44 -050039 nlsropt.add_option('--with-tests', action='store_true', default=False, help='build unit tests')
akmhoque05d5fcf2014-04-15 14:58:45 -050040
akmhoque298385a2014-02-13 14:13:09 -060041def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050042 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040043 'default-compiler-flags', 'boost',
Vince Lehmanb722b102014-08-24 16:33:49 -050044 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060045
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070046 if 'PKG_CONFIG_PATH' not in os.environ:
47 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
48
akmhoquec8a10f72014-04-25 18:42:55 -050049 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
Vince Lehmanb45eed22015-01-13 14:58:07 -060050 uselib_store='NDN_CXX', mandatory=True)
akmhoque85d88332014-02-17 21:11:21 -060051
dmcoomescf8d0ed2017-02-21 11:39:01 -060052 boost_libs = 'system chrono program_options iostreams thread regex filesystem log log_setup'
Yingdi Yu40cd1c32014-04-17 15:02:17 -070053 if conf.options.with_tests:
Alexander Afanasyev67758b12018-03-06 18:36:44 -050054 conf.env['WITH_TESTS'] = True
55 conf.define('WITH_TESTS', 1)
Yingdi Yu40cd1c32014-04-17 15:02:17 -070056 boost_libs += ' unit_test_framework'
akmhoque85d88332014-02-17 21:11:21 -060057
dmcoomescf8d0ed2017-02-21 11:39:01 -060058 conf.check_boost(lib=boost_libs, mt=True)
Ashlesh Gawande39cf81a2018-02-22 13:37:07 -060059 if conf.env.BOOST_VERSION_NUMBER < 105400:
Alexander Afanasyev67758b12018-03-06 18:36:44 -050060 conf.fatal('Minimum required Boost version is 1.54.0\n'
61 'Please upgrade your distribution or manually install a newer version of Boost'
62 ' (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)')
akmhoque05d5fcf2014-04-15 14:58:45 -050063
Ashlesh Gawande39cf81a2018-02-22 13:37:07 -060064 conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'],
Ashlesh Gawande415676b2016-12-22 00:26:23 -060065 uselib_store='SYNC', mandatory=True)
akmhoque05d5fcf2014-04-15 14:58:45 -050066
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -050067 conf.check_cfg(package='PSync', args=['--cflags', '--libs'],
68 uselib_store='PSYNC', mandatory=True)
69
Alexander Afanasyev67758b12018-03-06 18:36:44 -050070 conf.check_compiler_flags()
71
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
akmhoque298385a2014-02-13 14:13:09 -060080
Vince Lehmanb722b102014-08-24 16:33:49 -050081def build(bld):
82 version(bld)
83
84 bld(features="subst",
Alexander Afanasyev67758b12018-03-06 18:36:44 -050085 name='version.hpp',
Vince Lehmanb722b102014-08-24 16:33:49 -050086 source='src/version.hpp.in',
87 target='src/version.hpp',
88 install_path=None,
89 VERSION_STRING=VERSION_BASE,
90 VERSION_BUILD=VERSION,
91 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
92 int(VERSION_SPLIT[1]) * 1000 +
93 int(VERSION_SPLIT[2]),
94 VERSION_MAJOR=VERSION_SPLIT[0],
95 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050096 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -050097
Alexander Afanasyev67758b12018-03-06 18:36:44 -050098 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -070099 target='nlsr-objects',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700100 source=bld.path.ant_glob(['src/**/*.cpp'],
101 excl=['src/main.cpp']),
Ashlesh Gawande32ec3fd2018-07-18 13:42:32 -0500102 use='NDN_CXX BOOST SYNC PSYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700103 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500104 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600105
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500106 bld.program(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700107 target='bin/nlsr',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500108 name='nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700109 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500110 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600111
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500112 bld.program(
Vince Lehmanc439d662015-04-27 10:56:00 -0500113 target='bin/nlsrc',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500114 name='nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500115 source='tools/nlsrc.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500116 use='nlsr-objects BOOST')
Vince Lehmanc439d662015-04-27 10:56:00 -0500117
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500118 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500119
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500120 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700121 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500122
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500123 if bld.env.SPHINX_BUILD:
124 bld(features='sphinx',
125 name='manpages',
126 builder='man',
127 outdir='docs/manpages',
128 config='docs/conf.py',
Vince Lehmanc439d662015-04-27 10:56:00 -0500129 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500130 install_path='${MANDIR}',
Vince Lehmanc439d662015-04-27 10:56:00 -0500131 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500132
133def docs(bld):
134 from waflib import Options
135 Options.commands = ['doxygen', 'sphinx'] + Options.commands
136
137def doxygen(bld):
138 version(bld)
139
140 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500141 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500142
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500143 bld(features='subst',
144 name='doxygen.conf',
145 source=['docs/doxygen.conf.in',
146 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
147 target=['docs/doxygen.conf',
148 'docs/named_data_theme/named_data_footer-with-analytics.html'],
149 VERSION=VERSION,
150 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
151 if os.getenv('GOOGLE_ANALYTICS', None) \
152 else '../docs/named_data_theme/named_data_footer.html',
153 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
154
155 bld(features='doxygen',
156 doxyfile='docs/doxygen.conf',
157 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500158
159def sphinx(bld):
160 version(bld)
161
162 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500163 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
164
165 bld(features='sphinx',
166 config='docs/conf.py',
167 outdir='docs',
168 source=bld.path.ant_glob('docs/**/*.rst'),
169 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500170
171def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500172 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500173 if getattr(Context.g_module, 'VERSION_BASE', None):
174 return
175
176 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500177 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500178
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500179 # first, try to get a version string from git
180 gotVersionFromGit = False
Vince Lehmanb722b102014-08-24 16:33:49 -0500181 try:
182 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500183 out = subprocess.check_output(cmd, universal_newlines=True).strip()
184 if out:
185 gotVersionFromGit = True
Vince Lehmanb722b102014-08-24 16:33:49 -0500186 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500187 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Vince Lehmanb722b102014-08-24 16:33:49 -0500188 else:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500189 # no tags matched
190 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesaventoa08dc3f2018-05-24 00:40:28 -0400191 except (OSError, subprocess.CalledProcessError):
Vince Lehmanb722b102014-08-24 16:33:49 -0500192 pass
193
194 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500195 if not gotVersionFromGit and versionFile is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500196 try:
197 Context.g_module.VERSION = versionFile.read()
198 return
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500199 except EnvironmentError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500200 pass
201
202 # version was obtained from git, update VERSION file if necessary
203 if versionFile is not None:
204 try:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500205 if versionFile.read() == Context.g_module.VERSION:
206 # already up-to-date
207 return
208 except EnvironmentError as e:
209 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500210 else:
211 versionFile = ctx.path.make_node('VERSION')
212
Vince Lehmanb722b102014-08-24 16:33:49 -0500213 try:
214 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500215 except EnvironmentError as e:
216 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500217
218def dist(ctx):
219 version(ctx)
220
221def distcheck(ctx):
222 version(ctx)