Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 2 | |
Davide Pesavento | 4a43e87 | 2018-05-03 22:10:56 -0400 | [diff] [blame] | 3 | VERSION = '0.6.1' |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 4 | APPNAME = 'ndn-tools' |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 5 | GIT_TAG_PREFIX = 'ndn-tools-' |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 6 | |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 7 | from waflib import Utils, Context |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 8 | import os, subprocess |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 9 | |
| 10 | def options(opt): |
| 11 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Eric Newberry | 716ab60 | 2016-12-29 21:49:57 -0700 | [diff] [blame] | 12 | opt.load(['default-compiler-flags', 'coverage', 'sanitizers', 'boost', |
| 13 | 'sphinx_build'], |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 14 | tooldir=['.waf-tools']) |
Shock Jiang | 0f0bc4b | 2015-06-22 15:11:30 -0700 | [diff] [blame] | 15 | |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 16 | opt.add_option('--with-tests', action='store_true', default=False, |
| 17 | dest='with_tests', help='''Build unit tests''') |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 18 | |
| 19 | opt.recurse('tools') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 20 | |
| 21 | def configure(conf): |
| 22 | conf.load(['compiler_cxx', 'gnu_dirs', |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 23 | 'default-compiler-flags', 'sphinx_build', 'boost']) |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 24 | |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 25 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 26 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 27 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 28 | uselib_store='NDN_CXX', mandatory=True) |
| 29 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 30 | boost_libs = 'system filesystem program_options regex thread log log_setup' |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 31 | if conf.options.with_tests: |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 32 | conf.env['WITH_TESTS'] = True |
| 33 | conf.define('WITH_TESTS', 1) |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 34 | boost_libs += ' unit_test_framework' |
| 35 | conf.check_boost(lib=boost_libs, mt=True) |
Junxiao Shi | 2222a61 | 2015-06-06 08:01:38 -0700 | [diff] [blame] | 36 | |
Alexander Afanasyev | 11e74eb | 2017-09-21 19:01:54 -0400 | [diff] [blame] | 37 | conf.recurse('tools') |
| 38 | |
| 39 | conf.check_compiler_flags() |
| 40 | |
Eric Newberry | 716ab60 | 2016-12-29 21:49:57 -0700 | [diff] [blame] | 41 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 42 | conf.load('coverage') |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 43 | conf.load('sanitizers') |
| 44 | |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 45 | conf.msg('Tools to build', ', '.join(conf.env['BUILD_TOOLS'])) |
| 46 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 47 | def build(bld): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 48 | version(bld) |
| 49 | |
| 50 | bld(features='subst', |
| 51 | source='core/version.cpp.in', |
| 52 | target='core/version.cpp', |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 53 | name='version.cpp', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 54 | VERSION_BUILD=VERSION) |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 55 | |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 56 | bld.objects(target='core-objects', |
| 57 | source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'], |
| 58 | use='NDN_CXX BOOST', |
| 59 | includes='.', |
| 60 | export_includes='.') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 61 | |
| 62 | bld.recurse('tools') |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 63 | bld.recurse('tests') |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 64 | bld.recurse('manpages') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 65 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 66 | def version(ctx): |
| 67 | # don't execute more than once |
| 68 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 69 | return |
| 70 | |
| 71 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 72 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 73 | |
| 74 | # first, try to get a version string from git |
| 75 | gotVersionFromGit = False |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 76 | try: |
| 77 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 78 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 79 | if out: |
| 80 | gotVersionFromGit = True |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 81 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 82 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 83 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 84 | # no tags matched |
| 85 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 26ea1ac | 2018-05-10 20:20:03 -0400 | [diff] [blame] | 86 | except (OSError, subprocess.CalledProcessError): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 87 | pass |
| 88 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 89 | versionFile = ctx.path.find_node('VERSION') |
| 90 | if not gotVersionFromGit and versionFile is not None: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 91 | try: |
| 92 | Context.g_module.VERSION = versionFile.read() |
| 93 | return |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 94 | except EnvironmentError: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 95 | pass |
| 96 | |
| 97 | # version was obtained from git, update VERSION file if necessary |
| 98 | if versionFile is not None: |
| 99 | try: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 100 | if versionFile.read() == Context.g_module.VERSION: |
| 101 | # already up-to-date |
| 102 | return |
| 103 | except EnvironmentError as e: |
| 104 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 105 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 106 | versionFile = ctx.path.make_node('VERSION') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 107 | |
| 108 | try: |
| 109 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 110 | except EnvironmentError as e: |
| 111 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 112 | |
| 113 | def dist(ctx): |
| 114 | version(ctx) |
| 115 | |
| 116 | def distcheck(ctx): |
| 117 | version(ctx) |