Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
| 3 | """ |
| 4 | Copyright (c) 2014-2015, Regents of the University of California |
| 5 | |
| 6 | This file is part of ndn-group-encrypt (Group-based Encryption Protocol for NDN). |
| 7 | See AUTHORS.md for complete list of ndn-group-encrypt authors and contributors. |
| 8 | |
| 9 | ndn-group-encrypt is free software: you can redistribute it and/or modify it under the terms |
| 10 | of the GNU General Public License as published by the Free Software Foundation, |
| 11 | either version 3 of the License, or (at your option) any later version. |
| 12 | |
| 13 | ndn-group-encrypt is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 14 | without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 15 | PURPOSE. See the GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License along with |
| 18 | ndn-group-encrypt, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 19 | """ |
| 20 | |
| 21 | VERSION = "0.0.1" |
| 22 | APPNAME = "libndn-group-encrypt" |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 23 | PACKAGE_BUGREPORT = "http://redmine.named-data.net/projects/gep" |
| 24 | PACKAGE_URL = "http://named-data.net/doc/ndn-group-encrypt/" |
| 25 | GIT_TAG_PREFIX = "ndn-group-encrypt" |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 26 | |
| 27 | from waflib import Logs, Utils, Context |
| 28 | import os |
| 29 | |
| 30 | def options(opt): |
| 31 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
Alexander Afanasyev | 867228e | 2016-10-17 16:54:55 -0700 | [diff] [blame] | 32 | opt.load(['boost', 'default-compiler-flags', 'sanitizers', 'doxygen'], |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 33 | tooldir=['.waf-tools']) |
| 34 | |
| 35 | syncopt = opt.add_option_group ("NDN-GROUP-ENCRYPT Options") |
| 36 | |
| 37 | syncopt.add_option('--debug', action='store_true', default=False, dest='debug', |
| 38 | help='''debugging mode''') |
| 39 | syncopt.add_option('--with-tests', action='store_true', default=False, dest='_tests', |
| 40 | help='''build unit tests''') |
| 41 | |
| 42 | def configure(conf): |
Alexander Afanasyev | 867228e | 2016-10-17 16:54:55 -0700 | [diff] [blame] | 43 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'boost', 'default-compiler-flags', 'sanitizers', 'doxygen']) |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 44 | |
Yingdi Yu | da495a9 | 2015-05-05 13:57:59 -0700 | [diff] [blame] | 45 | if 'PKG_CONFIG_PATH' not in os.environ: |
| 46 | os.environ['PKG_CONFIG_PATH'] = Utils.subst_vars('${LIBDIR}/pkgconfig', conf.env) |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 47 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 48 | uselib_store='NDN_CXX', mandatory=True) |
| 49 | |
| 50 | boost_libs = 'system iostreams' |
| 51 | if conf.options._tests: |
| 52 | conf.env['NDN_GEP_HAVE_TESTS'] = 1 |
| 53 | conf.define('NDN_GEP_HAVE_TESTS', 1); |
| 54 | boost_libs += ' unit_test_framework' |
| 55 | |
| 56 | conf.check_boost(lib=boost_libs) |
| 57 | |
| 58 | conf.write_config_header('config.hpp') |
| 59 | |
| 60 | def build(bld): |
| 61 | libndn_group_encrypt = bld( |
Yingdi Yu | da495a9 | 2015-05-05 13:57:59 -0700 | [diff] [blame] | 62 | target="ndn-group-encrypt", |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 63 | # vnum = "0.0.1", |
| 64 | features=['cxx', 'cxxshlib'], |
| 65 | source = bld.path.ant_glob(['src/**/*.cpp']), |
| 66 | use = 'BOOST NDN_CXX', |
| 67 | includes = ['src', '.'], |
| 68 | export_includes=['src', '.'], |
| 69 | ) |
| 70 | |
| 71 | # Unit tests |
| 72 | if bld.env["NDN_GEP_HAVE_TESTS"]: |
| 73 | bld.recurse('tests') |
| 74 | |
| 75 | bld.install_files( |
| 76 | dest = "%s/ndn-group-encrypt" % bld.env['INCLUDEDIR'], |
Yingdi Yu | 0a6663a | 2016-03-20 18:55:46 -0700 | [diff] [blame] | 77 | files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']), |
| 78 | cwd = bld.path.find_dir("src"), |
Yingdi Yu | b3c4776 | 2016-03-20 19:37:27 -0700 | [diff] [blame] | 79 | relative_trick = True, |
Yingdi Yu | 0a6663a | 2016-03-20 18:55:46 -0700 | [diff] [blame] | 80 | ) |
| 81 | |
| 82 | |
| 83 | bld.install_files( |
| 84 | dest = "%s/ndn-group-encrypt" % bld.env['INCLUDEDIR'], |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 85 | files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'common.hpp', 'config.hpp']), |
| 86 | cwd = bld.path.get_bld().find_dir("src"), |
| 87 | relative_trick = False, |
| 88 | ) |
| 89 | |
Yingdi Yu | da495a9 | 2015-05-05 13:57:59 -0700 | [diff] [blame] | 90 | bld(features = "subst", |
Yingdi Yu | ce94f35 | 2015-04-11 19:17:01 -0700 | [diff] [blame] | 91 | source='ndn-group-encrypt.pc.in', |
| 92 | target='ndn-group-encrypt.pc', |
| 93 | install_path = '${LIBDIR}/pkgconfig', |
| 94 | PREFIX = bld.env['PREFIX'], |
| 95 | INCLUDEDIR = "%s/ndn-group-encrypt" % bld.env['INCLUDEDIR'], |
| 96 | VERSION = VERSION, |
| 97 | ) |
Alexander Afanasyev | 9d7f8fe | 2016-08-05 11:28:06 -0700 | [diff] [blame] | 98 | |
| 99 | def docs(bld): |
| 100 | from waflib import Options |
| 101 | Options.commands = ['doxygen'] + Options.commands |
| 102 | |
| 103 | def doxygen(bld): |
| 104 | version(bld) |
| 105 | |
| 106 | if not bld.env.DOXYGEN: |
| 107 | Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 108 | else: |
| 109 | bld(features="subst", |
| 110 | name="doxygen-conf", |
| 111 | source=["docs/doxygen.conf.in", |
| 112 | "docs/named_data_theme/named_data_footer-with-analytics.html.in"], |
| 113 | target=["docs/doxygen.conf", |
| 114 | "docs/named_data_theme/named_data_footer-with-analytics.html"], |
| 115 | VERSION=VERSION, |
| 116 | HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \ |
| 117 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 118 | else "../docs/named_data_theme/named_data_footer.html", |
| 119 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""), |
| 120 | ) |
| 121 | |
| 122 | bld(features="doxygen", |
| 123 | doxyfile='docs/doxygen.conf', |
| 124 | use="doxygen-conf") |
| 125 | |
| 126 | def version(ctx): |
| 127 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 128 | return |
| 129 | |
| 130 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 131 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 132 | |
| 133 | didGetVersion = False |
| 134 | try: |
| 135 | cmd = ['git', 'describe', '--always', '--match', '%s*' % GIT_TAG_PREFIX] |
| 136 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 137 | stderr=None, stdin=None) |
| 138 | out = str(p.communicate()[0].strip()) |
| 139 | didGetVersion = (p.returncode == 0 and out != "") |
| 140 | if didGetVersion: |
| 141 | if out.startswith(GIT_TAG_PREFIX): |
| 142 | Context.g_module.VERSION = out[len(GIT_TAG_PREFIX):] |
| 143 | else: |
| 144 | Context.g_module.VERSION = "%s-commit-%s" % (Context.g_module.VERSION_BASE, out) |
| 145 | except OSError: |
| 146 | pass |
| 147 | |
| 148 | versionFile = ctx.path.find_node('VERSION') |
| 149 | |
| 150 | if not didGetVersion and versionFile is not None: |
| 151 | try: |
| 152 | Context.g_module.VERSION = versionFile.read() |
| 153 | return |
| 154 | except (OSError, IOError): |
| 155 | pass |
| 156 | |
| 157 | # version was obtained from git, update VERSION file if necessary |
| 158 | if versionFile is not None: |
| 159 | try: |
| 160 | version = versionFile.read() |
| 161 | if version == Context.g_module.VERSION: |
| 162 | return # no need to update |
| 163 | except (OSError, IOError): |
| 164 | Logs.warn("VERSION file exists, but not readable") |
| 165 | else: |
| 166 | versionFile = ctx.path.make_node('VERSION') |
| 167 | |
| 168 | if versionFile is None: |
| 169 | return |
| 170 | |
| 171 | try: |
| 172 | versionFile.write(Context.g_module.VERSION) |
| 173 | except (OSError, IOError): |
| 174 | Logs.warn("VERSION file is not writeable") |
| 175 | |
| 176 | def dist(ctx): |
| 177 | version(ctx) |
| 178 | |
| 179 | def distcheck(ctx): |
| 180 | version(ctx) |