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