Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
| 3 | from waflib import Context, Logs, Utils |
| 4 | import os, subprocess |
| 5 | |
| 6 | VERSION = '0.1.0' |
| 7 | APPNAME = 'ndn-nac' |
| 8 | PACKAGE_BUGREPORT = "http://redmine.named-data.net/projects/nac" |
| 9 | GIT_TAG_PREFIX = "nac-" |
| 10 | |
| 11 | def options(opt): |
| 12 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
| 13 | opt.load(['boost', 'default-compiler-flags', 'sanitizers', 'coverage', 'sphinx_build', 'doxygen'], |
| 14 | tooldir=['.waf-tools']) |
| 15 | |
| 16 | opt = opt.add_option_group("NDN-NAC Options") |
| 17 | |
| 18 | opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests', |
| 19 | help='''Build unit tests''') |
| 20 | |
| 21 | def configure(conf): |
Alexander Afanasyev | f293ceb | 2018-06-14 18:56:27 -0400 | [diff] [blame] | 22 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'boost', 'default-compiler-flags', 'sphinx_build', 'doxygen']) |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 23 | |
| 24 | conf.env['WITH_TESTS'] = conf.options.with_tests |
| 25 | |
| 26 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 27 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
| 28 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 29 | uselib_store='NDN_CXX', mandatory=True) |
| 30 | |
| 31 | USED_BOOST_LIBS = ['system', 'thread', 'log', 'log_setup'] |
| 32 | if conf.env['WITH_TESTS']: |
| 33 | USED_BOOST_LIBS += ['unit_test_framework'] |
| 34 | conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True, mt=True) |
| 35 | |
| 36 | conf.check_compiler_flags() |
| 37 | |
| 38 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 39 | conf.load('coverage') |
| 40 | |
| 41 | conf.load('sanitizers') |
| 42 | |
| 43 | conf.define('SYSCONFDIR', conf.env['SYSCONFDIR']) |
| 44 | |
| 45 | # If there happens to be a static library, waf will put the corresponding -L flags |
| 46 | # before dynamic library flags. This can result in compilation failure when the |
| 47 | # system has a different version of the ChronoSync library installed. |
| 48 | conf.env['STLIBPATH'] = ['.'] + conf.env['STLIBPATH'] |
| 49 | |
| 50 | conf.write_config_header('config.hpp') |
| 51 | |
| 52 | def build(bld): |
| 53 | version(bld) |
| 54 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 55 | bld(features='subst', |
| 56 | name='version.hpp', |
| 57 | source='src/version.hpp.in', |
| 58 | target='src/version.hpp', |
| 59 | install_path=None, |
| 60 | VERSION_STRING=VERSION_BASE, |
| 61 | VERSION_BUILD=VERSION, |
| 62 | VERSION=int(VERSION_SPLIT[0]) * 1000000 + |
| 63 | int(VERSION_SPLIT[1]) * 1000 + |
| 64 | int(VERSION_SPLIT[2]), |
| 65 | VERSION_MAJOR=VERSION_SPLIT[0], |
| 66 | VERSION_MINOR=VERSION_SPLIT[1], |
| 67 | VERSION_PATCH=VERSION_SPLIT[2]) |
| 68 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 69 | bld.shlib( |
| 70 | target="ndn-nac", |
| 71 | name="libndn-nac", |
| 72 | vnum=VERSION_BASE, |
| 73 | cnum=VERSION_BASE, |
| 74 | source = bld.path.ant_glob(['src/**/*.cpp']), |
| 75 | use = 'BOOST NDN_CXX', |
| 76 | includes = ['src', '.'], |
| 77 | export_includes=['src', '.']) |
| 78 | |
Alexander Afanasyev | 77f6ae1 | 2018-06-14 17:54:17 -0400 | [diff] [blame] | 79 | # Unit tests |
| 80 | if bld.env['WITH_TESTS']: |
| 81 | bld.recurse('tests') |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 82 | |
Alexander Afanasyev | 2b57aeb | 2018-06-15 18:32:28 -0400 | [diff] [blame] | 83 | bld.recurse('tools') |
| 84 | |
Alexander Afanasyev | 6e64ac9 | 2018-06-14 17:25:38 -0400 | [diff] [blame] | 85 | bld.install_files( |
| 86 | dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'], |
| 87 | files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']), |
| 88 | cwd = bld.path.find_dir("src"), |
| 89 | relative_trick = True) |
| 90 | |
| 91 | bld.install_files( |
| 92 | dest = "%s/ndn-nac" % bld.env['INCLUDEDIR'], |
| 93 | files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']), |
| 94 | cwd = bld.path.get_bld().find_dir("src"), |
| 95 | relative_trick = False ) |
| 96 | |
| 97 | bld(features = "subst", |
| 98 | source='libndn-nac.pc.in', |
| 99 | target='libndn-nac.pc', |
| 100 | install_path = '${LIBDIR}/pkgconfig', |
| 101 | PREFIX = bld.env['PREFIX'], |
| 102 | INCLUDEDIR = "%s/ndn-nac" % bld.env['INCLUDEDIR'], |
| 103 | VERSION = VERSION) |
| 104 | |
| 105 | def docs(bld): |
| 106 | from waflib import Options |
| 107 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 108 | |
| 109 | def doxygen(bld): |
| 110 | version(bld) |
| 111 | |
| 112 | if not bld.env.DOXYGEN: |
| 113 | bld.fatal('Cannot build documentation ("doxygen" not found in PATH)') |
| 114 | |
| 115 | bld(features='subst', |
| 116 | name='doxygen.conf', |
| 117 | source=['docs/doxygen.conf.in', |
| 118 | 'docs/named_data_theme/named_data_footer-with-analytics.html.in'], |
| 119 | target=['docs/doxygen.conf', |
| 120 | 'docs/named_data_theme/named_data_footer-with-analytics.html'], |
| 121 | VERSION=VERSION, |
| 122 | HTML_FOOTER='../build/docs/named_data_theme/named_data_footer-with-analytics.html' \ |
| 123 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 124 | else '../docs/named_data_theme/named_data_footer.html', |
| 125 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', '')) |
| 126 | |
| 127 | bld(features='doxygen', |
| 128 | doxyfile='docs/doxygen.conf', |
| 129 | use='doxygen.conf') |
| 130 | |
| 131 | def sphinx(bld): |
| 132 | version(bld) |
| 133 | |
| 134 | if not bld.env.SPHINX_BUILD: |
| 135 | bld.fatal('Cannot build documentation ("sphinx-build" not found in PATH)') |
| 136 | |
| 137 | bld(features='sphinx', |
| 138 | config='docs/conf.py', |
| 139 | outdir='docs', |
| 140 | source=bld.path.ant_glob('docs/**/*.rst'), |
| 141 | VERSION=VERSION) |
| 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 | |
| 166 | versionFile = ctx.path.find_node('VERSION') |
| 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: |
| 183 | versionFile = ctx.path.make_node('VERSION') |
| 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) |