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 | f0a301d | 2016-08-14 11:43:08 +0200 | [diff] [blame] | 3 | VERSION = '0.3' |
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 | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 8 | import os |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 9 | |
| 10 | def options(opt): |
| 11 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 12 | opt.load(['default-compiler-flags', 'sanitizers', 'sphinx_build', 'boost'], |
| 13 | tooldir=['.waf-tools']) |
Shock Jiang | 0f0bc4b | 2015-06-22 15:11:30 -0700 | [diff] [blame] | 14 | |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 15 | opt.add_option('--with-tests', action='store_true', default=False, |
| 16 | dest='with_tests', help='''Build unit tests''') |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 17 | |
| 18 | opt.recurse('tools') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 19 | |
| 20 | def configure(conf): |
| 21 | conf.load(['compiler_cxx', 'gnu_dirs', |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 22 | 'default-compiler-flags', 'sphinx_build', 'boost']) |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 23 | |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 24 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 25 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 26 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 27 | uselib_store='NDN_CXX', mandatory=True) |
| 28 | |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 29 | boost_libs = 'system iostreams regex' |
| 30 | if conf.options.with_tests: |
| 31 | conf.env['WITH_TESTS'] = 1 |
| 32 | conf.define('WITH_TESTS', 1); |
| 33 | boost_libs += ' unit_test_framework' |
| 34 | conf.check_boost(lib=boost_libs) |
Junxiao Shi | 2222a61 | 2015-06-06 08:01:38 -0700 | [diff] [blame] | 35 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 36 | conf.recurse('tools') |
| 37 | |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 38 | conf.load('sanitizers') |
| 39 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 40 | def build(bld): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 41 | version(bld) |
| 42 | |
| 43 | bld(features='subst', |
| 44 | source='core/version.cpp.in', |
| 45 | target='core/version.cpp', |
| 46 | VERSION_BUILD=VERSION) |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 47 | |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 48 | bld(target='core-objects', |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 49 | name='core-objects', |
| 50 | features='cxx', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 51 | source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'], |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 52 | use='NDN_CXX BOOST', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 53 | includes='.', |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 54 | export_includes='.') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 55 | |
| 56 | bld.recurse('tools') |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 57 | bld.recurse('tests') |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 58 | bld.recurse('manpages') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 59 | |
| 60 | def version(bld): |
| 61 | # Modified from ndn-cxx wscript |
| 62 | try: |
| 63 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 64 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 65 | stderr=None, stdin=None) |
| 66 | out = str(p.communicate()[0].strip()) |
| 67 | didGetVersion = (p.returncode == 0 and out != "") |
| 68 | if didGetVersion: |
| 69 | if out.startswith(GIT_TAG_PREFIX): |
| 70 | Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] |
| 71 | else: |
| 72 | Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION, out) |
| 73 | except OSError: |
| 74 | pass |
| 75 | |
| 76 | versionFile = bld.path.find_node('VERSION') |
| 77 | |
| 78 | if not didGetVersion and versionFile is not None: |
| 79 | try: |
| 80 | Context.g_module.VERSION = versionFile.read() |
| 81 | return |
| 82 | except (OSError, IOError): |
| 83 | pass |
| 84 | |
| 85 | # version was obtained from git, update VERSION file if necessary |
| 86 | if versionFile is not None: |
| 87 | try: |
| 88 | version = versionFile.read() |
| 89 | if version == Context.g_module.VERSION: |
| 90 | return # no need to update |
| 91 | except (OSError, IOError): |
| 92 | Logs.warn("VERSION file exists, but not readable") |
| 93 | else: |
| 94 | versionFile = bld.path.make_node('VERSION') |
| 95 | |
| 96 | # neither git describe nor VERSION file contain the version, so fall back to constant in wscript |
| 97 | if versionFile is None: |
| 98 | Context.g_module.VERSION = VERSION |
| 99 | |
| 100 | try: |
| 101 | versionFile.write(Context.g_module.VERSION) |
| 102 | except (OSError, IOError): |
| 103 | Logs.warn("VERSION file is not writeable") |