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