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