blob: 04445f372438d424f9b79e0b6d8ee00b2e5d8480 [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
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050016 opt.add_option('--with-examples', action='store_true', default=False,
17 help='Build examples')
18
19 opt.add_option('--with-tests', action='store_true', default=False,
20 help='Build unit tests')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050021
22def configure(conf):
23 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'default-compiler-flags',
24 'boost', 'pch', 'doxygen', 'sphinx_build'])
25
26 if 'PKG_CONFIG_PATH' not in os.environ:
27 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
28
29 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
30 uselib_store='NDN_CXX', mandatory=True)
31
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050032 conf.env['WITH_TESTS'] = conf.options.with_tests
33 conf.env['WITH_EXAMPLES'] = conf.options.with_examples
34
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050035 boost_libs = 'system thread log log_setup'
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050036 if conf.env['WITH_TESTS']:
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050037 conf.define('WITH_TESTS', 1);
38 boost_libs += ' unit_test_framework'
39
40 conf.check_boost(lib=boost_libs, mt=True)
41
42 conf.check_compiler_flags()
43
44 conf.load('coverage')
45
46 conf.load('sanitizers')
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 PSync library installed.
51 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
52
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060053 conf.write_config_header('PSync/detail/config.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050054
55def build(bld):
56 bld.shlib(
57 target='PSync',
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060058 source = bld.path.ant_glob('PSync/**/*.cpp'),
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050059 use = 'BOOST NDN_CXX',
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060060 includes = '.',
61 export_includes='.',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050062 )
63
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060064 headers = bld.path.ant_glob('PSync/**/*.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050065
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060066 bld.install_files(bld.env['INCLUDEDIR'], headers, relative_trick=True)
67
68 bld.install_files('${INCLUDEDIR}/PSync/detail',
69 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050070
71 pc = bld(
72 features = "subst",
73 source='PSync.pc.in',
74 target='PSync.pc',
75 install_path = '${LIBDIR}/pkgconfig',
76 PREFIX = bld.env['PREFIX'],
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060077 INCLUDEDIR = bld.env['INCLUDEDIR'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050078 VERSION = VERSION,
79 )
80
81 if bld.env['WITH_TESTS']:
82 bld.recurse('tests')
83
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050084 if bld.env['WITH_EXAMPLES']:
85 bld.recurse('examples')
86
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050087def docs(bld):
88 from waflib import Options
89 Options.commands = ['doxygen', 'sphinx'] + Options.commands
90
91def doxygen(bld):
92 version(bld)
93
94 if not bld.env.DOXYGEN:
95 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
96
97 bld(features='subst',
98 name='doxygen.conf',
99 source=['docs/doxygen.conf.in',
100 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
101 target=['docs/doxygen.conf',
102 'docs/named_data_theme/named_data_footer-with-analytics.html'],
103 VERSION=VERSION,
104 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
105 if os.getenv('GOOGLE_ANALYTICS', None) \
106 else '../docs/named_data_theme/named_data_footer.html',
107 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
108
109 bld(features='doxygen',
110 doxyfile='docs/doxygen.conf',
111 use='doxygen.conf')
112
113def sphinx(bld):
114 version(bld)
115
116 if not bld.env.SPHINX_BUILD:
117 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
118
119 bld(features='sphinx',
120 config='docs/conf.py',
121 outdir='docs',
122 source=bld.path.ant_glob('docs/**/*.rst'),
123 VERSION=VERSION)
124
125def version(ctx):
126 # don't execute more than once
127 if getattr(Context.g_module, 'VERSION_BASE', None):
128 return
129
130 Context.g_module.VERSION_BASE = Context.g_module.VERSION
131 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
132
133 # first, try to get a version string from git
134 gotVersionFromGit = False
135 try:
136 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
137 out = subprocess.check_output(cmd, universal_newlines=True).strip()
138 if out:
139 gotVersionFromGit = True
140 if out.startswith(GIT_TAG_PREFIX):
141 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
142 else:
143 # no tags matched
144 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
145 except (OSError, subprocess.CalledProcessError):
146 pass
147
148 versionFile = ctx.path.find_node('VERSION')
149 if not gotVersionFromGit and versionFile is not None:
150 try:
151 Context.g_module.VERSION = versionFile.read()
152 return
153 except EnvironmentError:
154 pass
155
156 # version was obtained from git, update VERSION file if necessary
157 if versionFile is not None:
158 try:
159 if versionFile.read() == Context.g_module.VERSION:
160 # already up-to-date
161 return
162 except EnvironmentError as e:
163 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
164 else:
165 versionFile = ctx.path.make_node('VERSION')
166
167 try:
168 versionFile.write(Context.g_module.VERSION)
169 except EnvironmentError as e:
170 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
171
172def dist(ctx):
173 version(ctx)
174
175def distcheck(ctx):
176 version(ctx)