blob: 447f6b5188b156a60195627a744655415bb2ce5f [file] [log] [blame]
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3from waflib import Logs, Utils, Context
4import os, subprocess
5
6VERSION = '0.1.0'
7APPNAME = 'PSync'
8GIT_TAG_PREFIX = ''
9
10def options(opt):
11 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
12 opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build',
13 'sanitizers', 'coverage', 'pch'],
14 tooldir=['.waf-tools'])
15
16 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
17 help='''build unit tests''')
18
19def configure(conf):
20 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'default-compiler-flags',
21 'boost', 'pch', 'doxygen', 'sphinx_build'])
22
23 if 'PKG_CONFIG_PATH' not in os.environ:
24 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
25
26 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
27 uselib_store='NDN_CXX', mandatory=True)
28
29 boost_libs = 'system thread log log_setup'
30 if conf.options.with_tests:
31 conf.env['WITH_TESTS'] = 1
32 conf.define('WITH_TESTS', 1);
33 boost_libs += ' unit_test_framework'
34
35 conf.check_boost(lib=boost_libs, mt=True)
36
37 conf.check_compiler_flags()
38
39 conf.load('coverage')
40
41 conf.load('sanitizers')
42
43 # If there happens to be a static library, waf will put the corresponding -L flags
44 # before dynamic library flags. This can result in compilation failure when the
45 # system has a different version of the PSync library installed.
46 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
47
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060048 conf.write_config_header('PSync/detail/config.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050049
50def build(bld):
51 bld.shlib(
52 target='PSync',
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060053 source = bld.path.ant_glob('PSync/**/*.cpp'),
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050054 use = 'BOOST NDN_CXX',
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060055 includes = '.',
56 export_includes='.',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050057 )
58
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060059 headers = bld.path.ant_glob('PSync/**/*.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050060
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060061 bld.install_files(bld.env['INCLUDEDIR'], headers, relative_trick=True)
62
63 bld.install_files('${INCLUDEDIR}/PSync/detail',
64 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050065
66 pc = bld(
67 features = "subst",
68 source='PSync.pc.in',
69 target='PSync.pc',
70 install_path = '${LIBDIR}/pkgconfig',
71 PREFIX = bld.env['PREFIX'],
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060072 INCLUDEDIR = bld.env['INCLUDEDIR'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050073 VERSION = VERSION,
74 )
75
76 if bld.env['WITH_TESTS']:
77 bld.recurse('tests')
78
79def docs(bld):
80 from waflib import Options
81 Options.commands = ['doxygen', 'sphinx'] + Options.commands
82
83def doxygen(bld):
84 version(bld)
85
86 if not bld.env.DOXYGEN:
87 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
88
89 bld(features='subst',
90 name='doxygen.conf',
91 source=['docs/doxygen.conf.in',
92 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
93 target=['docs/doxygen.conf',
94 'docs/named_data_theme/named_data_footer-with-analytics.html'],
95 VERSION=VERSION,
96 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
97 if os.getenv('GOOGLE_ANALYTICS', None) \
98 else '../docs/named_data_theme/named_data_footer.html',
99 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
100
101 bld(features='doxygen',
102 doxyfile='docs/doxygen.conf',
103 use='doxygen.conf')
104
105def sphinx(bld):
106 version(bld)
107
108 if not bld.env.SPHINX_BUILD:
109 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
110
111 bld(features='sphinx',
112 config='docs/conf.py',
113 outdir='docs',
114 source=bld.path.ant_glob('docs/**/*.rst'),
115 VERSION=VERSION)
116
117def version(ctx):
118 # don't execute more than once
119 if getattr(Context.g_module, 'VERSION_BASE', None):
120 return
121
122 Context.g_module.VERSION_BASE = Context.g_module.VERSION
123 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
124
125 # first, try to get a version string from git
126 gotVersionFromGit = False
127 try:
128 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
129 out = subprocess.check_output(cmd, universal_newlines=True).strip()
130 if out:
131 gotVersionFromGit = True
132 if out.startswith(GIT_TAG_PREFIX):
133 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
134 else:
135 # no tags matched
136 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
137 except (OSError, subprocess.CalledProcessError):
138 pass
139
140 versionFile = ctx.path.find_node('VERSION')
141 if not gotVersionFromGit and versionFile is not None:
142 try:
143 Context.g_module.VERSION = versionFile.read()
144 return
145 except EnvironmentError:
146 pass
147
148 # version was obtained from git, update VERSION file if necessary
149 if versionFile is not None:
150 try:
151 if versionFile.read() == Context.g_module.VERSION:
152 # already up-to-date
153 return
154 except EnvironmentError as e:
155 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
156 else:
157 versionFile = ctx.path.make_node('VERSION')
158
159 try:
160 versionFile.write(Context.g_module.VERSION)
161 except EnvironmentError as e:
162 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
163
164def dist(ctx):
165 version(ctx)
166
167def distcheck(ctx):
168 version(ctx)