Quell some valgrind errors.
[asdcplib.git] / wscript
1 import subprocess
2 import os
3 import sys
4 import distutils.spawn
5 from waflib import Logs
6
7 APPNAME = 'libasdcp-cth'
8 VERSION = '2.5.11-cth1'
9
10 def options(opt):
11     opt.load('compiler_cxx')
12     opt.add_option('--target-windows', action='store_true', default=False, help='set up to do a cross-compile to Windows')
13     opt.add_option('--enable-debug', action='store_true', default=False, help='build with debugging information and without optimisation')
14     opt.add_option('--static', action='store_true', default=False, help='build statically')
15
16 def configure(conf):
17     conf.load('compiler_cxx')
18     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-D_FILE_OFFSET_BITS=64', '-D__STDC_FORMAT_MACROS'])
19
20     conf.env.TARGET_WINDOWS = conf.options.target_windows
21     conf.env.TARGET_OSX = sys.platform == 'darwin'
22     conf.env.TARGET_LINUX = not conf.env.TARGET_WINDOWS and not conf.env.TARGET_OSX
23     conf.env.STATIC = conf.options.static
24     conf.env.VERSION = VERSION
25
26     if conf.env.TARGET_OSX:
27         conf.env.append_value('CXXFLAGS', ['-Wno-unused-result', '-Wno-unused-parameter', '-Wno-unused-local-typedef'])
28
29     if conf.env.TARGET_LINUX:
30         gcc = conf.env['CC_VERSION']
31         if int(gcc[0]) >= 4 and int(gcc[1]) > 1:
32             conf.env.append_value('CXXFLAGS', ['-Wno-unused-result'])
33
34     conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
35
36     if conf.options.target_windows:
37         boost_lib_suffix = '-mt'
38     else:
39         boost_lib_suffix = ''
40
41     if conf.options.enable_debug:
42         conf.env.append_value('CXXFLAGS', '-g')
43     else:
44         conf.env.append_value('CXXFLAGS', '-O2')
45
46     conf.check_cxx(fragment="""
47                             #include <boost/version.hpp>\n
48                             #if BOOST_VERSION < 104500\n
49                             #error boost too old\n
50                             #endif\n
51                             int main(void) { return 0; }\n
52                             """,
53                    mandatory=True,
54                    msg='Checking for boost library >= 1.45',
55                    okmsg='yes',
56                    errmsg='too old\nPlease install boost version 1.45 or higher.')
57
58     conf.check_cxx(fragment="""
59                             #include <boost/filesystem.hpp>\n
60                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
61                             """,
62                    msg='Checking for boost filesystem library',
63                    libpath='/usr/local/lib',
64                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
65                    uselib_store='BOOST_FILESYSTEM')
66
67     conf.check(header_name='valgrind/memcheck.h', mandatory=False)
68
69     conf.recurse('src')
70
71 def build(bld):
72     if bld.env.TARGET_WINDOWS:
73         boost_lib_suffix = '-mt'
74         flags = '-DKM_WIN32'
75     else:
76         boost_lib_suffix = ''
77         flags = ''
78
79     bld(source='libasdcp-cth.pc.in',
80         version=VERSION,
81         includedir='%s/include/libasdcp-cth' % bld.env.PREFIX,
82         libs="-L${libdir} -lasdcp-cth -lkumu-cth -lboost_system%s" % boost_lib_suffix,
83         cflags=flags,
84         install_path='${LIBDIR}/pkgconfig')
85
86     bld.recurse('src')
87
88     bld.add_post_fun(post)
89
90 def post(ctx):
91     if ctx.cmd == 'install':
92         ctx.exec_command('/sbin/ldconfig')
93
94 def tags(bld):
95     os.system('etags src/*.cc src/*.h')