waf build system.
[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-carl'
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.STATIC = conf.options.static
35     conf.env.VERSION = VERSION
36
37     if conf.env.TARGET_OSX:
38         conf.env.append_value('CXXFLAGS', ['-Wno-unused-result', '-Wno-unused-parameter', '-Wno-unused-local-typedef'])
39
40     conf.check_cfg(package='openssl', args='--cflags --libs', uselib_store='OPENSSL', mandatory=True)
41
42     if conf.options.target_windows:
43         boost_lib_suffix = '-mt'
44     else:
45         boost_lib_suffix = ''
46
47     if conf.options.enable_debug:
48         conf.env.append_value('CXXFLAGS', '-g')
49     else:
50         conf.env.append_value('CXXFLAGS', '-O2')
51
52     conf.check_cxx(fragment="""
53                             #include <boost/version.hpp>\n
54                             #if BOOST_VERSION < 104500\n
55                             #error boost too old\n
56                             #endif\n
57                             int main(void) { return 0; }\n
58                             """,
59                    mandatory=True,
60                    msg='Checking for boost library >= 1.45',
61                    okmsg='yes',
62                    errmsg='too old\nPlease install boost version 1.45 or higher.')
63
64     conf.check_cxx(fragment="""
65                             #include <boost/filesystem.hpp>\n
66                             int main() { boost::filesystem::copy_file ("a", "b"); }\n
67                             """,
68                    msg='Checking for boost filesystem library',
69                    libpath='/usr/local/lib',
70                    lib=['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
71                    uselib_store='BOOST_FILESYSTEM')
72
73     conf.recurse('src')
74
75 def build(bld):
76     if bld.env.TARGET_WINDOWS:
77         boost_lib_suffix = '-mt'
78         flags = '-DKM_WIN32 -DWIN32_LEAN_AND_MEAN'
79     else:
80         boost_lib_suffix = ''
81         flags = ''
82
83     bld(source='libasdcp-carl.pc.in',
84         version=VERSION,
85         includedir='%s/include/libasdcp-carl' % bld.env.PREFIX,
86         libs="-L${libdir} -lasdcp-carl -lkumu-carl -lboost_system%s" % boost_lib_suffix,
87         cflags=flags,
88         install_path='${LIBDIR}/pkgconfig')
89
90     bld.recurse('src')
91
92     bld.add_post_fun(post)
93
94 def post(ctx):
95     if ctx.cmd == 'install':
96         ctx.exec_command('/sbin/ldconfig')
97
98 def tags(bld):
99     os.system('etags src/*.cc src/*.h')
100
101 def dist(bld):
102     f = open('VERSION', 'w')
103     print(VERSION, file=f)
104     f.close()