Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | # -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*- |
| 2 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 3 | from waflib import Logs, Utils, Context |
| 4 | import os |
Alexander Afanasyev | 182fdc2 | 2012-03-05 18:06:52 -0800 | [diff] [blame] | 5 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 6 | VERSION = '0.2' |
| 7 | APPNAME = 'ChronoSync' |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 8 | |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 9 | def options(opt): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 10 | opt.load(['compiler_c', 'compiler_cxx', 'gnu_dirs']) |
| 11 | opt.load(['boost', 'doxygen', 'sphinx_build', 'default-compiler-flags', |
| 12 | 'pch', 'protoc'], |
| 13 | tooldir=['.waf-tools']) |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 14 | |
| 15 | syncopt = opt.add_option_group ("ChronoSync Options") |
| 16 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 17 | syncopt.add_option('--debug', action='store_true', default=False, dest='debug', |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 18 | help='''debugging mode''') |
| 19 | syncopt.add_option('--with-log4cxx', action='store_true', default=False, dest='log4cxx', |
| 20 | help='''Compile with log4cxx''') |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 21 | syncopt.add_option('--with-tests', action='store_true', default=False, dest='_tests', |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 22 | help='''build unit tests''') |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 23 | |
Alexander Afanasyev | 8f25cbb | 2012-03-01 23:53:40 -0800 | [diff] [blame] | 24 | def configure(conf): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 25 | conf.load(['compiler_c', 'compiler_cxx', 'gnu_dirs', 'boost', 'pch', |
| 26 | 'doxygen', 'sphinx_build', 'default-compiler-flags', 'protoc']) |
Alexander Afanasyev | 158ec0d | 2012-04-05 13:48:55 -0700 | [diff] [blame] | 27 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 28 | conf.check_cfg(package='libndn-cxx', args=['--cflags', '--libs'], |
| 29 | uselib_store='NDN_CXX', mandatory=True) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 30 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 31 | boost_libs = 'system iostreams' |
| 32 | if conf.options._tests: |
| 33 | conf.env['_TESTS'] = 1 |
| 34 | conf.define('_TESTS', 1); |
| 35 | boost_libs += ' unit_test_framework' |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 36 | |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame^] | 37 | conf.check_boost(lib=boost_libs) |
| 38 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 39 | if conf.options.log4cxx: |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 40 | conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', |
| 41 | mandatory=True) |
Alexander Afanasyev | 0ad7c21 | 2012-04-05 13:31:14 -0700 | [diff] [blame] | 42 | |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame^] | 43 | conf.write_config_header('config.hpp') |
| 44 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 45 | def build(bld): |
| 46 | libsync = bld( |
Alexander Afanasyev | f46eac5 | 2013-07-26 11:27:39 -0700 | [diff] [blame] | 47 | target="ChronoSync", |
Yingdi Yu | ce841ca | 2013-12-14 08:28:00 +0800 | [diff] [blame] | 48 | # vnum = "1.0.0", |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 49 | features=['cxx', 'cxxshlib'], |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame^] | 50 | source = bld.path.ant_glob(['src/**/*.cpp', 'src/**/*.proto']), |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 51 | use = 'BOOST NDN_CXX', |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame^] | 52 | includes = ['src', '.'], |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 53 | ) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 54 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 55 | # Unit tests |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame^] | 56 | if bld.env["_TESTS"]: |
| 57 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 58 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 59 | if bld.get_define("HAVE_LOG4CXX"): |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 60 | libsync.use += ' LOG4CXX' |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame^] | 61 | if bld.env["_TESTS"]: |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 62 | unittests.use += ' LOG4CXX' |
Alexander Afanasyev | 4f9ea48 | 2012-03-15 11:57:29 -0700 | [diff] [blame] | 63 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 64 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 65 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
| 66 | files = bld.path.ant_glob(['src/**/*.h']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 67 | cwd = bld.path.find_dir("src"), |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 68 | relative_trick = True, |
| 69 | ) |
| 70 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 71 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 72 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
| 73 | files = bld.path.get_bld().ant_glob(['src/**/*.h']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 74 | cwd = bld.path.get_bld().find_dir("src"), |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 75 | relative_trick = True, |
| 76 | ) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 77 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 78 | pc = bld( |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 79 | features = "subst", |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 80 | source='ChronoSync.pc.in', |
| 81 | target='ChronoSync.pc', |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 82 | install_path = '${LIBDIR}/pkgconfig', |
| 83 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 84 | INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 85 | VERSION = VERSION, |
| 86 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 87 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 88 | # docs |
| 89 | def docs(bld): |
| 90 | from waflib import Options |
| 91 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 92 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 93 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 94 | version(bld) |
| 95 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 96 | if not bld.env.DOXYGEN: |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 97 | Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 98 | else: |
| 99 | bld(features="subst", |
| 100 | name="doxygen-conf", |
| 101 | source=["docs/doxygen.conf.in", |
| 102 | "docs/named_data_theme/named_data_footer-with-analytics.html.in"], |
| 103 | target=["docs/doxygen.conf", |
| 104 | "docs/named_data_theme/named_data_footer-with-analytics.html"], |
| 105 | VERSION=VERSION, |
| 106 | HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \ |
| 107 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 108 | else "../docs/named_data_theme/named_data_footer.html", |
| 109 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""), |
| 110 | ) |
| 111 | |
| 112 | bld(features="doxygen", |
| 113 | doxyfile='docs/doxygen.conf', |
| 114 | use="doxygen-conf") |
| 115 | |
| 116 | def sphinx(bld): |
| 117 | version(bld) |
| 118 | |
| 119 | if not bld.env.SPHINX_BUILD: |
| 120 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)") |
| 121 | else: |
| 122 | bld(features="sphinx", |
| 123 | outdir="docs", |
| 124 | source=bld.path.ant_glob("docs/**/*.rst"), |
| 125 | config="docs/conf.py", |
| 126 | VERSION=VERSION) |
| 127 | |
| 128 | def version(ctx): |
| 129 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 130 | return |
| 131 | |
| 132 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 133 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 134 | |
| 135 | try: |
| 136 | cmd = ['git', 'describe', '--match', 'ChronoSync-*'] |
| 137 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 138 | stderr=None, stdin=None) |
| 139 | out = p.communicate()[0].strip() |
| 140 | if p.returncode == 0 and out != "": |
| 141 | Context.g_module.VERSION = out[11:] |
| 142 | except: |
| 143 | pass |
| 144 | |
| 145 | def dist(ctx): |
| 146 | version(ctx) |
| 147 | |
| 148 | def distcheck(ctx): |
| 149 | version(ctx) |