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