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 | |
| 3 | from waflib import Logs, Utils, Context |
| 4 | import os, subprocess |
| 5 | |
| 6 | VERSION = '0.1.0' |
| 7 | APPNAME = 'PSync' |
| 8 | GIT_TAG_PREFIX = '' |
| 9 | |
| 10 | def options(opt): |
| 11 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | da27849 | 2019-01-29 15:00:49 -0500 | [diff] [blame^] | 12 | opt.load(['default-compiler-flags', 'coverage', 'sanitizers', |
| 13 | 'boost', 'doxygen', 'sphinx_build'], |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 14 | tooldir=['.waf-tools']) |
| 15 | |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 16 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 21 | |
| 22 | def configure(conf): |
Davide Pesavento | da27849 | 2019-01-29 15:00:49 -0500 | [diff] [blame^] | 23 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', |
| 24 | 'default-compiler-flags', 'boost', |
| 25 | 'doxygen', 'sphinx_build']) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 26 | |
| 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 Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 33 | conf.env['WITH_TESTS'] = conf.options.with_tests |
| 34 | conf.env['WITH_EXAMPLES'] = conf.options.with_examples |
| 35 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 36 | boost_libs = 'system thread log log_setup' |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 37 | if conf.env['WITH_TESTS']: |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 38 | 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 Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 54 | conf.write_config_header('PSync/detail/config.hpp') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 55 | |
| 56 | def build(bld): |
| 57 | bld.shlib( |
| 58 | target='PSync', |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 59 | source = bld.path.ant_glob('PSync/**/*.cpp'), |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 60 | use = 'BOOST NDN_CXX', |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 61 | includes = '.', |
| 62 | export_includes='.', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 63 | ) |
| 64 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 65 | headers = bld.path.ant_glob('PSync/**/*.hpp') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 66 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 67 | 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 Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 71 | |
| 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 Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 78 | INCLUDEDIR = bld.env['INCLUDEDIR'], |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 79 | VERSION = VERSION, |
| 80 | ) |
| 81 | |
| 82 | if bld.env['WITH_TESTS']: |
| 83 | bld.recurse('tests') |
| 84 | |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame] | 85 | if bld.env['WITH_EXAMPLES']: |
| 86 | bld.recurse('examples') |
| 87 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 88 | def docs(bld): |
| 89 | from waflib import Options |
| 90 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 91 | |
| 92 | def 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 | |
| 114 | def 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 | |
| 126 | def 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 | |
| 173 | def dist(ctx): |
| 174 | version(ctx) |
| 175 | |
| 176 | def distcheck(ctx): |
| 177 | version(ctx) |