blob: b9601cd73a434592c20cc493169b5803586ae4dd [file] [log] [blame]
Yingdi Yuc9843cf2014-08-04 17:52:19 -07001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
3"""
4Copyright (c) 2014, Regents of the University of California
5
6This file is part of NSL (NDN Signature Logger).
7See AUTHORS.md for complete list of NSL authors and contributors.
8
9NSL is free software: you can redistribute it and/or modify it under the terms
10of the GNU General Public License as published by the Free Software Foundation,
11either version 3 of the License, or (at your option) any later version.
12
13NSL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15PURPOSE. See the GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License along with
18NSL, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
19"""
20
21from waflib import Logs, Utils, Context
22import os
23
24VERSION = "0.1.0"
25APPNAME = "nsl"
26
27def options(opt):
28 opt.load(['compiler_cxx', 'gnu_dirs', 'c_osx'])
29 opt.load(['default-compiler-flags', 'boost', 'cryptopp',
30 'sqlite3', 'doxygen', 'sphinx_build'],
31 tooldir=['.waf-tools'])
32
33 opt = opt.add_option_group('NSL Options')
34
35 opt.add_option('--with-tests', action='store_true', default=False, dest='with_tests',
36 help='''build unit tests''')
37
38 opt.add_option('--without-tools', action='store_false', default=True, dest='with_tools',
39 help='''Do not build tools''')
40
41 opt.add_option('--without-sqlite-locking', action='store_false', default=True,
42 dest='with_sqlite_locking',
43 help='''Disable filesystem locking in sqlite3 database '''
44 '''(use unix-dot locking mechanism instead). '''
45 '''This option may be necessary if home directory is hosted on NFS.''')
46
47def configure(conf):
48 conf.load(['compiler_cxx', 'gnu_dirs', 'c_osx',
49 'default-compiler-flags', 'boost', 'cryptopp',
50 'sqlite3', 'doxygen', 'sphinx_build'])
51
52 conf.env['WITH_TESTS'] = conf.options.with_tests
53 conf.env['WITH_TOOLS'] = conf.options.with_tools
54
55 conf.find_program('sh', var='SH', mandatory=True)
56
57 conf.check_cxx(lib='pthread', uselib_store='PTHREAD', define_name='HAVE_PTHREAD',
58 mandatory=False)
59 conf.check_sqlite3(mandatory=True)
60 conf.check_cryptopp(mandatory=True, use='PTHREAD')
61
62 conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'],
63 uselib_store='NDN_CXX', mandatory=True)
64
65 USED_BOOST_LIBS = ['system', 'filesystem', 'date_time', 'iostreams',
66 'program_options', 'chrono']
67 if conf.env['WITH_TESTS']:
68 USED_BOOST_LIBS += ['unit_test_framework']
69 conf.define('HAVE_TESTS', 1)
70
71 conf.check_boost(lib=USED_BOOST_LIBS, mandatory=True)
72 if conf.env.BOOST_VERSION_NUMBER < 104800:
73 Logs.error("Minimum required boost version is 1.48.0")
74 Logs.error("Please upgrade your distribution or install custom boost libraries" +
75 " (http://redmine.named-data.net/projects/nfd/wiki/Boost_FAQ)")
76 return
77
78 if not conf.options.with_sqlite_locking:
79 conf.define('DISABLE_SQLITE3_FS_LOCKING', 1)
80
81 conf.define('DEFAULT_CONFIG_FILE', '%s/ndn/nsl.conf' % conf.env['SYSCONFDIR'])
82
Yingdi Yu0c3e5912015-03-17 14:22:38 -070083 conf.write_config_header('config.hpp', define_prefix='NSL_')
Yingdi Yuc9843cf2014-08-04 17:52:19 -070084
85def build(bld):
86 version(bld)
87
88 bld(features="subst",
89 name='version',
90 source='version.hpp.in',
91 target='version.hpp',
92 install_path=None,
93 VERSION_STRING=VERSION_BASE,
94 VERSION_BUILD=VERSION,
95 VERSION=int(VERSION_SPLIT[0]) * 1000000 +
96 int(VERSION_SPLIT[1]) * 1000 +
97 int(VERSION_SPLIT[2]),
98 VERSION_MAJOR=VERSION_SPLIT[0],
99 VERSION_MINOR=VERSION_SPLIT[1],
100 VERSION_PATCH=VERSION_SPLIT[2],
101 )
102
103 core = bld(
104 target='core-objects',
105 name='core-objects',
106 features='cxx',
107 source=bld.path.ant_glob(['core/**/*.cpp']),
108 use='version BOOST NDN_CXX CRYPTOPP SQLITE3',
109 includes='. core',
110 export_includes='. core',
111 headers='common.hpp',
112 )
113
114 logger_objects = bld(
115 target='daemon-objects',
116 name='daemon-objects',
117 features='cxx',
118 source=bld.path.ant_glob(['daemon/**/*.cpp'],
119 excl=['daemon/main.cpp']),
120 use='core-objects',
121 includes='daemon',
122 export_includes='daemon',
123 )
124
125 bld(target='bin/nsl',
126 features='cxx cxxprogram',
127 source='daemon/main.cpp',
128 use='daemon-objects',
129 )
130
131 if bld.env['WITH_TESTS']:
132 bld.recurse('tests')
133
134 if bld.env['WITH_TOOLS']:
135 bld.recurse("tools")
136
137 bld(features="subst",
138 source='nsl.conf.sample.in',
139 target='nsl.conf.sample',
140 install_path="${SYSCONFDIR}/ndn",
141 )
142
143 if bld.env['SPHINX_BUILD']:
144 bld(features="sphinx",
145 builder="man",
146 outdir="docs/manpages",
147 config="docs/conf.py",
148 source=bld.path.ant_glob('docs/manpages/**/*.rst'),
149 install_path="${MANDIR}/",
150 VERSION=VERSION)
151
152def docs(bld):
153 from waflib import Options
154 Options.commands = ['doxygen', 'sphinx'] + Options.commands
155
156def doxygen(bld):
157 version(bld)
158
159 if not bld.env.DOXYGEN:
160 Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
161 else:
162 bld(features="subst",
163 name="doxygen-conf",
164 source=["docs/doxygen.conf.in",
165 "docs/named_data_theme/named_data_footer-with-analytics.html.in"],
166 target=["docs/doxygen.conf",
167 "docs/named_data_theme/named_data_footer-with-analytics.html"],
168 VERSION=VERSION,
169 HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \
170 if os.getenv('GOOGLE_ANALYTICS', None) \
171 else "../docs/named_data_theme/named_data_footer.html",
172 GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""),
173 )
174
175 bld(features="doxygen",
176 doxyfile='docs/doxygen.conf',
177 use="doxygen-conf")
178
179def sphinx(bld):
180 version(bld)
181
182 if not bld.env.SPHINX_BUILD:
183 bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)")
184 else:
185 bld(features="sphinx",
186 outdir="docs",
187 source=bld.path.ant_glob("docs/**/*.rst"),
188 config="docs/conf.py",
189 VERSION=VERSION)
190
191
192def version(ctx):
193 if getattr(Context.g_module, 'VERSION_BASE', None):
194 return
195
196 Context.g_module.VERSION_BASE = Context.g_module.VERSION
197 Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')]
198
199 try:
200 cmd = ['git', 'describe', '--match', 'nsl-*']
201 p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE,
202 stderr=None, stdin=None)
203 out = p.communicate()[0].strip()
204 if p.returncode == 0 and out != "":
205 Context.g_module.VERSION = out[8:]
206 except:
207 pass