blob: c6a2fa74a785e128c61409624e28a0b5ab65c7c0 [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 Pesaventob6e10dd2023-09-11 21:41:24 -04003import os
4import subprocess
Davide Pesaventob07d7a92020-05-13 23:30:07 -04005from waflib import Context, Logs, Utils
Davide Pesaventob07d7a92020-05-13 23:30:07 -04006
Davide Pesavento3b4ee2f2022-12-31 01:55:06 -05007VERSION = '22.12'
Alexander Afanasyev821a0142016-03-02 15:42:28 -08008APPNAME = 'ndn-tools'
Eric Newberry59869d22017-01-05 22:25:07 -07009GIT_TAG_PREFIX = 'ndn-tools-'
Alexander Afanasyev821a0142016-03-02 15:42:28 -080010
Junxiao Shif7191242015-03-19 05:53:41 -070011def options(opt):
12 opt.load(['compiler_cxx', 'gnu_dirs'])
Davide Pesaventoae37cf32019-02-20 18:19:22 -050013 opt.load(['default-compiler-flags',
14 'coverage', 'sanitizers', 'boost',
Eric Newberry716ab602016-12-29 21:49:57 -070015 'sphinx_build'],
Davide Pesavento89d91752016-08-14 11:34:09 +020016 tooldir=['.waf-tools'])
Shock Jiang0f0bc4b2015-06-22 15:11:30 -070017
Davide Pesaventob07d7a92020-05-13 23:30:07 -040018 optgrp = opt.add_option_group('Tools Options')
19 optgrp.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 Pesaventob07d7a92020-05-13 23:30:07 -040026 'default-compiler-flags', 'boost',
27 'sphinx_build'])
Davide Pesaventoae37cf32019-02-20 18:19:22 -050028
29 conf.env.WITH_TESTS = conf.options.with_tests
Junxiao Shif7191242015-03-19 05:53:41 -070030
Davide Pesaventof597d072022-07-04 21:20:21 -040031 # Prefer pkgconf if it's installed, because it gives more correct results
32 # on Fedora/CentOS/RHEL/etc. See https://bugzilla.redhat.com/show_bug.cgi?id=1953348
33 # Store the result in env.PKGCONFIG, which is the variable used inside check_cfg()
34 conf.find_program(['pkgconf', 'pkg-config'], var='PKGCONFIG')
35
Davide Pesavento242d5062022-03-11 16:34:23 -050036 pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig')
Davide Pesavento3b4ee2f2022-12-31 01:55:06 -050037 conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'],
Davide Pesavento242d5062022-03-11 16:34:23 -050038 uselib_store='NDN_CXX', pkg_config_path=pkg_config_path)
Junxiao Shif7191242015-03-19 05:53:41 -070039
Davide Pesavento6b430e92022-09-18 18:16:02 -040040 boost_libs = ['system', 'program_options']
Davide Pesaventoae37cf32019-02-20 18:19:22 -050041 if conf.env.WITH_TESTS:
42 boost_libs.append('unit_test_framework')
Davide Pesavento1aa91432018-02-19 22:43:31 -050043 conf.define('WITH_TESTS', 1)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050044
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050045 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventob04c52b2022-02-20 15:20:02 -050046 if conf.env.BOOST_VERSION_NUMBER < 106501:
Davide Pesaventob07d7a92020-05-13 23:30:07 -040047 conf.fatal('The minimum supported version of Boost is 1.65.1.\n'
48 'Please upgrade your distribution or manually install a newer version of Boost.\n'
49 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost')
Junxiao Shi2222a612015-06-06 08:01:38 -070050
Alexander Afanasyev11e74eb2017-09-21 19:01:54 -040051 conf.recurse('tools')
52
53 conf.check_compiler_flags()
54
Eric Newberry716ab602016-12-29 21:49:57 -070055 # Loading "late" to prevent tests from being compiled with profiling flags
56 conf.load('coverage')
Eric Newberrye16bc312016-11-04 01:00:27 +000057 conf.load('sanitizers')
58
Davide Pesaventoae37cf32019-02-20 18:19:22 -050059 conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS))
Davide Pesavento1aa91432018-02-19 22:43:31 -050060
Junxiao Shif7191242015-03-19 05:53:41 -070061def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070062 version(bld)
63
64 bld(features='subst',
Davide Pesaventocb903ea2019-01-16 16:31:00 -050065 name='version.cpp',
Eric Newberry59869d22017-01-05 22:25:07 -070066 source='core/version.cpp.in',
67 target='core/version.cpp',
68 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070069
Davide Pesaventoebea9092022-02-18 11:30:32 -050070 bld.objects(
71 target='core-objects',
72 source=bld.path.find_node('core').ant_glob('*.cpp') + ['core/version.cpp'],
73 use='NDN_CXX BOOST',
74 includes='.',
75 export_includes='.')
76
77 bld.recurse('tools')
Davide Pesavento6b430e92022-09-18 18:16:02 -040078
79 if bld.env.WITH_TESTS:
80 bld.recurse('tests')
Junxiao Shif7191242015-03-19 05:53:41 -070081
Davide Pesaventocb903ea2019-01-16 16:31:00 -050082 if Utils.unversioned_sys_platform() == 'linux':
83 systemd_units = bld.path.ant_glob('systemd/*.in')
84 bld(features='subst',
85 name='systemd-units',
86 source=systemd_units,
87 target=[u.change_ext('') for u in systemd_units])
88
Davide Pesavento786a7f22019-04-14 17:18:14 -040089 if bld.env.SPHINX_BUILD:
90 bld(features='sphinx',
91 name='manpages',
92 builder='man',
93 config='manpages/conf.py',
94 outdir='manpages',
95 source=bld.path.ant_glob('manpages/*.rst'),
96 install_path='${MANDIR}',
97 version=VERSION_BASE,
98 release=VERSION)
Eric Newberry59869d22017-01-05 22:25:07 -070099
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500100def version(ctx):
101 # don't execute more than once
102 if getattr(Context.g_module, 'VERSION_BASE', None):
103 return
104
105 Context.g_module.VERSION_BASE = Context.g_module.VERSION
106 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
107
108 # first, try to get a version string from git
109 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -0700110 try:
Davide Pesaventob6e10dd2023-09-11 21:41:24 -0400111 cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*']
112 out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip()
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500113 if out:
114 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -0700115 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500116 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -0700117 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500118 # no tags matched
Davide Pesaventob6e10dd2023-09-11 21:41:24 -0400119 Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}'
120 except (OSError, subprocess.SubprocessError):
Eric Newberry59869d22017-01-05 22:25:07 -0700121 pass
122
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400123 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500124 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -0700125 try:
126 Context.g_module.VERSION = versionFile.read()
127 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500128 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700129 pass
130
131 # version was obtained from git, update VERSION file if necessary
132 if versionFile is not None:
133 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500134 if versionFile.read() == Context.g_module.VERSION:
135 # already up-to-date
136 return
137 except EnvironmentError as e:
Davide Pesaventob6e10dd2023-09-11 21:41:24 -0400138 Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})')
Eric Newberry59869d22017-01-05 22:25:07 -0700139 else:
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400140 versionFile = ctx.path.make_node('VERSION.info')
Eric Newberry59869d22017-01-05 22:25:07 -0700141
142 try:
143 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500144 except EnvironmentError as e:
Davide Pesaventob6e10dd2023-09-11 21:41:24 -0400145 Logs.warn(f'{versionFile} is not writable ({e.strerror})')
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500146
147def dist(ctx):
Davide Pesaventoa22a7422023-02-14 23:56:46 -0500148 ctx.algo = 'tar.xz'
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500149 version(ctx)
150
151def distcheck(ctx):
Davide Pesaventoa22a7422023-02-14 23:56:46 -0500152 ctx.algo = 'tar.xz'
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500153 version(ctx)