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 | """ |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 3 | Copyright (c) 2014-2019, The University of Memphis, |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | Regents of the University of California, |
| 5 | Arizona Board of Regents. |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 6 | |
| 7 | This file is part of NLSR (Named-data Link State Routing). |
| 8 | See AUTHORS.md for complete list of NLSR authors and contributors. |
| 9 | |
| 10 | NLSR is free software: you can redistribute it and/or modify it under the terms |
| 11 | of the GNU General Public License as published by the Free Software Foundation, |
| 12 | either version 3 of the License, or (at your option) any later version. |
| 13 | |
| 14 | NLSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 16 | PURPOSE. See the GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License along with |
| 19 | NLSR, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
Saurab Dulal | 3012203 | 2018-05-07 23:20:59 +0000 | [diff] [blame] | 22 | VERSION = "0.4.3" |
sfayer | 93d9ec3 | 2014-12-04 23:34:41 +0000 | [diff] [blame] | 23 | APPNAME = "nlsr" |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame] | 24 | BUGREPORT = "https://redmine.named-data.net/projects/nlsr" |
| 25 | URL = "https://named-data.net/doc/NLSR/" |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 26 | GIT_TAG_PREFIX = "NLSR-" |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 27 | |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame] | 28 | from waflib import Logs, Utils, Context |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 29 | import os, subprocess |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 30 | |
| 31 | def options(opt): |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 32 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 33 | opt.load(['default-compiler-flags', 'coverage', 'sanitizers', |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame] | 34 | 'boost', 'doxygen', 'sphinx_build'], |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 35 | tooldir=['.waf-tools']) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 36 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 37 | nlsropt = opt.add_option_group('NLSR Options') |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 38 | 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] | 39 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 40 | def configure(conf): |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 41 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame] | 42 | 'default-compiler-flags', 'boost', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 43 | 'doxygen', 'sphinx_build']) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 44 | |
Alexander Afanasyev | fb2adee | 2015-03-30 10:56:55 -0700 | [diff] [blame] | 45 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 46 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
| 47 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 48 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
Vince Lehman | b45eed2 | 2015-01-13 14:58:07 -0600 | [diff] [blame] | 49 | uselib_store='NDN_CXX', mandatory=True) |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 50 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 51 | 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] | 52 | if conf.options.with_tests: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 53 | conf.env['WITH_TESTS'] = True |
| 54 | conf.define('WITH_TESTS', 1) |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 55 | boost_libs += ' unit_test_framework' |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 56 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 57 | conf.check_boost(lib=boost_libs, mt=True) |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 58 | if conf.env.BOOST_VERSION_NUMBER < 105800: |
| 59 | conf.fatal('Minimum required Boost version is 1.58.0\n' |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 60 | 'Please upgrade your distribution or manually install a newer version of Boost' |
| 61 | ' (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 62 | |
Ashlesh Gawande | 39cf81a | 2018-02-22 13:37:07 -0600 | [diff] [blame] | 63 | conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'], |
Ashlesh Gawande | 415676b | 2016-12-22 00:26:23 -0600 | [diff] [blame] | 64 | uselib_store='SYNC', mandatory=True) |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 65 | |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 66 | conf.check_cfg(package='PSync', args=['--cflags', '--libs'], |
| 67 | uselib_store='PSYNC', mandatory=True) |
| 68 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 69 | conf.check_compiler_flags() |
| 70 | |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 71 | # Loading "late" to prevent tests from being compiled with profiling flags |
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.write_config_header('config.hpp') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 77 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 78 | def build(bld): |
| 79 | version(bld) |
| 80 | |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 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', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 85 | VERSION_STRING=VERSION_BASE, |
| 86 | VERSION_BUILD=VERSION, |
| 87 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 88 | int(VERSION_SPLIT[1]) * 1000 + |
| 89 | int(VERSION_SPLIT[2]), |
| 90 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 91 | VERSION_MINOR=VERSION_SPLIT[1], |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 92 | VERSION_PATCH=VERSION_SPLIT[2]) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 93 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 94 | bld.objects( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 95 | target='nlsr-objects', |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 96 | source=bld.path.ant_glob('src/**/*.cpp', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 97 | excl=['src/main.cpp']), |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 98 | use='NDN_CXX BOOST SYNC PSYNC', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 99 | includes='. src', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 100 | export_includes='. src') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 101 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 102 | bld.program( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 103 | target='bin/nlsr', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 104 | name='nlsr', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 105 | source='src/main.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 106 | use='nlsr-objects') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 107 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 108 | bld.program( |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 109 | target='bin/nlsrc', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 110 | name='nlsrc', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 111 | source='tools/nlsrc.cpp', |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 112 | use='nlsr-objects') |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 113 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 114 | if bld.env.WITH_TESTS: |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 115 | bld.recurse('tests') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 116 | |
Davide Pesavento | 0da3eab | 2019-01-31 01:10:00 -0500 | [diff] [blame^] | 117 | bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf') |
| 118 | |
| 119 | if Utils.unversioned_sys_platform() == 'linux': |
| 120 | bld(features='subst', |
| 121 | name='nlsr.service', |
| 122 | source='systemd/nlsr.service.in', |
| 123 | target='systemd/nlsr.service') |
| 124 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 125 | if bld.env.SPHINX_BUILD: |
| 126 | bld(features='sphinx', |
| 127 | name='manpages', |
| 128 | builder='man', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 129 | config='docs/conf.py', |
Davide Pesavento | 0da3eab | 2019-01-31 01:10:00 -0500 | [diff] [blame^] | 130 | outdir='docs/manpages', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 131 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 132 | install_path='${MANDIR}', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 133 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 134 | |
| 135 | def docs(bld): |
| 136 | from waflib import Options |
| 137 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 138 | |
| 139 | def doxygen(bld): |
| 140 | version(bld) |
| 141 | |
| 142 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 143 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 144 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 145 | bld(features='subst', |
| 146 | name='doxygen.conf', |
| 147 | source=['docs/doxygen.conf.in', |
| 148 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 149 | target=['docs/doxygen.conf', |
| 150 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 151 | VERSION=VERSION, |
| 152 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 153 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 154 | else '../docs/named_data_theme/named_data_footer.html', |
| 155 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 156 | |
| 157 | bld(features='doxygen', |
| 158 | doxyfile='docs/doxygen.conf', |
| 159 | use='doxygen.conf') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 160 | |
| 161 | def sphinx(bld): |
| 162 | version(bld) |
| 163 | |
| 164 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 165 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 166 | |
| 167 | bld(features='sphinx', |
| 168 | config='docs/conf.py', |
| 169 | outdir='docs', |
| 170 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 171 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 172 | |
| 173 | def version(ctx): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 174 | # don't execute more than once |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 175 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 176 | return |
| 177 | |
| 178 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 179 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 180 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 181 | # first, try to get a version string from git |
| 182 | gotVersionFromGit = False |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 183 | try: |
| 184 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 185 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 186 | if out: |
| 187 | gotVersionFromGit = True |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 188 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 189 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 190 | else: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 191 | # no tags matched |
| 192 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | a08dc3f | 2018-05-24 00:40:28 -0400 | [diff] [blame] | 193 | except (OSError, subprocess.CalledProcessError): |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 194 | pass |
| 195 | |
| 196 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 197 | if not gotVersionFromGit and versionFile is not None: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 198 | try: |
| 199 | Context.g_module.VERSION = versionFile.read() |
| 200 | return |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 201 | except EnvironmentError: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 202 | pass |
| 203 | |
| 204 | # version was obtained from git, update VERSION file if necessary |
| 205 | if versionFile is not None: |
| 206 | try: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 207 | if versionFile.read() == Context.g_module.VERSION: |
| 208 | # already up-to-date |
| 209 | return |
| 210 | except EnvironmentError as e: |
| 211 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 212 | else: |
| 213 | versionFile = ctx.path.make_node('VERSION') |
| 214 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 215 | try: |
| 216 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 217 | except EnvironmentError as e: |
| 218 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 219 | |
| 220 | def dist(ctx): |
| 221 | version(ctx) |
| 222 | |
| 223 | def distcheck(ctx): |
| 224 | version(ctx) |