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