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 | 350d584 | 2018-03-02 13:15:25 -0600 | [diff] [blame] | 23 | VERSION = "0.4.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 | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 30 | import os, subprocess |
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') |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 39 | nlsropt.add_option('--with-tests', action='store_true', default=False, help='build unit tests') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 40 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 41 | def configure(conf): |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 42 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame] | 43 | 'default-compiler-flags', 'boost', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 44 | 'doxygen', 'sphinx_build']) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 45 | |
Alexander Afanasyev | fb2adee | 2015-03-30 10:56:55 -0700 | [diff] [blame] | 46 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 47 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
| 48 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 49 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
Vince Lehman | b45eed2 | 2015-01-13 14:58:07 -0600 | [diff] [blame] | 50 | uselib_store='NDN_CXX', mandatory=True) |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 51 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 52 | 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] | 53 | if conf.options.with_tests: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 54 | conf.env['WITH_TESTS'] = True |
| 55 | conf.define('WITH_TESTS', 1) |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 56 | boost_libs += ' unit_test_framework' |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 57 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 58 | conf.check_boost(lib=boost_libs, mt=True) |
Ashlesh Gawande | 39cf81a | 2018-02-22 13:37:07 -0600 | [diff] [blame] | 59 | if conf.env.BOOST_VERSION_NUMBER < 105400: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 60 | conf.fatal('Minimum required Boost version is 1.54.0\n' |
| 61 | 'Please upgrade your distribution or manually install a newer version of Boost' |
| 62 | ' (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 63 | |
Ashlesh Gawande | 39cf81a | 2018-02-22 13:37:07 -0600 | [diff] [blame] | 64 | conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'], |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 65 | uselib_store='SYNC', mandatory=True) |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 66 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 67 | conf.check_compiler_flags() |
| 68 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 69 | conf.load('coverage') |
| 70 | |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 71 | conf.load('sanitizers') |
| 72 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 73 | conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR']) |
| 74 | |
| 75 | conf.write_config_header('config.hpp') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 76 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 77 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 78 | def build(bld): |
| 79 | version(bld) |
| 80 | |
| 81 | bld(features="subst", |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 82 | name='version.hpp', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 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], |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 93 | VERSION_PATCH=VERSION_SPLIT[2]) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 94 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 95 | bld.objects( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 96 | target='nlsr-objects', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 97 | source=bld.path.ant_glob(['src/**/*.cpp'], |
| 98 | excl=['src/main.cpp']), |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 99 | use='NDN_CXX BOOST SYNC', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 100 | includes='. src', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 101 | export_includes='. src') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 102 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 103 | bld.program( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 104 | target='bin/nlsr', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 105 | name='nlsr', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 106 | source='src/main.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 107 | use='nlsr-objects') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 108 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 109 | bld.program( |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 110 | target='bin/nlsrc', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 111 | name='nlsrc', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 112 | source='tools/nlsrc.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 113 | use='nlsr-objects BOOST') |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 114 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 115 | bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf') |
Ashlesh Gawande | 9b71bbc | 2017-07-21 15:52:25 -0500 | [diff] [blame] | 116 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 117 | if bld.env.WITH_TESTS: |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 118 | bld.recurse('tests') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 119 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 120 | if bld.env.SPHINX_BUILD: |
| 121 | bld(features='sphinx', |
| 122 | name='manpages', |
| 123 | builder='man', |
| 124 | outdir='docs/manpages', |
| 125 | config='docs/conf.py', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 126 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 127 | install_path='${MANDIR}', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 128 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 129 | |
| 130 | def docs(bld): |
| 131 | from waflib import Options |
| 132 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 133 | |
| 134 | def doxygen(bld): |
| 135 | version(bld) |
| 136 | |
| 137 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 138 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 139 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 140 | bld(features='subst', |
| 141 | name='doxygen.conf', |
| 142 | source=['docs/doxygen.conf.in', |
| 143 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 144 | target=['docs/doxygen.conf', |
| 145 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 146 | VERSION=VERSION, |
| 147 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 148 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 149 | else '../docs/named_data_theme/named_data_footer.html', |
| 150 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 151 | |
| 152 | bld(features='doxygen', |
| 153 | doxyfile='docs/doxygen.conf', |
| 154 | use='doxygen.conf') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 155 | |
| 156 | def sphinx(bld): |
| 157 | version(bld) |
| 158 | |
| 159 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 160 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 161 | |
| 162 | bld(features='sphinx', |
| 163 | config='docs/conf.py', |
| 164 | outdir='docs', |
| 165 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 166 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 167 | |
| 168 | def version(ctx): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 169 | # don't execute more than once |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 170 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 171 | return |
| 172 | |
| 173 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 174 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 175 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 176 | # first, try to get a version string from git |
| 177 | gotVersionFromGit = False |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 178 | try: |
| 179 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 180 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 181 | if out: |
| 182 | gotVersionFromGit = True |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 183 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 184 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 185 | else: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 186 | # no tags matched |
| 187 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
| 188 | except subprocess.CalledProcessError: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 189 | pass |
| 190 | |
| 191 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 192 | if not gotVersionFromGit and versionFile is not None: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 193 | try: |
| 194 | Context.g_module.VERSION = versionFile.read() |
| 195 | return |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 196 | except EnvironmentError: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 197 | pass |
| 198 | |
| 199 | # version was obtained from git, update VERSION file if necessary |
| 200 | if versionFile is not None: |
| 201 | try: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 202 | if versionFile.read() == Context.g_module.VERSION: |
| 203 | # already up-to-date |
| 204 | return |
| 205 | except EnvironmentError as e: |
| 206 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 207 | else: |
| 208 | versionFile = ctx.path.make_node('VERSION') |
| 209 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 210 | try: |
| 211 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame^] | 212 | except EnvironmentError as e: |
| 213 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 214 | |
| 215 | def dist(ctx): |
| 216 | version(ctx) |
| 217 | |
| 218 | def distcheck(ctx): |
| 219 | version(ctx) |