blob: 6ee6d576caecd2f308e83d6596297dcf90d50caf [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']
32 if conf.env['WITH_TESTS']:
33 USED_BOOST_LIBS += ['unit_test_framework']
34 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, mt=True)
35
36 conf.check_compiler_flags()
37
38 # Loading "late" to prevent tests from being compiled with profiling flags
39 conf.load('coverage')
40
41 conf.load('sanitizers')
42
43 conf.define('SYSCONFDIR', conf.env['SYSCONFDIR'])
44
45 # If there happens to be a static library, waf will put the corresponding -L flags
46 # before dynamic library flags. This can result in compilation failure when the
47 # system has a different version of the ChronoSync library installed.
48 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
49
50 conf.write_config_header('config.hpp')
51
52def build(bld):
53 version(bld)
54
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040055 bld(features='subst',
56 name='version.hpp',
57 source='src/version.hpp.in',
58 target='src/version.hpp',
59 install_path=None,
60 VERSION_STRING=VERSION_BASE,
61 VERSION_BUILD=VERSION,
62 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
63 int(VERSION_SPLIT[1]) * 1000 +
64 int(VERSION_SPLIT[2]),
65 VERSION_MAJOR=VERSION_SPLIT[0],
66 VERSION_MINOR=VERSION_SPLIT[1],
67 VERSION_PATCH=VERSION_SPLIT[2])
68
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040069 bld.shlib(
70 target="ndn-nac",
71 name="libndn-nac",
72 vnum=VERSION_BASE,
73 cnum=VERSION_BASE,
74 source = bld.path.ant_glob(['src/**/*.cpp']),
75 use = 'BOOST NDN_CXX',
76 includes = ['src', '.'],
77 export_includes=['src', '.'])
78
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040079 # Unit tests
80 if bld.env['WITH_TESTS']:
81 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040082
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040083 bld.recurse('tools')
Alexander Afanasyevc3d29902018-06-29 18:20:55 -040084 bld.recurse('examples')
Alexander Afanasyev2b57aeb2018-06-15 18:32:28 -040085
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040086 bld.install_files(
87 dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
88 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
89 cwd = bld.path.find_dir("src"),
90 relative_trick = True)
91
92 bld.install_files(
93 dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
94 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']),
95 cwd = bld.path.get_bld().find_dir("src"),
96 relative_trick = False )
97
98 bld(features = "subst",
99 source='libndn-nac.pc.in',
100 target='libndn-nac.pc',
101 install_path = '${LIBDIR}/pkgconfig',
102 PREFIX = bld.env['PREFIX'],
103 INCLUDEDIR = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
104 VERSION = VERSION)
105
106def docs(bld):
107 from waflib import Options
108 Options.commands = ['doxygen', 'sphinx'] + Options.commands
109
110def doxygen(bld):
111 version(bld)
112
113 if not bld.env.DOXYGEN:
114 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
115
116 bld(features='subst',
117 name='doxygen.conf',
118 source=['docs/doxygen.conf.in',
119 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
120 target=['docs/doxygen.conf',
121 'docs/named_data_theme/named_data_footer-with-analytics.html'],
122 VERSION=VERSION,
123 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
124 if os.getenv('GOOGLE_ANALYTICS', None) \
125 else '../docs/named_data_theme/named_data_footer.html',
126 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
127
128 bld(features='doxygen',
129 doxyfile='docs/doxygen.conf',
130 use='doxygen.conf')
131
132def sphinx(bld):
133 version(bld)
134
135 if not bld.env.SPHINX_BUILD:
136 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
137
138 bld(features='sphinx',
139 config='docs/conf.py',
140 outdir='docs',
141 source=bld.path.ant_glob('docs/**/*.rst'),
142 VERSION=VERSION)
143
144def version(ctx):
145 # don't execute more than once
146 if getattr(Context.g_module, 'VERSION_BASE', None):
147 return
148
149 Context.g_module.VERSION_BASE = Context.g_module.VERSION
150 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
151
152 # first, try to get a version string from git
153 gotVersionFromGit = False
154 try:
155 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
156 out = subprocess.check_output(cmd, universal_newlines=True).strip()
157 if out:
158 gotVersionFromGit = True
159 if out.startswith(GIT_TAG_PREFIX):
160 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
161 else:
162 # no tags matched
163 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
164 except (OSError, subprocess.CalledProcessError):
165 pass
166
167 versionFile = ctx.path.find_node('VERSION')
168 if not gotVersionFromGit and versionFile is not None:
169 try:
170 Context.g_module.VERSION = versionFile.read()
171 return
172 except EnvironmentError:
173 pass
174
175 # version was obtained from git, update VERSION file if necessary
176 if versionFile is not None:
177 try:
178 if versionFile.read() == Context.g_module.VERSION:
179 # already up-to-date
180 return
181 except EnvironmentError as e:
182 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
183 else:
184 versionFile = ctx.path.make_node('VERSION')
185
186 try:
187 versionFile.write(Context.g_module.VERSION)
188 except EnvironmentError as e:
189 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
190
191def dist(ctx):
192 version(ctx)
193
194def distcheck(ctx):
195 version(ctx)