blob: 919b827a591cd3858cd88b4fc4f6fe20e44abca5 [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
Ashlesh Gawande350d5842018-03-02 13:15:25 -060023VERSION = "0.4.2"
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
Alexander Afanasyev67758b12018-03-06 18:36:44 -050067 conf.check_compiler_flags()
68
Yingdi Yu40cd1c32014-04-17 15:02:17 -070069 conf.load('coverage')
70
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050071 conf.load('sanitizers')
72
Yingdi Yu40cd1c32014-04-17 15:02:17 -070073 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
74
75 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050076
akmhoque298385a2014-02-13 14:13:09 -060077
Vince Lehmanb722b102014-08-24 16:33:49 -050078def build(bld):
79 version(bld)
80
81 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',
85 install_path=None,
86 VERSION_STRING=VERSION_BASE,
87 VERSION_BUILD=VERSION,
88 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
89 int(VERSION_SPLIT[1]) * 1000 +
90 int(VERSION_SPLIT[2]),
91 VERSION_MAJOR=VERSION_SPLIT[0],
92 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050093 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -050094
Alexander Afanasyev67758b12018-03-06 18:36:44 -050095 bld.objects(
Yingdi Yu40cd1c32014-04-17 15:02:17 -070096 target='nlsr-objects',
Yingdi Yu40cd1c32014-04-17 15:02:17 -070097 source=bld.path.ant_glob(['src/**/*.cpp'],
98 excl=['src/main.cpp']),
dmcoomescf8d0ed2017-02-21 11:39:01 -060099 use='NDN_CXX BOOST SYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700100 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500101 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600102
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500103 bld.program(
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700104 target='bin/nlsr',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500105 name='nlsr',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700106 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500107 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600108
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500109 bld.program(
Vince Lehmanc439d662015-04-27 10:56:00 -0500110 target='bin/nlsrc',
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500111 name='nlsrc',
Vince Lehmanc439d662015-04-27 10:56:00 -0500112 source='tools/nlsrc.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500113 use='nlsr-objects BOOST')
Vince Lehmanc439d662015-04-27 10:56:00 -0500114
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500115 bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf')
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500116
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500117 if bld.env.WITH_TESTS:
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700118 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500119
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500120 if bld.env.SPHINX_BUILD:
121 bld(features='sphinx',
122 name='manpages',
123 builder='man',
124 outdir='docs/manpages',
125 config='docs/conf.py',
Vince Lehmanc439d662015-04-27 10:56:00 -0500126 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500127 install_path='${MANDIR}',
Vince Lehmanc439d662015-04-27 10:56:00 -0500128 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500129
130def docs(bld):
131 from waflib import Options
132 Options.commands = ['doxygen', 'sphinx'] + Options.commands
133
134def doxygen(bld):
135 version(bld)
136
137 if not bld.env.DOXYGEN:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500138 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
Vince Lehmanb722b102014-08-24 16:33:49 -0500139
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500140 bld(features='subst',
141 name='doxygen.conf',
142 source=['docs/doxygen.conf.in',
143 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
144 target=['docs/doxygen.conf',
145 'docs/named_data_theme/named_data_footer-with-analytics.html'],
146 VERSION=VERSION,
147 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
148 if os.getenv('GOOGLE_ANALYTICS', None) \
149 else '../docs/named_data_theme/named_data_footer.html',
150 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
151
152 bld(features='doxygen',
153 doxyfile='docs/doxygen.conf',
154 use='doxygen.conf')
Vince Lehmanb722b102014-08-24 16:33:49 -0500155
156def sphinx(bld):
157 version(bld)
158
159 if not bld.env.SPHINX_BUILD:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500160 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
161
162 bld(features='sphinx',
163 config='docs/conf.py',
164 outdir='docs',
165 source=bld.path.ant_glob('docs/**/*.rst'),
166 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500167
168def version(ctx):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500169 # don't execute more than once
Vince Lehmanb722b102014-08-24 16:33:49 -0500170 if getattr(Context.g_module, 'VERSION_BASE', None):
171 return
172
173 Context.g_module.VERSION_BASE = Context.g_module.VERSION
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500174 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
Vince Lehmanb722b102014-08-24 16:33:49 -0500175
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500176 # first, try to get a version string from git
177 gotVersionFromGit = False
Vince Lehmanb722b102014-08-24 16:33:49 -0500178 try:
179 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500180 out = subprocess.check_output(cmd, universal_newlines=True).strip()
181 if out:
182 gotVersionFromGit = True
Vince Lehmanb722b102014-08-24 16:33:49 -0500183 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500184 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Vince Lehmanb722b102014-08-24 16:33:49 -0500185 else:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500186 # no tags matched
187 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
188 except subprocess.CalledProcessError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500189 pass
190
191 versionFile = ctx.path.find_node('VERSION')
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500192 if not gotVersionFromGit and versionFile is not None:
Vince Lehmanb722b102014-08-24 16:33:49 -0500193 try:
194 Context.g_module.VERSION = versionFile.read()
195 return
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500196 except EnvironmentError:
Vince Lehmanb722b102014-08-24 16:33:49 -0500197 pass
198
199 # version was obtained from git, update VERSION file if necessary
200 if versionFile is not None:
201 try:
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500202 if versionFile.read() == Context.g_module.VERSION:
203 # already up-to-date
204 return
205 except EnvironmentError as e:
206 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500207 else:
208 versionFile = ctx.path.make_node('VERSION')
209
Vince Lehmanb722b102014-08-24 16:33:49 -0500210 try:
211 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev67758b12018-03-06 18:36:44 -0500212 except EnvironmentError as e:
213 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
Vince Lehmanb722b102014-08-24 16:33:49 -0500214
215def dist(ctx):
216 version(ctx)
217
218def distcheck(ctx):
219 version(ctx)