blob: 1f25960b0ee8fb32bad1c1b6cac213a2b29eb515 [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"""
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -05004Copyright (c) 2014-2017, 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
Muktadir R Chowdhuryf023a882017-03-14 10:02:05 -050023VERSION = '0.3.2'
sfayer93d9ec32014-12-04 23:34:41 +000024APPNAME = "nlsr"
Vince Lehmanb722b102014-08-24 16:33:49 -050025BUGREPORT = "http://redmine.named-data.net/projects/nlsr"
26URL = "http://named-data.net/doc/NLSR/"
27GIT_TAG_PREFIX = "NLSR-"
akmhoque298385a2014-02-13 14:13:09 -060028
Vince Lehmanb722b102014-08-24 16:33:49 -050029from waflib import Build, Logs, Utils, Task, TaskGen, Configure, Context
akmhoque05d5fcf2014-04-15 14:58:45 -050030from waflib.Tools import c_preproc
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070031import os
akmhoque298385a2014-02-13 14:13:09 -060032
33def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070034 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050035 opt.load(['default-compiler-flags', 'coverage', 'sanitizers',
Ashlesh Gawande415676b2016-12-22 00:26:23 -060036 'boost', 'doxygen', 'sphinx_build'],
Yingdi Yu40cd1c32014-04-17 15:02:17 -070037 tooldir=['.waf-tools'])
akmhoque298385a2014-02-13 14:13:09 -060038
Yingdi Yu40cd1c32014-04-17 15:02:17 -070039 nlsropt = opt.add_option_group('NLSR Options')
akmhoque05d5fcf2014-04-15 14:58:45 -050040
Yingdi Yu40cd1c32014-04-17 15:02:17 -070041 nlsropt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
42 help='''build unit tests''')
akmhoque298385a2014-02-13 14:13:09 -060043
akmhoque05d5fcf2014-04-15 14:58:45 -050044
akmhoque298385a2014-02-13 14:13:09 -060045def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050046 conf.load(['compiler_cxx', 'gnu_dirs',
Ashlesh Gawande415676b2016-12-22 00:26:23 -060047 'boost', 'default-compiler-flags',
Vince Lehmanb722b102014-08-24 16:33:49 -050048 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060049
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070050 if 'PKG_CONFIG_PATH' not in os.environ:
51 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
52
akmhoquec8a10f72014-04-25 18:42:55 -050053 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
Vince Lehmanb45eed22015-01-13 14:58:07 -060054 uselib_store='NDN_CXX', mandatory=True)
akmhoque85d88332014-02-17 21:11:21 -060055
akmhoque674b0b12014-05-20 14:33:28 -050056 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'],
57 uselib_store='LOG4CXX', mandatory=True)
58
59 boost_libs = 'system chrono program_options iostreams thread regex filesystem'
Yingdi Yu40cd1c32014-04-17 15:02:17 -070060 if conf.options.with_tests:
61 conf.env['WITH_TESTS'] = 1
62 conf.define('WITH_TESTS', 1);
63 boost_libs += ' unit_test_framework'
akmhoque85d88332014-02-17 21:11:21 -060064
Yingdi Yu40cd1c32014-04-17 15:02:17 -070065 conf.check_boost(lib=boost_libs)
akmhoque298385a2014-02-13 14:13:09 -060066
akmhoquec8a10f72014-04-25 18:42:55 -050067 if conf.env.BOOST_VERSION_NUMBER < 104800:
akmhoquefdbddb12014-05-02 18:35:19 -050068 Logs.error("Minimum required boost version is 1.48.0")
Yingdi Yu40cd1c32014-04-17 15:02:17 -070069 Logs.error("Please upgrade your distribution or install custom boost libraries")
akmhoque05d5fcf2014-04-15 14:58:45 -050070 return
71
Ashlesh Gawande7600c902017-06-21 13:28:35 -050072 conf.check_cfg(package='ChronoSync', args=['ChronoSync >= 0.3', '--cflags', '--libs'],
Ashlesh Gawande415676b2016-12-22 00:26:23 -060073 uselib_store='SYNC', mandatory=True)
akmhoque05d5fcf2014-04-15 14:58:45 -050074
Yingdi Yu40cd1c32014-04-17 15:02:17 -070075 conf.load('coverage')
76
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050077 conf.load('sanitizers')
78
Yingdi Yu40cd1c32014-04-17 15:02:17 -070079 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
80
81 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050082
akmhoque298385a2014-02-13 14:13:09 -060083
Vince Lehmanb722b102014-08-24 16:33:49 -050084def build(bld):
85 version(bld)
86
87 bld(features="subst",
88 name='version',
89 source='src/version.hpp.in',
90 target='src/version.hpp',
91 install_path=None,
92 VERSION_STRING=VERSION_BASE,
93 VERSION_BUILD=VERSION,
94 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
95 int(VERSION_SPLIT[1]) * 1000 +
96 int(VERSION_SPLIT[2]),
97 VERSION_MAJOR=VERSION_SPLIT[0],
98 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050099 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -0500100
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700101 nlsr_objects = bld(
102 target='nlsr-objects',
103 name='nlsr-objects',
104 features='cxx',
105 source=bld.path.ant_glob(['src/**/*.cpp'],
106 excl=['src/main.cpp']),
Ashlesh Gawande415676b2016-12-22 00:26:23 -0600107 use='NDN_CXX BOOST LOG4CXX SYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700108 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500109 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600110
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700111 nlsr = bld(
112 target='bin/nlsr',
113 features='cxx cxxprogram',
114 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500115 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600116
Vince Lehmanc439d662015-04-27 10:56:00 -0500117 nlsrc = bld(
118 target='bin/nlsrc',
119 features='cxx cxxprogram',
120 source='tools/nlsrc.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500121 use='nlsr-objects BOOST')
Vince Lehmanc439d662015-04-27 10:56:00 -0500122
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500123 bld(features="subst",
124 source='nlsr.conf',
125 target='nlsr.conf.sample',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500126 install_path="${SYSCONFDIR}/ndn")
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500127
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700128 if bld.env['WITH_TESTS']:
129 bld.recurse('tests')
130 bld.recurse('tests-integrated')
Vince Lehmanb722b102014-08-24 16:33:49 -0500131
Vince Lehmanc439d662015-04-27 10:56:00 -0500132 if bld.env['SPHINX_BUILD']:
133 bld(features="sphinx",
134 builder="man",
135 outdir="docs/manpages",
136 config="docs/conf.py",
137 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
138 install_path="${MANDIR}/",
139 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500140
141def docs(bld):
142 from waflib import Options
143 Options.commands = ['doxygen', 'sphinx'] + Options.commands
144
145def doxygen(bld):
146 version(bld)
147
148 if not bld.env.DOXYGEN:
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500149 Logs.error("ERROR: cannot build documentation (`doxygen' not found in $PATH)")
Vince Lehmanb722b102014-08-24 16:33:49 -0500150 else:
151 bld(features="subst",
152 name="doxygen-conf",
153 source="docs/doxygen.conf.in",
154 target="docs/doxygen.conf",
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500155 VERSION=VERSION_BASE)
Vince Lehmanb722b102014-08-24 16:33:49 -0500156
157 bld(features="doxygen",
158 doxyfile='docs/doxygen.conf',
159 use="doxygen-conf")
160
161def sphinx(bld):
162 version(bld)
163
164 if not bld.env.SPHINX_BUILD:
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500165 bld.fatal("ERROR: cannot build documentation (`sphinx-build' not found in $PATH)")
Vince Lehmanb722b102014-08-24 16:33:49 -0500166 else:
167 bld(features="sphinx",
168 outdir="docs",
169 source=bld.path.ant_glob('docs/**/*.rst'),
170 config="docs/conf.py",
171 VERSION=VERSION_BASE)
172
173def version(ctx):
174 if getattr(Context.g_module, 'VERSION_BASE', None):
175 return
176
177 Context.g_module.VERSION_BASE = Context.g_module.VERSION
178 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
179
180 didGetVersion = False
181 try:
182 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
183 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
184 stderr=None, stdin=None)
Alexander Afanasyevc0b97af2014-09-01 13:23:50 -0700185 out = str(p.communicate()[0].strip())
Vince Lehmanb722b102014-08-24 16:33:49 -0500186 didGetVersion = (p.returncode == 0 and out != "")
187 if didGetVersion:
188 if out.startswith(GIT_TAG_PREFIX):
189 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
190 else:
191 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
192 except OSError:
193 pass
194
195 versionFile = ctx.path.find_node('VERSION')
196
197 if not didGetVersion and versionFile is not None:
198 try:
199 Context.g_module.VERSION = versionFile.read()
200 return
201 except (OSError, IOError):
202 pass
203
204 # version was obtained from git, update VERSION file if necessary
205 if versionFile is not None:
206 try:
207 version = versionFile.read()
208 if version == Context.g_module.VERSION:
209 return # no need to update
210 except (OSError, IOError):
211 Logs.warn("VERSION file exists, but not readable")
212 else:
213 versionFile = ctx.path.make_node('VERSION')
214
215 if versionFile is None:
216 return
217
218 try:
219 versionFile.write(Context.g_module.VERSION)
220 except (OSError, IOError):
221 Logs.warn("VERSION file is not writeable")
222
223def dist(ctx):
224 version(ctx)
225
226def distcheck(ctx):
227 version(ctx)