3 from waflib import Context
6 VERSION = '1.1.13devel'
10 opt.load('compiler_cxx')
11 opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
12 opt.add_option('--static', action='store_true', default=False, help='build libsub statically and link statically to cxml and dcp')
13 opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to make a Windows package')
14 opt.add_option('--disable-tests', action='store_true', default=False, help='disable building of tests')
17 conf.load('compiler_cxx')
18 conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
19 conf.env.append_value('CXXFLAGS', ['-DLIBSUB_VERSION="%s"' % VERSION])
21 conf.env.ENABLE_DEBUG = conf.options.enable_debug
22 conf.env.STATIC = conf.options.static
23 conf.env.TARGET_WINDOWS = conf.options.target_windows
24 conf.env.DISABLE_TESTS = conf.options.disable_tests
25 conf.env.API_VERSION = API_VERSION
27 if conf.options.enable_debug:
28 conf.env.append_value('CXXFLAGS', '-g')
30 conf.env.append_value('CXXFLAGS', '-O3')
32 # Disable libxml++ deprecation warnings for now
33 conf.env.append_value('CXXFLAGS', ['-Wno-deprecated-declarations'])
35 conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
37 if conf.options.static:
38 conf.env.HAVE_CXML = 1
39 conf.env.LIB_CXML = ['glibmm-2.4', 'glib-2.0', 'pcre', 'sigc-2.0', 'rt', 'xml++-2.6', 'xml2', 'pthread', 'lzma', 'dl', 'z']
40 conf.env.STLIB_CXML = ['cxml']
41 conf.check_cfg(package='libcxml', atleast_version='0.14.0', args='--cflags', uselib_store='CXML', mandatory=True)
42 conf.env.HAVE_ASDCPLIB_CTH = 1
43 conf.env.STLIB_ASDCPLIB_CTH = ['asdcp-cth', 'kumu-cth']
44 conf.env.LIB_ASDCPLIB_CTH = ['ssl', 'crypto']
45 conf.check_cfg(package='libasdcp-cth', atleast_version='0.0.1', args='--cflags', uselib_store='ASDCPLIB_CTH', mandatory=True)
47 conf.check_cfg(package='libcxml', atleast_version='0.15.1', args='--cflags --libs', uselib_store='CXML', mandatory=True)
48 conf.check_cfg(package='libasdcp-cth', atleast_version='0.1.0', args='--cflags --libs', uselib_store='ASDCPLIB_CTH', mandatory=True)
51 if conf.env.TARGET_WINDOWS:
52 boost_lib_suffix = '-mt'
54 conf.check_cxx(fragment="""
55 #include <boost/version.hpp>\n
56 #if BOOST_VERSION < 104500\n
57 #error boost too old\n
59 int main(void) { return 0; }\n
62 msg='Checking for boost library >= 1.45',
64 errmsg='too old\nPlease install boost version 1.45 or higher.')
66 conf.check_cxx(fragment="""
67 #include <boost/filesystem.hpp>\n
68 int main() { boost::filesystem::copy_file ("a", "b"); }\n
70 msg='Checking for boost filesystem library',
71 libpath='/usr/local/lib',
72 lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
73 uselib_store='BOOST_FILESYSTEM')
75 conf.check_cxx(fragment="""
76 #include <boost/locale.hpp>\n
77 int main() { boost::locale::conv::to_utf<char> ("a", "cp850"); }\n
79 msg='Checking for boost locale library',
80 libpath='/usr/local/lib',
81 lib=['boost_locale%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
82 uselib_store='BOOST_LOCALE')
84 conf.check_cxx(fragment="""
85 #include <boost/regex.hpp>\n
86 int main() { boost::regex re ("foo"); }\n
88 msg='Checking for boost regex library',
89 libpath='/usr/local/lib',
90 lib=['boost_regex%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
91 uselib_store='BOOST_REGEX')
93 if not conf.env.DISABLE_TESTS:
96 # libxml++ 2.39.1 and later must be built with -std=c++11
97 libxmlpp_version = conf.cmd_and_log(['pkg-config', '--modversion', 'libxml++-2.6'], output=Context.STDOUT, quiet=Context.BOTH)
98 s = libxmlpp_version.split('.')
99 v = (int(s[0]) << 16) | (int(s[1]) << 8) | int(s[2])
101 conf.env.append_value('CXXFLAGS', '-std=c++11')
104 create_version_cc(bld, VERSION)
106 if bld.env.TARGET_WINDOWS:
107 boost_lib_suffix = '-mt'
109 boost_lib_suffix = ''
111 bld(source='libsub%s.pc.in' % bld.env.API_VERSION,
113 includedir='%s/include/libsub%s' % (bld.env.PREFIX, bld.env.API_VERSION),
114 libs="-L${libdir} -lsub%s -lboost_system%s" % (bld.env.API_VERSION, boost_lib_suffix),
115 install_path='${LIBDIR}/pkgconfig')
118 if not bld.env.DISABLE_TESTS:
122 bld.add_post_fun(post)
125 ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~ __pycache__ GPATH GRTAGS GSYMS GTAGS'
127 def create_version_cc(bld, version):
128 if os.path.exists('.git'):
129 cmd = "LANG= git log --abbrev HEAD^..HEAD ."
130 output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
131 o = output[0].decode('utf-8')
132 commit = o.replace ("commit ", "")[0:10]
137 text = '#include "version.h"\n'
138 text += 'char const * sub::git_commit = \"%s\";\n' % commit
139 text += 'char const * sub::version = \"%s\";\n' % version
140 if bld.env.ENABLE_DEBUG:
141 debug_string = 'true'
143 debug_string = 'false'
144 text += 'bool const built_with_debug = %s;\n' % debug_string
145 print('Writing version information to src/version.cc')
146 o = open('src/version.cc', 'w')
150 print('Could not open src/version.cc for writing\n')
154 if ctx.cmd == 'install':
155 ctx.exec_command('/sbin/ldconfig')
158 os.system('etags src/*.cc src/*.h')