Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
| 3 | VERSION='0.1.0' |
| 4 | APPNAME="ndns" |
| 5 | BUGREPORT = "http://redmine.named-data.net/projects/ndns" |
| 6 | URL = "http://named-data.net/doc/ndns/" |
| 7 | GIT_TAG_PREFIX = "ndns-" |
| 8 | |
| 9 | from waflib import Logs, Utils, Context |
| 10 | import os |
| 11 | |
| 12 | def options(opt): |
| 13 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 14 | opt.load(['boost', 'default-compiler-flags', 'doxygen', 'sphinx_build', |
Alexander Afanasyev | 984ca9d | 2016-12-19 13:09:14 -0800 | [diff] [blame^] | 15 | 'sqlite3', 'pch', 'sanitizers', 'coverage'], tooldir=['.waf-tools']) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 16 | |
| 17 | ropt = opt.add_option_group('NDNS Options') |
| 18 | |
| 19 | ropt.add_option('--with-tests', action='store_true', default=False, dest='with_tests', |
| 20 | help='''build unit tests''') |
| 21 | |
| 22 | def configure(conf): |
| 23 | conf.load(['compiler_cxx', 'gnu_dirs', |
| 24 | 'boost', 'default-compiler-flags', 'doxygen', 'sphinx_build', |
Alexander Afanasyev | 984ca9d | 2016-12-19 13:09:14 -0800 | [diff] [blame^] | 25 | 'sqlite3', 'pch', 'sanitizers', 'coverage']) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 26 | |
Alexander Afanasyev | 6ba3ae0 | 2015-03-30 10:55:15 -0700 | [diff] [blame] | 27 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 28 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Alexander Afanasyev | 83b7c2f | 2015-01-23 13:08:34 -0800 | [diff] [blame] | 29 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 30 | conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], |
| 31 | uselib_store='LOG4CXX', mandatory=True) |
| 32 | |
| 33 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 34 | uselib_store='NDN_CXX', mandatory=True) |
| 35 | |
| 36 | conf.check_sqlite3(mandatory=True) |
| 37 | |
| 38 | if conf.options.with_tests: |
| 39 | conf.env['WITH_TESTS'] = True |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 40 | conf.define('NDNS_HAVE_TESTS', 1) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 41 | |
Shock Jiang | 4e0ab7c | 2014-09-11 16:23:21 -0700 | [diff] [blame] | 42 | USED_BOOST_LIBS = ['system', 'filesystem'] |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 43 | if conf.env['WITH_TESTS']: |
| 44 | USED_BOOST_LIBS += ['unit_test_framework'] |
| 45 | conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True) |
| 46 | |
| 47 | if not conf.options.with_sqlite_locking: |
| 48 | conf.define('DISABLE_SQLITE3_FS_LOCKING', 1) |
| 49 | |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 50 | conf.define("DEFAULT_CONFIG_PATH", "%s/ndns" % conf.env['SYSCONFDIR']) |
| 51 | conf.define("DEFAULT_DATABASE_PATH", "%s/ndns" % conf.env['LOCALSTATEDIR']) |
Shock Jiang | 3c72318 | 2014-09-10 16:41:18 -0700 | [diff] [blame] | 52 | |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 53 | conf.write_config_header('src/config.hpp') |
| 54 | |
| 55 | def build (bld): |
| 56 | version(bld) |
| 57 | |
| 58 | bld(features="subst", |
| 59 | name='version', |
| 60 | source='src/version.hpp.in', |
| 61 | target='src/version.hpp', |
| 62 | install_path=None, |
| 63 | VERSION_STRING=VERSION_BASE, |
| 64 | VERSION_BUILD=VERSION, |
| 65 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 66 | int(VERSION_SPLIT[1]) * 1000 + |
| 67 | int(VERSION_SPLIT[2]), |
| 68 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 69 | VERSION_MINOR=VERSION_SPLIT[1], |
| 70 | VERSION_PATCH=VERSION_SPLIT[2], |
| 71 | ) |
| 72 | |
| 73 | bld( |
| 74 | features='cxx', |
| 75 | name='ndns-objects', |
| 76 | source=bld.path.ant_glob(['src/**/*.cpp'], |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 77 | excl=['src/main.cpp',]), |
Alexander Afanasyev | 59a42ec | 2014-09-02 18:21:16 -0700 | [diff] [blame] | 78 | use='version NDN_CXX LOG4CXX BOOST', |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 79 | includes='src', |
| 80 | export_includes='src', |
| 81 | ) |
| 82 | |
| 83 | if bld.env['SPHINX_BUILD']: |
| 84 | bld(features="sphinx", |
| 85 | builder="man", |
| 86 | outdir="docs/manpages", |
| 87 | config="docs/conf.py", |
| 88 | source=bld.path.ant_glob('docs/manpages/**/*.rst'), |
| 89 | install_path="${MANDIR}/", |
| 90 | VERSION=VERSION) |
| 91 | |
| 92 | bld.recurse('tests') |
| 93 | |
| 94 | bld.recurse('tools') |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 95 | |
| 96 | bld(features='subst', |
Shock Jiang | cde2871 | 2014-10-19 21:17:20 -0700 | [diff] [blame] | 97 | source=['validator.conf.sample.in', 'ndns.conf.sample.in'], |
| 98 | target=['validator.conf.sample', 'ndns.conf.sample'], |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 99 | install_path='${SYSCONFDIR}/ndns', |
| 100 | name='validator-sample', |
| 101 | ANCHORPATH='anchors/root.cert', |
| 102 | RELATION='is-prefix-of', |
Shock Jiang | e1a81fd | 2014-11-20 20:25:49 -0800 | [diff] [blame] | 103 | DEFAULT_CONFIG_PATH="%s/ndns" % bld.env['SYSCONFDIR'], |
| 104 | DEFAULT_DATABASE_PATH="%s/ndns" % bld.env['LOCALSTATEDIR'], |
Shock Jiang | 0b165f4 | 2014-10-24 09:08:09 -0700 | [diff] [blame] | 105 | help='the validator configuration of ndns', |
| 106 | ) |
| 107 | |
| 108 | bld(features='subst', |
| 109 | source='log4cxx.properties.sample.in', |
| 110 | target='log4cxx.properties.sample', |
| 111 | install_path='${SYSCONFDIR}/ndns', |
| 112 | is_copy = True, |
| 113 | name='log4cxx-sample', |
| 114 | help='the log4cxx configration file', |
| 115 | ) |
Alexander Afanasyev | 4ffcff2 | 2014-09-02 15:39:20 -0700 | [diff] [blame] | 116 | |
| 117 | def docs(bld): |
| 118 | from waflib import Options |
| 119 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 120 | |
| 121 | def doxygen(bld): |
| 122 | version(bld) |
| 123 | |
| 124 | if not bld.env.DOXYGEN: |
| 125 | Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 126 | else: |
| 127 | bld(features="subst", |
| 128 | name="doxygen-conf", |
| 129 | source=["docs/doxygen.conf.in", |
| 130 | "docs/named_data_theme/named_data_footer-with-analytics.html.in"], |
| 131 | target=["docs/doxygen.conf", |
| 132 | "docs/named_data_theme/named_data_footer-with-analytics.html"], |
| 133 | VERSION=VERSION_BASE, |
| 134 | HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \ |
| 135 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 136 | else "../docs/named_data_theme/named_data_footer.html", |
| 137 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""), |
| 138 | ) |
| 139 | |
| 140 | bld(features="doxygen", |
| 141 | doxyfile='docs/doxygen.conf', |
| 142 | use="doxygen-conf") |
| 143 | |
| 144 | def sphinx(bld): |
| 145 | version(bld) |
| 146 | |
| 147 | if not bld.env.SPHINX_BUILD: |
| 148 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)") |
| 149 | else: |
| 150 | bld(features="sphinx", |
| 151 | outdir="docs", |
| 152 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 153 | config="docs/conf.py", |
| 154 | VERSION=VERSION_BASE) |
| 155 | |
| 156 | def version(ctx): |
| 157 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 158 | return |
| 159 | |
| 160 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 161 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 162 | |
| 163 | didGetVersion = False |
| 164 | try: |
| 165 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 166 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 167 | stderr=None, stdin=None) |
| 168 | out = str(p.communicate()[0].strip()) |
| 169 | didGetVersion = (p.returncode == 0 and out != "") |
| 170 | if didGetVersion: |
| 171 | if out.startswith(GIT_TAG_PREFIX): |
| 172 | Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] |
| 173 | else: |
| 174 | Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out) |
| 175 | except OSError: |
| 176 | pass |
| 177 | |
| 178 | versionFile = ctx.path.find_node('VERSION') |
| 179 | |
| 180 | if not didGetVersion and versionFile is not None: |
| 181 | try: |
| 182 | Context.g_module.VERSION = versionFile.read() |
| 183 | return |
| 184 | except (OSError, IOError): |
| 185 | pass |
| 186 | |
| 187 | # version was obtained from git, update VERSION file if necessary |
| 188 | if versionFile is not None: |
| 189 | try: |
| 190 | version = versionFile.read() |
| 191 | if version == Context.g_module.VERSION: |
| 192 | return # no need to update |
| 193 | except (OSError, IOError): |
| 194 | Logs.warn("VERSION file exists, but not readable") |
| 195 | else: |
| 196 | versionFile = ctx.path.make_node('VERSION') |
| 197 | |
| 198 | if versionFile is None: |
| 199 | return |
| 200 | |
| 201 | try: |
| 202 | versionFile.write(Context.g_module.VERSION) |
| 203 | except (OSError, IOError): |
| 204 | Logs.warn("VERSION file is not writeable") |
| 205 | |
| 206 | def dist(ctx): |
| 207 | version(ctx) |
| 208 | |
| 209 | def distcheck(ctx): |
| 210 | version(ctx) |