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