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