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