blob: b40f41600d19d2468801e407f67ef9529f37d811 [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"""
4Copyright (c) 2014 University of Memphis,
5 Regents of the University of California
6
7This file is part of NLSR (Named-data Link State Routing).
8See AUTHORS.md for complete list of NLSR authors and contributors.
9
10NLSR is free software: you can redistribute it and/or modify it under the terms
11of the GNU General Public License as published by the Free Software Foundation,
12either version 3 of the License, or (at your option) any later version.
13
14NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16PURPOSE. See the GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License along with
19NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20"""
21
Alexander Afanasyev7decbbf2014-08-24 21:29:01 -070022VERSION = '0.1.0'
23NAME = "nlsr"
Vince Lehmanb722b102014-08-24 16:33:49 -050024BUGREPORT = "http://redmine.named-data.net/projects/nlsr"
25URL = "http://named-data.net/doc/NLSR/"
26GIT_TAG_PREFIX = "NLSR-"
akmhoque298385a2014-02-13 14:13:09 -060027
Vince Lehmanb722b102014-08-24 16:33:49 -050028from waflib import Build, Logs, Utils, Task, TaskGen, Configure, Context
akmhoque05d5fcf2014-04-15 14:58:45 -050029from waflib.Tools import c_preproc
akmhoque298385a2014-02-13 14:13:09 -060030
31def options(opt):
Yingdi Yu40cd1c32014-04-17 15:02:17 -070032 opt.load(['compiler_cxx', 'gnu_dirs'])
33 opt.load(['default-compiler-flags', 'coverage',
34 'boost', 'protoc', 'openssl',
35 'doxygen', 'sphinx_build'],
36 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',
46 'boost', 'openssl',
47 'default-compiler-flags',
48 'doxygen', 'sphinx_build'])
akmhoque298385a2014-02-13 14:13:09 -060049
akmhoquec8a10f72014-04-25 18:42:55 -050050 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
Yingdi Yu40cd1c32014-04-17 15:02:17 -070051 uselib_store='NDN_CPP', mandatory=True)
akmhoque85d88332014-02-17 21:11:21 -060052
akmhoque674b0b12014-05-20 14:33:28 -050053 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'],
54 uselib_store='LOG4CXX', mandatory=True)
55
56 boost_libs = 'system chrono program_options iostreams thread regex filesystem'
Yingdi Yu40cd1c32014-04-17 15:02:17 -070057 if conf.options.with_tests:
58 conf.env['WITH_TESTS'] = 1
59 conf.define('WITH_TESTS', 1);
60 boost_libs += ' unit_test_framework'
akmhoque85d88332014-02-17 21:11:21 -060061
Yingdi Yu40cd1c32014-04-17 15:02:17 -070062 conf.check_boost(lib=boost_libs)
akmhoque298385a2014-02-13 14:13:09 -060063
akmhoquec8a10f72014-04-25 18:42:55 -050064 if conf.env.BOOST_VERSION_NUMBER < 104800:
akmhoquefdbddb12014-05-02 18:35:19 -050065 Logs.error("Minimum required boost version is 1.48.0")
Yingdi Yu40cd1c32014-04-17 15:02:17 -070066 Logs.error("Please upgrade your distribution or install custom boost libraries")
akmhoque05d5fcf2014-04-15 14:58:45 -050067 return
68
Yingdi Yu40cd1c32014-04-17 15:02:17 -070069 conf.load('protoc')
akmhoque05d5fcf2014-04-15 14:58:45 -050070
Yingdi Yu40cd1c32014-04-17 15:02:17 -070071 conf.load('coverage')
72
73 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR'])
74
75 conf.write_config_header('config.hpp')
akmhoque05d5fcf2014-04-15 14:58:45 -050076
akmhoque298385a2014-02-13 14:13:09 -060077
Vince Lehmanb722b102014-08-24 16:33:49 -050078def build(bld):
79 version(bld)
80
81 bld(features="subst",
82 name='version',
83 source='src/version.hpp.in',
84 target='src/version.hpp',
85 install_path=None,
86 VERSION_STRING=VERSION_BASE,
87 VERSION_BUILD=VERSION,
88 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
89 int(VERSION_SPLIT[1]) * 1000 +
90 int(VERSION_SPLIT[2]),
91 VERSION_MAJOR=VERSION_SPLIT[0],
92 VERSION_MINOR=VERSION_SPLIT[1],
93 VERSION_PATCH=VERSION_SPLIT[2],
94 )
95
Yingdi Yu40cd1c32014-04-17 15:02:17 -070096 nsync_objects = bld(
97 target='nsync-objects',
98 name='nsync-objects',
99 features='cxx',
100 source=bld.path.ant_glob(['nsync/**/*.cc', 'nsync/**/*.proto']),
101 use='BOOST NDN_CPP OPENSSL',
102 includes='nsync',
103 export_includes='nsync',
akmhoque298385a2014-02-13 14:13:09 -0600104 )
105
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700106 nlsr_objects = bld(
107 target='nlsr-objects',
108 name='nlsr-objects',
109 features='cxx',
110 source=bld.path.ant_glob(['src/**/*.cpp'],
111 excl=['src/main.cpp']),
akmhoque674b0b12014-05-20 14:33:28 -0500112 use='nsync-objects NDN_CPP BOOST LOG4CXX',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700113 includes='. src',
114 export_includes='. src',
115 )
akmhoque298385a2014-02-13 14:13:09 -0600116
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700117 nlsr = bld(
118 target='bin/nlsr',
119 features='cxx cxxprogram',
120 source='src/main.cpp',
121 use='nlsr-objects',
122 )
akmhoque298385a2014-02-13 14:13:09 -0600123
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700124 if bld.env['WITH_TESTS']:
125 bld.recurse('tests')
126 bld.recurse('tests-integrated')
Vince Lehmanb722b102014-08-24 16:33:49 -0500127
128
129def docs(bld):
130 from waflib import Options
131 Options.commands = ['doxygen', 'sphinx'] + Options.commands
132
133def doxygen(bld):
134 version(bld)
135
136 if not bld.env.DOXYGEN:
137 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
138 else:
139 bld(features="subst",
140 name="doxygen-conf",
141 source="docs/doxygen.conf.in",
142 target="docs/doxygen.conf",
143 VERSION=VERSION_BASE,
144 )
145
146 bld(features="doxygen",
147 doxyfile='docs/doxygen.conf',
148 use="doxygen-conf")
149
150def sphinx(bld):
151 version(bld)
152
153 if not bld.env.SPHINX_BUILD:
154 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
155 else:
156 bld(features="sphinx",
157 outdir="docs",
158 source=bld.path.ant_glob('docs/**/*.rst'),
159 config="docs/conf.py",
160 VERSION=VERSION_BASE)
161
162def version(ctx):
163 if getattr(Context.g_module, 'VERSION_BASE', None):
164 return
165
166 Context.g_module.VERSION_BASE = Context.g_module.VERSION
167 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
168
169 didGetVersion = False
170 try:
171 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
172 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
173 stderr=None, stdin=None)
174 out = p.communicate()[0].strip()
175 didGetVersion = (p.returncode == 0 and out != "")
176 if didGetVersion:
177 if out.startswith(GIT_TAG_PREFIX):
178 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
179 else:
180 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
181 except OSError:
182 pass
183
184 versionFile = ctx.path.find_node('VERSION')
185
186 if not didGetVersion and versionFile is not None:
187 try:
188 Context.g_module.VERSION = versionFile.read()
189 return
190 except (OSError, IOError):
191 pass
192
193 # version was obtained from git, update VERSION file if necessary
194 if versionFile is not None:
195 try:
196 version = versionFile.read()
197 if version == Context.g_module.VERSION:
198 return # no need to update
199 except (OSError, IOError):
200 Logs.warn("VERSION file exists, but not readable")
201 else:
202 versionFile = ctx.path.make_node('VERSION')
203
204 if versionFile is None:
205 return
206
207 try:
208 versionFile.write(Context.g_module.VERSION)
209 except (OSError, IOError):
210 Logs.warn("VERSION file is not writeable")
211
212def dist(ctx):
213 version(ctx)
214
215def distcheck(ctx):
216 version(ctx)