blob: 0af89bae0fbb79d8b404a71073825c986692a219 [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'])
Davide Pesaventoae37cf32019-02-20 18:19:22 -050012 opt.load(['default-compiler-flags',
13 'coverage', 'sanitizers', 'boost',
Eric Newberry716ab602016-12-29 21:49:57 -070014 'sphinx_build'],
Davide Pesavento89d91752016-08-14 11:34:09 +020015 tooldir=['.waf-tools'])
Shock Jiang0f0bc4b2015-06-22 15:11:30 -070016
Davide Pesaventoae37cf32019-02-20 18:19:22 -050017 opt_group = opt.add_option_group('Tools Options')
18
19 opt_group.add_option('--with-tests', action='store_true', default=False,
20 help='Build unit tests')
Davide Pesavento89d91752016-08-14 11:34:09 +020021
22 opt.recurse('tools')
Junxiao Shif7191242015-03-19 05:53:41 -070023
24def configure(conf):
25 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesaventoae37cf32019-02-20 18:19:22 -050026 'default-compiler-flags', 'boost', 'sphinx_build'])
27
28 conf.env.WITH_TESTS = conf.options.with_tests
Junxiao Shif7191242015-03-19 05:53:41 -070029
Alexander Afanasyev821a0142016-03-02 15:42:28 -080030 if 'PKG_CONFIG_PATH' not in os.environ:
31 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050032 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX')
Junxiao Shif7191242015-03-19 05:53:41 -070033
Davide Pesaventoae37cf32019-02-20 18:19:22 -050034 boost_libs = ['system', 'program_options', 'filesystem']
35 if conf.env.WITH_TESTS:
36 boost_libs.append('unit_test_framework')
Davide Pesavento1aa91432018-02-19 22:43:31 -050037 conf.define('WITH_TESTS', 1)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050038
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050039 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050040 if conf.env.BOOST_VERSION_NUMBER < 105800:
41 conf.fatal('Minimum required Boost version is 1.58.0\n'
42 'Please upgrade your distribution or manually install a newer version of Boost'
43 ' (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)')
Junxiao Shi2222a612015-06-06 08:01:38 -070044
Alexander Afanasyev11e74eb2017-09-21 19:01:54 -040045 conf.recurse('tools')
46
47 conf.check_compiler_flags()
48
Eric Newberry716ab602016-12-29 21:49:57 -070049 # Loading "late" to prevent tests from being compiled with profiling flags
50 conf.load('coverage')
Eric Newberrye16bc312016-11-04 01:00:27 +000051 conf.load('sanitizers')
52
Davide Pesaventoae37cf32019-02-20 18:19:22 -050053 conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS))
Davide Pesavento1aa91432018-02-19 22:43:31 -050054
Junxiao Shif7191242015-03-19 05:53:41 -070055def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070056 version(bld)
57
58 bld(features='subst',
Davide Pesaventocb903ea2019-01-16 16:31:00 -050059 name='version.cpp',
Eric Newberry59869d22017-01-05 22:25:07 -070060 source='core/version.cpp.in',
61 target='core/version.cpp',
62 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070063
Davide Pesavento1aa91432018-02-19 22:43:31 -050064 bld.objects(target='core-objects',
Davide Pesavento3347eaa2019-01-16 18:41:46 -050065 source=bld.path.ant_glob('core/*.cpp') + ['core/version.cpp'],
Davide Pesavento1aa91432018-02-19 22:43:31 -050066 use='NDN_CXX BOOST',
67 includes='.',
68 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070069
Davide Pesaventocb903ea2019-01-16 16:31:00 -050070 if Utils.unversioned_sys_platform() == 'linux':
71 systemd_units = bld.path.ant_glob('systemd/*.in')
72 bld(features='subst',
73 name='systemd-units',
74 source=systemd_units,
75 target=[u.change_ext('') for u in systemd_units])
76
Junxiao Shif7191242015-03-19 05:53:41 -070077 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070078 bld.recurse('tests')
Junxiao Shi2219a052015-05-28 02:53:48 -070079 bld.recurse('manpages')
Eric Newberry59869d22017-01-05 22:25:07 -070080
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050081def version(ctx):
82 # don't execute more than once
83 if getattr(Context.g_module, 'VERSION_BASE', None):
84 return
85
86 Context.g_module.VERSION_BASE = Context.g_module.VERSION
87 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
88
89 # first, try to get a version string from git
90 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -070091 try:
92 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050093 out = subprocess.check_output(cmd, universal_newlines=True).strip()
94 if out:
95 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -070096 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050097 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -070098 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050099 # no tags matched
100 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -0400101 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -0700102 pass
103
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500104 versionFile = ctx.path.find_node('VERSION')
105 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -0700106 try:
107 Context.g_module.VERSION = versionFile.read()
108 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500109 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700110 pass
111
112 # version was obtained from git, update VERSION file if necessary
113 if versionFile is not None:
114 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500115 if versionFile.read() == Context.g_module.VERSION:
116 # already up-to-date
117 return
118 except EnvironmentError as e:
119 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Eric Newberry59869d22017-01-05 22:25:07 -0700120 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500121 versionFile = ctx.path.make_node('VERSION')
Eric Newberry59869d22017-01-05 22:25:07 -0700122
123 try:
124 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500125 except EnvironmentError as e:
126 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
127
128def dist(ctx):
129 version(ctx)
130
131def distcheck(ctx):
132 version(ctx)