blob: 961c3277d8ccead57a0794e9877049d372ec68a9 [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"""
Vince Lehman0ff5d452016-01-04 17:20:19 -06004Copyright (c) 2014-2016, 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'])
35 opt.load(['default-compiler-flags', 'coverage',
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
77 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
78
79 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050080
akmhoque298385a2014-02-13 14:13:09 -060081
Vince Lehmanb722b102014-08-24 16:33:49 -050082def build(bld):
83 version(bld)
84
85 bld(features="subst",
86 name='version',
87 source='src/version.hpp.in',
88 target='src/version.hpp',
89 install_path=None,
90 VERSION_STRING=VERSION_BASE,
91 VERSION_BUILD=VERSION,
92 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
93 int(VERSION_SPLIT[1]) * 1000 +
94 int(VERSION_SPLIT[2]),
95 VERSION_MAJOR=VERSION_SPLIT[0],
96 VERSION_MINOR=VERSION_SPLIT[1],
97 VERSION_PATCH=VERSION_SPLIT[2],
98 )
99
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700100 nlsr_objects = bld(
101 target='nlsr-objects',
102 name='nlsr-objects',
103 features='cxx',
104 source=bld.path.ant_glob(['src/**/*.cpp'],
105 excl=['src/main.cpp']),
Ashlesh Gawande415676b2016-12-22 00:26:23 -0600106 use='NDN_CXX BOOST LOG4CXX SYNC',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700107 includes='. src',
108 export_includes='. src',
109 )
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',
115 use='nlsr-objects',
116 )
akmhoque298385a2014-02-13 14:13:09 -0600117
Vince Lehmanc439d662015-04-27 10:56:00 -0500118 nlsrc = bld(
119 target='bin/nlsrc',
120 features='cxx cxxprogram',
121 source='tools/nlsrc.cpp',
122 use='nlsr-objects BOOST',
123 )
124
Ashlesh Gawande9b71bbc2017-07-21 15:52:25 -0500125 bld(features="subst",
126 source='nlsr.conf',
127 target='nlsr.conf.sample',
128 install_path="${SYSCONFDIR}/ndn",
129 )
130
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700131 if bld.env['WITH_TESTS']:
132 bld.recurse('tests')
133 bld.recurse('tests-integrated')
Vince Lehmanb722b102014-08-24 16:33:49 -0500134
Vince Lehmanc439d662015-04-27 10:56:00 -0500135 if bld.env['SPHINX_BUILD']:
136 bld(features="sphinx",
137 builder="man",
138 outdir="docs/manpages",
139 config="docs/conf.py",
140 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
141 install_path="${MANDIR}/",
142 VERSION=VERSION)
Vince Lehmanb722b102014-08-24 16:33:49 -0500143
144def docs(bld):
145 from waflib import Options
146 Options.commands = ['doxygen', 'sphinx'] + Options.commands
147
148def doxygen(bld):
149 version(bld)
150
151 if not bld.env.DOXYGEN:
152 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
153 else:
154 bld(features="subst",
155 name="doxygen-conf",
156 source="docs/doxygen.conf.in",
157 target="docs/doxygen.conf",
158 VERSION=VERSION_BASE,
159 )
160
161 bld(features="doxygen",
162 doxyfile='docs/doxygen.conf',
163 use="doxygen-conf")
164
165def sphinx(bld):
166 version(bld)
167
168 if not bld.env.SPHINX_BUILD:
169 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
170 else:
171 bld(features="sphinx",
172 outdir="docs",
173 source=bld.path.ant_glob('docs/**/*.rst'),
174 config="docs/conf.py",
175 VERSION=VERSION_BASE)
176
177def version(ctx):
178 if getattr(Context.g_module, 'VERSION_BASE', None):
179 return
180
181 Context.g_module.VERSION_BASE = Context.g_module.VERSION
182 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
183
184 didGetVersion = False
185 try:
186 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
187 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
188 stderr=None, stdin=None)
Alexander Afanasyevc0b97af2014-09-01 13:23:50 -0700189 out = str(p.communicate()[0].strip())
Vince Lehmanb722b102014-08-24 16:33:49 -0500190 didGetVersion = (p.returncode == 0 and out != "")
191 if didGetVersion:
192 if out.startswith(GIT_TAG_PREFIX):
193 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
194 else:
195 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
196 except OSError:
197 pass
198
199 versionFile = ctx.path.find_node('VERSION')
200
201 if not didGetVersion and versionFile is not None:
202 try:
203 Context.g_module.VERSION = versionFile.read()
204 return
205 except (OSError, IOError):
206 pass
207
208 # version was obtained from git, update VERSION file if necessary
209 if versionFile is not None:
210 try:
211 version = versionFile.read()
212 if version == Context.g_module.VERSION:
213 return # no need to update
214 except (OSError, IOError):
215 Logs.warn("VERSION file exists, but not readable")
216 else:
217 versionFile = ctx.path.make_node('VERSION')
218
219 if versionFile is None:
220 return
221
222 try:
223 versionFile.write(Context.g_module.VERSION)
224 except (OSError, IOError):
225 Logs.warn("VERSION file is not writeable")
226
227def dist(ctx):
228 version(ctx)
229
230def distcheck(ctx):
231 version(ctx)