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 | """ |
Vince Lehman | c2e51f6 | 2015-01-20 15:03:11 -0600 | [diff] [blame] | 4 | Copyright (c) 2014-2015, The University of Memphis, |
| 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 | |
Alexander Afanasyev | 7decbbf | 2014-08-24 21:29:01 -0700 | [diff] [blame] | 23 | VERSION = '0.1.0' |
sfayer | 93d9ec3 | 2014-12-04 23:34:41 +0000 | [diff] [blame] | 24 | APPNAME = "nlsr" |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 25 | BUGREPORT = "http://redmine.named-data.net/projects/nlsr" |
| 26 | URL = "http://named-data.net/doc/NLSR/" |
| 27 | GIT_TAG_PREFIX = "NLSR-" |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 28 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 29 | from waflib import Build, Logs, Utils, Task, TaskGen, Configure, Context |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 30 | from waflib.Tools import c_preproc |
Alexander Afanasyev | fb2adee | 2015-03-30 10:56:55 -0700 | [diff] [blame] | 31 | import os |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 32 | |
| 33 | def options(opt): |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 34 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 35 | opt.load(['default-compiler-flags', 'coverage', |
| 36 | 'boost', 'protoc', 'openssl', |
| 37 | 'doxygen', 'sphinx_build'], |
| 38 | tooldir=['.waf-tools']) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 39 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 40 | nlsropt = opt.add_option_group('NLSR Options') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 41 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 42 | nlsropt.add_option('--with-tests', action='store_true', default=False, dest='with_tests', |
| 43 | help='''build unit tests''') |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 44 | |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 45 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 46 | def configure(conf): |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 47 | conf.load(['compiler_cxx', 'gnu_dirs', |
| 48 | 'boost', 'openssl', |
| 49 | 'default-compiler-flags', |
| 50 | 'doxygen', 'sphinx_build']) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 51 | |
Alexander Afanasyev | fb2adee | 2015-03-30 10:56:55 -0700 | [diff] [blame] | 52 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 53 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
| 54 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 55 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
Vince Lehman | b45eed2 | 2015-01-13 14:58:07 -0600 | [diff] [blame] | 56 | uselib_store='NDN_CXX', mandatory=True) |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 57 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 58 | conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], |
| 59 | uselib_store='LOG4CXX', mandatory=True) |
| 60 | |
Vince Lehman | b45eed2 | 2015-01-13 14:58:07 -0600 | [diff] [blame] | 61 | conf.check_openssl(mandatory=True) |
| 62 | |
akmhoque | 674b0b1 | 2014-05-20 14:33:28 -0500 | [diff] [blame] | 63 | boost_libs = 'system chrono program_options iostreams thread regex filesystem' |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 64 | if conf.options.with_tests: |
| 65 | conf.env['WITH_TESTS'] = 1 |
| 66 | conf.define('WITH_TESTS', 1); |
| 67 | boost_libs += ' unit_test_framework' |
akmhoque | 85d8833 | 2014-02-17 21:11:21 -0600 | [diff] [blame] | 68 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 69 | conf.check_boost(lib=boost_libs) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 70 | |
akmhoque | c8a10f7 | 2014-04-25 18:42:55 -0500 | [diff] [blame] | 71 | if conf.env.BOOST_VERSION_NUMBER < 104800: |
akmhoque | fdbddb1 | 2014-05-02 18:35:19 -0500 | [diff] [blame] | 72 | Logs.error("Minimum required boost version is 1.48.0") |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 73 | Logs.error("Please upgrade your distribution or install custom boost libraries") |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 74 | return |
| 75 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 76 | conf.load('protoc') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 77 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 78 | conf.load('coverage') |
| 79 | |
| 80 | conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nlsr.conf' % conf.env['SYSCONFDIR']) |
| 81 | |
| 82 | conf.write_config_header('config.hpp') |
akmhoque | 05d5fcf | 2014-04-15 14:58:45 -0500 | [diff] [blame] | 83 | |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 84 | |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 85 | def build(bld): |
| 86 | version(bld) |
| 87 | |
| 88 | bld(features="subst", |
| 89 | name='version', |
| 90 | source='src/version.hpp.in', |
| 91 | target='src/version.hpp', |
| 92 | install_path=None, |
| 93 | VERSION_STRING=VERSION_BASE, |
| 94 | VERSION_BUILD=VERSION, |
| 95 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 96 | int(VERSION_SPLIT[1]) * 1000 + |
| 97 | int(VERSION_SPLIT[2]), |
| 98 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 99 | VERSION_MINOR=VERSION_SPLIT[1], |
| 100 | VERSION_PATCH=VERSION_SPLIT[2], |
| 101 | ) |
| 102 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 103 | nsync_objects = bld( |
| 104 | target='nsync-objects', |
| 105 | name='nsync-objects', |
| 106 | features='cxx', |
| 107 | source=bld.path.ant_glob(['nsync/**/*.cc', 'nsync/**/*.proto']), |
Vince Lehman | b45eed2 | 2015-01-13 14:58:07 -0600 | [diff] [blame] | 108 | use='BOOST NDN_CXX OPENSSL', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 109 | includes='nsync', |
| 110 | export_includes='nsync', |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 111 | ) |
| 112 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 113 | nlsr_objects = bld( |
| 114 | target='nlsr-objects', |
| 115 | name='nlsr-objects', |
| 116 | features='cxx', |
| 117 | source=bld.path.ant_glob(['src/**/*.cpp'], |
| 118 | excl=['src/main.cpp']), |
Vince Lehman | b45eed2 | 2015-01-13 14:58:07 -0600 | [diff] [blame] | 119 | use='nsync-objects NDN_CXX BOOST LOG4CXX', |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 120 | includes='. src', |
| 121 | export_includes='. src', |
| 122 | ) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 123 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 124 | nlsr = bld( |
| 125 | target='bin/nlsr', |
| 126 | features='cxx cxxprogram', |
| 127 | source='src/main.cpp', |
| 128 | use='nlsr-objects', |
| 129 | ) |
akmhoque | 298385a | 2014-02-13 14:13:09 -0600 | [diff] [blame] | 130 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame^] | 131 | nlsrc = bld( |
| 132 | target='bin/nlsrc', |
| 133 | features='cxx cxxprogram', |
| 134 | source='tools/nlsrc.cpp', |
| 135 | use='nlsr-objects BOOST', |
| 136 | ) |
| 137 | |
Yingdi Yu | 40cd1c3 | 2014-04-17 15:02:17 -0700 | [diff] [blame] | 138 | if bld.env['WITH_TESTS']: |
| 139 | bld.recurse('tests') |
| 140 | bld.recurse('tests-integrated') |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 141 | |
Vince Lehman | c439d66 | 2015-04-27 10:56:00 -0500 | [diff] [blame^] | 142 | if bld.env['SPHINX_BUILD']: |
| 143 | bld(features="sphinx", |
| 144 | builder="man", |
| 145 | outdir="docs/manpages", |
| 146 | config="docs/conf.py", |
| 147 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
| 148 | install_path="${MANDIR}/", |
| 149 | VERSION=VERSION) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 150 | |
| 151 | def docs(bld): |
| 152 | from waflib import Options |
| 153 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 154 | |
| 155 | def doxygen(bld): |
| 156 | version(bld) |
| 157 | |
| 158 | if not bld.env.DOXYGEN: |
| 159 | Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 160 | else: |
| 161 | bld(features="subst", |
| 162 | name="doxygen-conf", |
| 163 | source="docs/doxygen.conf.in", |
| 164 | target="docs/doxygen.conf", |
| 165 | VERSION=VERSION_BASE, |
| 166 | ) |
| 167 | |
| 168 | bld(features="doxygen", |
| 169 | doxyfile='docs/doxygen.conf', |
| 170 | use="doxygen-conf") |
| 171 | |
| 172 | def sphinx(bld): |
| 173 | version(bld) |
| 174 | |
| 175 | if not bld.env.SPHINX_BUILD: |
| 176 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)") |
| 177 | else: |
| 178 | bld(features="sphinx", |
| 179 | outdir="docs", |
| 180 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 181 | config="docs/conf.py", |
| 182 | VERSION=VERSION_BASE) |
| 183 | |
| 184 | def version(ctx): |
| 185 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 186 | return |
| 187 | |
| 188 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 189 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 190 | |
| 191 | didGetVersion = False |
| 192 | try: |
| 193 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 194 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 195 | stderr=None, stdin=None) |
Alexander Afanasyev | c0b97af | 2014-09-01 13:23:50 -0700 | [diff] [blame] | 196 | out = str(p.communicate()[0].strip()) |
Vince Lehman | b722b10 | 2014-08-24 16:33:49 -0500 | [diff] [blame] | 197 | didGetVersion = (p.returncode == 0 and out != "") |
| 198 | if didGetVersion: |
| 199 | if out.startswith(GIT_TAG_PREFIX): |
| 200 | Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] |
| 201 | else: |
| 202 | Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out) |
| 203 | except OSError: |
| 204 | pass |
| 205 | |
| 206 | versionFile = ctx.path.find_node('VERSION') |
| 207 | |
| 208 | if not didGetVersion and versionFile is not None: |
| 209 | try: |
| 210 | Context.g_module.VERSION = versionFile.read() |
| 211 | return |
| 212 | except (OSError, IOError): |
| 213 | pass |
| 214 | |
| 215 | # version was obtained from git, update VERSION file if necessary |
| 216 | if versionFile is not None: |
| 217 | try: |
| 218 | version = versionFile.read() |
| 219 | if version == Context.g_module.VERSION: |
| 220 | return # no need to update |
| 221 | except (OSError, IOError): |
| 222 | Logs.warn("VERSION file exists, but not readable") |
| 223 | else: |
| 224 | versionFile = ctx.path.make_node('VERSION') |
| 225 | |
| 226 | if versionFile is None: |
| 227 | return |
| 228 | |
| 229 | try: |
| 230 | versionFile.write(Context.g_module.VERSION) |
| 231 | except (OSError, IOError): |
| 232 | Logs.warn("VERSION file is not writeable") |
| 233 | |
| 234 | def dist(ctx): |
| 235 | version(ctx) |
| 236 | |
| 237 | def distcheck(ctx): |
| 238 | version(ctx) |