blob: 8931c7a8d855e3f0ae43e18169ae7fa2401230d4 [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
55 bld.shlib(
56 target="ndn-nac",
57 name="libndn-nac",
58 vnum=VERSION_BASE,
59 cnum=VERSION_BASE,
60 source = bld.path.ant_glob(['src/**/*.cpp']),
61 use = 'BOOST NDN_CXX',
62 includes = ['src', '.'],
63 export_includes=['src', '.'])
64
Alexander Afanasyev77f6ae12018-06-14 17:54:17 -040065 # Unit tests
66 if bld.env['WITH_TESTS']:
67 bld.recurse('tests')
Alexander Afanasyev6e64ac92018-06-14 17:25:38 -040068
69 bld.install_files(
70 dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
71 files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']),
72 cwd = bld.path.find_dir("src"),
73 relative_trick = True)
74
75 bld.install_files(
76 dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
77 files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']),
78 cwd = bld.path.get_bld().find_dir("src"),
79 relative_trick = False )
80
81 bld(features = "subst",
82 source='libndn-nac.pc.in',
83 target='libndn-nac.pc',
84 install_path = '${LIBDIR}/pkgconfig',
85 PREFIX = bld.env['PREFIX'],
86 INCLUDEDIR = "%s/ndn-nac" % bld.env['INCLUDEDIR'],
87 VERSION = VERSION)
88
89def docs(bld):
90 from waflib import Options
91 Options.commands = ['doxygen', 'sphinx'] + Options.commands
92
93def doxygen(bld):
94 version(bld)
95
96 if not bld.env.DOXYGEN:
97 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
98
99 bld(features='subst',
100 name='doxygen.conf',
101 source=['docs/doxygen.conf.in',
102 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
103 target=['docs/doxygen.conf',
104 'docs/named_data_theme/named_data_footer-with-analytics.html'],
105 VERSION=VERSION,
106 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
107 if os.getenv('GOOGLE_ANALYTICS', None) \
108 else '../docs/named_data_theme/named_data_footer.html',
109 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
110
111 bld(features='doxygen',
112 doxyfile='docs/doxygen.conf',
113 use='doxygen.conf')
114
115def sphinx(bld):
116 version(bld)
117
118 if not bld.env.SPHINX_BUILD:
119 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
120
121 bld(features='sphinx',
122 config='docs/conf.py',
123 outdir='docs',
124 source=bld.path.ant_glob('docs/**/*.rst'),
125 VERSION=VERSION)
126
127def version(ctx):
128 # don't execute more than once
129 if getattr(Context.g_module, 'VERSION_BASE', None):
130 return
131
132 Context.g_module.VERSION_BASE = Context.g_module.VERSION
133 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
134
135 # first, try to get a version string from git
136 gotVersionFromGit = False
137 try:
138 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
139 out = subprocess.check_output(cmd, universal_newlines=True).strip()
140 if out:
141 gotVersionFromGit = True
142 if out.startswith(GIT_TAG_PREFIX):
143 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
144 else:
145 # no tags matched
146 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
147 except (OSError, subprocess.CalledProcessError):
148 pass
149
150 versionFile = ctx.path.find_node('VERSION')
151 if not gotVersionFromGit and versionFile is not None:
152 try:
153 Context.g_module.VERSION = versionFile.read()
154 return
155 except EnvironmentError:
156 pass
157
158 # version was obtained from git, update VERSION file if necessary
159 if versionFile is not None:
160 try:
161 if versionFile.read() == Context.g_module.VERSION:
162 # already up-to-date
163 return
164 except EnvironmentError as e:
165 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
166 else:
167 versionFile = ctx.path.make_node('VERSION')
168
169 try:
170 versionFile.write(Context.g_module.VERSION)
171 except EnvironmentError as e:
172 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
173
174def dist(ctx):
175 version(ctx)
176
177def distcheck(ctx):
178 version(ctx)