blob: e699fd3e5c10e4078e2cb9a3c9f7f409085339ce [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 Pesaventoebea9092022-02-18 11:30:32 -05006VERSION = '22.02'
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')
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 Shif7191242015-03-19 05:53:41 -070038
Davide Pesaventoae37cf32019-02-20 18:19:22 -050039 boost_libs = ['system', 'program_options', 'filesystem']
40 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')
77 bld.recurse('tests')
Junxiao Shif7191242015-03-19 05:53:41 -070078
Davide Pesaventocb903ea2019-01-16 16:31:00 -050079 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 Pesavento786a7f22019-04-14 17:18:14 -040086 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 Newberry59869d22017-01-05 22:25:07 -070096
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050097def 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 Newberry59869d22017-01-05 22:25:07 -0700107 try:
108 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500109 out = subprocess.check_output(cmd, universal_newlines=True).strip()
110 if out:
111 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -0700112 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500113 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -0700114 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500115 # no tags matched
116 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -0400117 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -0700118 pass
119
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400120 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500121 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -0700122 try:
123 Context.g_module.VERSION = versionFile.read()
124 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500125 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700126 pass
127
128 # version was obtained from git, update VERSION file if necessary
129 if versionFile is not None:
130 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500131 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 Newberry59869d22017-01-05 22:25:07 -0700136 else:
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400137 versionFile = ctx.path.make_node('VERSION.info')
Eric Newberry59869d22017-01-05 22:25:07 -0700138
139 try:
140 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500141 except EnvironmentError as e:
142 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
143
144def dist(ctx):
145 version(ctx)
146
147def distcheck(ctx):
148 version(ctx)