blob: c7ccb627f6bbe7f7f69b5f68b9e02587dab86563 [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 Pesavento4a43e872018-05-03 22:10:56 -04003VERSION = '0.6.1'
Alexander Afanasyev821a0142016-03-02 15:42:28 -08004APPNAME = 'ndn-tools'
Eric Newberry59869d22017-01-05 22:25:07 -07005GIT_TAG_PREFIX = 'ndn-tools-'
Alexander Afanasyev821a0142016-03-02 15:42:28 -08006
Eric Newberry59869d22017-01-05 22:25:07 -07007from waflib import Utils, Context
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -05008import os, subprocess
Junxiao Shif7191242015-03-19 05:53:41 -07009
10def options(opt):
11 opt.load(['compiler_cxx', 'gnu_dirs'])
Eric Newberry716ab602016-12-29 21:49:57 -070012 opt.load(['default-compiler-flags', 'coverage', 'sanitizers', 'boost',
13 'sphinx_build'],
Davide Pesavento89d91752016-08-14 11:34:09 +020014 tooldir=['.waf-tools'])
Shock Jiang0f0bc4b2015-06-22 15:11:30 -070015
Junxiao Shi2713a3b2015-06-22 16:19:05 -070016 opt.add_option('--with-tests', action='store_true', default=False,
17 dest='with_tests', help='''Build unit tests''')
Davide Pesavento89d91752016-08-14 11:34:09 +020018
19 opt.recurse('tools')
Junxiao Shif7191242015-03-19 05:53:41 -070020
21def configure(conf):
22 conf.load(['compiler_cxx', 'gnu_dirs',
Eric Newberrye16bc312016-11-04 01:00:27 +000023 'default-compiler-flags', 'sphinx_build', 'boost'])
Junxiao Shif7191242015-03-19 05:53:41 -070024
Alexander Afanasyev821a0142016-03-02 15:42:28 -080025 if 'PKG_CONFIG_PATH' not in os.environ:
26 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
Junxiao Shif7191242015-03-19 05:53:41 -070027 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
28 uselib_store='NDN_CXX', mandatory=True)
29
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050030 boost_libs = 'system filesystem program_options regex thread log log_setup'
Junxiao Shi2713a3b2015-06-22 16:19:05 -070031 if conf.options.with_tests:
Davide Pesavento1aa91432018-02-19 22:43:31 -050032 conf.env['WITH_TESTS'] = True
33 conf.define('WITH_TESTS', 1)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050034 boost_libs += ' unit_test_framework'
35 conf.check_boost(lib=boost_libs, mt=True)
Junxiao Shi2222a612015-06-06 08:01:38 -070036
Alexander Afanasyev11e74eb2017-09-21 19:01:54 -040037 conf.recurse('tools')
38
39 conf.check_compiler_flags()
40
Eric Newberry716ab602016-12-29 21:49:57 -070041 # Loading "late" to prevent tests from being compiled with profiling flags
42 conf.load('coverage')
Eric Newberrye16bc312016-11-04 01:00:27 +000043 conf.load('sanitizers')
44
Davide Pesavento1aa91432018-02-19 22:43:31 -050045 conf.msg('Tools to build', ', '.join(conf.env['BUILD_TOOLS']))
46
Junxiao Shif7191242015-03-19 05:53:41 -070047def build(bld):
Eric Newberry59869d22017-01-05 22:25:07 -070048 version(bld)
49
50 bld(features='subst',
51 source='core/version.cpp.in',
52 target='core/version.cpp',
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050053 name='version.cpp',
Eric Newberry59869d22017-01-05 22:25:07 -070054 VERSION_BUILD=VERSION)
Junxiao Shi2219a052015-05-28 02:53:48 -070055
Davide Pesavento1aa91432018-02-19 22:43:31 -050056 bld.objects(target='core-objects',
57 source=bld.path.ant_glob(['core/*.cpp']) + ['core/version.cpp'],
58 use='NDN_CXX BOOST',
59 includes='.',
60 export_includes='.')
Junxiao Shif7191242015-03-19 05:53:41 -070061
62 bld.recurse('tools')
Junxiao Shi2713a3b2015-06-22 16:19:05 -070063 bld.recurse('tests')
Junxiao Shi2219a052015-05-28 02:53:48 -070064 bld.recurse('manpages')
Eric Newberry59869d22017-01-05 22:25:07 -070065
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050066def version(ctx):
67 # don't execute more than once
68 if getattr(Context.g_module, 'VERSION_BASE', None):
69 return
70
71 Context.g_module.VERSION_BASE = Context.g_module.VERSION
72 Context.g_module.VERSION_SPLIT = VERSION_BASE.split('.')
73
74 # first, try to get a version string from git
75 gotVersionFromGit = False
Eric Newberry59869d22017-01-05 22:25:07 -070076 try:
77 cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX]
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050078 out = subprocess.check_output(cmd, universal_newlines=True).strip()
79 if out:
80 gotVersionFromGit = True
Eric Newberry59869d22017-01-05 22:25:07 -070081 if out.startswith(GIT_TAG_PREFIX):
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050082 Context.g_module.VERSION = out.lstrip(GIT_TAG_PREFIX)
Eric Newberry59869d22017-01-05 22:25:07 -070083 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050084 # no tags matched
85 Context.g_module.VERSION = '%s-commit-%s' % (VERSION_BASE, out)
Davide Pesavento26ea1ac2018-05-10 20:20:03 -040086 except (OSError, subprocess.CalledProcessError):
Eric Newberry59869d22017-01-05 22:25:07 -070087 pass
88
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050089 versionFile = ctx.path.find_node('VERSION')
90 if not gotVersionFromGit and versionFile is not None:
Eric Newberry59869d22017-01-05 22:25:07 -070091 try:
92 Context.g_module.VERSION = versionFile.read()
93 return
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -050094 except EnvironmentError:
Eric Newberry59869d22017-01-05 22:25:07 -070095 pass
96
97 # version was obtained from git, update VERSION file if necessary
98 if versionFile is not None:
99 try:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500100 if versionFile.read() == Context.g_module.VERSION:
101 # already up-to-date
102 return
103 except EnvironmentError as e:
104 Logs.warn('%s exists but is not readable (%s)' % (versionFile, e.strerror))
Eric Newberry59869d22017-01-05 22:25:07 -0700105 else:
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500106 versionFile = ctx.path.make_node('VERSION')
Eric Newberry59869d22017-01-05 22:25:07 -0700107
108 try:
109 versionFile.write(Context.g_module.VERSION)
Alexander Afanasyev20c85cb2018-03-09 17:50:14 -0500110 except EnvironmentError as e:
111 Logs.warn('%s is not writable (%s)' % (versionFile, e.strerror))
112
113def dist(ctx):
114 version(ctx)
115
116def distcheck(ctx):
117 version(ctx)