blob: ddba0d8554e43db545c6b30f5ec9e46647ea6f8c [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001# -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
2
Alexander Afanasyev182fdc22012-03-05 18:06:52 -08003VERSION='0.0.1'
4APPNAME='sync'
5
Alexander Afanasyev6af3c152012-06-07 21:14:24 -07006from waflib import Build, Logs
7
Alexander Afanasyeve76f2632012-03-05 00:18:42 -08008def options(opt):
Zhenkai Zhu699d7402012-05-29 16:47:39 -07009 opt.add_option('--debug',action='store_true',default=False,dest='debug',help='''debugging mode''')
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070010 opt.add_option('--log4cxx', action='store_true',default=False,dest='log4cxx',help='''Compile with log4cxx/native NS3 logging support''')
11 opt.add_option('--ns3', action='store_true',default=False,dest='ns3_enable',help='''Compile as NS-3 module''')
Alexander Afanasyev983b0e92012-04-26 12:44:18 -070012 opt.add_option('--ns3-debug', action='store_true',default=False,dest='ns3_debug',help='''Link against debug NS3 libraries. Optimized version will be used otherwise''')
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070013 opt.add_option('--test', action='store_true',default=False,dest='_test',help='''build unit tests''')
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080014 opt.load('compiler_c')
15 opt.load('compiler_cxx')
Alexander Afanasyev182fdc22012-03-05 18:06:52 -080016 opt.load('boost')
17 opt.load('doxygen')
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070018 opt.load('gnu_dirs')
19 opt.load('ccnx ns3 protobuf', tooldir=["waf-tools"])
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080020
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080021def configure(conf):
Alexander Afanasyeve76f2632012-03-05 00:18:42 -080022 conf.load("compiler_cxx")
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070023 conf.load('gnu_dirs')
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080024
25 if not conf.check_cfg(package='openssl', args=['--cflags', '--libs'], uselib_store='SSL', mandatory=False):
26 libcrypto = conf.check_cc(lib='crypto',
27 header_name='openssl/crypto.h',
28 define_name='HAVE_SSL',
29 uselib_store='SSL')
30 if not conf.get_define ("HAVE_SSL"):
31 conf.fatal ("Cannot find SSL libraries")
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080032
Alexander Afanasyev182fdc22012-03-05 18:06:52 -080033 conf.load('boost')
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070034
35 if conf.options.ns3_enable:
36 conf.load('ns3')
37 conf.define('NS3_MODULE', 1)
38 conf.check_modules(['core', 'network', 'internet'], mandatory = True)
39 conf.check_modules(['NDNabstraction'], mandatory = True)
40 conf.check_modules(['point-to-point'], mandatory = False)
41 conf.check_modules(['point-to-point-layout'], mandatory = False)
42
43 conf.check_boost(lib='system iostreams thread')
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -070044 conf.define ('NS3_LOG_ENABLE', 1)
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070045 else:
46 conf.check_boost(lib='system iostreams test thread')
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070047
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070048 conf.load ('ccnx')
49 conf.check_ccnx (path=conf.options.ccnx_dir)
50
51 if conf.options.log4cxx:
52 conf.check_cfg(package='liblog4cxx', args=['--cflags', '--libs'], uselib_store='LOG4CXX', mandatory=True)
53
Zhenkai Zhu699d7402012-05-29 16:47:39 -070054 if conf.options.debug:
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070055 conf.define ('_DEBUG', 1)
Alexander Afanasyeva0c8a1d2012-04-05 13:55:42 -070056 conf.env.append_value('CXXFLAGS', ['-O0', '-g3'])
57 else:
Zhenkai Zhudc70a292012-06-01 14:00:59 -070058 conf.env.append_value('CXXFLAGS', ['-O3', '-g'])
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070059
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -070060 if conf.options._test:
61 conf.define('_TEST', 1)
62
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -080063 try:
64 conf.load('doxygen')
65 except:
66 pass
67
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070068 conf.load('protobuf')
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070069
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080070def build (bld):
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070071 bld.post_mode = Build.POST_LAZY
72
73 bld.add_group ("protobuf")
74
75 x = bld (
76 features = ["protobuf"],
77 source = ["model/sync-state.proto"],
78 target = ["model/sync-state.pb"],
79 )
80
81 bld.add_group ("code")
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -070082
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070083 if bld.get_define ("NS3_MODULE"):
Alexander Afanasyev6af3c152012-06-07 21:14:24 -070084 libsync = bld.shlib (
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -070085 target = "sync-ns3",
86 features=['cxx', 'cxxshlib'],
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070087 source = [
Alexander Afanasyev181d7e52012-04-09 13:54:11 -070088 'ns3/sync-ccnx-wrapper.cc',
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070089 'ns3/sync-ns3-name-info.cc',
Alexander Afanasyevca6f3292012-04-09 10:03:30 -070090 'ns3/sync-scheduler.cc',
Alexander Afanasyev09e8d752012-04-10 16:05:55 -070091 'ns3/sync-logic-helper.cc',
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070092
Alexander Afanasyevca6f3292012-04-09 10:03:30 -070093 # 'model/sync-app-data-fetch.cc',
94 # 'model/sync-app-data-publish.cc',
95 # 'ns3/sync-app.cc',
96
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -070097 'model/sync-diff-leaf.cc',
98 'model/sync-diff-state.cc',
99 'model/sync-digest.cc',
100 'model/sync-full-leaf.cc',
101 'model/sync-full-state.cc',
102 'model/sync-interest-table.cc',
103 'model/sync-leaf.cc',
104 'model/sync-logic.cc',
105 'model/sync-name-info.cc',
106 'model/sync-seq-no.cc',
107 'model/sync-state.cc',
108 'model/sync-std-name-info.cc',
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700109 ],
110 dynamic_source = [
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -0700111 'model/sync-state.pb.cc',
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -0700112 ],
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -0700113 use = 'BOOST BOOST_IOSTREAMS SSL PROTOBUF ' + ' '.join (['ns3_'+dep for dep in ['core', 'network', 'internet', 'NDNabstraction']]).upper (),
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700114 includes = ['include', 'model', 'include/ns3', 'helper'],
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -0700115 )
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -0700116
117 example = bld.program (
118 target = "sync-example",
119 features=['cxx', 'cxxprogram'],
120 source = ['examples/sync-example.cc'],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700121 use = 'libsync',
122 includes = ['include', 'model', 'include/ns3', 'helper'],
Alexander Afanasyevb550d6a2012-04-09 15:03:16 -0700123 )
Alexander Afanasyevd7fc7c02012-04-19 15:36:26 -0700124
125 sync_eval = bld.program (
126 target = "sync-eval",
127 features=['cxx', 'cxxprogram'],
128 source = ['evaluation/sync-eval.cc',
129 'evaluation/standard-muc.cc',
Alexander Afanasyev40942f42012-04-21 20:53:16 -0700130 'evaluation/sync-muc.cc',
Alexander Afanasyevd7fc7c02012-04-19 15:36:26 -0700131 ],
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700132 use = 'libsync',
133 includes = ['include', 'model', 'include/ns3', 'helper'],
Alexander Afanasyevd7fc7c02012-04-19 15:36:26 -0700134 )
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -0700135 # from waflib import Utils,Logs,Errors
136 # Logs.pprint ('CYAN', program.use)
137
138 else:
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700139 libsync = bld (
140 target=APPNAME,
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -0700141 features=['cxx', 'cxxshlib'],
142 source = [
143 'ccnx/sync-ccnx-wrapper.cc',
144 'ccnx/sync-scheduler.cc',
145 'ccnx/sync-log.cc',
Chaoyi Bian2f2d6412012-06-04 16:53:08 -0700146 'ccnx/sync-app-socket-c.cc',
Alexander Afanasyevca6f3292012-04-09 10:03:30 -0700147 'ccnx/sync-app-socket.cc',
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -0700148 'model/sync-diff-leaf.cc',
149 'model/sync-diff-state.cc',
150 'model/sync-digest.cc',
151 'model/sync-full-leaf.cc',
152 'model/sync-full-state.cc',
153 'model/sync-interest-table.cc',
154 'model/sync-leaf.cc',
155 'model/sync-logic.cc',
156 'model/sync-name-info.cc',
157 'model/sync-seq-no.cc',
158 'model/sync-state.cc',
159 'model/sync-std-name-info.cc',
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700160 ],
161 dynamic_source = [
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -0700162 'model/sync-state.pb.cc',
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -0700163 ],
Zhenkai Zhu3cfdcb92012-06-06 15:20:10 -0700164 use = 'BOOST BOOST_IOSTREAMS BOOST_THREAD SSL PROTOBUF CCNX',
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700165 includes = ['include', 'model', 'helper'],
Alexander Afanasyev158ec0d2012-04-05 13:48:55 -0700166 )
167
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -0700168 # Unit tests
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -0700169 if bld.get_define("_TEST"):
170 unittests = bld.program (
171 target="unit-tests",
172 source = bld.path.ant_glob(['test/**/*.cc']),
173 features=['cxx', 'cxxprogram'],
174 use = 'BOOST_TEST sync',
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700175 includes = ['include', 'model', 'helper'],
Zhenkai Zhu43ae5c72012-05-31 23:18:45 -0700176 )
Alexander Afanasyev4f9ea482012-03-15 11:57:29 -0700177
Alexander Afanasyev0ad7c212012-04-05 13:31:14 -0700178 if bld.get_define ("HAVE_LOG4CXX"):
179 libsync.use += ' LOG4CXX'
180 unittests.use += ' LOG4CXX'
Alexander Afanasyeve76f2632012-03-05 00:18:42 -0800181
Alexander Afanasyev6af3c152012-06-07 21:14:24 -0700182 headers = bld.path.ant_glob(['include/*.h'])
183 headers.extend (bld.path.get_bld().ant_glob(['model/sync-state.pb.h']))
184 bld.install_files ("%s/sync" % bld.env['INCLUDEDIR'], headers)
185
186 pc = bld (
187 features = "subst",
188 source='libsync.pc.in',
189 target='libsync.pc',
190 install_path = '${LIBDIR}/pkgconfig',
191 PREFIX = bld.env['PREFIX'],
192 INCLUDEDIR = "%s/sync" % bld.env['INCLUDEDIR'],
193 VERSION = VERSION,
194 )
195
Alexander Afanasyev150f14d2012-03-05 21:24:49 -0800196# doxygen docs
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800197from waflib.Build import BuildContext
198class doxy (BuildContext):
199 cmd = "doxygen"
200 fun = "doxygen"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -0800201
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800202def doxygen (bld):
Alexander Afanasyev34ebcb72012-03-08 15:54:55 -0800203 if not bld.env.DOXYGEN:
204 bld.fatal ("ERROR: cannot build documentation (`doxygen' is not found in $PATH)")
Alexander Afanasyev182fdc22012-03-05 18:06:52 -0800205 bld (features="doxygen",
206 doxyfile='doc/doxygen.conf',
207 output_dir = 'doc')