blob: 76adf7acd7d8e9dbb1956ccbc53241cb0ce72e40 [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
Ashlesh Gawande9e955bc2017-11-30 17:33:03 -060023VERSION = "0.4.0"
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 Afanasyevfb2adee2015-03-30 10:56:55 -070030import os
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')
akmhoque05d5fcf2014-04-15 14:58:45 -050039
Yingdi Yu40cd1c32014-04-17 15:02:17 -070040 nlsropt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
41 help='''build unit tests''')
akmhoque298385a2014-02-13 14:13:09 -060042
akmhoque05d5fcf2014-04-15 14:58:45 -050043
akmhoque298385a2014-02-13 14:13:09 -060044def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050045 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesavento6ebfd7c2017-08-26 17:52:54 -040046 'default-compiler-flags', 'boost',
Vince Lehmanb722b102014-08-24 16:33:49 -050047 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060048
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070049 if 'PKG_CONFIG_PATH' not in os.environ:
50 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
51
akmhoquec8a10f72014-04-25 18:42:55 -050052 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
Vince Lehmanb45eed22015-01-13 14:58:07 -060053 uselib_store='NDN_CXX', mandatory=True)
akmhoque85d88332014-02-17 21:11:21 -060054
dmcoomescf8d0ed2017-02-21 11:39:01 -060055 boost_libs = 'system chrono program_options iostreams thread regex filesystem log log_setup'
Yingdi Yu40cd1c32014-04-17 15:02:17 -070056 if conf.options.with_tests:
57 conf.env['WITH_TESTS'] = 1
58 conf.define('WITH_TESTS', 1);
59 boost_libs += ' unit_test_framework'
akmhoque85d88332014-02-17 21:11:21 -060060
dmcoomescf8d0ed2017-02-21 11:39:01 -060061 conf.check_boost(lib=boost_libs, mt=True)
akmhoque298385a2014-02-13 14:13:09 -060062
akmhoquec8a10f72014-04-25 18:42:55 -050063 if conf.env.BOOST_VERSION_NUMBER < 104800:
akmhoquefdbddb12014-05-02 18:35:19 -050064 Logs.error("Minimum required boost version is 1.48.0")
Yingdi Yu40cd1c32014-04-17 15:02:17 -070065 Logs.error("Please upgrade your distribution or install custom boost libraries")
akmhoque05d5fcf2014-04-15 14:58:45 -050066 return
67
Ashlesh Gawande7600c902017-06-21 13:28:35 -050068 conf.check_cfg(package='ChronoSync', args=['ChronoSync >= 0.3', '--cflags', '--libs'],
Ashlesh Gawande415676b2016-12-22 00:26:23 -060069 uselib_store='SYNC', mandatory=True)
akmhoque05d5fcf2014-04-15 14:58:45 -050070
Yingdi Yu40cd1c32014-04-17 15:02:17 -070071 conf.load('coverage')
72
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050073 conf.load('sanitizers')
74
Yingdi Yu40cd1c32014-04-17 15:02:17 -070075 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
76
77 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050078
akmhoque298385a2014-02-13 14:13:09 -060079
Vince Lehmanb722b102014-08-24 16:33:49 -050080def build(bld):
81 version(bld)
82
83 bld(features="subst",
84 name='version',
85 source='src/version.hpp.in',
86 target='src/version.hpp',
87 install_path=None,
88 VERSION_STRING=VERSION_BASE,
89 VERSION_BUILD=VERSION,
90 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
91 int(VERSION_SPLIT[1]) * 1000 +
92 int(VERSION_SPLIT[2]),
93 VERSION_MAJOR=VERSION_SPLIT[0],
94 VERSION_MINOR=VERSION_SPLIT[1],
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -050095 VERSION_PATCH=VERSION_SPLIT[2])
Vince Lehmanb722b102014-08-24 16:33:49 -050096
Yingdi Yu40cd1c32014-04-17 15:02:17 -070097 nlsr_objects = bld(
98 target='nlsr-objects',
99 name='nlsr-objects',
100 features='cxx',
101 source=bld.path.ant_glob(['src/**/*.cpp'],
102 excl=['src/main.cpp']),
dmcoomescf8d0ed2017-02-21 11:39:01 -0600103 use='NDN_CXX BOOST SYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700104 includes='. src',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500105 export_includes='. src')
akmhoque298385a2014-02-13 14:13:09 -0600106
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700107 nlsr = bld(
108 target='bin/nlsr',
109 features='cxx cxxprogram',
110 source='src/main.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500111 use='nlsr-objects')
akmhoque298385a2014-02-13 14:13:09 -0600112
Vince Lehmanc439d662015-04-27 10:56:00 -0500113 nlsrc = bld(
114 target='bin/nlsrc',
115 features='cxx cxxprogram',
116 source='tools/nlsrc.cpp',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500117 use='nlsr-objects BOOST')
Vince Lehmanc439d662015-04-27 10:56:00 -0500118
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500119 bld(features="subst",
120 source='nlsr.conf',
121 target='nlsr.conf.sample',
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500122 install_path="${SYSCONFDIR}/ndn")
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500123
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700124 if bld.env['WITH_TESTS']:
125 bld.recurse('tests')
Vince Lehmanb722b102014-08-24 16:33:49 -0500126
Vince Lehmanc439d662015-04-27 10:56:00 -0500127 if bld.env['SPHINX_BUILD']:
128 bld(features="sphinx",
129 builder="man",
130 outdir="docs/manpages",
131 config="docs/conf.py",
132 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
133 install_path="${MANDIR}/",
134 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500135
136def docs(bld):
137 from waflib import Options
138 Options.commands = ['doxygen', 'sphinx'] + Options.commands
139
140def doxygen(bld):
141 version(bld)
142
143 if not bld.env.DOXYGEN:
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500144 Logs.error("ERROR: cannot build documentation (`doxygen' not found in $PATH)")
Vince Lehmanb722b102014-08-24 16:33:49 -0500145 else:
146 bld(features="subst",
147 name="doxygen-conf",
148 source="docs/doxygen.conf.in",
149 target="docs/doxygen.conf",
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500150 VERSION=VERSION_BASE)
Vince Lehmanb722b102014-08-24 16:33:49 -0500151
152 bld(features="doxygen",
153 doxyfile='docs/doxygen.conf',
154 use="doxygen-conf")
155
156def sphinx(bld):
157 version(bld)
158
159 if not bld.env.SPHINX_BUILD:
Davide Pesaventoc58cc7f2017-08-08 16:51:28 -0500160 bld.fatal("ERROR: cannot build documentation (`sphinx-build' not found in $PATH)")
Vince Lehmanb722b102014-08-24 16:33:49 -0500161 else:
162 bld(features="sphinx",
163 outdir="docs",
164 source=bld.path.ant_glob('docs/**/*.rst'),
165 config="docs/conf.py",
166 VERSION=VERSION_BASE)
167
168def version(ctx):
169 if getattr(Context.g_module, 'VERSION_BASE', None):
170 return
171
172 Context.g_module.VERSION_BASE = Context.g_module.VERSION
173 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
174
175 didGetVersion = False
176 try:
177 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
178 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
179 stderr=None, stdin=None)
Alexander Afanasyevc0b97af2014-09-01 13:23:50 -0700180 out = str(p.communicate()[0].strip())
Vince Lehmanb722b102014-08-24 16:33:49 -0500181 didGetVersion = (p.returncode == 0 and out != "")
182 if didGetVersion:
183 if out.startswith(GIT_TAG_PREFIX):
184 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
185 else:
186 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
187 except OSError:
188 pass
189
190 versionFile = ctx.path.find_node('VERSION')
191
192 if not didGetVersion and versionFile is not None:
193 try:
194 Context.g_module.VERSION = versionFile.read()
195 return
196 except (OSError, IOError):
197 pass
198
199 # version was obtained from git, update VERSION file if necessary
200 if versionFile is not None:
201 try:
202 version = versionFile.read()
203 if version == Context.g_module.VERSION:
204 return # no need to update
205 except (OSError, IOError):
206 Logs.warn("VERSION file exists, but not readable")
207 else:
208 versionFile = ctx.path.make_node('VERSION')
209
210 if versionFile is None:
211 return
212
213 try:
214 versionFile.write(Context.g_module.VERSION)
215 except (OSError, IOError):
216 Logs.warn("VERSION file is not writeable")
217
218def dist(ctx):
219 version(ctx)
220
221def distcheck(ctx):
222 version(ctx)