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 | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 3 | from waflib import Context, Logs, Utils |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 4 | import os, subprocess |
| 5 | |
Davide Pesavento | ec8f854 | 2023-01-18 23:10:24 -0500 | [diff] [blame] | 6 | VERSION = '0.4.0' |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 7 | APPNAME = 'PSync' |
| 8 | GIT_TAG_PREFIX = '' |
| 9 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 10 | BOOST_COMPRESSION_CODE = ''' |
| 11 | #include <boost/iostreams/filter/{0}.hpp> |
| 12 | int main() {{ boost::iostreams::{0}_compressor test; }} |
| 13 | ''' |
| 14 | |
| 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', |
| 21 | 'doxygen', 'sphinx_build'], |
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: |
| 31 | optgrp.add_option('--without-{}'.format(scheme), action='store_true', default=False, |
| 32 | help='Build without {}'.format(scheme)) |
| 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', |
| 37 | 'doxygen', 'sphinx_build']) |
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 | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 53 | boost_libs = ['system', 'iostreams'] |
| 54 | if conf.env.WITH_TESTS: |
| 55 | boost_libs.append('unit_test_framework') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 56 | |
| 57 | conf.check_boost(lib=boost_libs, mt=True) |
| 58 | |
Ashlesh Gawande | d51690a | 2019-11-11 22:51:06 -0600 | [diff] [blame] | 59 | for scheme in COMPRESSION_SCHEMES: |
| 60 | if getattr(conf.options, 'without_{}'.format(scheme)): |
| 61 | continue |
| 62 | conf.check_cxx(fragment=BOOST_COMPRESSION_CODE.format(scheme), |
| 63 | use='BOOST', execute=False, mandatory=False, |
| 64 | msg='Checking for {} support in boost iostreams'.format(scheme), |
| 65 | define_name='HAVE_{}'.format(scheme.upper())) |
| 66 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 67 | conf.check_compiler_flags() |
| 68 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 69 | # Loading "late" to prevent tests from being compiled with profiling flags |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 70 | conf.load('coverage') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 71 | conf.load('sanitizers') |
| 72 | |
| 73 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 74 | # before dynamic library flags. This can result in compilation failure when the |
| 75 | # system has a different version of the PSync library installed. |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 76 | conf.env.prepend_value('STLIBPATH', ['.']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 77 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 78 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
| 79 | # The config header will contain all defines that were added using conf.define() |
| 80 | # or conf.define_cond(). Everything that was added directly to conf.env.DEFINES |
| 81 | # will not appear in the config header, but will instead be passed directly to the |
| 82 | # compiler on the command line. |
| 83 | conf.write_config_header('PSync/detail/config.hpp', define_prefix='PSYNC_') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 84 | |
| 85 | def build(bld): |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 86 | bld.shlib(target='PSync', |
| 87 | vnum=VERSION, |
| 88 | cnum=VERSION, |
| 89 | source=bld.path.ant_glob('PSync/**/*.cpp'), |
| 90 | use='NDN_CXX BOOST', |
| 91 | includes='.', |
| 92 | export_includes='.') |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 93 | |
| 94 | if bld.env.WITH_TESTS: |
| 95 | bld.recurse('tests') |
| 96 | |
| 97 | if bld.env.WITH_EXAMPLES: |
| 98 | bld.recurse('examples') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 99 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 100 | headers = bld.path.ant_glob('PSync/**/*.hpp') |
Davide Pesavento | c407dee | 2022-07-21 23:56:05 -0400 | [diff] [blame] | 101 | bld.install_files('${INCLUDEDIR}', headers, relative_trick=True) |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 102 | |
| 103 | bld.install_files('${INCLUDEDIR}/PSync/detail', |
| 104 | bld.path.find_resource('PSync/detail/config.hpp')) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 105 | |
Davide Pesavento | 17b266c | 2019-04-06 21:37:43 -0400 | [diff] [blame] | 106 | bld(features='subst', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 107 | source='PSync.pc.in', |
| 108 | target='PSync.pc', |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 109 | install_path='${LIBDIR}/pkgconfig', |
| 110 | VERSION=VERSION) |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 111 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 112 | def docs(bld): |
| 113 | from waflib import Options |
| 114 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 115 | |
| 116 | def doxygen(bld): |
| 117 | version(bld) |
| 118 | |
| 119 | if not bld.env.DOXYGEN: |
| 120 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 121 | |
| 122 | bld(features='subst', |
| 123 | name='doxygen.conf', |
| 124 | source=['docs/doxygen.conf.in', |
| 125 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 126 | target=['docs/doxygen.conf', |
| 127 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 128 | VERSION=VERSION, |
Davide Pesavento | 7549628 | 2021-04-25 16:38:22 -0400 | [diff] [blame] | 129 | HAVE_DOT='YES' if bld.env.DOT else 'NO', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 130 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 131 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 132 | else '../docs/named_data_theme/named_data_footer.html', |
| 133 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 134 | |
| 135 | bld(features='doxygen', |
| 136 | doxyfile='docs/doxygen.conf', |
| 137 | use='doxygen.conf') |
| 138 | |
| 139 | def sphinx(bld): |
| 140 | version(bld) |
| 141 | |
| 142 | if not bld.env.SPHINX_BUILD: |
| 143 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 144 | |
| 145 | bld(features='sphinx', |
| 146 | config='docs/conf.py', |
| 147 | outdir='docs', |
| 148 | source=bld.path.ant_glob('docs/**/*.rst'), |
Davide Pesavento | 34f7eea | 2019-11-09 17:33:45 -0500 | [diff] [blame] | 149 | version=VERSION_BASE, |
| 150 | release=VERSION) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 151 | |
| 152 | def version(ctx): |
| 153 | # don't execute more than once |
| 154 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 155 | return |
| 156 | |
| 157 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 158 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 159 | |
| 160 | # first, try to get a version string from git |
| 161 | gotVersionFromGit = False |
| 162 | try: |
| 163 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 164 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 165 | if out: |
| 166 | gotVersionFromGit = True |
| 167 | if out.startswith(GIT_TAG_PREFIX): |
| 168 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
| 169 | else: |
| 170 | # no tags matched |
| 171 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
| 172 | except (OSError, subprocess.CalledProcessError): |
| 173 | pass |
| 174 | |
Alexander Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 175 | versionFile = ctx.path.find_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 176 | if not gotVersionFromGit and versionFile is not None: |
| 177 | try: |
| 178 | Context.g_module.VERSION = versionFile.read() |
| 179 | return |
| 180 | except EnvironmentError: |
| 181 | pass |
| 182 | |
| 183 | # version was obtained from git, update VERSION file if necessary |
| 184 | if versionFile is not None: |
| 185 | try: |
| 186 | if versionFile.read() == Context.g_module.VERSION: |
| 187 | # already up-to-date |
| 188 | return |
| 189 | except EnvironmentError as e: |
| 190 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
| 191 | else: |
Alexander Afanasyev | 89edd8f | 2020-06-01 18:58:54 -0400 | [diff] [blame] | 192 | versionFile = ctx.path.make_node('VERSION.info') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 193 | |
| 194 | try: |
| 195 | versionFile.write(Context.g_module.VERSION) |
| 196 | except EnvironmentError as e: |
| 197 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 198 | |
| 199 | def dist(ctx): |
Davide Pesavento | 46bac78 | 2023-02-19 20:32:24 -0500 | [diff] [blame^] | 200 | ctx.algo = 'tar.xz' |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 201 | version(ctx) |
| 202 | |
| 203 | def distcheck(ctx): |
Davide Pesavento | 46bac78 | 2023-02-19 20:32:24 -0500 | [diff] [blame^] | 204 | ctx.algo = 'tar.xz' |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 205 | version(ctx) |