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