blob: 47723b253e78bab557b0063fbb78f6b6d22723eb [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
susmit48cb0b62018-02-13 12:27:24 -07003VERSION = '0.6'
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
Davide Pesavento1aa91432018-02-19 22:43:31 -050030 boost_libs = 'program_options regex system'
Junxiao Shi2713a3b2015-06-22 16:19:05 -070031 if conf.options.with_tests:
Davide Pesavento1aa91432018-02-19 22:43:31 -050032 conf.env['WITH_TESTS'] = True
33 conf.define('WITH_TESTS', 1)
34 boost_libs += ' filesystem unit_test_framework'
Junxiao Shi2713a3b2015-06-22 16:19:05 -070035 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')
Eric Newberrye16bc312016-11-04 01:00:27 +000043 conf.load('sanitizers')
44
Davide Pesavento1aa91432018-02-19 22:43:31 -050045 conf.msg('Tools to build', ', '.join(conf.env['BUILD_TOOLS']))
46
Junxiao Shif7191242015-03-19 05:53:41 -070047def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070048 version(bld)
49
50 bld(features='subst',
51 source='core/version.cpp.in',
52 target='core/version.cpp',
53 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070054
Davide Pesavento1aa91432018-02-19 22:43:31 -050055 bld.objects(target='core-objects',
56 source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'],
57 use='NDN_CXX BOOST',
58 includes='.',
59 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070060
61 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070062 bld.recurse('tests')
Junxiao Shi2219a052015-05-28 02:53:48 -070063 bld.recurse('manpages')
Eric Newberry59869d22017-01-05 22:25:07 -070064
65def version(bld):
66 # Modified from ndn-cxx wscript
67 try:
68 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
69 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
70 stderr=None, stdin=None)
71 out = str(p.communicate()[0].strip())
72 didGetVersion = (p.returncode == 0 and out != "")
73 if didGetVersion:
74 if out.startswith(GIT_TAG_PREFIX):
75 Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):]
76 else:
77 Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION, out)
78 except OSError:
79 pass
80
81 versionFile = bld.path.find_node('VERSION')
82
83 if not didGetVersion and versionFile is not None:
84 try:
85 Context.g_module.VERSION = versionFile.read()
86 return
87 except (OSError, IOError):
88 pass
89
90 # version was obtained from git, update VERSION file if necessary
91 if versionFile is not None:
92 try:
93 version = versionFile.read()
94 if version == Context.g_module.VERSION:
95 return # no need to update
96 except (OSError, IOError):
97 Logs.warn("VERSION file exists, but not readable")
98 else:
99 versionFile = bld.path.make_node('VERSION')
100
101 # neither git describe nor VERSION file contain the version, so fall back to constant in wscript
102 if versionFile is None:
103 Context.g_module.VERSION = VERSION
104
105 try:
106 versionFile.write(Context.g_module.VERSION)
107 except (OSError, IOError):
108 Logs.warn("VERSION file is not writeable")