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 | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 3 | from waflib import Context, Logs, Utils |
| 4 | import os, subprocess |
| 5 | |
Davide Pesavento | ebea909 | 2022-02-18 11:30:32 -0500 | [diff] [blame] | 6 | VERSION = '22.02' |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 7 | APPNAME = 'ndn-tools' |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 8 | GIT_TAG_PREFIX = 'ndn-tools-' |
Alexander Afanasyev | 821a014 | 2016-03-02 15:42:28 -0800 | [diff] [blame] | 9 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 10 | def options(opt): |
| 11 | opt.load(['compiler_cxx', 'gnu_dirs']) |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 12 | opt.load(['default-compiler-flags', |
| 13 | 'coverage', 'sanitizers', 'boost', |
Eric Newberry | 716ab60 | 2016-12-29 21:49:57 -0700 | [diff] [blame] | 14 | 'sphinx_build'], |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 15 | tooldir=['.waf-tools']) |
Shock Jiang | 0f0bc4b | 2015-06-22 15:11:30 -0700 | [diff] [blame] | 16 | |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 17 | optgrp = opt.add_option_group('Tools Options') |
| 18 | optgrp.add_option('--with-tests', action='store_true', default=False, |
| 19 | help='Build unit tests') |
Davide Pesavento | 89d9175 | 2016-08-14 11:34:09 +0200 | [diff] [blame] | 20 | |
| 21 | opt.recurse('tools') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 22 | |
| 23 | def configure(conf): |
| 24 | conf.load(['compiler_cxx', 'gnu_dirs', |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 25 | 'default-compiler-flags', 'boost', |
| 26 | 'sphinx_build']) |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 27 | |
| 28 | conf.env.WITH_TESTS = conf.options.with_tests |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 29 | |
Davide Pesavento | f597d07 | 2022-07-04 21:20:21 -0400 | [diff] [blame] | 30 | # 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 Pesavento | 242d506 | 2022-03-11 16:34:23 -0500 | [diff] [blame] | 35 | pkg_config_path = os.environ.get('PKG_CONFIG_PATH', f'{conf.env.LIBDIR}/pkgconfig') |
| 36 | conf.check_cfg(package='libndn-cxx', args=['libndn-cxx >= 0.8.0', '--cflags', '--libs'], |
| 37 | uselib_store='NDN_CXX', pkg_config_path=pkg_config_path) |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 38 | |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 39 | boost_libs = ['system', 'program_options', 'filesystem'] |
| 40 | if conf.env.WITH_TESTS: |
| 41 | boost_libs.append('unit_test_framework') |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 42 | conf.define('WITH_TESTS', 1) |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 43 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 44 | conf.check_boost(lib=boost_libs, mt=True) |
Davide Pesavento | b04c52b | 2022-02-20 15:20:02 -0500 | [diff] [blame] | 45 | if conf.env.BOOST_VERSION_NUMBER < 106501: |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame] | 46 | 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 Shi | 2222a61 | 2015-06-06 08:01:38 -0700 | [diff] [blame] | 49 | |
Alexander Afanasyev | 11e74eb | 2017-09-21 19:01:54 -0400 | [diff] [blame] | 50 | conf.recurse('tools') |
| 51 | |
| 52 | conf.check_compiler_flags() |
| 53 | |
Eric Newberry | 716ab60 | 2016-12-29 21:49:57 -0700 | [diff] [blame] | 54 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 55 | conf.load('coverage') |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 56 | conf.load('sanitizers') |
| 57 | |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 58 | conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS)) |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 59 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 60 | def build(bld): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 61 | version(bld) |
| 62 | |
| 63 | bld(features='subst', |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 64 | name='version.cpp', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 65 | source='core/version.cpp.in', |
| 66 | target='core/version.cpp', |
| 67 | VERSION_BUILD=VERSION) |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 68 | |
Davide Pesavento | ebea909 | 2022-02-18 11:30:32 -0500 | [diff] [blame] | 69 | 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') |
| 77 | bld.recurse('tests') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 78 | |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 79 | if Utils.unversioned_sys_platform() == 'linux': |
| 80 | systemd_units = bld.path.ant_glob('systemd/*.in') |
| 81 | bld(features='subst', |
| 82 | name='systemd-units', |
| 83 | source=systemd_units, |
| 84 | target=[u.change_ext('') for u in systemd_units]) |
| 85 | |
Davide Pesavento | 786a7f2 | 2019-04-14 17:18:14 -0400 | [diff] [blame] | 86 | if bld.env.SPHINX_BUILD: |
| 87 | bld(features='sphinx', |
| 88 | name='manpages', |
| 89 | builder='man', |
| 90 | config='manpages/conf.py', |
| 91 | outdir='manpages', |
| 92 | source=bld.path.ant_glob('manpages/*.rst'), |
| 93 | install_path='${MANDIR}', |
| 94 | version=VERSION_BASE, |
| 95 | release=VERSION) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 96 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 97 | def version(ctx): |
| 98 | # don't execute more than once |
| 99 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 100 | return |
| 101 | |
| 102 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 103 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 104 | |
| 105 | # first, try to get a version string from git |
| 106 | gotVersionFromGit = False |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 107 | try: |
| 108 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 109 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 110 | if out: |
| 111 | gotVersionFromGit = True |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 112 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 113 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 114 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 115 | # no tags matched |
| 116 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 26ea1ac | 2018-05-10 20:20:03 -0400 | [diff] [blame] | 117 | except (OSError, subprocess.CalledProcessError): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 118 | pass |
| 119 | |
Alexander Afanasyev | 298c435 | 2020-05-31 15:40:28 -0400 | [diff] [blame] | 120 | versionFile = ctx.path.find_node('VERSION.info') |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 121 | if not gotVersionFromGit and versionFile is not None: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 122 | try: |
| 123 | Context.g_module.VERSION = versionFile.read() |
| 124 | return |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 125 | except EnvironmentError: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 126 | pass |
| 127 | |
| 128 | # version was obtained from git, update VERSION file if necessary |
| 129 | if versionFile is not None: |
| 130 | try: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 131 | if versionFile.read() == Context.g_module.VERSION: |
| 132 | # already up-to-date |
| 133 | return |
| 134 | except EnvironmentError as e: |
| 135 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 136 | else: |
Alexander Afanasyev | 298c435 | 2020-05-31 15:40:28 -0400 | [diff] [blame] | 137 | versionFile = ctx.path.make_node('VERSION.info') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 138 | |
| 139 | try: |
| 140 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 141 | except EnvironmentError as e: |
| 142 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 143 | |
| 144 | def dist(ctx): |
| 145 | version(ctx) |
| 146 | |
| 147 | def distcheck(ctx): |
| 148 | version(ctx) |