blob: 271b076c2fa4f9068f3b0868d39d9ec14eb5fccd [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
akmhoque298385a2014-02-13 14:13:09 -060031
32def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070033 opt.load(['compiler_cxx', 'gnu_dirs'])
34 opt.load(['default-compiler-flags', 'coverage',
35 'boost', 'protoc', 'openssl',
36 'doxygen', 'sphinx_build'],
37 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',
47 'boost', 'openssl',
48 'default-compiler-flags',
49 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060050
akmhoquec8a10f72014-04-25 18:42:55 -050051 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
Vince Lehmanb45eed22015-01-13 14:58:07 -060052 uselib_store='NDN_CXX', mandatory=True)
akmhoque85d88332014-02-17 21:11:21 -060053
akmhoque674b0b12014-05-20 14:33:28 -050054 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'],
55 uselib_store='LOG4CXX', mandatory=True)
56
Vince Lehmanb45eed22015-01-13 14:58:07 -060057 conf.check_openssl(mandatory=True)
58
akmhoque674b0b12014-05-20 14:33:28 -050059 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
Yingdi Yu40cd1c32014-04-17 15:02:17 -070072 conf.load('protoc')
akmhoque05d5fcf2014-04-15 14:58:45 -050073
Yingdi Yu40cd1c32014-04-17 15:02:17 -070074 conf.load('coverage')
75
76 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
77
78 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050079
akmhoque298385a2014-02-13 14:13:09 -060080
Vince Lehmanb722b102014-08-24 16:33:49 -050081def build(bld):
82 version(bld)
83
84 bld(features="subst",
85 name='version',
86 source='src/version.hpp.in',
87 target='src/version.hpp',
88 install_path=None,
89 VERSION_STRING=VERSION_BASE,
90 VERSION_BUILD=VERSION,
91 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
92 int(VERSION_SPLIT[1]) * 1000 +
93 int(VERSION_SPLIT[2]),
94 VERSION_MAJOR=VERSION_SPLIT[0],
95 VERSION_MINOR=VERSION_SPLIT[1],
96 VERSION_PATCH=VERSION_SPLIT[2],
97 )
98
Yingdi Yu40cd1c32014-04-17 15:02:17 -070099 nsync_objects = bld(
100 target='nsync-objects',
101 name='nsync-objects',
102 features='cxx',
103 source=bld.path.ant_glob(['nsync/**/*.cc', 'nsync/**/*.proto']),
Vince Lehmanb45eed22015-01-13 14:58:07 -0600104 use='BOOST NDN_CXX OPENSSL',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700105 includes='nsync',
106 export_includes='nsync',
akmhoque298385a2014-02-13 14:13:09 -0600107 )
108
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700109 nlsr_objects = bld(
110 target='nlsr-objects',
111 name='nlsr-objects',
112 features='cxx',
113 source=bld.path.ant_glob(['src/**/*.cpp'],
114 excl=['src/main.cpp']),
Vince Lehmanb45eed22015-01-13 14:58:07 -0600115 use='nsync-objects NDN_CXX BOOST LOG4CXX',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700116 includes='. src',
117 export_includes='. src',
118 )
akmhoque298385a2014-02-13 14:13:09 -0600119
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700120 nlsr = bld(
121 target='bin/nlsr',
122 features='cxx cxxprogram',
123 source='src/main.cpp',
124 use='nlsr-objects',
125 )
akmhoque298385a2014-02-13 14:13:09 -0600126
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700127 if bld.env['WITH_TESTS']:
128 bld.recurse('tests')
129 bld.recurse('tests-integrated')
Vince Lehmanb722b102014-08-24 16:33:49 -0500130
131
132def docs(bld):
133 from waflib import Options
134 Options.commands = ['doxygen', 'sphinx'] + Options.commands
135
136def doxygen(bld):
137 version(bld)
138
139 if not bld.env.DOXYGEN:
140 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
141 else:
142 bld(features="subst",
143 name="doxygen-conf",
144 source="docs/doxygen.conf.in",
145 target="docs/doxygen.conf",
146 VERSION=VERSION_BASE,
147 )
148
149 bld(features="doxygen",
150 doxyfile='docs/doxygen.conf',
151 use="doxygen-conf")
152
153def sphinx(bld):
154 version(bld)
155
156 if not bld.env.SPHINX_BUILD:
157 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
158 else:
159 bld(features="sphinx",
160 outdir="docs",
161 source=bld.path.ant_glob('docs/**/*.rst'),
162 config="docs/conf.py",
163 VERSION=VERSION_BASE)
164
165def version(ctx):
166 if getattr(Context.g_module, 'VERSION_BASE', None):
167 return
168
169 Context.g_module.VERSION_BASE = Context.g_module.VERSION
170 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
171
172 didGetVersion = False
173 try:
174 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
175 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
176 stderr=None, stdin=None)
Alexander Afanasyevc0b97af2014-09-01 13:23:50 -0700177 out = str(p.communicate()[0].strip())
Vince Lehmanb722b102014-08-24 16:33:49 -0500178 didGetVersion = (p.returncode == 0 and out != "")
179 if didGetVersion:
180 if out.startswith(GIT_TAG_PREFIX):
181 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
182 else:
183 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
184 except OSError:
185 pass
186
187 versionFile = ctx.path.find_node('VERSION')
188
189 if not didGetVersion and versionFile is not None:
190 try:
191 Context.g_module.VERSION = versionFile.read()
192 return
193 except (OSError, IOError):
194 pass
195
196 # version was obtained from git, update VERSION file if necessary
197 if versionFile is not None:
198 try:
199 version = versionFile.read()
200 if version == Context.g_module.VERSION:
201 return # no need to update
202 except (OSError, IOError):
203 Logs.warn("VERSION file exists, but not readable")
204 else:
205 versionFile = ctx.path.make_node('VERSION')
206
207 if versionFile is None:
208 return
209
210 try:
211 versionFile.write(Context.g_module.VERSION)
212 except (OSError, IOError):
213 Logs.warn("VERSION file is not writeable")
214
215def dist(ctx):
216 version(ctx)
217
218def distcheck(ctx):
219 version(ctx)