blob: 07a75243c7db11b797658c54f8515842c3756c89 [file] [log] [blame]
Junxiao Shif7191242015-03-19 05:53:41 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
Junxiao Shif7191242015-03-19 05:53:41 -07002
Davide Pesaventof0a301d2016-08-14 11:43:08 +02003VERSION = '0.3'
Alexander Afanasyev821a0142016-03-02 15:42:28 -08004APPNAME = 'ndn-tools'
Eric Newberry59869d22017-01-05 22:25:07 -07005GIT_TAG_PREFIX = 'ndn-tools-'
Alexander Afanasyev821a0142016-03-02 15:42:28 -08006
Eric Newberry59869d22017-01-05 22:25:07 -07007from waflib import Utils, Context
Alexander Afanasyev821a0142016-03-02 15:42:28 -08008import os
Junxiao Shif7191242015-03-19 05:53:41 -07009
10def options(opt):
11 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesavento89d91752016-08-14 11:34:09 +020012 opt.load(['default-compiler-flags', 'sanitizers', 'sphinx_build', 'boost'],
13 tooldir=['.waf-tools'])
Shock Jiang0f0bc4b2015-06-22 15:11:30 -070014
Junxiao Shi2713a3b2015-06-22 16:19:05 -070015 opt.add_option('--with-tests', action='store_true', default=False,
16 dest='with_tests', help='''Build unit tests''')
Davide Pesavento89d91752016-08-14 11:34:09 +020017
18 opt.recurse('tools')
Junxiao Shif7191242015-03-19 05:53:41 -070019
20def configure(conf):
21 conf.load(['compiler_cxx', 'gnu_dirs',
Eric Newberrye16bc312016-11-04 01:00:27 +000022 'default-compiler-flags', 'sphinx_build', 'boost'])
Junxiao Shif7191242015-03-19 05:53:41 -070023
Alexander Afanasyev821a0142016-03-02 15:42:28 -080024 if 'PKG_CONFIG_PATH' not in os.environ:
25 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Junxiao Shif7191242015-03-19 05:53:41 -070026 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
27 uselib_store='NDN_CXX', mandatory=True)
28
Junxiao Shi2713a3b2015-06-22 16:19:05 -070029 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 Shi2222a612015-06-06 08:01:38 -070035
Junxiao Shif7191242015-03-19 05:53:41 -070036 conf.recurse('tools')
37
Eric Newberrye16bc312016-11-04 01:00:27 +000038 conf.load('sanitizers')
39
Junxiao Shif7191242015-03-19 05:53:41 -070040def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070041 version(bld)
42
43 bld(features='subst',
44 source='core/version.cpp.in',
45 target='core/version.cpp',
46 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070047
Davide Pesavento89d91752016-08-14 11:34:09 +020048 bld(target='core-objects',
Junxiao Shif7191242015-03-19 05:53:41 -070049 name='core-objects',
50 features='cxx',
Eric Newberry59869d22017-01-05 22:25:07 -070051 source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'],
Junxiao Shi2713a3b2015-06-22 16:19:05 -070052 use='NDN_CXX BOOST',
Eric Newberry59869d22017-01-05 22:25:07 -070053 includes='.',
Davide Pesavento89d91752016-08-14 11:34:09 +020054 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070055
56 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070057 bld.recurse('tests')
Junxiao Shi2219a052015-05-28 02:53:48 -070058 bld.recurse('manpages')
Eric Newberry59869d22017-01-05 22:25:07 -070059
60def 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")