blob: 708d7d9fc2758f9dc45ebb53e39aae35d0c28a58 [file] [log] [blame]
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -04001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3from waflib import Context, Logs, Utils
4import os, subprocess
5
6VERSION = '0.1.0'
7APPNAME = 'ndn-nac'
Davide Pesavento8f9d0622018-11-27 01:23:37 -05008PACKAGE_BUGREPORT = 'https://redmine.named-data.net/projects/nac'
9GIT_TAG_PREFIX = 'nac-'
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040010
11def options(opt):
Davide Pesavento8f9d0622018-11-27 01:23:37 -050012 opt.load(['compiler_cxx', 'gnu_dirs'])
13 opt.load(['default-compiler-flags', 'boost',
14 'coverage', 'sanitizers',
15 'doxygen', 'sphinx_build'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040016 tooldir=['.waf-tools'])
17
Davide Pesavento8f9d0622018-11-27 01:23:37 -050018 opt = opt.add_option_group('NDN-NAC Options')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040019
Davide Pesavento8f9d0622018-11-27 01:23:37 -050020 opt.add_option('--with-tests', action='store_true', default=False,
21 help='Build unit tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040022
23def configure(conf):
Davide Pesavento8f9d0622018-11-27 01:23:37 -050024 conf.load(['compiler_cxx', 'gnu_dirs',
25 'default-compiler-flags', 'boost',
26 'doxygen', 'sphinx_build'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040027
28 conf.env['WITH_TESTS'] = conf.options.with_tests
29
30 if 'PKG_CONFIG_PATH' not in os.environ:
31 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
32 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
33 uselib_store='NDN_CXX', mandatory=True)
34
35 USED_BOOST_LIBS = ['system', 'thread', 'log', 'log_setup']
Alexander Afanasyevc9934282018-07-17 18:41:36 -040036
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040037 if conf.env['WITH_TESTS']:
38 USED_BOOST_LIBS += ['unit_test_framework']
Alexander Afanasyevc9934282018-07-17 18:41:36 -040039 conf.define('NDN_NAC_HAVE_TESTS', 1)
40
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040041 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, mt=True)
42
43 conf.check_compiler_flags()
44
45 # Loading "late" to prevent tests from being compiled with profiling flags
46 conf.load('coverage')
47
48 conf.load('sanitizers')
49
50 conf.define('SYSCONFDIR', conf.env['SYSCONFDIR'])
51
52 # If there happens to be a static library, waf will put the corresponding -L flags
53 # before dynamic library flags. This can result in compilation failure when the
54 # system has a different version of the ChronoSync library installed.
55 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
56
57 conf.write_config_header('config.hpp')
58
59def build(bld):
60 version(bld)
61
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040062 bld(features='subst',
63 name='version.hpp',
64 source='src/version.hpp.in',
65 target='src/version.hpp',
66 install_path=None,
67 VERSION_STRING=VERSION_BASE,
68 VERSION_BUILD=VERSION,
69 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
70 int(VERSION_SPLIT[1]) * 1000 +
71 int(VERSION_SPLIT[2]),
72 VERSION_MAJOR=VERSION_SPLIT[0],
73 VERSION_MINOR=VERSION_SPLIT[1],
74 VERSION_PATCH=VERSION_SPLIT[2])
75
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040076 bld.shlib(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050077 target='ndn-nac',
78 name='libndn-nac',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040079 vnum=VERSION_BASE,
80 cnum=VERSION_BASE,
Davide Pesavento8f9d0622018-11-27 01:23:37 -050081 source=bld.path.ant_glob('src/**/*.cpp'),
82 use='BOOST NDN_CXX',
83 includes=['src', '.'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040084 export_includes=['src', '.'])
85
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040086 # Unit tests
87 if bld.env['WITH_TESTS']:
88 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040089
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040090 bld.recurse('tools')
Alexander Afanasyevc3d29902018-06-29 18:20:55 -040091 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040092
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040093 bld.install_files(
Davide Pesavento8f9d0622018-11-27 01:23:37 -050094 dest = '%s/ndn-nac' % bld.env['INCLUDEDIR'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040095 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -050096 cwd = bld.path.find_dir('src'),
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040097 relative_trick = True)
98
99 bld.install_files(
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500100 dest = '%s/ndn-nac' % bld.env['INCLUDEDIR'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400101 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']),
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500102 cwd = bld.path.get_bld().find_dir('src'),
103 relative_trick = False)
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400104
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500105 bld(features='subst',
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400106 source='libndn-nac.pc.in',
107 target='libndn-nac.pc',
108 install_path = '${LIBDIR}/pkgconfig',
109 PREFIX = bld.env['PREFIX'],
Davide Pesavento8f9d0622018-11-27 01:23:37 -0500110 INCLUDEDIR = '%s/ndn-nac' % bld.env['INCLUDEDIR'],
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -0400111 VERSION = VERSION)
112
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 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
122
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,
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 bld(features='doxygen',
136 doxyfile='docs/doxygen.conf',
137 use='doxygen.conf')
138
139def sphinx(bld):
140 version(bld)
141
142 if not bld.env.SPHINX_BUILD:
143 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
144
145 bld(features='sphinx',
146 config='docs/conf.py',
147 outdir='docs',
148 source=bld.path.ant_glob('docs/**/*.rst'),
149 VERSION=VERSION)
150
151def version(ctx):
152 # don't execute more than once
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 = VERSION_BASE.split('.')
158
159 # first, try to get a version string from git
160 gotVersionFromGit = False
161 try:
162 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
163 out = subprocess.check_output(cmd, universal_newlines=True).strip()
164 if out:
165 gotVersionFromGit = True
166 if out.startswith(GIT_TAG_PREFIX):
167 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
168 else:
169 # no tags matched
170 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
171 except (OSError, subprocess.CalledProcessError):
172 pass
173
174 versionFile = ctx.path.find_node('VERSION')
175 if not gotVersionFromGit and versionFile is not None:
176 try:
177 Context.g_module.VERSION = versionFile.read()
178 return
179 except EnvironmentError:
180 pass
181
182 # version was obtained from git, update VERSION file if necessary
183 if versionFile is not None:
184 try:
185 if versionFile.read() == Context.g_module.VERSION:
186 # already up-to-date
187 return
188 except EnvironmentError as e:
189 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
190 else:
191 versionFile = ctx.path.make_node('VERSION')
192
193 try:
194 versionFile.write(Context.g_module.VERSION)
195 except EnvironmentError as e:
196 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
197
198def dist(ctx):
199 version(ctx)
200
201def distcheck(ctx):
202 version(ctx)