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 | eacd617 | 2017-10-16 16:40:31 -0400 | [diff] [blame] | 3 | VERSION = '0.5' |
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']) |
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 | |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 30 | boost_libs = 'system iostreams regex' |
| 31 | if conf.options.with_tests: |
| 32 | conf.env['WITH_TESTS'] = 1 |
| 33 | conf.define('WITH_TESTS', 1); |
| 34 | boost_libs += ' unit_test_framework' |
| 35 | conf.check_boost(lib=boost_libs) |
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') |
| 43 | |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 44 | conf.load('sanitizers') |
| 45 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 46 | def build(bld): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 47 | version(bld) |
| 48 | |
| 49 | bld(features='subst', |
| 50 | source='core/version.cpp.in', |
| 51 | target='core/version.cpp', |
| 52 | VERSION_BUILD=VERSION) |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 53 | |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 54 | bld(target='core-objects', |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 55 | name='core-objects', |
| 56 | features='cxx', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 57 | source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'], |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 58 | use='NDN_CXX BOOST', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 59 | includes='.', |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 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 | |
| 66 | def version(bld): |
| 67 | # Modified from ndn-cxx wscript |
| 68 | try: |
| 69 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 70 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 71 | stderr=None, stdin=None) |
| 72 | out = str(p.communicate()[0].strip()) |
| 73 | didGetVersion = (p.returncode == 0 and out != "") |
| 74 | if didGetVersion: |
| 75 | if out.startswith(GIT_TAG_PREFIX): |
| 76 | Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] |
| 77 | else: |
| 78 | Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION, out) |
| 79 | except OSError: |
| 80 | pass |
| 81 | |
| 82 | versionFile = bld.path.find_node('VERSION') |
| 83 | |
| 84 | if not didGetVersion and versionFile is not None: |
| 85 | try: |
| 86 | Context.g_module.VERSION = versionFile.read() |
| 87 | return |
| 88 | except (OSError, IOError): |
| 89 | pass |
| 90 | |
| 91 | # version was obtained from git, update VERSION file if necessary |
| 92 | if versionFile is not None: |
| 93 | try: |
| 94 | version = versionFile.read() |
| 95 | if version == Context.g_module.VERSION: |
| 96 | return # no need to update |
| 97 | except (OSError, IOError): |
| 98 | Logs.warn("VERSION file exists, but not readable") |
| 99 | else: |
| 100 | versionFile = bld.path.make_node('VERSION') |
| 101 | |
| 102 | # neither git describe nor VERSION file contain the version, so fall back to constant in wscript |
| 103 | if versionFile is None: |
| 104 | Context.g_module.VERSION = VERSION |
| 105 | |
| 106 | try: |
| 107 | versionFile.write(Context.g_module.VERSION) |
| 108 | except (OSError, IOError): |
| 109 | Logs.warn("VERSION file is not writeable") |