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 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 22 | from waflib import Context, Logs, Utils |
| 23 | import os, subprocess |
| 24 | |
Saurab Dulal | 1158c55 | 2020-01-19 18:36:00 -0600 | [diff] [blame^] | 25 | VERSION = "0.5.2" |
sfayer | 93d9ec3 | 2014-12-04 23:34:41 +0000 | [diff] [blame] | 26 | APPNAME = "nlsr" |
Davide Pesavento | 6ebfd7c | 2017-08-26 17:52:54 -0400 | [diff] [blame] | 27 | BUGREPORT = "https://redmine.named-data.net/projects/nlsr" |
| 28 | URL = "https://named-data.net/doc/NLSR/" |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 29 | GIT_TAG_PREFIX = "NLSR-" |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 30 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 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 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 37 | optgrp = opt.add_option_group('NLSR Options') |
| 38 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 39 | 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 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 46 | conf.env.WITH_TESTS = conf.options.with_tests |
Alexander Afanasyev | fb2adee | 2015-03-30 10:56:55 -0700 | [diff] [blame] | 47 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 48 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR) |
| 49 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', |
| 50 | pkg_config_path=pkg_config_path) |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 51 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 52 | boost_libs = ['system', 'iostreams', 'filesystem', 'regex'] |
| 53 | if conf.env.WITH_TESTS: |
| 54 | boost_libs += ['program_options', 'unit_test_framework'] |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 55 | |
dmcoomes | cf8d0ed | 2017-02-21 11:39:01 -0600 | [diff] [blame] | 56 | conf.check_boost(lib=boost_libs, mt=True) |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 57 | if conf.env.BOOST_VERSION_NUMBER < 105800: |
| 58 | conf.fatal('Minimum required Boost version is 1.58.0\n' |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 59 | 'Please upgrade your distribution or manually install a newer version of Boost' |
| 60 | ' (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 61 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 62 | conf.check_cfg(package='ChronoSync', args=['--cflags', '--libs'], uselib_store='SYNC', |
| 63 | pkg_config_path=pkg_config_path) |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 64 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 65 | conf.check_cfg(package='PSync', args=['--cflags', '--libs'], uselib_store='PSYNC', |
| 66 | pkg_config_path=pkg_config_path) |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 67 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 68 | conf.check_compiler_flags() |
| 69 | |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 70 | # Loading "late" to prevent tests from being compiled with profiling flags |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 71 | conf.load('coverage') |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 72 | conf.load('sanitizers') |
| 73 | |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 74 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
| 75 | # The config header will contain all defines that were added using conf.define() |
| 76 | # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES |
| 77 | # will not appear in the config header, but will instead be passed directly to the |
| 78 | # compiler on the command line. |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 79 | conf.write_config_header('config.hpp') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 80 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 81 | def build(bld): |
| 82 | version(bld) |
| 83 | |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 84 | bld(features='subst', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 85 | name='version.hpp', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 86 | source='src/version.hpp.in', |
| 87 | target='src/version.hpp', |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 88 | VERSION_STRING=VERSION_BASE, |
| 89 | VERSION_BUILD=VERSION, |
| 90 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 91 | int(VERSION_SPLIT[1]) * 1000 + |
| 92 | int(VERSION_SPLIT[2]), |
| 93 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 94 | VERSION_MINOR=VERSION_SPLIT[1], |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 95 | VERSION_PATCH=VERSION_SPLIT[2]) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 96 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 97 | bld.objects( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 98 | target='nlsr-objects', |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 99 | source=bld.path.ant_glob('src/**/*.cpp', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 100 | excl=['src/main.cpp']), |
Ashlesh Gawande | 32ec3fd | 2018-07-18 13:42:32 -0500 | [diff] [blame] | 101 | use='NDN_CXX BOOST SYNC PSYNC', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 102 | includes='. src', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 103 | export_includes='. src') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 104 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 105 | bld.program( |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 106 | target='bin/nlsr', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 107 | name='nlsr', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 108 | source='src/main.cpp', |
Davide Pesavento | c58cc7f | 2017-08-08 16:51:28 -0500 | [diff] [blame] | 109 | use='nlsr-objects') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 110 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 111 | bld.program( |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 112 | target='bin/nlsrc', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 113 | name='nlsrc', |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame] | 114 | source='tools/nlsrc.cpp', |
Davide Pesavento | e556991 | 2019-01-29 19:39:06 -0500 | [diff] [blame] | 115 | use='nlsr-objects') |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -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 | |
Davide Pesavento | 0da3eab | 2019-01-31 01:10:00 -0500 | [diff] [blame] | 120 | bld.install_as('${SYSCONFDIR}/ndn/nlsr.conf.sample', 'nlsr.conf') |
| 121 | |
| 122 | if Utils.unversioned_sys_platform() == 'linux': |
| 123 | bld(features='subst', |
| 124 | name='nlsr.service', |
| 125 | source='systemd/nlsr.service.in', |
| 126 | target='systemd/nlsr.service') |
| 127 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 128 | if bld.env.SPHINX_BUILD: |
| 129 | bld(features='sphinx', |
| 130 | name='manpages', |
| 131 | builder='man', |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 132 | config='docs/conf.py', |
Davide Pesavento | 0da3eab | 2019-01-31 01:10:00 -0500 | [diff] [blame] | 133 | outdir='docs/manpages', |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 134 | source=bld.path.ant_glob('docs/manpages/*.rst'), |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 135 | install_path='${MANDIR}', |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 136 | version=VERSION_BASE, |
| 137 | release=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 138 | |
| 139 | def docs(bld): |
| 140 | from waflib import Options |
| 141 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 142 | |
| 143 | def doxygen(bld): |
| 144 | version(bld) |
| 145 | |
| 146 | if not bld.env.DOXYGEN: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 147 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 148 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 149 | bld(features='subst', |
| 150 | name='doxygen.conf', |
| 151 | source=['docs/doxygen.conf.in', |
| 152 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 153 | target=['docs/doxygen.conf', |
| 154 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 155 | VERSION=VERSION, |
| 156 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 157 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 158 | else '../docs/named_data_theme/named_data_footer.html', |
| 159 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 160 | |
| 161 | bld(features='doxygen', |
| 162 | doxyfile='docs/doxygen.conf', |
| 163 | use='doxygen.conf') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 164 | |
| 165 | def sphinx(bld): |
| 166 | version(bld) |
| 167 | |
| 168 | if not bld.env.SPHINX_BUILD: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 169 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 170 | |
| 171 | bld(features='sphinx', |
| 172 | config='docs/conf.py', |
| 173 | outdir='docs', |
| 174 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | f75bfda | 2019-11-10 18:34:13 -0500 | [diff] [blame] | 175 | version=VERSION_BASE, |
| 176 | release=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 177 | |
| 178 | def version(ctx): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 179 | # don't execute more than once |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 180 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 181 | return |
| 182 | |
| 183 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 184 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 185 | |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 186 | # first, try to get a version string from git |
| 187 | gotVersionFromGit = False |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 188 | try: |
| 189 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 190 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 191 | if out: |
| 192 | gotVersionFromGit = True |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 193 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 194 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 195 | else: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 196 | # no tags matched |
| 197 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | a08dc3f | 2018-05-24 00:40:28 -0400 | [diff] [blame] | 198 | except (OSError, subprocess.CalledProcessError): |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 199 | pass |
| 200 | |
| 201 | versionFile = ctx.path.find_node('VERSION') |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 202 | if not gotVersionFromGit and versionFile is not None: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 203 | try: |
| 204 | Context.g_module.VERSION = versionFile.read() |
| 205 | return |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 206 | except EnvironmentError: |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 207 | pass |
| 208 | |
| 209 | # version was obtained from git, update VERSION file if necessary |
| 210 | if versionFile is not None: |
| 211 | try: |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 212 | if versionFile.read() == Context.g_module.VERSION: |
| 213 | # already up-to-date |
| 214 | return |
| 215 | except EnvironmentError as e: |
| 216 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 217 | else: |
| 218 | versionFile = ctx.path.make_node('VERSION') |
| 219 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 220 | try: |
| 221 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 67758b1 | 2018-03-06 18:36:44 -0500 | [diff] [blame] | 222 | except EnvironmentError as e: |
| 223 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 224 | |
| 225 | def dist(ctx): |
| 226 | version(ctx) |
| 227 | |
| 228 | def distcheck(ctx): |
| 229 | version(ctx) |