blob: b6fd73139d1b8c365fda19b94eaf80774a8bdd40 [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
Davide Pesavento7d148152020-01-15 01:03:41 -05003VERSION = '0.7'
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
Davide Pesavento2cd6ae82019-11-04 00:11:07 -050030 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX',
31 pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR))
Junxiao Shif7191242015-03-19 05:53:41 -070032
Davide Pesaventoae37cf32019-02-20 18:19:22 -050033 boost_libs = ['system', 'program_options', 'filesystem']
34 if conf.env.WITH_TESTS:
35 boost_libs.append('unit_test_framework')
Davide Pesavento1aa91432018-02-19 22:43:31 -050036 conf.define('WITH_TESTS', 1)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050037
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050038 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050039 if conf.env.BOOST_VERSION_NUMBER < 105800:
40 conf.fatal('Minimum required Boost version is 1.58.0\n'
41 'Please upgrade your distribution or manually install a newer version of Boost'
42 ' (https://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)')
Junxiao Shi2222a612015-06-06 08:01:38 -070043
Alexander Afanasyev11e74eb2017-09-21 19:01:54 -040044 conf.recurse('tools')
45
46 conf.check_compiler_flags()
47
Eric Newberry716ab602016-12-29 21:49:57 -070048 # Loading "late" to prevent tests from being compiled with profiling flags
49 conf.load('coverage')
Eric Newberrye16bc312016-11-04 01:00:27 +000050 conf.load('sanitizers')
51
Davide Pesaventoae37cf32019-02-20 18:19:22 -050052 conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS))
Davide Pesavento1aa91432018-02-19 22:43:31 -050053
Junxiao Shif7191242015-03-19 05:53:41 -070054def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070055 version(bld)
56
57 bld(features='subst',
Davide Pesaventocb903ea2019-01-16 16:31:00 -050058 name='version.cpp',
Eric Newberry59869d22017-01-05 22:25:07 -070059 source='core/version.cpp.in',
60 target='core/version.cpp',
61 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070062
Davide Pesavento1aa91432018-02-19 22:43:31 -050063 bld.objects(target='core-objects',
Davide Pesavento3347eaa2019-01-16 18:41:46 -050064 source=bld.path.ant_glob('core/*.cpp') + ['core/version.cpp'],
Davide Pesavento1aa91432018-02-19 22:43:31 -050065 use='NDN_CXX BOOST',
66 includes='.',
67 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070068
Davide Pesaventocb903ea2019-01-16 16:31:00 -050069 if Utils.unversioned_sys_platform() == 'linux':
70 systemd_units = bld.path.ant_glob('systemd/*.in')
71 bld(features='subst',
72 name='systemd-units',
73 source=systemd_units,
74 target=[u.change_ext('') for u in systemd_units])
75
Junxiao Shif7191242015-03-19 05:53:41 -070076 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070077 bld.recurse('tests')
Davide Pesavento786a7f22019-04-14 17:18:14 -040078
79 if bld.env.SPHINX_BUILD:
80 bld(features='sphinx',
81 name='manpages',
82 builder='man',
83 config='manpages/conf.py',
84 outdir='manpages',
85 source=bld.path.ant_glob('manpages/*.rst'),
86 install_path='${MANDIR}',
87 version=VERSION_BASE,
88 release=VERSION)
Eric Newberry59869d22017-01-05 22:25:07 -070089
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050090def version(ctx):
91 # don't execute more than once
92 if getattr(Context.g_module, 'VERSION_BASE', None):
93 return
94
95 Context.g_module.VERSION_BASE = Context.g_module.VERSION
96 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
97
98 # first, try to get a version string from git
99 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -0700100 try:
101 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500102 out = subprocess.check_output(cmd, universal_newlines=True).strip()
103 if out:
104 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -0700105 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500106 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -0700107 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500108 # no tags matched
109 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -0400110 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -0700111 pass
112
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500113 versionFile = ctx.path.find_node('VERSION')
114 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -0700115 try:
116 Context.g_module.VERSION = versionFile.read()
117 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500118 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700119 pass
120
121 # version was obtained from git, update VERSION file if necessary
122 if versionFile is not None:
123 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500124 if versionFile.read() == Context.g_module.VERSION:
125 # already up-to-date
126 return
127 except EnvironmentError as e:
128 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Eric Newberry59869d22017-01-05 22:25:07 -0700129 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500130 versionFile = ctx.path.make_node('VERSION')
Eric Newberry59869d22017-01-05 22:25:07 -0700131
132 try:
133 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500134 except EnvironmentError as e:
135 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
136
137def dist(ctx):
138 version(ctx)
139
140def distcheck(ctx):
141 version(ctx)