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.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 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 80 | def build(bld): |
| 81 | version(bld) |
| 82 | |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 83 | bld(features='subst', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 84 | name='version.hpp', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 85 | source='src/version.hpp.in', |
| 86 | target='src/version.hpp', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 87 | VERSION_STRING=VERSION_BASE, |
| 88 | VERSION_BUILD=VERSION, |
| 89 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 90 | int(VERSION_SPLIT[1]) * 1000 + |
| 91 | int(VERSION_SPLIT[2]), |
| 92 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 93 | VERSION_MINOR=VERSION_SPLIT[1], |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 94 | VERSION_PATCH=VERSION_SPLIT[2]) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 95 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 96 | bld.objects( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 97 | target='nlsr-objects', |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 98 | source=bld.path.ant_glob('src/**/*.cpp', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 99 | excl=['src/main.cpp']), |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 100 | use='NDN_CXX BOOST SYNC PSYNC', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 101 | includes='. src', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 102 | export_includes='. src') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 103 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 104 | bld.program( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 105 | target='bin/nlsr', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 106 | name='nlsr', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 107 | source='src/main.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 108 | use='nlsr-objects') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 109 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 110 | bld.program( |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 111 | target='bin/nlsrc', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 112 | name='nlsrc', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 113 | source='tools/nlsrc.cpp', |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 114 | use='nlsr-objects') |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 115 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 116 | bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf') |
Ashlesh Gawande | 9b71bbc | 2017-07-21 15:52:25 -0500 | [diff] [blame] | 117 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 118 | if bld.env.WITH_TESTS: |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 119 | bld.recurse('tests') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 120 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 121 | if bld.env.SPHINX_BUILD: |
| 122 | bld(features='sphinx', |
| 123 | name='manpages', |
| 124 | builder='man', |
| 125 | outdir='docs/manpages', |
| 126 | config='docs/conf.py', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 127 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 128 | install_path='${MANDIR}', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 129 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 130 | |
| 131 | def docs(bld): |
| 132 | from waflib import Options |
| 133 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 134 | |
| 135 | def doxygen(bld): |
| 136 | version(bld) |
| 137 | |
| 138 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 139 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 140 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 141 | bld(features='subst', |
| 142 | name='doxygen.conf', |
| 143 | source=['docs/doxygen.conf.in', |
| 144 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 145 | target=['docs/doxygen.conf', |
| 146 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 147 | VERSION=VERSION, |
| 148 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 149 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 150 | else '../docs/named_data_theme/named_data_footer.html', |
| 151 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 152 | |
| 153 | bld(features='doxygen', |
| 154 | doxyfile='docs/doxygen.conf', |
| 155 | use='doxygen.conf') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 156 | |
| 157 | def sphinx(bld): |
| 158 | version(bld) |
| 159 | |
| 160 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 161 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 162 | |
| 163 | bld(features='sphinx', |
| 164 | config='docs/conf.py', |
| 165 | outdir='docs', |
| 166 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 167 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 168 | |
| 169 | def version(ctx): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 170 | # don't execute more than once |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 171 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 172 | return |
| 173 | |
| 174 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 175 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 176 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 177 | # first, try to get a version string from git |
| 178 | gotVersionFromGit = False |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 179 | try: |
| 180 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 181 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 182 | if out: |
| 183 | gotVersionFromGit = True |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 184 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 185 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 186 | else: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 187 | # no tags matched |
| 188 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | a08dc3f | 2018-05-24 00:40:28 -0400 | [diff] [blame] | 189 | except (OSError, subprocess.CalledProcessError): |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 190 | pass |
| 191 | |
| 192 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 193 | if not gotVersionFromGit and versionFile is not None: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 194 | try: |
| 195 | Context.g_module.VERSION = versionFile.read() |
| 196 | return |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 197 | except EnvironmentError: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 198 | pass |
| 199 | |
| 200 | # version was obtained from git, update VERSION file if necessary |
| 201 | if versionFile is not None: |
| 202 | try: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 203 | if versionFile.read() == Context.g_module.VERSION: |
| 204 | # already up-to-date |
| 205 | return |
| 206 | except EnvironmentError as e: |
| 207 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 208 | else: |
| 209 | versionFile = ctx.path.make_node('VERSION') |
| 210 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 211 | try: |
| 212 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 213 | except EnvironmentError as e: |
| 214 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 215 | |
| 216 | def dist(ctx): |
| 217 | version(ctx) |
| 218 | |
| 219 | def distcheck(ctx): |
| 220 | version(ctx) |