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 | """ |
Ashlesh Gawande | 39cf81a | 2018-02-22 13:37:07 -0600 | [diff] [blame] | 4 | Copyright (c) 2014-2018, 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 | |
Ashlesh Gawande | 39cf81a | 2018-02-22 13:37:07 -0600 | [diff] [blame] | 23 | VERSION = "0.4.1" |
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 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 55 | boost_libs = 'system chrono program_options iostreams thread regex filesystem log log_setup' |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 56 | if conf.options.with_tests: |
| 57 | conf.env['WITH_TESTS'] = 1 |
| 58 | conf.define('WITH_TESTS', 1); |
| 59 | boost_libs += ' unit_test_framework' |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 60 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 61 | conf.check_boost(lib=boost_libs, mt=True) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 62 | |
Ashlesh Gawande | 39cf81a | 2018-02-22 13:37:07 -0600 | [diff] [blame] | 63 | if conf.env.BOOST_VERSION_NUMBER < 105400: |
| 64 | Logs.error("Minimum required boost version is 1.54.0") |
| 65 | Logs.error("Please upgrade your distribution or install custom boost libraries" + |
| 66 | " (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)") |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 67 | return |
| 68 | |
Ashlesh Gawande | 39cf81a | 2018-02-22 13:37:07 -0600 | [diff] [blame] | 69 | conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'], |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 70 | uselib_store='SYNC', mandatory=True) |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 71 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 72 | conf.load('coverage') |
| 73 | |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 74 | conf.load('sanitizers') |
| 75 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 76 | conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR']) |
| 77 | |
| 78 | conf.write_config_header('config.hpp') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 79 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 80 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 81 | def 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], |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 96 | VERSION_PATCH=VERSION_SPLIT[2]) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 97 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 98 | nlsr_objects = bld( |
| 99 | target='nlsr-objects', |
| 100 | name='nlsr-objects', |
| 101 | features='cxx', |
| 102 | source=bld.path.ant_glob(['src/**/*.cpp'], |
| 103 | excl=['src/main.cpp']), |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 104 | use='NDN_CXX BOOST SYNC', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 105 | includes='. src', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 106 | export_includes='. src') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 107 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 108 | nlsr = bld( |
| 109 | target='bin/nlsr', |
| 110 | features='cxx cxxprogram', |
| 111 | source='src/main.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 112 | use='nlsr-objects') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 113 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 114 | nlsrc = bld( |
| 115 | target='bin/nlsrc', |
| 116 | features='cxx cxxprogram', |
| 117 | source='tools/nlsrc.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 118 | use='nlsr-objects BOOST') |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 119 | |
Ashlesh Gawande | 9b71bbc | 2017-07-21 15:52:25 -0500 | [diff] [blame] | 120 | bld(features="subst", |
| 121 | source='nlsr.conf', |
| 122 | target='nlsr.conf.sample', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 123 | install_path="${SYSCONFDIR}/ndn") |
Ashlesh Gawande | 9b71bbc | 2017-07-21 15:52:25 -0500 | [diff] [blame] | 124 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 125 | if bld.env['WITH_TESTS']: |
| 126 | bld.recurse('tests') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 127 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 128 | if bld.env['SPHINX_BUILD']: |
| 129 | bld(features="sphinx", |
| 130 | builder="man", |
| 131 | outdir="docs/manpages", |
| 132 | config="docs/conf.py", |
| 133 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
| 134 | install_path="${MANDIR}/", |
| 135 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 136 | |
| 137 | def docs(bld): |
| 138 | from waflib import Options |
| 139 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 140 | |
| 141 | def doxygen(bld): |
| 142 | version(bld) |
| 143 | |
| 144 | if not bld.env.DOXYGEN: |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 145 | Logs.error("ERROR: cannot build documentation (`doxygen' not found in $PATH)") |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 146 | else: |
| 147 | bld(features="subst", |
| 148 | name="doxygen-conf", |
| 149 | source="docs/doxygen.conf.in", |
| 150 | target="docs/doxygen.conf", |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 151 | VERSION=VERSION_BASE) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 152 | |
| 153 | bld(features="doxygen", |
| 154 | doxyfile='docs/doxygen.conf', |
| 155 | use="doxygen-conf") |
| 156 | |
| 157 | def sphinx(bld): |
| 158 | version(bld) |
| 159 | |
| 160 | if not bld.env.SPHINX_BUILD: |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 161 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' not found in $PATH)") |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 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 | |
| 169 | def 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 Afanasyev | c0b97af | 2014-09-01 13:23:50 -0700 | [diff] [blame] | 181 | out = str(p.communicate()[0].strip()) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 182 | 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 | |
| 219 | def dist(ctx): |
| 220 | version(ctx) |
| 221 | |
| 222 | def distcheck(ctx): |
| 223 | version(ctx) |