Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 3 | import os |
| 4 | import subprocess |
| 5 | from waflib import Context, Logs |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 6 | |
Davide Pesavento | ec8f854 | 2023-01-18 23:10:24 -0500 | [diff] [blame] | 7 | VERSION = '0.4.0' |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 8 | APPNAME = 'PSync' |
| 9 | GIT_TAG_PREFIX = '' |
| 10 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 11 | BOOST_COMPRESSION_CODE = ''' |
| 12 | #include <boost/iostreams/filter/{0}.hpp> |
| 13 | int main() {{ boost::iostreams::{0}_compressor test; }} |
| 14 | ''' |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 15 | COMPRESSION_SCHEMES = ['zlib', 'gzip', 'bzip2', 'lzma', 'zstd'] |
| 16 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 17 | def options(opt): |
Davide Pesavento | 042dfb3 | 2020-07-23 21:07:16 -0400 | [diff] [blame] | 18 | opt.load(['compiler_cxx', 'gnu_dirs']) |
| 19 | opt.load(['default-compiler-flags', |
| 20 | 'coverage', 'sanitizers', 'boost', |
Davide Pesavento | 8c7c228 | 2024-03-13 18:32:32 -0400 | [diff] [blame^] | 21 | 'doxygen', 'sphinx'], |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 22 | tooldir=['.waf-tools']) |
| 23 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 24 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 29 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 30 | for scheme in COMPRESSION_SCHEMES: |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 31 | optgrp.add_option(f'--without-{scheme}', action='store_true', default=False, |
| 32 | help=f'Disable support for {scheme} (de)compression') |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 33 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 34 | def configure(conf): |
Davide Pesavento | 042dfb3 | 2020-07-23 21:07:16 -0400 | [diff] [blame] | 35 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | da27849 | 2019-01-29 15:00:49 -0500 | [diff] [blame] | 36 | 'default-compiler-flags', 'boost', |
Davide Pesavento | 8c7c228 | 2024-03-13 18:32:32 -0400 | [diff] [blame^] | 37 | 'doxygen', 'sphinx']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 38 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 39 | conf.env.WITH_EXAMPLES = conf.options.with_examples |
| 40 | conf.env.WITH_TESTS = conf.options.with_tests |
| 41 | |
Davide Pesavento | f278438 | 2022-07-09 19:58:53 -0400 | [diff] [blame] | 42 | 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 Pesavento | 7549628 | 2021-04-25 16:38:22 -0400 | [diff] [blame] | 48 | |
Davide Pesavento | 85a73d2 | 2022-03-06 16:00:01 -0500 | [diff] [blame] | 49 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig') |
Davide Pesavento | ec8f854 | 2023-01-18 23:10:24 -0500 | [diff] [blame] | 50 | conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'], |
Davide Pesavento | 85a73d2 | 2022-03-06 16:00:01 -0500 | [diff] [blame] | 51 | uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 52 | |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 53 | conf.check_boost(lib='iostreams', mt=True) |
Davide Pesavento | 690272d | 2023-09-23 20:33:42 -0400 | [diff] [blame] | 54 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 58 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 59 | for scheme in COMPRESSION_SCHEMES: |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 60 | if getattr(conf.options, f'without_{scheme}'): |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 61 | continue |
| 62 | conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme), |
| 63 | use='BOOST', execute=False, mandatory=False, |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 64 | 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 Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 69 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 70 | conf.check_compiler_flags() |
| 71 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 72 | # Loading "late" to prevent tests from being compiled with profiling flags |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 73 | conf.load('coverage') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 74 | 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 Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 79 | conf.env.prepend_value('STLIBPATH', ['.']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 80 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 81 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 87 | |
| 88 | def build(bld): |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 89 | bld.shlib( |
| 90 | target='PSync', |
| 91 | vnum=VERSION, |
| 92 | cnum=VERSION, |
| 93 | source=bld.path.ant_glob('PSync/**/*.cpp'), |
| 94 | use='BOOST NDN_CXX', |
| 95 | includes='.', |
| 96 | export_includes='.') |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 97 | |
| 98 | if bld.env.WITH_TESTS: |
| 99 | bld.recurse('tests') |
| 100 | |
| 101 | if bld.env.WITH_EXAMPLES: |
| 102 | bld.recurse('examples') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 103 | |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 104 | # Install header files |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 105 | headers = bld.path.ant_glob('PSync/**/*.hpp') |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 106 | bld.install_files('${INCLUDEDIR}', headers, relative_trick=True) |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 107 | bld.install_files('${INCLUDEDIR}/PSync/detail', 'PSync/detail/config.hpp') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 108 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 109 | bld(features='subst', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 110 | source='PSync.pc.in', |
| 111 | target='PSync.pc', |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 112 | install_path='${LIBDIR}/pkgconfig', |
| 113 | VERSION=VERSION) |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 114 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 115 | def docs(bld): |
| 116 | from waflib import Options |
| 117 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 118 | |
| 119 | def doxygen(bld): |
| 120 | version(bld) |
| 121 | |
| 122 | if not bld.env.DOXYGEN: |
| 123 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 124 | |
| 125 | bld(features='subst', |
| 126 | name='doxygen.conf', |
| 127 | source=['docs/doxygen.conf.in', |
| 128 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 129 | target=['docs/doxygen.conf', |
| 130 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 131 | VERSION=VERSION, |
Davide Pesavento | 7549628 | 2021-04-25 16:38:22 -0400 | [diff] [blame] | 132 | HAVE_DOT='YES' if bld.env.DOT else 'NO', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 133 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 134 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 135 | else '../docs/named_data_theme/named_data_footer.html', |
| 136 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 137 | |
| 138 | bld(features='doxygen', |
| 139 | doxyfile='docs/doxygen.conf', |
| 140 | use='doxygen.conf') |
| 141 | |
| 142 | def sphinx(bld): |
| 143 | version(bld) |
| 144 | |
| 145 | if not bld.env.SPHINX_BUILD: |
| 146 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 147 | |
| 148 | bld(features='sphinx', |
| 149 | config='docs/conf.py', |
| 150 | outdir='docs', |
| 151 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 152 | version=VERSION_BASE, |
| 153 | release=VERSION) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 154 | |
| 155 | def version(ctx): |
| 156 | # don't execute more than once |
| 157 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 158 | return |
| 159 | |
| 160 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 161 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 162 | |
| 163 | # first, try to get a version string from git |
| 164 | gotVersionFromGit = False |
| 165 | try: |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 166 | cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*'] |
| 167 | out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip() |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 168 | if out: |
| 169 | gotVersionFromGit = True |
| 170 | if out.startswith(GIT_TAG_PREFIX): |
| 171 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
| 172 | else: |
| 173 | # no tags matched |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 174 | Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}' |
| 175 | except (OSError, subprocess.SubprocessError): |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 176 | pass |
| 177 | |
Alexander Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 178 | versionFile = ctx.path.find_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 179 | if not gotVersionFromGit and versionFile is not None: |
| 180 | try: |
| 181 | Context.g_module.VERSION = versionFile.read() |
| 182 | return |
| 183 | except EnvironmentError: |
| 184 | pass |
| 185 | |
| 186 | # version was obtained from git, update VERSION file if necessary |
| 187 | if versionFile is not None: |
| 188 | try: |
| 189 | if versionFile.read() == Context.g_module.VERSION: |
| 190 | # already up-to-date |
| 191 | return |
| 192 | except EnvironmentError as e: |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 193 | Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 194 | else: |
Alexander Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 195 | versionFile = ctx.path.make_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 196 | |
| 197 | try: |
| 198 | versionFile.write(Context.g_module.VERSION) |
| 199 | except EnvironmentError as e: |
Davide Pesavento | 0b272e0 | 2023-09-23 20:22:01 -0400 | [diff] [blame] | 200 | Logs.warn(f'{versionFile} is not writable ({e.strerror})') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 201 | |
| 202 | def dist(ctx): |
Davide Pesavento | 46bac78 | 2023-02-19 20:32:24 -0500 | [diff] [blame] | 203 | ctx.algo = 'tar.xz' |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 204 | version(ctx) |
| 205 | |
| 206 | def distcheck(ctx): |
Davide Pesavento | 46bac78 | 2023-02-19 20:32:24 -0500 | [diff] [blame] | 207 | ctx.algo = 'tar.xz' |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 208 | version(ctx) |