blob: 99283eded586ff2e7640c5fdd914fa7e85b15025 [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 Pesavento3b4ee2f2022-12-31 01:55:06 -05006VERSION = '22.12'
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 Pesaventof597d072022-07-04 21:20:21 -040030 # Prefer pkgconf if it's installed, because it gives more correct results
31 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
32 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
33 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
34
Davide Pesavento242d5062022-03-11 16:34:23 -050035 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento3b4ee2f2022-12-31 01:55:06 -050036 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento242d5062022-03-11 16:34:23 -050037 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Junxiao Shif7191242015-03-19 05:53:41 -070038
Davide Pesavento6b430e92022-09-18 18:16:02 -040039 boost_libs = ['system', 'program_options']
Davide Pesaventoae37cf32019-02-20 18:19:22 -050040 if conf.env.WITH_TESTS:
41 boost_libs.append('unit_test_framework')
Davide Pesavento1aa91432018-02-19 22:43:31 -050042 conf.define('WITH_TESTS', 1)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050043
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050044 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventob04c52b2022-02-20 15:20:02 -050045 if conf.env.BOOST_VERSION_NUMBER < 106501:
Davide Pesaventob07d7a92020-05-13 23:30:07 -040046 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
47 'Please upgrade your distribution or manually install a newer version of Boost.\n'
48 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
Junxiao Shi2222a612015-06-06 08:01:38 -070049
Alexander Afanasyev11e74eb2017-09-21 19:01:54 -040050 conf.recurse('tools')
51
52 conf.check_compiler_flags()
53
Eric Newberry716ab602016-12-29 21:49:57 -070054 # Loading "late" to prevent tests from being compiled with profiling flags
55 conf.load('coverage')
Eric Newberrye16bc312016-11-04 01:00:27 +000056 conf.load('sanitizers')
57
Davide Pesaventoae37cf32019-02-20 18:19:22 -050058 conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS))
Davide Pesavento1aa91432018-02-19 22:43:31 -050059
Junxiao Shif7191242015-03-19 05:53:41 -070060def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070061 version(bld)
62
63 bld(features='subst',
Davide Pesaventocb903ea2019-01-16 16:31:00 -050064 name='version.cpp',
Eric Newberry59869d22017-01-05 22:25:07 -070065 source='core/version.cpp.in',
66 target='core/version.cpp',
67 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070068
Davide Pesaventoebea9092022-02-18 11:30:32 -050069 bld.objects(
70 target='core-objects',
71 source=bld.path.find_node('core').ant_glob('*.cpp') + ['core/version.cpp'],
72 use='NDN_CXX BOOST',
73 includes='.',
74 export_includes='.')
75
76 bld.recurse('tools')
Davide Pesavento6b430e92022-09-18 18:16:02 -040077
78 if bld.env.WITH_TESTS:
79 bld.recurse('tests')
Junxiao Shif7191242015-03-19 05:53:41 -070080
Davide Pesaventocb903ea2019-01-16 16:31:00 -050081 if Utils.unversioned_sys_platform() == 'linux':
82 systemd_units = bld.path.ant_glob('systemd/*.in')
83 bld(features='subst',
84 name='systemd-units',
85 source=systemd_units,
86 target=[u.change_ext('') for u in systemd_units])
87
Davide Pesavento786a7f22019-04-14 17:18:14 -040088 if bld.env.SPHINX_BUILD:
89 bld(features='sphinx',
90 name='manpages',
91 builder='man',
92 config='manpages/conf.py',
93 outdir='manpages',
94 source=bld.path.ant_glob('manpages/*.rst'),
95 install_path='${MANDIR}',
96 version=VERSION_BASE,
97 release=VERSION)
Eric Newberry59869d22017-01-05 22:25:07 -070098
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050099def version(ctx):
100 # don't execute more than once
101 if getattr(Context.g_module, 'VERSION_BASE', None):
102 return
103
104 Context.g_module.VERSION_BASE = Context.g_module.VERSION
105 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
106
107 # first, try to get a version string from git
108 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -0700109 try:
110 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500111 out = subprocess.check_output(cmd, universal_newlines=True).strip()
112 if out:
113 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -0700114 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500115 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -0700116 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500117 # no tags matched
118 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -0400119 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -0700120 pass
121
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400122 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500123 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -0700124 try:
125 Context.g_module.VERSION = versionFile.read()
126 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500127 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700128 pass
129
130 # version was obtained from git, update VERSION file if necessary
131 if versionFile is not None:
132 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500133 if versionFile.read() == Context.g_module.VERSION:
134 # already up-to-date
135 return
136 except EnvironmentError as e:
137 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Eric Newberry59869d22017-01-05 22:25:07 -0700138 else:
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400139 versionFile = ctx.path.make_node('VERSION.info')
Eric Newberry59869d22017-01-05 22:25:07 -0700140
141 try:
142 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500143 except EnvironmentError as e:
144 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
145
146def dist(ctx):
Davide Pesaventoa22a7422023-02-14 23:56:46 -0500147 ctx.algo = 'tar.xz'
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500148 version(ctx)
149
150def distcheck(ctx):
Davide Pesaventoa22a7422023-02-14 23:56:46 -0500151 ctx.algo = 'tar.xz'
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500152 version(ctx)