blob: 54f23ea703dca53b6c381f09e69db06ae91b7600 [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 Afanasyeva8b03df2018-09-16 21:06:07 -04003VERSION = '0.6.2'
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 Afanasyev20c85cb2018-03-09 17:50:14 -05008import os, subprocess
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,
Davide Pesaventocb903ea2019-01-16 16:31:00 -050017 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 Pesavento78de7352018-07-22 00:35:45 -040030 boost_libs = 'system filesystem program_options thread log log_setup'
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)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050034 boost_libs += ' unit_test_framework'
35 conf.check_boost(lib=boost_libs, mt=True)
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',
Davide Pesaventocb903ea2019-01-16 16:31:00 -050051 name='version.cpp',
Eric Newberry59869d22017-01-05 22:25:07 -070052 source='core/version.cpp.in',
53 target='core/version.cpp',
54 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070055
Davide Pesavento1aa91432018-02-19 22:43:31 -050056 bld.objects(target='core-objects',
Davide Pesavento3347eaa2019-01-16 18:41:46 -050057 source=bld.path.ant_glob('core/*.cpp') + ['core/version.cpp'],
Davide Pesavento1aa91432018-02-19 22:43:31 -050058 use='NDN_CXX BOOST',
59 includes='.',
60 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070061
Davide Pesaventocb903ea2019-01-16 16:31:00 -050062 if Utils.unversioned_sys_platform() == 'linux':
63 systemd_units = bld.path.ant_glob('systemd/*.in')
64 bld(features='subst',
65 name='systemd-units',
66 source=systemd_units,
67 target=[u.change_ext('') for u in systemd_units])
68
Junxiao Shif7191242015-03-19 05:53:41 -070069 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070070 bld.recurse('tests')
Junxiao Shi2219a052015-05-28 02:53:48 -070071 bld.recurse('manpages')
Eric Newberry59869d22017-01-05 22:25:07 -070072
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050073def version(ctx):
74 # don't execute more than once
75 if getattr(Context.g_module, 'VERSION_BASE', None):
76 return
77
78 Context.g_module.VERSION_BASE = Context.g_module.VERSION
79 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
80
81 # first, try to get a version string from git
82 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -070083 try:
84 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050085 out = subprocess.check_output(cmd, universal_newlines=True).strip()
86 if out:
87 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -070088 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050089 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -070090 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050091 # no tags matched
92 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -040093 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -070094 pass
95
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050096 versionFile = ctx.path.find_node('VERSION')
97 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -070098 try:
99 Context.g_module.VERSION = versionFile.read()
100 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500101 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700102 pass
103
104 # version was obtained from git, update VERSION file if necessary
105 if versionFile is not None:
106 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500107 if versionFile.read() == Context.g_module.VERSION:
108 # already up-to-date
109 return
110 except EnvironmentError as e:
111 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Eric Newberry59869d22017-01-05 22:25:07 -0700112 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500113 versionFile = ctx.path.make_node('VERSION')
Eric Newberry59869d22017-01-05 22:25:07 -0700114
115 try:
116 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500117 except EnvironmentError as e:
118 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
119
120def dist(ctx):
121 version(ctx)
122
123def distcheck(ctx):
124 version(ctx)