blob: 4eb442384af1f3a33611ef95ba3a9d99f619828b [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
Davide Pesavento0b272e02023-09-23 20:22:01 -04003import os
4import subprocess
5from waflib import Context, Logs
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05006
awlane880e7152024-07-26 18:48:05 -05007VERSION = '0.5.0'
Davide Pesaventob65d6db2024-08-08 23:00:02 -04008APPNAME = 'psync'
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -05009GIT_TAG_PREFIX = ''
10
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060011BOOST_COMPRESSION_CODE = '''
12#include <boost/iostreams/filter/{0}.hpp>
13int main() {{ boost::iostreams::{0}_compressor test; }}
14'''
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060015COMPRESSION_SCHEMES = ['zlib', 'gzip', 'bzip2', 'lzma', 'zstd']
16
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050017def options(opt):
Davide Pesavento042dfb32020-07-23 21:07:16 -040018 opt.load(['compiler_cxx', 'gnu_dirs'])
19 opt.load(['default-compiler-flags',
20 'coverage', 'sanitizers', 'boost',
Davide Pesavento8c7c2282024-03-13 18:32:32 -040021 'doxygen', 'sphinx'],
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050022 tooldir=['.waf-tools'])
23
Davide Pesavento17b266c2019-04-06 21:37:43 -040024 optgrp = opt.add_option_group('PSync Options')
25 optgrp.add_option('--with-examples', action='store_true', default=False,
26 help='Build examples')
27 optgrp.add_option('--with-tests', action='store_true', default=False,
28 help='Build unit tests')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050029
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060030 for scheme in COMPRESSION_SCHEMES:
Davide Pesavento0b272e02023-09-23 20:22:01 -040031 optgrp.add_option(f'--without-{scheme}', action='store_true', default=False,
32 help=f'Disable support for {scheme} (de)compression')
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060033
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050034def configure(conf):
Davide Pesavento042dfb32020-07-23 21:07:16 -040035 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesaventoda278492019-01-29 15:00:49 -050036 'default-compiler-flags', 'boost',
Davide Pesavento8c7c2282024-03-13 18:32:32 -040037 'doxygen', 'sphinx'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050038
Davide Pesavento17b266c2019-04-06 21:37:43 -040039 conf.env.WITH_EXAMPLES = conf.options.with_examples
40 conf.env.WITH_TESTS = conf.options.with_tests
41
Davide Pesaventof2784382022-07-09 19:58:53 -040042 conf.find_program('dot', mandatory=False)
43
44 # Prefer pkgconf if it's installed, because it gives more correct results
45 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
46 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
47 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
Davide Pesavento75496282021-04-25 16:38:22 -040048
Davide Pesavento85a73d22022-03-06 16:00:01 -050049 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
awlane880e7152024-07-26 18:48:05 -050050 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.9.0', '--cflags', '--libs'],
Davide Pesavento85a73d22022-03-06 16:00:01 -050051 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050052
Davide Pesavento0b272e02023-09-23 20:22:01 -040053 conf.check_boost(lib='iostreams', mt=True)
Davide Pesavento690272d2023-09-23 20:33:42 -040054 if conf.env.BOOST_VERSION_NUMBER < 107100:
55 conf.fatal('The minimum supported version of Boost is 1.71.0.\n'
56 'Please upgrade your distribution or manually install a newer version of Boost.\n'
57 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050058
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060059 for scheme in COMPRESSION_SCHEMES:
Davide Pesavento0b272e02023-09-23 20:22:01 -040060 if getattr(conf.options, f'without_{scheme}'):
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060061 continue
62 conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme),
63 use='BOOST', execute=False, mandatory=False,
Davide Pesavento0b272e02023-09-23 20:22:01 -040064 msg=f'Checking for {scheme} support in boost iostreams',
65 define_name=f'HAVE_{scheme.upper()}')
66
67 if conf.env.WITH_TESTS:
68 conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS')
Ashlesh Gawanded51690a2019-11-11 22:51:06 -060069
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050070 conf.check_compiler_flags()
71
Davide Pesavento17b266c2019-04-06 21:37:43 -040072 # Loading "late" to prevent tests from being compiled with profiling flags
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050073 conf.load('coverage')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050074 conf.load('sanitizers')
75
76 # If there happens to be a static library, waf will put the corresponding -L flags
77 # before dynamic library flags. This can result in compilation failure when the
78 # system has a different version of the PSync library installed.
Davide Pesavento17b266c2019-04-06 21:37:43 -040079 conf.env.prepend_value('STLIBPATH', ['.'])
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050080
Davide Pesavento17b266c2019-04-06 21:37:43 -040081 conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS)
82 # The config header will contain all defines that were added using conf.define()
83 # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES
84 # will not appear in the config header, but will instead be passed directly to the
85 # compiler on the command line.
86 conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -050087
88def build(bld):
Davide Pesavento93da5fc2025-04-04 18:00:21 -040089 version(bld)
90
Davide Pesavento0b272e02023-09-23 20:22:01 -040091 bld.shlib(
92 target='PSync',
Davide Pesavento93da5fc2025-04-04 18:00:21 -040093 vnum=VERSION_BASE,
94 cnum=VERSION_BASE,
Davide Pesavento0b272e02023-09-23 20:22:01 -040095 source=bld.path.ant_glob('PSync/**/*.cpp'),
96 use='BOOST NDN_CXX',
97 includes='.',
98 export_includes='.')
Davide Pesavento17b266c2019-04-06 21:37:43 -040099
100 if bld.env.WITH_TESTS:
101 bld.recurse('tests')
102
103 if bld.env.WITH_EXAMPLES:
104 bld.recurse('examples')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500105
Davide Pesavento0b272e02023-09-23 20:22:01 -0400106 # Install header files
Ashlesh Gawande78b94ad2018-12-13 15:29:19 -0600107 headers = bld.path.ant_glob('PSync/**/*.hpp')
Davide Pesaventoc407dee2022-07-21 23:56:05 -0400108 bld.install_files('${INCLUDEDIR}', headers, relative_trick=True)
Davide Pesavento0b272e02023-09-23 20:22:01 -0400109 bld.install_files('${INCLUDEDIR}/PSync/detail', 'PSync/detail/config.hpp')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500110
Davide Pesavento17b266c2019-04-06 21:37:43 -0400111 bld(features='subst',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500112 source='PSync.pc.in',
113 target='PSync.pc',
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500114 install_path='${LIBDIR}/pkgconfig',
Davide Pesavento93da5fc2025-04-04 18:00:21 -0400115 VERSION=VERSION_BASE)
Ashlesh Gawande4c0a7472018-08-08 12:20:33 -0500116
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500117def docs(bld):
118 from waflib import Options
119 Options.commands = ['doxygen', 'sphinx'] + Options.commands
120
121def doxygen(bld):
122 version(bld)
123
124 if not bld.env.DOXYGEN:
125 bld.fatal('Cannot build documentation ("doxygen" not found in PATH)')
126
127 bld(features='subst',
128 name='doxygen.conf',
129 source=['docs/doxygen.conf.in',
130 'docs/named_data_theme/named_data_footer-with-analytics.html.in'],
131 target=['docs/doxygen.conf',
132 'docs/named_data_theme/named_data_footer-with-analytics.html'],
133 VERSION=VERSION,
Davide Pesavento75496282021-04-25 16:38:22 -0400134 HAVE_DOT='YES' if bld.env.DOT else 'NO',
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500135 HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \
136 if os.getenv('GOOGLE_ANALYTICS', None) \
137 else '../docs/named_data_theme/named_data_footer.html',
138 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ''))
139
140 bld(features='doxygen',
141 doxyfile='docs/doxygen.conf',
142 use='doxygen.conf')
143
144def sphinx(bld):
145 version(bld)
146
147 if not bld.env.SPHINX_BUILD:
148 bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)')
149
150 bld(features='sphinx',
151 config='docs/conf.py',
152 outdir='docs',
153 source=bld.path.ant_glob('docs/**/*.rst'),
Davide Pesavento34f7eea2019-11-09 17:33:45 -0500154 version=VERSION_BASE,
155 release=VERSION)
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500156
157def version(ctx):
158 # don't execute more than once
159 if getattr(Context.g_module, 'VERSION_BASE', None):
160 return
161
162 Context.g_module.VERSION_BASE = Context.g_module.VERSION
163 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
164
165 # first, try to get a version string from git
Davide Pesavento6a562f02024-04-22 01:11:31 -0400166 version_from_git = ''
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500167 try:
Davide Pesavento6a562f02024-04-22 01:11:31 -0400168 cmd = ['git', 'describe', '--abbrev=8', '--always', '--match', f'{GIT_TAG_PREFIX}*']
169 version_from_git = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
170 if version_from_git:
171 if GIT_TAG_PREFIX and version_from_git.startswith(GIT_TAG_PREFIX):
172 Context.g_module.VERSION = version_from_git[len(GIT_TAG_PREFIX):]
173 elif not GIT_TAG_PREFIX and ('.' in version_from_git or '-' in version_from_git):
174 Context.g_module.VERSION = version_from_git
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500175 else:
Davide Pesavento6a562f02024-04-22 01:11:31 -0400176 # no tags matched (or we are in a shallow clone)
177 Context.g_module.VERSION = f'{VERSION_BASE}+git.{version_from_git}'
Davide Pesavento0b272e02023-09-23 20:22:01 -0400178 except (OSError, subprocess.SubprocessError):
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500179 pass
180
Davide Pesavento6a562f02024-04-22 01:11:31 -0400181 # fallback to the VERSION.info file, if it exists and is not empty
182 version_from_file = ''
183 version_file = ctx.path.find_node('VERSION.info')
184 if version_file is not None:
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500185 try:
Davide Pesavento6a562f02024-04-22 01:11:31 -0400186 version_from_file = version_file.read().strip()
187 except OSError as e:
188 Logs.warn(f'{e.filename} exists but is not readable ({e.strerror})')
189 if version_from_file and not version_from_git:
190 Context.g_module.VERSION = version_from_file
191 return
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500192
Davide Pesavento6a562f02024-04-22 01:11:31 -0400193 # update VERSION.info if necessary
194 if version_from_file == Context.g_module.VERSION:
195 # already up-to-date
196 return
197 if version_file is None:
198 version_file = ctx.path.make_node('VERSION.info')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500199 try:
Davide Pesavento6a562f02024-04-22 01:11:31 -0400200 version_file.write(Context.g_module.VERSION)
201 except OSError as e:
202 Logs.warn(f'{e.filename} is not writable ({e.strerror})')
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500203
204def dist(ctx):
Davide Pesavento46bac782023-02-19 20:32:24 -0500205 ctx.algo = 'tar.xz'
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500206 version(ctx)
207
208def distcheck(ctx):
Davide Pesavento46bac782023-02-19 20:32:24 -0500209 ctx.algo = 'tar.xz'
Ashlesh Gawande0b2897e2018-06-20 14:40:47 -0500210 version(ctx)