blob: 551c57219e8d693adc7c830acbc177deb6c6790a [file] [log] [blame]
spirosmastorakisa99994c2016-01-24 15:26:53 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2VERSION='0.1.0'
3APPNAME='nTorrent'
4
5from waflib import Configure, Utils, Logs, Context
6import os
7
8def options(opt):
9
10 opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs'])
11
12 opt.load(['default-compiler-flags', 'boost',
13 'doxygen', 'sphinx_build'],
14 tooldir=['.waf-tools'])
15
16 opt = opt.add_option_group('nTorrent Options')
17
18 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
19 help='''build unit tests''')
20
21def configure(conf):
22 conf.load(['compiler_c', 'compiler_cxx',
23 'default-compiler-flags', 'boost', 'gnu_dirs',
24 'doxygen', 'sphinx_build'])
25
26 if 'PKG_CONFIG_PATH' not in os.environ:
27 os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env)
28
29 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
30 uselib_store='NDN_CXX', mandatory=True)
31
32 boost_libs = 'system random thread filesystem'
33 if conf.options.with_tests:
34 conf.env['WITH_TESTS'] = 1
35 conf.define('WITH_TESTS', 1);
36 boost_libs += ' unit_test_framework'
37
38 conf.check_boost(lib=boost_libs)
39 if conf.env.BOOST_VERSION_NUMBER < 104800:
40 Logs.error("Minimum required boost version is 1.48.0")
41 Logs.error("Please upgrade your distribution or install custom boost libraries" +
42 " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
43 return
44
45 conf.write_config_header('src/config.h')
46
47def build (bld):
48 feature_list = 'cxx'
49
50 bld(
51 features='cxx',
52 name='nTorrent',
53 source=bld.path.ant_glob(['src/**/*.cpp'],
54 excl=['src/main.cpp',]),
55 use='version NDN_CXX BOOST',
56 includes='src',
57 export_includes='src',
58 )
59
60 if bld.env["WITH_TESTS"]:
61 feature_list += ' cxxstlib'
62 else:
63 feature_list += ' cxxprogram'
64
65 # Unit tests
66 if bld.env["WITH_TESTS"]:
67 unittests = bld.program (
68 target="unit-tests",
69 source = bld.path.ant_glob(['tests/**/*.cpp']),
70 features=['cxx', 'cxxprogram'],
71 use = 'BOOST nTorrent',
72 includes = "src .",
73 install_path = None
74 )
75
76# docs
77def docs(bld):
78 from waflib import Options
79 Options.commands = ['doxygen', 'sphinx'] + Options.commands
80
81def doxygen(bld):
82 version(bld)
83
84 if not bld.env.DOXYGEN:
85 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
86 else:
87 bld(features="subst",
88 name="doxygen-conf",
89 source=["docs/doxygen.conf.in",
90 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
91 target=["docs/doxygen.conf",
92 "docs/named_data_theme/named_data_footer-with-analytics.html"],
93 VERSION=VERSION,
94 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
95 if os.getenv('GOOGLE_ANALYTICS', None) \
96 else "../docs/named_data_theme/named_data_footer.html",
97 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
98 )
99
100 bld(features="doxygen",
101 doxyfile='docs/doxygen.conf',
102 use="doxygen-conf")
103
104def sphinx(bld):
105 version(bld)
106
107 if not bld.env.SPHINX_BUILD:
108 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
109 else:
110 bld(features="sphinx",
111 outdir="docs",
112 source=bld.path.ant_glob("docs/**/*.rst"),
113 config="docs/conf.py",
114 VERSION=VERSION)
115
116def version(ctx):
117 if getattr(Context.g_module, 'VERSION_BASE', None):
118 return
119
120 Context.g_module.VERSION_BASE = Context.g_module.VERSION
121 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
122
123 try:
124 cmd = ['git', 'describe', '--match', 'nTorrent-*']
125 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
126 stderr=None, stdin=None)
127 out = p.communicate()[0].strip()
128 if p.returncode == 0 and out != "":
129 Context.g_module.VERSION = out[11:]
130 except:
131 pass