blob: 6a3c29b5f9b2a31462adfe125e098e695672f35f [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',
95 source='validator.conf.sample.in',
96 target='validator.conf',
97 install_path='${SYSCONFDIR}/ndns',
98 name='validator-sample',
99 ANCHORPATH='anchors/root.cert',
100 RELATION='is-prefix-of',
101 help='the validator configuration of ndns',
102 )
103
104 bld(features='subst',
105 source='log4cxx.properties.sample.in',
106 target='log4cxx.properties.sample',
107 install_path='${SYSCONFDIR}/ndns',
108 is_copy = True,
109 name='log4cxx-sample',
110 help='the log4cxx configration file',
111 )
Alexander Afanasyev4ffcff22014-09-02 15:39:20 -0700112
113def docs(bld):
114 from waflib import Options
115 Options.commands = ['doxygen', 'sphinx'] + Options.commands
116
117def doxygen(bld):
118 version(bld)
119
120 if not bld.env.DOXYGEN:
121 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
122 else:
123 bld(features="subst",
124 name="doxygen-conf",
125 source=["docs/doxygen.conf.in",
126 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
127 target=["docs/doxygen.conf",
128 "docs/named_data_theme/named_data_footer-with-analytics.html"],
129 VERSION=VERSION_BASE,
130 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
131 if os.getenv('GOOGLE_ANALYTICS', None) \
132 else "../docs/named_data_theme/named_data_footer.html",
133 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
134 )
135
136 bld(features="doxygen",
137 doxyfile='docs/doxygen.conf',
138 use="doxygen-conf")
139
140def sphinx(bld):
141 version(bld)
142
143 if not bld.env.SPHINX_BUILD:
144 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
145 else:
146 bld(features="sphinx",
147 outdir="docs",
148 source=bld.path.ant_glob('docs/**/*.rst'),
149 config="docs/conf.py",
150 VERSION=VERSION_BASE)
151
152def version(ctx):
153 if getattr(Context.g_module, 'VERSION_BASE', None):
154 return
155
156 Context.g_module.VERSION_BASE = Context.g_module.VERSION
157 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
158
159 didGetVersion = False
160 try:
161 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
162 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
163 stderr=None, stdin=None)
164 out = str(p.communicate()[0].strip())
165 didGetVersion = (p.returncode == 0 and out != "")
166 if didGetVersion:
167 if out.startswith(GIT_TAG_PREFIX):
168 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
169 else:
170 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out)
171 except OSError:
172 pass
173
174 versionFile = ctx.path.find_node('VERSION')
175
176 if not didGetVersion and versionFile is not None:
177 try:
178 Context.g_module.VERSION = versionFile.read()
179 return
180 except (OSError, IOError):
181 pass
182
183 # version was obtained from git, update VERSION file if necessary
184 if versionFile is not None:
185 try:
186 version = versionFile.read()
187 if version == Context.g_module.VERSION:
188 return # no need to update
189 except (OSError, IOError):
190 Logs.warn("VERSION file exists, but not readable")
191 else:
192 versionFile = ctx.path.make_node('VERSION')
193
194 if versionFile is None:
195 return
196
197 try:
198 versionFile.write(Context.g_module.VERSION)
199 except (OSError, IOError):
200 Logs.warn("VERSION file is not writeable")
201
202def dist(ctx):
203 version(ctx)
204
205def distcheck(ctx):
206 version(ctx)