blob: 7364b07e70f7049ef9cdaa2b8ab70615e327b38d [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'
sfayer93d9ec32014-12-04 23:34:41 +000023APPNAME = "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'],
Vince Lehmanb45eed22015-01-13 14:58:07 -060051 uselib_store='NDN_CXX', 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
Vince Lehmanb45eed22015-01-13 14:58:07 -060056 conf.check_openssl(mandatory=True)
57
akmhoque674b0b12014-05-20 14:33:28 -050058 boost_libs = 'system chrono program_options iostreams thread regex filesystem'
Yingdi Yu40cd1c32014-04-17 15:02:17 -070059 if conf.options.with_tests:
60 conf.env['WITH_TESTS'] = 1
61 conf.define('WITH_TESTS', 1);
62 boost_libs += ' unit_test_framework'
akmhoque85d88332014-02-17 21:11:21 -060063
Yingdi Yu40cd1c32014-04-17 15:02:17 -070064 conf.check_boost(lib=boost_libs)
akmhoque298385a2014-02-13 14:13:09 -060065
akmhoquec8a10f72014-04-25 18:42:55 -050066 if conf.env.BOOST_VERSION_NUMBER < 104800:
akmhoquefdbddb12014-05-02 18:35:19 -050067 Logs.error("Minimum required boost version is 1.48.0")
Yingdi Yu40cd1c32014-04-17 15:02:17 -070068 Logs.error("Please upgrade your distribution or install custom boost libraries")
akmhoque05d5fcf2014-04-15 14:58:45 -050069 return
70
Yingdi Yu40cd1c32014-04-17 15:02:17 -070071 conf.load('protoc')
akmhoque05d5fcf2014-04-15 14:58:45 -050072
Yingdi Yu40cd1c32014-04-17 15:02:17 -070073 conf.load('coverage')
74
75 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],
95 VERSION_PATCH=VERSION_SPLIT[2],
96 )
97
Yingdi Yu40cd1c32014-04-17 15:02:17 -070098 nsync_objects = bld(
99 target='nsync-objects',
100 name='nsync-objects',
101 features='cxx',
102 source=bld.path.ant_glob(['nsync/**/*.cc', 'nsync/**/*.proto']),
Vince Lehmanb45eed22015-01-13 14:58:07 -0600103 use='BOOST NDN_CXX OPENSSL',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700104 includes='nsync',
105 export_includes='nsync',
akmhoque298385a2014-02-13 14:13:09 -0600106 )
107
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700108 nlsr_objects = bld(
109 target='nlsr-objects',
110 name='nlsr-objects',
111 features='cxx',
112 source=bld.path.ant_glob(['src/**/*.cpp'],
113 excl=['src/main.cpp']),
Vince Lehmanb45eed22015-01-13 14:58:07 -0600114 use='nsync-objects NDN_CXX BOOST LOG4CXX',
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700115 includes='. src',
116 export_includes='. src',
117 )
akmhoque298385a2014-02-13 14:13:09 -0600118
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700119 nlsr = bld(
120 target='bin/nlsr',
121 features='cxx cxxprogram',
122 source='src/main.cpp',
123 use='nlsr-objects',
124 )
akmhoque298385a2014-02-13 14:13:09 -0600125
Yingdi Yu40cd1c32014-04-17 15:02:17 -0700126 if bld.env['WITH_TESTS']:
127 bld.recurse('tests')
128 bld.recurse('tests-integrated')
Vince Lehmanb722b102014-08-24 16:33:49 -0500129
130
131def docs(bld):
132 from waflib import Options
133 Options.commands = ['doxygen', 'sphinx'] + Options.commands
134
135def doxygen(bld):
136 version(bld)
137
138 if not bld.env.DOXYGEN:
139 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
140 else:
141 bld(features="subst",
142 name="doxygen-conf",
143 source="docs/doxygen.conf.in",
144 target="docs/doxygen.conf",
145 VERSION=VERSION_BASE,
146 )
147
148 bld(features="doxygen",
149 doxyfile='docs/doxygen.conf',
150 use="doxygen-conf")
151
152def sphinx(bld):
153 version(bld)
154
155 if not bld.env.SPHINX_BUILD:
156 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
157 else:
158 bld(features="sphinx",
159 outdir="docs",
160 source=bld.path.ant_glob('docs/**/*.rst'),
161 config="docs/conf.py",
162 VERSION=VERSION_BASE)
163
164def version(ctx):
165 if getattr(Context.g_module, 'VERSION_BASE', None):
166 return
167
168 Context.g_module.VERSION_BASE = Context.g_module.VERSION
169 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
170
171 didGetVersion = False
172 try:
173 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
174 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
175 stderr=None, stdin=None)
Alexander Afanasyevc0b97af2014-09-01 13:23:50 -0700176 out = str(p.communicate()[0].strip())
Vince Lehmanb722b102014-08-24 16:33:49 -0500177 didGetVersion = (p.returncode == 0 and out != "")
178 if didGetVersion:
179 if out.startswith(GIT_TAG_PREFIX):
180 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
181 else:
182 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
183 except OSError:
184 pass
185
186 versionFile = ctx.path.find_node('VERSION')
187
188 if not didGetVersion and versionFile is not None:
189 try:
190 Context.g_module.VERSION = versionFile.read()
191 return
192 except (OSError, IOError):
193 pass
194
195 # version was obtained from git, update VERSION file if necessary
196 if versionFile is not None:
197 try:
198 version = versionFile.read()
199 if version == Context.g_module.VERSION:
200 return # no need to update
201 except (OSError, IOError):
202 Logs.warn("VERSION file exists, but not readable")
203 else:
204 versionFile = ctx.path.make_node('VERSION')
205
206 if versionFile is None:
207 return
208
209 try:
210 versionFile.write(Context.g_module.VERSION)
211 except (OSError, IOError):
212 Logs.warn("VERSION file is not writeable")
213
214def dist(ctx):
215 version(ctx)
216
217def distcheck(ctx):
218 version(ctx)