akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 2 | |
| 3 | """ |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 4 | Copyright (c) 2014-2017, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 5 | Regents of the University of California, |
| 6 | Arizona Board of Regents. |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 7 | |
| 8 | This file is part of NLSR (Named-data Link State Routing). |
| 9 | See AUTHORS.md for complete list of NLSR authors and contributors. |
| 10 | |
| 11 | NLSR is free software: you can redistribute it and/or modify it under the terms |
| 12 | of the GNU General Public License as published by the Free Software Foundation, |
| 13 | either version 3 of the License, or (at your option) any later version. |
| 14 | |
| 15 | NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 16 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 17 | PURPOSE. See the GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License along with |
| 20 | NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 21 | """ |
| 22 | |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame^] | 23 | VERSION = "0.3.2" |
sfayer | 93d9ec3 | 2014-12-04 23:34:41 +0000 | [diff] [blame] | 24 | APPNAME = "nlsr" |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame^] | 25 | BUGREPORT = "https://redmine.named-data.net/projects/nlsr" |
| 26 | URL = "https://named-data.net/doc/NLSR/" |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 27 | GIT_TAG_PREFIX = "NLSR-" |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 28 | |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame^] | 29 | from waflib import Logs, Utils, Context |
Alexander Afanasyev | fb2adee | 2015-03-30 10:56:55 -0700 | [diff] [blame] | 30 | import os |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 31 | |
| 32 | def options(opt): |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 33 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 34 | opt.load(['default-compiler-flags', 'coverage', 'sanitizers', |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame^] | 35 | 'boost', 'doxygen', 'sphinx_build'], |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 36 | tooldir=['.waf-tools']) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 37 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 38 | nlsropt = opt.add_option_group('NLSR Options') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 39 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 40 | nlsropt.add_option('--with-tests', action='store_true', default=False, dest='with_tests', |
| 41 | help='''build unit tests''') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 42 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 43 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 44 | def configure(conf): |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 45 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame^] | 46 | 'default-compiler-flags', 'boost', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 47 | 'doxygen', 'sphinx_build']) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 48 | |
Alexander Afanasyev | fb2adee | 2015-03-30 10:56:55 -0700 | [diff] [blame] | 49 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 50 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
| 51 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 52 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
Vince Lehman | b45eed2 | 2015-01-13 14:58:07 -0600 | [diff] [blame] | 53 | uselib_store='NDN_CXX', mandatory=True) |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 54 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 55 | conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], |
| 56 | uselib_store='LOG4CXX', mandatory=True) |
| 57 | |
| 58 | boost_libs = 'system chrono program_options iostreams thread regex filesystem' |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 59 | if conf.options.with_tests: |
| 60 | conf.env['WITH_TESTS'] = 1 |
| 61 | conf.define('WITH_TESTS', 1); |
| 62 | boost_libs += ' unit_test_framework' |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 63 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 64 | conf.check_boost(lib=boost_libs) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 65 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 66 | if conf.env.BOOST_VERSION_NUMBER < 104800: |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 67 | Logs.error("Minimum required boost version is 1.48.0") |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 68 | Logs.error("Please upgrade your distribution or install custom boost libraries") |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 69 | return |
| 70 | |
Ashlesh Gawande | 7600c90 | 2017-06-21 13:28:35 -0500 | [diff] [blame] | 71 | conf.check_cfg(package='ChronoSync', args=['ChronoSync >= 0.3', '--cflags', '--libs'], |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 72 | uselib_store='SYNC', mandatory=True) |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 73 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 74 | conf.load('coverage') |
| 75 | |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 76 | conf.load('sanitizers') |
| 77 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 78 | conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR']) |
| 79 | |
| 80 | conf.write_config_header('config.hpp') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 81 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 82 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 83 | def build(bld): |
| 84 | version(bld) |
| 85 | |
| 86 | bld(features="subst", |
| 87 | name='version', |
| 88 | source='src/version.hpp.in', |
| 89 | target='src/version.hpp', |
| 90 | install_path=None, |
| 91 | VERSION_STRING=VERSION_BASE, |
| 92 | VERSION_BUILD=VERSION, |
| 93 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 94 | int(VERSION_SPLIT[1]) * 1000 + |
| 95 | int(VERSION_SPLIT[2]), |
| 96 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 97 | VERSION_MINOR=VERSION_SPLIT[1], |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 98 | VERSION_PATCH=VERSION_SPLIT[2]) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 99 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 100 | 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 Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 106 | use='NDN_CXX BOOST LOG4CXX SYNC', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 107 | includes='. src', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 108 | export_includes='. src') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 109 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 110 | nlsr = bld( |
| 111 | target='bin/nlsr', |
| 112 | features='cxx cxxprogram', |
| 113 | source='src/main.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 114 | use='nlsr-objects') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 115 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 116 | nlsrc = bld( |
| 117 | target='bin/nlsrc', |
| 118 | features='cxx cxxprogram', |
| 119 | source='tools/nlsrc.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 120 | use='nlsr-objects BOOST') |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 121 | |
Ashlesh Gawande | 9b71bbc | 2017-07-21 15:52:25 -0500 | [diff] [blame] | 122 | bld(features="subst", |
| 123 | source='nlsr.conf', |
| 124 | target='nlsr.conf.sample', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 125 | install_path="${SYSCONFDIR}/ndn") |
Ashlesh Gawande | 9b71bbc | 2017-07-21 15:52:25 -0500 | [diff] [blame] | 126 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 127 | if bld.env['WITH_TESTS']: |
| 128 | bld.recurse('tests') |
| 129 | bld.recurse('tests-integrated') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 130 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 131 | if bld.env['SPHINX_BUILD']: |
| 132 | bld(features="sphinx", |
| 133 | builder="man", |
| 134 | outdir="docs/manpages", |
| 135 | config="docs/conf.py", |
| 136 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
| 137 | install_path="${MANDIR}/", |
| 138 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 139 | |
| 140 | def docs(bld): |
| 141 | from waflib import Options |
| 142 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 143 | |
| 144 | def doxygen(bld): |
| 145 | version(bld) |
| 146 | |
| 147 | if not bld.env.DOXYGEN: |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 148 | Logs.error("ERROR: cannot build documentation (`doxygen' not found in $PATH)") |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 149 | else: |
| 150 | bld(features="subst", |
| 151 | name="doxygen-conf", |
| 152 | source="docs/doxygen.conf.in", |
| 153 | target="docs/doxygen.conf", |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 154 | VERSION=VERSION_BASE) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 155 | |
| 156 | bld(features="doxygen", |
| 157 | doxyfile='docs/doxygen.conf', |
| 158 | use="doxygen-conf") |
| 159 | |
| 160 | def sphinx(bld): |
| 161 | version(bld) |
| 162 | |
| 163 | if not bld.env.SPHINX_BUILD: |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 164 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' not found in $PATH)") |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 165 | else: |
| 166 | bld(features="sphinx", |
| 167 | outdir="docs", |
| 168 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 169 | config="docs/conf.py", |
| 170 | VERSION=VERSION_BASE) |
| 171 | |
| 172 | def version(ctx): |
| 173 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 174 | return |
| 175 | |
| 176 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 177 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 178 | |
| 179 | didGetVersion = False |
| 180 | try: |
| 181 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 182 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 183 | stderr=None, stdin=None) |
Alexander Afanasyev | c0b97af | 2014-09-01 13:23:50 -0700 | [diff] [blame] | 184 | out = str(p.communicate()[0].strip()) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 185 | didGetVersion = (p.returncode == 0 and out != "") |
| 186 | if didGetVersion: |
| 187 | if out.startswith(GIT_TAG_PREFIX): |
| 188 | Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] |
| 189 | else: |
| 190 | Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out) |
| 191 | except OSError: |
| 192 | pass |
| 193 | |
| 194 | versionFile = ctx.path.find_node('VERSION') |
| 195 | |
| 196 | if not didGetVersion and versionFile is not None: |
| 197 | try: |
| 198 | Context.g_module.VERSION = versionFile.read() |
| 199 | return |
| 200 | except (OSError, IOError): |
| 201 | pass |
| 202 | |
| 203 | # version was obtained from git, update VERSION file if necessary |
| 204 | if versionFile is not None: |
| 205 | try: |
| 206 | version = versionFile.read() |
| 207 | if version == Context.g_module.VERSION: |
| 208 | return # no need to update |
| 209 | except (OSError, IOError): |
| 210 | Logs.warn("VERSION file exists, but not readable") |
| 211 | else: |
| 212 | versionFile = ctx.path.make_node('VERSION') |
| 213 | |
| 214 | if versionFile is None: |
| 215 | return |
| 216 | |
| 217 | try: |
| 218 | versionFile.write(Context.g_module.VERSION) |
| 219 | except (OSError, IOError): |
| 220 | Logs.warn("VERSION file is not writeable") |
| 221 | |
| 222 | def dist(ctx): |
| 223 | version(ctx) |
| 224 | |
| 225 | def distcheck(ctx): |
| 226 | version(ctx) |