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 | 7d14815 | 2020-01-15 01:03:41 -0500 | [diff] [blame] | 6 | VERSION = '0.7' |
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 | 2cd6ae8 | 2019-11-04 00:11:07 -0500 | [diff] [blame] | 30 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], uselib_store='NDN_CXX', |
| 31 | pkg_config_path=os.environ.get('PKG_CONFIG_PATH', '%s/pkgconfig' % conf.env.LIBDIR)) |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 32 | |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 33 | boost_libs = ['system', 'program_options', 'filesystem'] |
| 34 | if conf.env.WITH_TESTS: |
| 35 | boost_libs.append('unit_test_framework') |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 36 | conf.define('WITH_TESTS', 1) |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 37 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 38 | conf.check_boost(lib=boost_libs, mt=True) |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 39 | if conf.env.BOOST_VERSION_NUMBER < 105800: |
Davide Pesavento | b07d7a9 | 2020-05-13 23:30:07 -0400 | [diff] [blame^] | 40 | conf.fatal('The minimum supported version of Boost is 1.65.1.\n' |
| 41 | 'Please upgrade your distribution or manually install a newer version of Boost.\n' |
| 42 | 'For more information, see https://redmine.named-data.net/projects/nfd/wiki/Boost') |
| 43 | elif conf.env.BOOST_VERSION_NUMBER < 106501: |
| 44 | Logs.warn('WARNING: Using a version of Boost older than 1.65.1 is not officially supported and may not work.\n' |
| 45 | 'If you encounter any problems, please upgrade your distribution or manually install a newer version of Boost.\n' |
| 46 | '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] | 47 | |
Alexander Afanasyev | 11e74eb | 2017-09-21 19:01:54 -0400 | [diff] [blame] | 48 | conf.recurse('tools') |
| 49 | |
| 50 | conf.check_compiler_flags() |
| 51 | |
Eric Newberry | 716ab60 | 2016-12-29 21:49:57 -0700 | [diff] [blame] | 52 | # Loading "late" to prevent tests from being compiled with profiling flags |
| 53 | conf.load('coverage') |
Eric Newberry | e16bc31 | 2016-11-04 01:00:27 +0000 | [diff] [blame] | 54 | conf.load('sanitizers') |
| 55 | |
Davide Pesavento | ae37cf3 | 2019-02-20 18:19:22 -0500 | [diff] [blame] | 56 | conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS)) |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 57 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 58 | def build(bld): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 59 | version(bld) |
| 60 | |
| 61 | bld(features='subst', |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 62 | name='version.cpp', |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 63 | source='core/version.cpp.in', |
| 64 | target='core/version.cpp', |
| 65 | VERSION_BUILD=VERSION) |
Junxiao Shi | 2219a05 | 2015-05-28 02:53:48 -0700 | [diff] [blame] | 66 | |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 67 | bld.objects(target='core-objects', |
Davide Pesavento | 3347eaa | 2019-01-16 18:41:46 -0500 | [diff] [blame] | 68 | source=bld.path.ant_glob('core/*.cpp') + ['core/version.cpp'], |
Davide Pesavento | 1aa9143 | 2018-02-19 22:43:31 -0500 | [diff] [blame] | 69 | use='NDN_CXX BOOST', |
| 70 | includes='.', |
| 71 | export_includes='.') |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 72 | |
Davide Pesavento | cb903ea | 2019-01-16 16:31:00 -0500 | [diff] [blame] | 73 | if Utils.unversioned_sys_platform() == 'linux': |
| 74 | systemd_units = bld.path.ant_glob('systemd/*.in') |
| 75 | bld(features='subst', |
| 76 | name='systemd-units', |
| 77 | source=systemd_units, |
| 78 | target=[u.change_ext('') for u in systemd_units]) |
| 79 | |
Junxiao Shi | f719124 | 2015-03-19 05:53:41 -0700 | [diff] [blame] | 80 | bld.recurse('tools') |
Junxiao Shi | 2713a3b | 2015-06-22 16:19:05 -0700 | [diff] [blame] | 81 | bld.recurse('tests') |
Davide Pesavento | 786a7f2 | 2019-04-14 17:18:14 -0400 | [diff] [blame] | 82 | |
| 83 | if bld.env.SPHINX_BUILD: |
| 84 | bld(features='sphinx', |
| 85 | name='manpages', |
| 86 | builder='man', |
| 87 | config='manpages/conf.py', |
| 88 | outdir='manpages', |
| 89 | source=bld.path.ant_glob('manpages/*.rst'), |
| 90 | install_path='${MANDIR}', |
| 91 | version=VERSION_BASE, |
| 92 | release=VERSION) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 93 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 94 | def version(ctx): |
| 95 | # don't execute more than once |
| 96 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 97 | return |
| 98 | |
| 99 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 100 | Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.') |
| 101 | |
| 102 | # first, try to get a version string from git |
| 103 | gotVersionFromGit = False |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 104 | try: |
| 105 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 106 | out = subprocess.check_output(cmd, universal_newlines=True).strip() |
| 107 | if out: |
| 108 | gotVersionFromGit = True |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 109 | if out.startswith(GIT_TAG_PREFIX): |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 110 | Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 111 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 112 | # no tags matched |
| 113 | Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out) |
Davide Pesavento | 26ea1ac | 2018-05-10 20:20:03 -0400 | [diff] [blame] | 114 | except (OSError, subprocess.CalledProcessError): |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 115 | pass |
| 116 | |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 117 | versionFile = ctx.path.find_node('VERSION') |
| 118 | if not gotVersionFromGit and versionFile is not None: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 119 | try: |
| 120 | Context.g_module.VERSION = versionFile.read() |
| 121 | return |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 122 | except EnvironmentError: |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 123 | pass |
| 124 | |
| 125 | # version was obtained from git, update VERSION file if necessary |
| 126 | if versionFile is not None: |
| 127 | try: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 128 | if versionFile.read() == Context.g_module.VERSION: |
| 129 | # already up-to-date |
| 130 | return |
| 131 | except EnvironmentError as e: |
| 132 | Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror)) |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 133 | else: |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 134 | versionFile = ctx.path.make_node('VERSION') |
Eric Newberry | 59869d2 | 2017-01-05 22:25:07 -0700 | [diff] [blame] | 135 | |
| 136 | try: |
| 137 | versionFile.write(Context.g_module.VERSION) |
Alexander Afanasyev | 20c85cb | 2018-03-09 17:50:14 -0500 | [diff] [blame] | 138 | except EnvironmentError as e: |
| 139 | Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror)) |
| 140 | |
| 141 | def dist(ctx): |
| 142 | version(ctx) |
| 143 | |
| 144 | def distcheck(ctx): |
| 145 | version(ctx) |