blob: 0bfb7f683679fefe8e694389b1f053bfc46f47ef [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 Pesaventob07d7a92020-05-13 23:30:07 -04003from waflib import Context, Logs, Utils
4import os, subprocess
5
Davide Pesaventoebea9092022-02-18 11:30:32 -05006VERSION = '22.02'
Alexander Afanasyev821a0142016-03-02 15:42:28 -08007APPNAME = 'ndn-tools'
Eric Newberry59869d22017-01-05 22:25:07 -07008GIT_TAG_PREFIX = 'ndn-tools-'
Alexander Afanasyev821a0142016-03-02 15:42:28 -08009
Junxiao Shif7191242015-03-19 05:53:41 -070010def 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 Pesaventob07d7a92020-05-13 23:30:07 -040017 optgrp = opt.add_option_group('Tools Options')
18 optgrp.add_option('--with-tests', action='store_true', default=False,
19 help='Build unit tests')
Davide Pesavento89d91752016-08-14 11:34:09 +020020
21 opt.recurse('tools')
Junxiao Shif7191242015-03-19 05:53:41 -070022
23def configure(conf):
24 conf.load(['compiler_cxx', 'gnu_dirs',
Davide Pesaventob07d7a92020-05-13 23:30:07 -040025 'default-compiler-flags', 'boost',
26 'sphinx_build'])
Davide Pesaventoae37cf32019-02-20 18:19:22 -050027
28 conf.env.WITH_TESTS = conf.options.with_tests
Junxiao Shif7191242015-03-19 05:53:41 -070029
Davide Pesavento242d5062022-03-11 16:34:23 -050030 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
31 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'],
32 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
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 Pesaventob04c52b2022-02-20 15:20:02 -050040 if conf.env.BOOST_VERSION_NUMBER < 106501:
Davide Pesaventob07d7a92020-05-13 23:30:07 -040041 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
42 'Please upgrade your distribution or manually install a newer version of Boost.\n'
43 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
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 Pesaventoebea9092022-02-18 11:30:32 -050064 bld.objects(
65 target='core-objects',
66 source=bld.path.find_node('core').ant_glob('*.cpp') + ['core/version.cpp'],
67 use='NDN_CXX BOOST',
68 includes='.',
69 export_includes='.')
70
71 bld.recurse('tools')
72 bld.recurse('tests')
Junxiao Shif7191242015-03-19 05:53:41 -070073
Davide Pesaventocb903ea2019-01-16 16:31:00 -050074 if Utils.unversioned_sys_platform() == 'linux':
75 systemd_units = bld.path.ant_glob('systemd/*.in')
76 bld(features='subst',
77 name='systemd-units',
78 source=systemd_units,
79 target=[u.change_ext('') for u in systemd_units])
80
Davide Pesavento786a7f22019-04-14 17:18:14 -040081 if bld.env.SPHINX_BUILD:
82 bld(features='sphinx',
83 name='manpages',
84 builder='man',
85 config='manpages/conf.py',
86 outdir='manpages',
87 source=bld.path.ant_glob('manpages/*.rst'),
88 install_path='${MANDIR}',
89 version=VERSION_BASE,
90 release=VERSION)
Eric Newberry59869d22017-01-05 22:25:07 -070091
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050092def version(ctx):
93 # don't execute more than once
94 if getattr(Context.g_module, 'VERSION_BASE', None):
95 return
96
97 Context.g_module.VERSION_BASE = Context.g_module.VERSION
98 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
99
100 # first, try to get a version string from git
101 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -0700102 try:
103 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500104 out = subprocess.check_output(cmd, universal_newlines=True).strip()
105 if out:
106 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -0700107 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500108 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -0700109 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500110 # no tags matched
111 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -0400112 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -0700113 pass
114
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400115 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500116 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -0700117 try:
118 Context.g_module.VERSION = versionFile.read()
119 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500120 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700121 pass
122
123 # version was obtained from git, update VERSION file if necessary
124 if versionFile is not None:
125 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500126 if versionFile.read() == Context.g_module.VERSION:
127 # already up-to-date
128 return
129 except EnvironmentError as e:
130 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Eric Newberry59869d22017-01-05 22:25:07 -0700131 else:
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400132 versionFile = ctx.path.make_node('VERSION.info')
Eric Newberry59869d22017-01-05 22:25:07 -0700133
134 try:
135 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500136 except EnvironmentError as e:
137 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
138
139def dist(ctx):
140 version(ctx)
141
142def distcheck(ctx):
143 version(ctx)