blob: e4991b3c758c2c771b342c0b47f8f60ba1b1c585 [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
Alexander Afanasyeveacd6172017-10-16 16:40:31 -04003VERSION = '0.5'
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'])
Eric Newberry716ab602016-12-29 21:49:57 -070012 opt.load(['default-compiler-flags', 'coverage', 'sanitizers', 'boost',
13 'sphinx_build'],
Davide Pesavento89d91752016-08-14 11:34:09 +020014 tooldir=['.waf-tools'])
Shock Jiang0f0bc4b2015-06-22 15:11:30 -070015
Junxiao Shi2713a3b2015-06-22 16:19:05 -070016 opt.add_option('--with-tests', action='store_true', default=False,
17 dest='with_tests', help='''Build unit tests''')
Davide Pesavento89d91752016-08-14 11:34:09 +020018
19 opt.recurse('tools')
Junxiao Shif7191242015-03-19 05:53:41 -070020
21def configure(conf):
22 conf.load(['compiler_cxx', 'gnu_dirs',
Eric Newberrye16bc312016-11-04 01:00:27 +000023 'default-compiler-flags', 'sphinx_build', 'boost'])
Junxiao Shif7191242015-03-19 05:53:41 -070024
Alexander Afanasyev821a0142016-03-02 15:42:28 -080025 if 'PKG_CONFIG_PATH' not in os.environ:
26 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Junxiao Shif7191242015-03-19 05:53:41 -070027 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
28 uselib_store='NDN_CXX', mandatory=True)
29
Junxiao Shi2713a3b2015-06-22 16:19:05 -070030 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 Shi2222a612015-06-06 08:01:38 -070036
Alexander Afanasyev11e74eb2017-09-21 19:01:54 -040037 conf.recurse('tools')
38
39 conf.check_compiler_flags()
40
Eric Newberry716ab602016-12-29 21:49:57 -070041 # Loading "late" to prevent tests from being compiled with profiling flags
42 conf.load('coverage')
43
Eric Newberrye16bc312016-11-04 01:00:27 +000044 conf.load('sanitizers')
45
Junxiao Shif7191242015-03-19 05:53:41 -070046def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070047 version(bld)
48
49 bld(features='subst',
50 source='core/version.cpp.in',
51 target='core/version.cpp',
52 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070053
Davide Pesavento89d91752016-08-14 11:34:09 +020054 bld(target='core-objects',
Junxiao Shif7191242015-03-19 05:53:41 -070055 name='core-objects',
56 features='cxx',
Eric Newberry59869d22017-01-05 22:25:07 -070057 source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'],
Junxiao Shi2713a3b2015-06-22 16:19:05 -070058 use='NDN_CXX BOOST',
Eric Newberry59869d22017-01-05 22:25:07 -070059 includes='.',
Davide Pesavento89d91752016-08-14 11:34:09 +020060 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070061
62 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070063 bld.recurse('tests')
Junxiao Shi2219a052015-05-28 02:53:48 -070064 bld.recurse('manpages')
Eric Newberry59869d22017-01-05 22:25:07 -070065
66def 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")