blob: 946bb5aea0310fc159c72f3e65e7310b1ff4bd0a [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 Lehmanc2e51f62015-01-20 15:03:11 -06004Copyright (c) 2014-2015, The University of Memphis,
5 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
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070023VERSION = '0.1.0'
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',
36 'boost', 'protoc', 'openssl',
37 'doxygen', 'sphinx_build'],
38 tooldir=['.waf-tools'])
akmhoque298385a2014-02-13 14:13:09 -060039
Yingdi Yu40cd1c32014-04-17 15:02:17 -070040 nlsropt = opt.add_option_group('NLSR Options')
akmhoque05d5fcf2014-04-15 14:58:45 -050041
Yingdi Yu40cd1c32014-04-17 15:02:17 -070042 nlsropt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
43 help='''build unit tests''')
akmhoque298385a2014-02-13 14:13:09 -060044
akmhoque05d5fcf2014-04-15 14:58:45 -050045
akmhoque298385a2014-02-13 14:13:09 -060046def configure(conf):
Vince Lehmanb722b102014-08-24 16:33:49 -050047 conf.load(['compiler_cxx', 'gnu_dirs',
48 'boost', 'openssl',
49 'default-compiler-flags',
50 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060051
Alexander Afanasyevfb2adee2015-03-30 10:56:55 -070052 if 'PKG_CONFIG_PATH' not in os.environ:
53 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
54
akmhoquec8a10f72014-04-25 18:42:55 -050055 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
Vince Lehmanb45eed22015-01-13 14:58:07 -060056 uselib_store='NDN_CXX', mandatory=True)
akmhoque85d88332014-02-17 21:11:21 -060057
akmhoque674b0b12014-05-20 14:33:28 -050058 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'],
59 uselib_store='LOG4CXX', mandatory=True)
60
Vince Lehmanb45eed22015-01-13 14:58:07 -060061 conf.check_openssl(mandatory=True)
62
akmhoque674b0b12014-05-20 14:33:28 -050063 boost_libs = 'system chrono program_options iostreams thread regex filesystem'
Yingdi Yu40cd1c32014-04-17 15:02:17 -070064 if conf.options.with_tests:
65 conf.env['WITH_TESTS'] = 1
66 conf.define('WITH_TESTS', 1);
67 boost_libs += ' unit_test_framework'
akmhoque85d88332014-02-17 21:11:21 -060068
Yingdi Yu40cd1c32014-04-17 15:02:17 -070069 conf.check_boost(lib=boost_libs)
akmhoque298385a2014-02-13 14:13:09 -060070
akmhoquec8a10f72014-04-25 18:42:55 -050071 if conf.env.BOOST_VERSION_NUMBER < 104800:
akmhoquefdbddb12014-05-02 18:35:19 -050072 Logs.error("Minimum required boost version is 1.48.0")
Yingdi Yu40cd1c32014-04-17 15:02:17 -070073 Logs.error("Please upgrade your distribution or install custom boost libraries")
akmhoque05d5fcf2014-04-15 14:58:45 -050074 return
75
Yingdi Yu40cd1c32014-04-17 15:02:17 -070076 conf.load('protoc')
akmhoque05d5fcf2014-04-15 14:58:45 -050077
Yingdi Yu40cd1c32014-04-17 15:02:17 -070078 conf.load('coverage')
79
80 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
81
82 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050083
akmhoque298385a2014-02-13 14:13:09 -060084
Vince Lehmanb722b102014-08-24 16:33:49 -050085def build(bld):
86 version(bld)
87
88 bld(features="subst",
89 name='version',
90 source='src/version.hpp.in',
91 target='src/version.hpp',
92 install_path=None,
93 VERSION_STRING=VERSION_BASE,
94 VERSION_BUILD=VERSION,
95 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
96 int(VERSION_SPLIT[1]) * 1000 +
97 int(VERSION_SPLIT[2]),
98 VERSION_MAJOR=VERSION_SPLIT[0],
99 VERSION_MINOR=VERSION_SPLIT[1],
100 VERSION_PATCH=VERSION_SPLIT[2],
101 )
102
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700103 nsync_objects = bld(
104 target='nsync-objects',
105 name='nsync-objects',
106 features='cxx',
107 source=bld.path.ant_glob(['nsync/**/*.cc', 'nsync/**/*.proto']),
Vince Lehmanb45eed22015-01-13 14:58:07 -0600108 use='BOOST NDN_CXX OPENSSL',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700109 includes='nsync',
110 export_includes='nsync',
akmhoque298385a2014-02-13 14:13:09 -0600111 )
112
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700113 nlsr_objects = bld(
114 target='nlsr-objects',
115 name='nlsr-objects',
116 features='cxx',
117 source=bld.path.ant_glob(['src/**/*.cpp'],
118 excl=['src/main.cpp']),
Vince Lehmanb45eed22015-01-13 14:58:07 -0600119 use='nsync-objects NDN_CXX BOOST LOG4CXX',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700120 includes='. src',
121 export_includes='. src',
122 )
akmhoque298385a2014-02-13 14:13:09 -0600123
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700124 nlsr = bld(
125 target='bin/nlsr',
126 features='cxx cxxprogram',
127 source='src/main.cpp',
128 use='nlsr-objects',
129 )
akmhoque298385a2014-02-13 14:13:09 -0600130
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
135
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:
144 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
145 else:
146 bld(features="subst",
147 name="doxygen-conf",
148 source="docs/doxygen.conf.in",
149 target="docs/doxygen.conf",
150 VERSION=VERSION_BASE,
151 )
152
153 bld(features="doxygen",
154 doxyfile='docs/doxygen.conf',
155 use="doxygen-conf")
156
157def sphinx(bld):
158 version(bld)
159
160 if not bld.env.SPHINX_BUILD:
161 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
162 else:
163 bld(features="sphinx",
164 outdir="docs",
165 source=bld.path.ant_glob('docs/**/*.rst'),
166 config="docs/conf.py",
167 VERSION=VERSION_BASE)
168
169def version(ctx):
170 if getattr(Context.g_module, 'VERSION_BASE', None):
171 return
172
173 Context.g_module.VERSION_BASE = Context.g_module.VERSION
174 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
175
176 didGetVersion = False
177 try:
178 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
179 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
180 stderr=None, stdin=None)
Alexander Afanasyevc0b97af2014-09-01 13:23:50 -0700181 out = str(p.communicate()[0].strip())
Vince Lehmanb722b102014-08-24 16:33:49 -0500182 didGetVersion = (p.returncode == 0 and out != "")
183 if didGetVersion:
184 if out.startswith(GIT_TAG_PREFIX):
185 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
186 else:
187 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
188 except OSError:
189 pass
190
191 versionFile = ctx.path.find_node('VERSION')
192
193 if not didGetVersion and versionFile is not None:
194 try:
195 Context.g_module.VERSION = versionFile.read()
196 return
197 except (OSError, IOError):
198 pass
199
200 # version was obtained from git, update VERSION file if necessary
201 if versionFile is not None:
202 try:
203 version = versionFile.read()
204 if version == Context.g_module.VERSION:
205 return # no need to update
206 except (OSError, IOError):
207 Logs.warn("VERSION file exists, but not readable")
208 else:
209 versionFile = ctx.path.make_node('VERSION')
210
211 if versionFile is None:
212 return
213
214 try:
215 versionFile.write(Context.g_module.VERSION)
216 except (OSError, IOError):
217 Logs.warn("VERSION file is not writeable")
218
219def dist(ctx):
220 version(ctx)
221
222def distcheck(ctx):
223 version(ctx)