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