blob: 6fc3bccd94ef1eaf07c493b7f5183c6668d010e4 [file] [log] [blame]
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3VERSION='0.1.0'
4APPNAME="ndns"
5BUGREPORT = "http://redmine.named-data.net/projects/ndns"
6URL = "http://named-data.net/doc/ndns/"
7GIT_TAG_PREFIX = "ndns-"
8
9from waflib import Logs, Utils, Context
10import os
11
12def options(opt):
13 opt.load(['compiler_cxx', 'gnu_dirs'])
14 opt.load(['boost', 'default-compiler-flags', 'doxygen', 'sphinx_build',
Alexander Afanasyev984ca9d2016-12-19 13:09:14 -080015 'sqlite3', 'pch', 'sanitizers', 'coverage'], tooldir=['.waf-tools'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070016
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
22def configure(conf):
23 conf.load(['compiler_cxx', 'gnu_dirs',
24 'boost', 'default-compiler-flags', 'doxygen', 'sphinx_build',
Alexander Afanasyev984ca9d2016-12-19 13:09:14 -080025 'sqlite3', 'pch', 'sanitizers', 'coverage'])
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070026
Alexander Afanasyev6ba3ae02015-03-30 10:55:15 -070027 if 'PKG_CONFIG_PATH' not in os.environ:
28 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Alexander Afanasyev83b7c2f2015-01-23 13:08:34 -080029
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070030 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 Jiang0b165f42014-10-24 09:08:09 -070040 conf.define('NDNS_HAVE_TESTS', 1)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070041
Shock Jiang4e0ab7c2014-09-11 16:23:21 -070042 USED_BOOST_LIBS = ['system', 'filesystem']
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070043 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 Jiang0b165f42014-10-24 09:08:09 -070050 conf.define("DEFAULT_CONFIG_PATH", "%s/ndns" % conf.env['SYSCONFDIR'])
51 conf.define("DEFAULT_DATABASE_PATH", "%s/ndns" % conf.env['LOCALSTATEDIR'])
Shock Jiang3c723182014-09-10 16:41:18 -070052
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070053 conf.write_config_header('src/config.hpp')
54
55def 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 Jiang0b165f42014-10-24 09:08:09 -070077 excl=['src/main.cpp',]),
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070078 use='version NDN_CXX LOG4CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070079 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 Jiang0b165f42014-10-24 09:08:09 -070095
96 bld(features='subst',
Shock Jiangcde28712014-10-19 21:17:20 -070097 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
98 target=['validator.conf.sample', 'ndns.conf.sample'],
Shock Jiang0b165f42014-10-24 09:08:09 -070099 install_path='${SYSCONFDIR}/ndns',
100 name='validator-sample',
101 ANCHORPATH='anchors/root.cert',
102 RELATION='is-prefix-of',
Shock Jiange1a81fd2014-11-20 20:25:49 -0800103 DEFAULT_CONFIG_PATH="%s/ndns" % bld.env['SYSCONFDIR'],
104 DEFAULT_DATABASE_PATH="%s/ndns" % bld.env['LOCALSTATEDIR'],
Shock Jiang0b165f42014-10-24 09:08:09 -0700105 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 Afanasyev4ffcff22014-09-02 15:39:20 -0700116
117def docs(bld):
118 from waflib import Options
119 Options.commands = ['doxygen', 'sphinx'] + Options.commands
120
121def 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
144def 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
156def 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
206def dist(ctx):
207 version(ctx)
208
209def distcheck(ctx):
210 version(ctx)