Merge branch 'master' of /home/carl/git/libdcp
[libdcp.git] / wscript
1 import subprocess
2 import os
3
4 APPNAME = 'libdcp'
5 VERSION = '0.09pre'
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     opt.add_option('--enable-debug', action='store_true', default = False, help = 'build with debugging information and without optimisation')
11
12 def configure(conf):
13     conf.load('compiler_cxx')
14     conf.env.append_value('CXXFLAGS', ['-Wall', '-Wextra', '-Wno-unused-result', '-O2', '-D_FILE_OFFSET_BITS=64'])
15     conf.env.append_value('CXXFLAGS', ['-DLIBDCP_VERSION="%s"' % VERSION])
16
17     if conf.options.target_windows:
18         conf.env.append_value('CXXFLAGS', '-DLIBDCP_WINDOWS')
19     else:
20         conf.env.append_value('CXXFLAGS', '-DLIBDCP_POSIX')
21
22     conf.check_cfg(package = 'openssl', args = '--cflags --libs', uselib_store = 'OPENSSL', mandatory = True)
23     conf.check_cfg(package = 'sigc++-2.0', args = '--cflags --libs', uselib_store = 'SIGC++', mandatory = True)
24     conf.check_cfg(package = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
25
26     conf.check_cc(fragment  = """
27                               #include <stdio.h>\n
28                               #include <openjpeg.h>\n
29                               int main () {\n
30                               void* p = (void *) opj_image_create;\n
31                               return 0;\n
32                               }
33                               """, msg = 'Checking for library openjpeg', lib = 'openjpeg', uselib_store = 'OPENJPEG')
34
35     if conf.options.target_windows:
36         boost_lib_suffix = '-mt'
37     else:
38         boost_lib_suffix = ''
39
40     if conf.options.enable_debug:
41         conf.env.append_value('CXXFLAGS', '-g')
42     else:
43         conf.env.append_value('CXXFLAGS', '-O3')
44
45     conf.check_cxx(fragment = """
46                               #include <boost/filesystem.hpp>\n
47                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
48                               """,
49                    msg = 'Checking for boost filesystem library',
50                    libpath = '/usr/local/lib',
51                    lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
52                    uselib_store = 'BOOST_FILESYSTEM')
53
54     conf.recurse('test')
55     conf.recurse('asdcplib')
56
57 def build(bld):
58     create_version_cc(VERSION)
59
60     bld(source = 'libdcp.pc.in',
61         version = VERSION,
62         includedir = '%s/include' % bld.env.PREFIX,
63         libs = "-L${libdir} -ldcp -lkumu-libdcp -lasdcp-libdcp",
64         install_path = '${LIBDIR}/pkgconfig')
65
66     bld.recurse('src')
67     bld.recurse('tools')
68     bld.recurse('test')
69     bld.recurse('asdcplib')
70
71 def dist(ctx):
72     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~'
73
74 def create_version_cc(version):
75     if os.path.exists('.git'):
76         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
77         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
78         o = output[0].decode('utf-8')
79         commit = o.replace ("commit ", "")[0:10]
80     else:
81         commit = "release"
82
83     try:
84         text =  '#include "version.h"\n'
85         text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
86         text += 'char const * libdcp::version = \"%s\";\n' % version
87         print('Writing version information to src/version.cc')
88         o = open('src/version.cc', 'w')
89         o.write(text)
90         o.close()
91     except IOError:
92         print('Could not open src/version.cc for writing\n')
93         sys.exit(-1)