blob: 26f4fc89862754ff25c517fb367b36a65d5f4e64 [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',
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
22def 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
Shock Jiang0b165f42014-10-24 09:08:09 -070035
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070036 if conf.options.with_tests:
37 conf.env['WITH_TESTS'] = True
Shock Jiang0b165f42014-10-24 09:08:09 -070038 conf.define('NDNS_HAVE_TESTS', 1)
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070039
Shock Jiang4e0ab7c2014-09-11 16:23:21 -070040 USED_BOOST_LIBS = ['system', 'filesystem']
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070041 if conf.env['WITH_TESTS']:
42 USED_BOOST_LIBS += ['unit_test_framework']
43 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True)
44
45 if not conf.options.with_sqlite_locking:
46 conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
47
Shock Jiang0b165f42014-10-24 09:08:09 -070048 conf.define("DEFAULT_CONFIG_PATH", "%s/ndns" % conf.env['SYSCONFDIR'])
49 conf.define("DEFAULT_DATABASE_PATH", "%s/ndns" % conf.env['LOCALSTATEDIR'])
Shock Jiang3c723182014-09-10 16:41:18 -070050
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070051 conf.write_config_header('src/config.hpp')
52
53def build (bld):
54 version(bld)
55
56 bld(features="subst",
57 name='version',
58 source='src/version.hpp.in',
59 target='src/version.hpp',
60 install_path=None,
61 VERSION_STRING=VERSION_BASE,
62 VERSION_BUILD=VERSION,
63 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
64 int(VERSION_SPLIT[1]) * 1000 +
65 int(VERSION_SPLIT[2]),
66 VERSION_MAJOR=VERSION_SPLIT[0],
67 VERSION_MINOR=VERSION_SPLIT[1],
68 VERSION_PATCH=VERSION_SPLIT[2],
69 )
70
71 bld(
72 features='cxx',
73 name='ndns-objects',
74 source=bld.path.ant_glob(['src/**/*.cpp'],
Shock Jiang0b165f42014-10-24 09:08:09 -070075 excl=['src/main.cpp',]),
Alexander Afanasyev59a42ec2014-09-02 18:21:16 -070076 use='version NDN_CXX LOG4CXX BOOST',
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -070077 includes='src',
78 export_includes='src',
79 )
80
81 if bld.env['SPHINX_BUILD']:
82 bld(features="sphinx",
83 builder="man",
84 outdir="docs/manpages",
85 config="docs/conf.py",
86 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
87 install_path="${MANDIR}/",
88 VERSION=VERSION)
89
90 bld.recurse('tests')
91
92 bld.recurse('tools')
Shock Jiang0b165f42014-10-24 09:08:09 -070093
94 bld(features='subst',
Shock Jiangcde28712014-10-19 21:17:20 -070095 source=['validator.conf.sample.in', 'ndns.conf.sample.in'],
96 target=['validator.conf.sample', 'ndns.conf.sample'],
Shock Jiang0b165f42014-10-24 09:08:09 -070097 install_path='${SYSCONFDIR}/ndns',
98 name='validator-sample',
99 ANCHORPATH='anchors/root.cert',
100 RELATION='is-prefix-of',
Shock Jiange1a81fd2014-11-20 20:25:49 -0800101 DEFAULT_CONFIG_PATH="%s/ndns" % bld.env['SYSCONFDIR'],
102 DEFAULT_DATABASE_PATH="%s/ndns" % bld.env['LOCALSTATEDIR'],
Shock Jiang0b165f42014-10-24 09:08:09 -0700103 help='the validator configuration of ndns',
104 )
105
106 bld(features='subst',
107 source='log4cxx.properties.sample.in',
108 target='log4cxx.properties.sample',
109 install_path='${SYSCONFDIR}/ndns',
110 is_copy = True,
111 name='log4cxx-sample',
112 help='the log4cxx configration file',
113 )
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700114
115def docs(bld):
116 from waflib import Options
117 Options.commands = ['doxygen', 'sphinx'] + Options.commands
118
119def doxygen(bld):
120 version(bld)
121
122 if not bld.env.DOXYGEN:
123 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
124 else:
125 bld(features="subst",
126 name="doxygen-conf",
127 source=["docs/doxygen.conf.in",
128 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
129 target=["docs/doxygen.conf",
130 "docs/named_data_theme/named_data_footer-with-analytics.html"],
131 VERSION=VERSION_BASE,
132 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
133 if os.getenv('GOOGLE_ANALYTICS', None) \
134 else "../docs/named_data_theme/named_data_footer.html",
135 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
136 )
137
138 bld(features="doxygen",
139 doxyfile='docs/doxygen.conf',
140 use="doxygen-conf")
141
142def sphinx(bld):
143 version(bld)
144
145 if not bld.env.SPHINX_BUILD:
146 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
147 else:
148 bld(features="sphinx",
149 outdir="docs",
150 source=bld.path.ant_glob('docs/**/*.rst'),
151 config="docs/conf.py",
152 VERSION=VERSION_BASE)
153
154def version(ctx):
155 if getattr(Context.g_module, 'VERSION_BASE', None):
156 return
157
158 Context.g_module.VERSION_BASE = Context.g_module.VERSION
159 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
160
161 didGetVersion = False
162 try:
163 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
164 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
165 stderr=None, stdin=None)
166 out = str(p.communicate()[0].strip())
167 didGetVersion = (p.returncode == 0 and out != "")
168 if didGetVersion:
169 if out.startswith(GIT_TAG_PREFIX):
170 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
171 else:
172 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
173 except OSError:
174 pass
175
176 versionFile = ctx.path.find_node('VERSION')
177
178 if not didGetVersion and versionFile is not None:
179 try:
180 Context.g_module.VERSION = versionFile.read()
181 return
182 except (OSError, IOError):
183 pass
184
185 # version was obtained from git, update VERSION file if necessary
186 if versionFile is not None:
187 try:
188 version = versionFile.read()
189 if version == Context.g_module.VERSION:
190 return # no need to update
191 except (OSError, IOError):
192 Logs.warn("VERSION file exists, but not readable")
193 else:
194 versionFile = ctx.path.make_node('VERSION')
195
196 if versionFile is None:
197 return
198
199 try:
200 versionFile.write(Context.g_module.VERSION)
201 except (OSError, IOError):
202 Logs.warn("VERSION file is not writeable")
203
204def dist(ctx):
205 version(ctx)
206
207def distcheck(ctx):
208 version(ctx)