Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 2 | |
Davide Pesavento | b6e10dd | 2023-09-11 21:41:24 -0400 | [diff] [blame] | 3 | import os |
| 4 | import subprocess |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 5 | from waflib import Context, Logs, Utils |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 6 | |
Davide Pesavento | 3b4ee2f | 2022-12-31 01:55:06 -0500 | [diff] [blame] | 7 | VERSION = '22.12' |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 8 | APPNAME = 'ndn-tools' |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 9 | GIT_TAG_PREFIX = 'ndn-tools-' |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 10 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 11 | def options(opt): |
| 12 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 13 | opt.load(['default-compiler-flags', |
| 14 | 'coverage', 'sanitizers', 'boost', |
Eric Newberry | 716ab60 | 2016-12-29 21:49:57 -0700 | [diff] [blame] | 15 | 'sphinx_build'], |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 16 | tooldir=['.waf-tools']) |
Shock Jiang | 0f0bc4b | 2015-06-22 15:11:30 -0700 | [diff] [blame] | 17 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 18 | optgrp = opt.add_option_group('Tools Options') |
| 19 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 20 | help='Build unit tests') |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 21 | |
| 22 | opt.recurse('tools') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 23 | |
| 24 | def configure(conf): |
| 25 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 26 | 'default-compiler-flags', 'boost', |
| 27 | 'sphinx_build']) |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 28 | |
| 29 | conf.env.WITH_TESTS = conf.options.with_tests |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 30 | |
Davide Pesavento | f597d07 | 2022-07-04 21:20:21 -0400 | [diff] [blame] | 31 | # 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 Pesavento | 242d506 | 2022-03-11 16:34:23 -0500 | [diff] [blame] | 36 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig') |
Davide Pesavento | 3b4ee2f | 2022-12-31 01:55:06 -0500 | [diff] [blame] | 37 | conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.1', '--cflags', '--libs'], |
Davide Pesavento | 242d506 | 2022-03-11 16:34:23 -0500 | [diff] [blame] | 38 | uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 39 | |
Davide Pesavento | 2ab04a2 | 2023-09-15 22:08:22 -0400 | [diff] [blame] | 40 | conf.check_boost(lib='program_options', mt=True) |
| 41 | if conf.env.BOOST_VERSION_NUMBER < 107100: |
| 42 | conf.fatal('The minimum supported version of Boost is 1.71.0.\n' |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 43 | 'Please upgrade your distribution or manually install a newer version of Boost.\n' |
| 44 | 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost') |
Junxiao Shi | 2222a61 | 2015-06-06 08:01:38 -0700 | [diff] [blame] | 45 | |
Davide Pesavento | 2ab04a2 | 2023-09-15 22:08:22 -0400 | [diff] [blame] | 46 | if conf.env.WITH_TESTS: |
| 47 | conf.check_boost(lib='unit_test_framework', mt=True, uselib_store='BOOST_TESTS') |
| 48 | |
Alexander Afanasyev | 11e74eb | 2017-09-21 19:01:54 -0400 | [diff] [blame] | 49 | conf.recurse('tools') |
| 50 | |
| 51 | conf.check_compiler_flags() |
| 52 | |
Eric Newberry | 716ab60 | 2016-12-29 21:49:57 -0700 | [diff] [blame] | 53 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 54 | conf.load('coverage') |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 55 | conf.load('sanitizers') |
| 56 | |
Davide Pesavento | 2ab04a2 | 2023-09-15 22:08:22 -0400 | [diff] [blame] | 57 | conf.define_cond('WITH_TESTS', conf.env.WITH_TESTS) |
| 58 | |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 59 | conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS)) |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 60 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 61 | def build(bld): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 62 | version(bld) |
| 63 | |
| 64 | bld(features='subst', |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 65 | name='version.cpp', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 66 | source='core/version.cpp.in', |
| 67 | target='core/version.cpp', |
| 68 | VERSION_BUILD=VERSION) |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 69 | |
Davide Pesavento | ebea909 | 2022-02-18 11:30:32 -0500 | [diff] [blame] | 70 | bld.objects( |
| 71 | target='core-objects', |
Davide Pesavento | 2ab04a2 | 2023-09-15 22:08:22 -0400 | [diff] [blame] | 72 | source=bld.path.find_dir('core').ant_glob('*.cpp') + ['core/version.cpp'], |
| 73 | use='BOOST NDN_CXX', |
Davide Pesavento | ebea909 | 2022-02-18 11:30:32 -0500 | [diff] [blame] | 74 | includes='.', |
| 75 | export_includes='.') |
| 76 | |
| 77 | bld.recurse('tools') |
Davide Pesavento | 6b430e9 | 2022-09-18 18:16:02 -0400 | [diff] [blame] | 78 | |
| 79 | if bld.env.WITH_TESTS: |
| 80 | bld.recurse('tests') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 81 | |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 82 | 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 Pesavento | 786a7f2 | 2019-04-14 17:18:14 -0400 | [diff] [blame] | 89 | 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 Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 99 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 100 | def 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 Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 110 | try: |
Davide Pesavento | b6e10dd | 2023-09-11 21:41:24 -0400 | [diff] [blame] | 111 | cmd = ['git', 'describe', '--always', '--match', f'{GIT_TAG_PREFIX}*'] |
| 112 | out = subprocess.run(cmd, capture_output=True, check=True, text=True).stdout.strip() |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 113 | if out: |
| 114 | gotVersionFromGit = True |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 115 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 116 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 117 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 118 | # no tags matched |
Davide Pesavento | b6e10dd | 2023-09-11 21:41:24 -0400 | [diff] [blame] | 119 | Context.g_module.VERSION = f'{VERSION_BASE}-commit-{out}' |
| 120 | except (OSError, subprocess.SubprocessError): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 121 | pass |
| 122 | |
Alexander Afanasyev | 298c435 | 2020-05-31 15:40:28 -0400 | [diff] [blame] | 123 | versionFile = ctx.path.find_node('VERSION.info') |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 124 | if not gotVersionFromGit and versionFile is not None: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 125 | try: |
| 126 | Context.g_module.VERSION = versionFile.read() |
| 127 | return |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 128 | except EnvironmentError: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 129 | pass |
| 130 | |
| 131 | # version was obtained from git, update VERSION file if necessary |
| 132 | if versionFile is not None: |
| 133 | try: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 134 | if versionFile.read() == Context.g_module.VERSION: |
| 135 | # already up-to-date |
| 136 | return |
| 137 | except EnvironmentError as e: |
Davide Pesavento | b6e10dd | 2023-09-11 21:41:24 -0400 | [diff] [blame] | 138 | Logs.warn(f'{versionFile} exists but is not readable ({e.strerror})') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 139 | else: |
Alexander Afanasyev | 298c435 | 2020-05-31 15:40:28 -0400 | [diff] [blame] | 140 | versionFile = ctx.path.make_node('VERSION.info') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 141 | |
| 142 | try: |
| 143 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 144 | except EnvironmentError as e: |
Davide Pesavento | b6e10dd | 2023-09-11 21:41:24 -0400 | [diff] [blame] | 145 | Logs.warn(f'{versionFile} is not writable ({e.strerror})') |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 146 | |
| 147 | def dist(ctx): |
Davide Pesavento | a22a742 | 2023-02-14 23:56:46 -0500 | [diff] [blame] | 148 | ctx.algo = 'tar.xz' |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 149 | version(ctx) |
| 150 | |
| 151 | def distcheck(ctx): |
Davide Pesavento | a22a742 | 2023-02-14 23:56:46 -0500 | [diff] [blame] | 152 | ctx.algo = 'tar.xz' |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 153 | version(ctx) |