blob: f0c4d6d1d085a51f19c8ec610067a25aa2a02d31 [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 Pesavento2cd6ae82019-11-04 00:11:07 -050030 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 Shif7191242015-03-19 05:53:41 -070032
Davide Pesaventoae37cf32019-02-20 18:19:22 -050033 boost_libs = ['system', 'program_options', 'filesystem']
34 if conf.env.WITH_TESTS:
35 boost_libs.append('unit_test_framework')
Davide Pesavento1aa91432018-02-19 22:43:31 -050036 conf.define('WITH_TESTS', 1)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050037
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050038 conf.check_boost(lib=boost_libs, mt=True)
Davide Pesaventoae37cf32019-02-20 18:19:22 -050039 if conf.env.BOOST_VERSION_NUMBER < 105800:
Davide Pesaventob07d7a92020-05-13 23:30:07 -040040 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 Shi2222a612015-06-06 08:01:38 -070047
Alexander Afanasyev11e74eb2017-09-21 19:01:54 -040048 conf.recurse('tools')
49
50 conf.check_compiler_flags()
51
Eric Newberry716ab602016-12-29 21:49:57 -070052 # Loading "late" to prevent tests from being compiled with profiling flags
53 conf.load('coverage')
Eric Newberrye16bc312016-11-04 01:00:27 +000054 conf.load('sanitizers')
55
Davide Pesaventoae37cf32019-02-20 18:19:22 -050056 conf.msg('Tools to build', ', '.join(conf.env.BUILD_TOOLS))
Davide Pesavento1aa91432018-02-19 22:43:31 -050057
Junxiao Shif7191242015-03-19 05:53:41 -070058def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070059 version(bld)
60
61 bld(features='subst',
Davide Pesaventocb903ea2019-01-16 16:31:00 -050062 name='version.cpp',
Eric Newberry59869d22017-01-05 22:25:07 -070063 source='core/version.cpp.in',
64 target='core/version.cpp',
65 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070066
Davide Pesaventoebea9092022-02-18 11:30:32 -050067 bld.objects(
68 target='core-objects',
69 source=bld.path.find_node('core').ant_glob('*.cpp') + ['core/version.cpp'],
70 use='NDN_CXX BOOST',
71 includes='.',
72 export_includes='.')
73
74 bld.recurse('tools')
75 bld.recurse('tests')
Junxiao Shif7191242015-03-19 05:53:41 -070076
Davide Pesaventocb903ea2019-01-16 16:31:00 -050077 if Utils.unversioned_sys_platform() == 'linux':
78 systemd_units = bld.path.ant_glob('systemd/*.in')
79 bld(features='subst',
80 name='systemd-units',
81 source=systemd_units,
82 target=[u.change_ext('') for u in systemd_units])
83
Davide Pesavento786a7f22019-04-14 17:18:14 -040084 if bld.env.SPHINX_BUILD:
85 bld(features='sphinx',
86 name='manpages',
87 builder='man',
88 config='manpages/conf.py',
89 outdir='manpages',
90 source=bld.path.ant_glob('manpages/*.rst'),
91 install_path='${MANDIR}',
92 version=VERSION_BASE,
93 release=VERSION)
Eric Newberry59869d22017-01-05 22:25:07 -070094
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050095def version(ctx):
96 # don't execute more than once
97 if getattr(Context.g_module, 'VERSION_BASE', None):
98 return
99
100 Context.g_module.VERSION_BASE = Context.g_module.VERSION
101 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
102
103 # first, try to get a version string from git
104 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -0700105 try:
106 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500107 out = subprocess.check_output(cmd, universal_newlines=True).strip()
108 if out:
109 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -0700110 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500111 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -0700112 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500113 # no tags matched
114 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -0400115 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -0700116 pass
117
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400118 versionFile = ctx.path.find_node('VERSION.info')
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500119 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -0700120 try:
121 Context.g_module.VERSION = versionFile.read()
122 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500123 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -0700124 pass
125
126 # version was obtained from git, update VERSION file if necessary
127 if versionFile is not None:
128 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500129 if versionFile.read() == Context.g_module.VERSION:
130 # already up-to-date
131 return
132 except EnvironmentError as e:
133 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Eric Newberry59869d22017-01-05 22:25:07 -0700134 else:
Alexander Afanasyev298c4352020-05-31 15:40:28 -0400135 versionFile = ctx.path.make_node('VERSION.info')
Eric Newberry59869d22017-01-05 22:25:07 -0700136
137 try:
138 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500139 except EnvironmentError as e:
140 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
141
142def dist(ctx):
143 version(ctx)
144
145def distcheck(ctx):
146 version(ctx)