blob: 00d472f9fdf137e4c37a2adf90c9a2b49cbdcdd1 [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 Afanasyev339161a2016-10-27 22:41:16 +00003VERSION = '0.4'
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
Eric Newberry716ab602016-12-29 21:49:57 -070037 # Loading "late" to prevent tests from being compiled with profiling flags
38 conf.load('coverage')
39
Junxiao Shif7191242015-03-19 05:53:41 -070040 conf.recurse('tools')
41
Eric Newberrye16bc312016-11-04 01:00:27 +000042 conf.load('sanitizers')
43
Junxiao Shif7191242015-03-19 05:53:41 -070044def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070045 version(bld)
46
47 bld(features='subst',
48 source='core/version.cpp.in',
49 target='core/version.cpp',
50 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070051
Davide Pesavento89d91752016-08-14 11:34:09 +020052 bld(target='core-objects',
Junxiao Shif7191242015-03-19 05:53:41 -070053 name='core-objects',
54 features='cxx',
Eric Newberry59869d22017-01-05 22:25:07 -070055 source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'],
Junxiao Shi2713a3b2015-06-22 16:19:05 -070056 use='NDN_CXX BOOST',
Eric Newberry59869d22017-01-05 22:25:07 -070057 includes='.',
Davide Pesavento89d91752016-08-14 11:34:09 +020058 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070059
60 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070061 bld.recurse('tests')
Junxiao Shi2219a052015-05-28 02:53:48 -070062 bld.recurse('manpages')
Eric Newberry59869d22017-01-05 22:25:07 -070063
64def version(bld):
65 # Modified from ndn-cxx wscript
66 try:
67 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
68 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
69 stderr=None, stdin=None)
70 out = str(p.communicate()[0].strip())
71 didGetVersion = (p.returncode == 0 and out != "")
72 if didGetVersion:
73 if out.startswith(GIT_TAG_PREFIX):
74 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
75 else:
76 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION, out)
77 except OSError:
78 pass
79
80 versionFile = bld.path.find_node('VERSION')
81
82 if not didGetVersion and versionFile is not None:
83 try:
84 Context.g_module.VERSION = versionFile.read()
85 return
86 except (OSError, IOError):
87 pass
88
89 # version was obtained from git, update VERSION file if necessary
90 if versionFile is not None:
91 try:
92 version = versionFile.read()
93 if version == Context.g_module.VERSION:
94 return # no need to update
95 except (OSError, IOError):
96 Logs.warn("VERSION file exists, but not readable")
97 else:
98 versionFile = bld.path.make_node('VERSION')
99
100 # neither git describe nor VERSION file contain the version, so fall back to constant in wscript
101 if versionFile is None:
102 Context.g_module.VERSION = VERSION
103
104 try:
105 versionFile.write(Context.g_module.VERSION)
106 except (OSError, IOError):
107 Logs.warn("VERSION file is not writeable")