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