Bump version
[libdcp.git] / wscript
1 import subprocess
2 import os
3 import lut
4
5 APPNAME = 'libdcp'
6 VERSION = '0.32pre'
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 = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
27
28     conf.check_cc(fragment  = """
29                               #include <stdio.h>\n
30                               #include <openjpeg.h>\n
31                               int main () {\n
32                               void* p = (void *) opj_image_create;\n
33                               return 0;\n
34                               }
35                               """, msg = 'Checking for library openjpeg', lib = 'openjpeg', uselib_store = 'OPENJPEG')
36
37     if conf.options.target_windows:
38         boost_lib_suffix = '-mt'
39     else:
40         boost_lib_suffix = ''
41
42     if conf.options.enable_debug:
43         conf.env.append_value('CXXFLAGS', '-g')
44     else:
45         conf.env.append_value('CXXFLAGS', '-O3')
46
47     conf.check_cxx(fragment = """
48                               #include <boost/filesystem.hpp>\n
49                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
50                               """,
51                    msg = 'Checking for boost filesystem library',
52                    libpath = '/usr/local/lib',
53                    lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
54                    uselib_store = 'BOOST_FILESYSTEM')
55
56     conf.check_cxx(fragment = """
57                               #include <boost/signals2.hpp>\n
58                               int main() { boost::signals2::signal<void (int)> x; }\n
59                               """,
60                    msg = 'Checking for boost signals2 library',
61                    uselib_store = 'BOOST_SIGNALS2')
62
63     lut.make_luts()
64
65     conf.recurse('test')
66     conf.recurse('asdcplib')
67
68 def build(bld):
69     create_version_cc(VERSION)
70
71     if bld.env.TARGET_WINDOWS:
72         boost_lib_suffix = '-mt'
73     else:
74         boost_lib_suffix = ''
75
76     bld(source = 'libdcp.pc.in',
77         version = VERSION,
78         includedir = '%s/include' % bld.env.PREFIX,
79         libs = "-L${libdir} -ldcp -lkumu-libdcp -lasdcp-libdcp -lboost_system%s" % boost_lib_suffix,
80         install_path = '${LIBDIR}/pkgconfig')
81
82     bld.recurse('src')
83     bld.recurse('tools')
84     bld.recurse('test')
85     bld.recurse('asdcplib')
86     bld.recurse('examples')
87
88     bld.add_post_fun(post)
89
90 def dist(ctx):
91     ctx.excl = 'TODO core *~ .git build .waf* .lock* doc/*~ src/*~ test/ref/*~'
92
93 def create_version_cc(version):
94     if os.path.exists('.git'):
95         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
96         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
97         o = output[0].decode('utf-8')
98         commit = o.replace ("commit ", "")[0:10]
99     else:
100         commit = "release"
101
102     try:
103         text =  '#include "version.h"\n'
104         text += 'char const * libdcp::git_commit = \"%s\";\n' % commit
105         text += 'char const * libdcp::version = \"%s\";\n' % version
106         print('Writing version information to src/version.cc')
107         o = open('src/version.cc', 'w')
108         o.write(text)
109         o.close()
110     except IOError:
111         print('Could not open src/version.cc for writing\n')
112         sys.exit(-1)
113
114 def post(ctx):
115     if ctx.cmd == 'install':
116         ctx.exec_command('/sbin/ldconfig')