blob: 70e0b5b0c654c419cc7d42601abbdb2124d8c5f1 [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'])
Davide Pesaventoda278492019-01-29 15:00:49 -050012 opt.load(['default-compiler-flags', 'coverage', 'sanitizers',
13 'boost', 'doxygen', 'sphinx_build'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050014 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):
Davide Pesaventoda278492019-01-29 15:00:49 -050023 conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs',
24 'default-compiler-flags', 'boost',
25 'doxygen', 'sphinx_build'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050026
27 if 'PKG_CONFIG_PATH' not in os.environ:
28 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
29
30 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
31 uselib_store='NDN_CXX', mandatory=True)
32
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050033 conf.env['WITH_TESTS'] = conf.options.with_tests
34 conf.env['WITH_EXAMPLES'] = conf.options.with_examples
35
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050036 boost_libs = 'system thread log log_setup'
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050037 if conf.env['WITH_TESTS']:
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050038 conf.define('WITH_TESTS', 1);
39 boost_libs += ' unit_test_framework'
40
41 conf.check_boost(lib=boost_libs, mt=True)
42
43 conf.check_compiler_flags()
44
45 conf.load('coverage')
46
47 conf.load('sanitizers')
48
49 # If there happens to be a static library, waf will put the corresponding -L flags
50 # before dynamic library flags. This can result in compilation failure when the
51 # system has a different version of the PSync library installed.
52 conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH']
53
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060054 conf.write_config_header('PSync/detail/config.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050055
56def build(bld):
57 bld.shlib(
58 target='PSync',
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060059 source = bld.path.ant_glob('PSync/**/*.cpp'),
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050060 use = 'BOOST NDN_CXX',
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060061 includes = '.',
62 export_includes='.',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050063 )
64
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060065 headers = bld.path.ant_glob('PSync/**/*.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050066
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060067 bld.install_files(bld.env['INCLUDEDIR'], headers, relative_trick=True)
68
69 bld.install_files('${INCLUDEDIR}/PSync/detail',
70 bld.path.find_resource('PSync/detail/config.hpp'))
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050071
72 pc = bld(
73 features = "subst",
74 source='PSync.pc.in',
75 target='PSync.pc',
76 install_path = '${LIBDIR}/pkgconfig',
77 PREFIX = bld.env['PREFIX'],
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -060078 INCLUDEDIR = bld.env['INCLUDEDIR'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050079 VERSION = VERSION,
80 )
81
82 if bld.env['WITH_TESTS']:
83 bld.recurse('tests')
84
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -050085 if bld.env['WITH_EXAMPLES']:
86 bld.recurse('examples')
87
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050088def docs(bld):
89 from waflib import Options
90 Options.commands = ['doxygen', 'sphinx'] + Options.commands
91
92def doxygen(bld):
93 version(bld)
94
95 if not bld.env.DOXYGEN:
96 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
97
98 bld(features='subst',
99 name='doxygen.conf',
100 source=['docs/doxygen.conf.in',
101 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
102 target=['docs/doxygen.conf',
103 'docs/named_data_theme/named_data_footer-with-analytics.html'],
104 VERSION=VERSION,
105 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
106 if os.getenv('GOOGLE_ANALYTICS', None) \
107 else '../docs/named_data_theme/named_data_footer.html',
108 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
109
110 bld(features='doxygen',
111 doxyfile='docs/doxygen.conf',
112 use='doxygen.conf')
113
114def sphinx(bld):
115 version(bld)
116
117 if not bld.env.SPHINX_BUILD:
118 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
119
120 bld(features='sphinx',
121 config='docs/conf.py',
122 outdir='docs',
123 source=bld.path.ant_glob('docs/**/*.rst'),
124 VERSION=VERSION)
125
126def version(ctx):
127 # don't execute more than once
128 if getattr(Context.g_module, 'VERSION_BASE', None):
129 return
130
131 Context.g_module.VERSION_BASE = Context.g_module.VERSION
132 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
133
134 # first, try to get a version string from git
135 gotVersionFromGit = False
136 try:
137 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
138 out = subprocess.check_output(cmd, universal_newlines=True).strip()
139 if out:
140 gotVersionFromGit = True
141 if out.startswith(GIT_TAG_PREFIX):
142 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
143 else:
144 # no tags matched
145 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
146 except (OSError, subprocess.CalledProcessError):
147 pass
148
149 versionFile = ctx.path.find_node('VERSION')
150 if not gotVersionFromGit and versionFile is not None:
151 try:
152 Context.g_module.VERSION = versionFile.read()
153 return
154 except EnvironmentError:
155 pass
156
157 # version was obtained from git, update VERSION file if necessary
158 if versionFile is not None:
159 try:
160 if versionFile.read() == Context.g_module.VERSION:
161 # already up-to-date
162 return
163 except EnvironmentError as e:
164 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
165 else:
166 versionFile = ctx.path.make_node('VERSION')
167
168 try:
169 versionFile.write(Context.g_module.VERSION)
170 except EnvironmentError as e:
171 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
172
173def dist(ctx):
174 version(ctx)
175
176def distcheck(ctx):
177 version(ctx)