blob: 2010b7f30f438ae24c0a8e7279af7ca9898b7986 [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'
8PACKAGE_BUGREPORT = "http://redmine.named-data.net/projects/nac"
9GIT_TAG_PREFIX = "nac-"
10
11def options(opt):
12 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
13 opt.load(['boost', 'default-compiler-flags', 'sanitizers', 'coverage', 'sphinx_build', 'doxygen'],
14 tooldir=['.waf-tools'])
15
16 opt = opt.add_option_group("NDN-NAC Options")
17
18 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
19 help='''Build unit tests''')
20
21def configure(conf):
Alexander Afanasyevf293ceb2018-06-14 18:56:27 -040022 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'boost', 'default-compiler-flags', 'sphinx_build', 'doxygen'])
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040023
24 conf.env['WITH_TESTS'] = conf.options.with_tests
25
26 if 'PKG_CONFIG_PATH' not in os.environ:
27 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
28 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
29 uselib_store='NDN_CXX', mandatory=True)
30
31 USED_BOOST_LIBS = ['system', 'thread', 'log', 'log_setup']
Alexander Afanasyevc9934282018-07-17 18:41:36 -040032
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040033 if conf.env['WITH_TESTS']:
34 USED_BOOST_LIBS += ['unit_test_framework']
Alexander Afanasyevc9934282018-07-17 18:41:36 -040035 conf.define('NDN_NAC_HAVE_TESTS', 1)
36
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040037 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, mt=True)
38
39 conf.check_compiler_flags()
40
41 # Loading "late" to prevent tests from being compiled with profiling flags
42 conf.load('coverage')
43
44 conf.load('sanitizers')
45
46 conf.define('SYSCONFDIR', conf.env['SYSCONFDIR'])
47
48 # If there happens to be a static library, waf will put the corresponding -L flags
49 # before dynamic library flags. This can result in compilation failure when the
50 # system has a different version of the ChronoSync library installed.
51 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
52
53 conf.write_config_header('config.hpp')
54
55def build(bld):
56 version(bld)
57
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040058 bld(features='subst',
59 name='version.hpp',
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
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040072 bld.shlib(
73 target="ndn-nac",
74 name="libndn-nac",
75 vnum=VERSION_BASE,
76 cnum=VERSION_BASE,
77 source = bld.path.ant_glob(['src/**/*.cpp']),
78 use = 'BOOST NDN_CXX',
79 includes = ['src', '.'],
80 export_includes=['src', '.'])
81
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040082 # Unit tests
83 if bld.env['WITH_TESTS']:
84 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040085
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040086 bld.recurse('tools')
Alexander Afanasyevc3d29902018-06-29 18:20:55 -040087 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040088
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040089 bld.install_files(
90 dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
91 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
92 cwd = bld.path.find_dir("src"),
93 relative_trick = True)
94
95 bld.install_files(
96 dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
97 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']),
98 cwd = bld.path.get_bld().find_dir("src"),
99 relative_trick = False )
100
101 bld(features = "subst",
102 source='libndn-nac.pc.in',
103 target='libndn-nac.pc',
104 install_path = '${LIBDIR}/pkgconfig',
105 PREFIX = bld.env['PREFIX'],
106 INCLUDEDIR = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
107 VERSION = VERSION)
108
109def docs(bld):
110 from waflib import Options
111 Options.commands = ['doxygen', 'sphinx'] + Options.commands
112
113def doxygen(bld):
114 version(bld)
115
116 if not bld.env.DOXYGEN:
117 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
118
119 bld(features='subst',
120 name='doxygen.conf',
121 source=['docs/doxygen.conf.in',
122 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
123 target=['docs/doxygen.conf',
124 'docs/named_data_theme/named_data_footer-with-analytics.html'],
125 VERSION=VERSION,
126 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
127 if os.getenv('GOOGLE_ANALYTICS', None) \
128 else '../docs/named_data_theme/named_data_footer.html',
129 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
130
131 bld(features='doxygen',
132 doxyfile='docs/doxygen.conf',
133 use='doxygen.conf')
134
135def sphinx(bld):
136 version(bld)
137
138 if not bld.env.SPHINX_BUILD:
139 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
140
141 bld(features='sphinx',
142 config='docs/conf.py',
143 outdir='docs',
144 source=bld.path.ant_glob('docs/**/*.rst'),
145 VERSION=VERSION)
146
147def version(ctx):
148 # don't execute more than once
149 if getattr(Context.g_module, 'VERSION_BASE', None):
150 return
151
152 Context.g_module.VERSION_BASE = Context.g_module.VERSION
153 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
154
155 # first, try to get a version string from git
156 gotVersionFromGit = False
157 try:
158 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
159 out = subprocess.check_output(cmd, universal_newlines=True).strip()
160 if out:
161 gotVersionFromGit = True
162 if out.startswith(GIT_TAG_PREFIX):
163 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
164 else:
165 # no tags matched
166 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
167 except (OSError, subprocess.CalledProcessError):
168 pass
169
170 versionFile = ctx.path.find_node('VERSION')
171 if not gotVersionFromGit and versionFile is not None:
172 try:
173 Context.g_module.VERSION = versionFile.read()
174 return
175 except EnvironmentError:
176 pass
177
178 # version was obtained from git, update VERSION file if necessary
179 if versionFile is not None:
180 try:
181 if versionFile.read() == Context.g_module.VERSION:
182 # already up-to-date
183 return
184 except EnvironmentError as e:
185 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
186 else:
187 versionFile = ctx.path.make_node('VERSION')
188
189 try:
190 versionFile.write(Context.g_module.VERSION)
191 except EnvironmentError as e:
192 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
193
194def dist(ctx):
195 version(ctx)
196
197def distcheck(ctx):
198 version(ctx)