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 | |
Alexander Afanasyev | a8b03df | 2018-09-16 21:06:07 -0400 | [diff] [blame] | 3 | VERSION = '0.6.2' |
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, |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 17 | 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 | |
Davide Pesavento | 78de735 | 2018-07-22 00:35:45 -0400 | [diff] [blame] | 30 | boost_libs = 'system filesystem program_options 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', |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 51 | name='version.cpp', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 52 | source='core/version.cpp.in', |
| 53 | target='core/version.cpp', |
| 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', |
Davide Pesavento | 3347eaa | 2019-01-16 18:41:46 -0500 | [diff] [blame] | 57 | source=bld.path.ant_glob('core/*.cpp') + ['core/version.cpp'], |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 58 | use='NDN_CXX BOOST', |
| 59 | includes='.', |
| 60 | export_includes='.') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 61 | |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 62 | if Utils.unversioned_sys_platform() == 'linux': |
| 63 | systemd_units = bld.path.ant_glob('systemd/*.in') |
| 64 | bld(features='subst', |
| 65 | name='systemd-units', |
| 66 | source=systemd_units, |
| 67 | target=[u.change_ext('') for u in systemd_units]) |
| 68 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 69 | bld.recurse('tools') |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 70 | bld.recurse('tests') |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 71 | bld.recurse('manpages') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 72 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 73 | def version(ctx): |
| 74 | # don't execute more than once |
| 75 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 76 | return |
| 77 | |
| 78 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 79 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 80 | |
| 81 | # first, try to get a version string from git |
| 82 | gotVersionFromGit = False |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 83 | try: |
| 84 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 85 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 86 | if out: |
| 87 | gotVersionFromGit = True |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 88 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 89 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 90 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 91 | # no tags matched |
| 92 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 26ea1ac | 2018-05-10 20:20:03 -0400 | [diff] [blame] | 93 | except (OSError, subprocess.CalledProcessError): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 94 | pass |
| 95 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 96 | versionFile = ctx.path.find_node('VERSION') |
| 97 | if not gotVersionFromGit and versionFile is not None: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 98 | try: |
| 99 | Context.g_module.VERSION = versionFile.read() |
| 100 | return |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 101 | except EnvironmentError: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 102 | pass |
| 103 | |
| 104 | # version was obtained from git, update VERSION file if necessary |
| 105 | if versionFile is not None: |
| 106 | try: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 107 | if versionFile.read() == Context.g_module.VERSION: |
| 108 | # already up-to-date |
| 109 | return |
| 110 | except EnvironmentError as e: |
| 111 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 112 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 113 | versionFile = ctx.path.make_node('VERSION') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 114 | |
| 115 | try: |
| 116 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 117 | except EnvironmentError as e: |
| 118 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 119 | |
| 120 | def dist(ctx): |
| 121 | version(ctx) |
| 122 | |
| 123 | def distcheck(ctx): |
| 124 | version(ctx) |