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 | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 51 | use = 'BOOST NDN_CXX LOG4CXX', |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 52 | includes = ['src', '.'], |
Yingdi Yu | dea99be | 2014-08-15 10:45:43 -0700 | [diff] [blame] | 53 | export_includes=['src', '.'], |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 54 | ) |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 55 | |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 56 | # Unit tests |
Yingdi Yu | b20ae81 | 2014-08-15 11:20:19 -0700 | [diff] [blame] | 57 | if bld.env["_TESTS"]: |
| 58 | bld.recurse('tests') |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 59 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 60 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 61 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 62 | files = bld.path.ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 63 | cwd = bld.path.find_dir("src"), |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 64 | relative_trick = False, |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 65 | ) |
| 66 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 67 | bld.install_files( |
Yingdi Yu | 7c64e5c | 2014-04-30 14:06:37 -0700 | [diff] [blame] | 68 | dest = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 69 | files = bld.path.get_bld().ant_glob(['src/**/*.hpp', 'src/**/*.h', 'common.hpp', 'config.hpp']), |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 70 | cwd = bld.path.get_bld().find_dir("src"), |
Yingdi Yu | f7ede41 | 2014-08-30 20:37:52 -0700 | [diff] [blame] | 71 | relative_trick = False, |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 72 | ) |
Alexander Afanasyev | e76f263 | 2012-03-05 00:18:42 -0800 | [diff] [blame] | 73 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 74 | pc = bld( |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 75 | features = "subst", |
Alexander Afanasyev | 7804c23 | 2013-07-14 12:15:41 -0700 | [diff] [blame] | 76 | source='ChronoSync.pc.in', |
| 77 | target='ChronoSync.pc', |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 78 | install_path = '${LIBDIR}/pkgconfig', |
| 79 | PREFIX = bld.env['PREFIX'], |
Alexander Afanasyev | ce00169 | 2013-07-14 11:34:41 -0700 | [diff] [blame] | 80 | INCLUDEDIR = "%s/ChronoSync" % bld.env['INCLUDEDIR'], |
Alexander Afanasyev | 6133f9a | 2013-07-14 10:58:26 -0700 | [diff] [blame] | 81 | VERSION = VERSION, |
| 82 | ) |
Alexander Afanasyev | 6af3c15 | 2012-06-07 21:14:24 -0700 | [diff] [blame] | 83 | |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 84 | # docs |
| 85 | def docs(bld): |
| 86 | from waflib import Options |
| 87 | Options.commands = ['doxygen', 'sphinx'] + Options.commands |
| 88 | |
Alexander Afanasyev | 7eb5911 | 2014-07-02 14:21:11 -0700 | [diff] [blame] | 89 | def doxygen(bld): |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 90 | version(bld) |
| 91 | |
Alexander Afanasyev | 34ebcb7 | 2012-03-08 15:54:55 -0800 | [diff] [blame] | 92 | if not bld.env.DOXYGEN: |
Yingdi Yu | 06a678a | 2014-08-01 17:07:08 -0700 | [diff] [blame] | 93 | Logs.error("ERROR: cannot build documentation (`doxygen' is not found in $PATH)") |
| 94 | else: |
| 95 | bld(features="subst", |
| 96 | name="doxygen-conf", |
| 97 | source=["docs/doxygen.conf.in", |
| 98 | "docs/named_data_theme/named_data_footer-with-analytics.html.in"], |
| 99 | target=["docs/doxygen.conf", |
| 100 | "docs/named_data_theme/named_data_footer-with-analytics.html"], |
| 101 | VERSION=VERSION, |
| 102 | HTML_FOOTER="../build/docs/named_data_theme/named_data_footer-with-analytics.html" \ |
| 103 | if os.getenv('GOOGLE_ANALYTICS', None) \ |
| 104 | else "../docs/named_data_theme/named_data_footer.html", |
| 105 | GOOGLE_ANALYTICS=os.getenv('GOOGLE_ANALYTICS', ""), |
| 106 | ) |
| 107 | |
| 108 | bld(features="doxygen", |
| 109 | doxyfile='docs/doxygen.conf', |
| 110 | use="doxygen-conf") |
| 111 | |
| 112 | def sphinx(bld): |
| 113 | version(bld) |
| 114 | |
| 115 | if not bld.env.SPHINX_BUILD: |
| 116 | bld.fatal("ERROR: cannot build documentation (`sphinx-build' is not found in $PATH)") |
| 117 | else: |
| 118 | bld(features="sphinx", |
| 119 | outdir="docs", |
| 120 | source=bld.path.ant_glob("docs/**/*.rst"), |
| 121 | config="docs/conf.py", |
| 122 | VERSION=VERSION) |
| 123 | |
| 124 | def version(ctx): |
| 125 | if getattr(Context.g_module, 'VERSION_BASE', None): |
| 126 | return |
| 127 | |
| 128 | Context.g_module.VERSION_BASE = Context.g_module.VERSION |
| 129 | Context.g_module.VERSION_SPLIT = [v for v in VERSION_BASE.split('.')] |
| 130 | |
| 131 | try: |
| 132 | cmd = ['git', 'describe', '--match', 'ChronoSync-*'] |
| 133 | p = Utils.subprocess.Popen(cmd, stdout=Utils.subprocess.PIPE, |
| 134 | stderr=None, stdin=None) |
| 135 | out = p.communicate()[0].strip() |
| 136 | if p.returncode == 0 and out != "": |
| 137 | Context.g_module.VERSION = out[11:] |
| 138 | except: |
| 139 | pass |
| 140 | |
| 141 | def dist(ctx): |
| 142 | version(ctx) |
| 143 | |
| 144 | def distcheck(ctx): |
| 145 | version(ctx) |