Hacks.
[libdcp.git] / wscript
1 import subprocess
2 import os
3
4 APPNAME = 'libdcp'
5 VERSION = '0.05'
6
7 def options(opt):
8     opt.load('compiler_cxx')
9     opt.add_option('--target-windows', action='store_true', default = False, help = 'set up to do a cross-compile to Windows')
10
11 def configure(conf):
12     conf.load('compiler_cxx')
13     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-Wno-unused-result', '-O2', '-D_FILE_OFFSET_BITS=64'])
14     conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
15
16     if conf.options.target_windows:
17         conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
18     else:
19         conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')
20
21     conf.check_cfg(package = 'openssl', args = '--cflags --libs', uselib_store = 'OPENSSL', mandatory = True)
22     conf.check_cfg(package = 'sigc++-2.0', args = '--cflags --libs', uselib_store = 'SIGC++', mandatory = True)
23
24     if conf.options.target_windows:
25         boost_lib_suffix = '-mt'
26     else:
27         boost_lib_suffix = ''
28     
29     conf.check_cxx(fragment = """
30                               #include <boost/filesystem.hpp>\n
31                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
32                               """,
33                    msg = 'Checking for boost filesystem library',
34                    libpath = '/usr/local/lib',
35                    lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
36                    uselib_store = 'BOOST_FILESYSTEM')
37
38     conf.recurse('test')
39     conf.recurse('asdcplib')
40
41 def build(bld):
42     create_version_cc(VERSION)
43
44     bld(source = 'libdcp.pc.in',
45         version = VERSION,
46         includedir = '%s/include' % bld.env.PREFIX,
47         libs = "-L${libdir} -ldcp -lkumu-libdcp -lasdcp-libdcp",
48         install_path = '${LIBDIR}/pkgconfig')
49
50     bld.recurse('src')
51     bld.recurse('test')
52     bld.recurse('asdcplib')
53
54 def dist(ctx):
55     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~'
56
57 def create_version_cc(version):
58     if os.path.exists('.git'):
59         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
60         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
61         o = output[0].decode('utf-8')
62         commit = o.replace ("commit ", "")[0:10]
63     else:
64         commit = "release"
65
66     try:
67         text =  '#include "version.h"\n'
68         text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
69         text += 'char const * libdcp::version = \"%s\";\n' % version
70         print('Writing version information to src/version.cc')
71         o = open('src/version.cc', 'w')
72         o.write(text)
73         o.close()
74     except IOError:
75         print('Could not open src/version.cc for writing\n')
76         sys.exit(-1)