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']) |
| 12 | opt.load(['default-compiler-flags', 'boost', 'doxygen', 'sphinx_build', |
| 13 | 'sanitizers', 'coverage', 'pch'], |
| 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): |
| 23 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'default-compiler-flags', |
| 24 | 'boost', 'pch', 'doxygen', 'sphinx_build']) |
| 25 | |
| 26 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 27 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
| 28 | |
| 29 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 30 | uselib_store='NDN_CXX', mandatory=True) |
| 31 | |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame^] | 32 | conf.env['WITH_TESTS'] = conf.options.with_tests |
| 33 | conf.env['WITH_EXAMPLES'] = conf.options.with_examples |
| 34 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 35 | boost_libs = 'system thread log log_setup' |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame^] | 36 | if conf.env['WITH_TESTS']: |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 37 | conf.define('WITH_TESTS', 1); |
| 38 | boost_libs += ' unit_test_framework' |
| 39 | |
| 40 | conf.check_boost(lib=boost_libs, mt=True) |
| 41 | |
| 42 | conf.check_compiler_flags() |
| 43 | |
| 44 | conf.load('coverage') |
| 45 | |
| 46 | conf.load('sanitizers') |
| 47 | |
| 48 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 49 | # before dynamic library flags. This can result in compilation failure when the |
| 50 | # system has a different version of the PSync library installed. |
| 51 | conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH'] |
| 52 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 53 | conf.write_config_header('PSync/detail/config.hpp') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 54 | |
| 55 | def build(bld): |
| 56 | bld.shlib( |
| 57 | target='PSync', |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 58 | source = bld.path.ant_glob('PSync/**/*.cpp'), |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 59 | use = 'BOOST NDN_CXX', |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 60 | includes = '.', |
| 61 | export_includes='.', |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 62 | ) |
| 63 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 64 | headers = bld.path.ant_glob('PSync/**/*.hpp') |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 65 | |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 66 | bld.install_files(bld.env['INCLUDEDIR'], headers, relative_trick=True) |
| 67 | |
| 68 | bld.install_files('${INCLUDEDIR}/PSync/detail', |
| 69 | bld.path.find_resource('PSync/detail/config.hpp')) |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 70 | |
| 71 | pc = bld( |
| 72 | features = "subst", |
| 73 | source='PSync.pc.in', |
| 74 | target='PSync.pc', |
| 75 | install_path = '${LIBDIR}/pkgconfig', |
| 76 | PREFIX = bld.env['PREFIX'], |
Ashlesh Gawande | 78b94ad | 2018-12-13 15:29:19 -0600 | [diff] [blame] | 77 | INCLUDEDIR = bld.env['INCLUDEDIR'], |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 78 | VERSION = VERSION, |
| 79 | ) |
| 80 | |
| 81 | if bld.env['WITH_TESTS']: |
| 82 | bld.recurse('tests') |
| 83 | |
Ashlesh Gawande | 4c0a747 | 2018-08-08 12:20:33 -0500 | [diff] [blame^] | 84 | if bld.env['WITH_EXAMPLES']: |
| 85 | bld.recurse('examples') |
| 86 | |
Ashlesh Gawande | 0b2897e | 2018-06-20 14:40:47 -0500 | [diff] [blame] | 87 | def docs(bld): |
| 88 | from waflib import Options |
| 89 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 90 | |
| 91 | def doxygen(bld): |
| 92 | version(bld) |
| 93 | |
| 94 | if not bld.env.DOXYGEN: |
| 95 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 96 | |
| 97 | bld(features='subst', |
| 98 | name='doxygen.conf', |
| 99 | source=['docs/doxygen.conf.in', |
| 100 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 101 | target=['docs/doxygen.conf', |
| 102 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 103 | VERSION=VERSION, |
| 104 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 105 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 106 | else '../docs/named_data_theme/named_data_footer.html', |
| 107 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 108 | |
| 109 | bld(features='doxygen', |
| 110 | doxyfile='docs/doxygen.conf', |
| 111 | use='doxygen.conf') |
| 112 | |
| 113 | def sphinx(bld): |
| 114 | version(bld) |
| 115 | |
| 116 | if not bld.env.SPHINX_BUILD: |
| 117 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 118 | |
| 119 | bld(features='sphinx', |
| 120 | config='docs/conf.py', |
| 121 | outdir='docs', |
| 122 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 123 | VERSION=VERSION) |
| 124 | |
| 125 | def version(ctx): |
| 126 | # don't execute more than once |
| 127 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 128 | return |
| 129 | |
| 130 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 131 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 132 | |
| 133 | # first, try to get a version string from git |
| 134 | gotVersionFromGit = False |
| 135 | try: |
| 136 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 137 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 138 | if out: |
| 139 | gotVersionFromGit = True |
| 140 | if out.startswith(GIT_TAG_PREFIX): |
| 141 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
| 142 | else: |
| 143 | # no tags matched |
| 144 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
| 145 | except (OSError, subprocess.CalledProcessError): |
| 146 | pass |
| 147 | |
| 148 | versionFile = ctx.path.find_node('VERSION') |
| 149 | if not gotVersionFromGit and versionFile is not None: |
| 150 | try: |
| 151 | Context.g_module.VERSION = versionFile.read() |
| 152 | return |
| 153 | except EnvironmentError: |
| 154 | pass |
| 155 | |
| 156 | # version was obtained from git, update VERSION file if necessary |
| 157 | if versionFile is not None: |
| 158 | try: |
| 159 | if versionFile.read() == Context.g_module.VERSION: |
| 160 | # already up-to-date |
| 161 | return |
| 162 | except EnvironmentError as e: |
| 163 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
| 164 | else: |
| 165 | versionFile = ctx.path.make_node('VERSION') |
| 166 | |
| 167 | try: |
| 168 | versionFile.write(Context.g_module.VERSION) |
| 169 | except EnvironmentError as e: |
| 170 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 171 | |
| 172 | def dist(ctx): |
| 173 | version(ctx) |
| 174 | |
| 175 | def distcheck(ctx): |
| 176 | version(ctx) |