Add versioning; tweak libdcp version reporting; make makedcp more useful for testing.
[dcpomatic.git] / wscript
1 import subprocess
2
3 APPNAME = 'dvdomatic'
4 VERSION = '0.27pre'
5
6 def options(opt):
7     opt.load('compiler_cxx')
8     opt.add_option('--debug-hash', action='store_true', default = False, help = 'print hashes of data at various points')
9     opt.add_option('--enable-debug', action='store_true', default = False, help = 'build with debugging information and without optimisation')
10     opt.add_option('--disable-gui', action='store_true', default = False, help = 'disable building of GUI tools')
11     opt.add_option('--ffmpeg-083', action='store_true', default = False, help = 'Use FFmpeg version in Ubuntu 12.04')
12
13 def configure(conf):
14     conf.load('compiler_cxx')
15
16     conf.env.append_value('CXXFLAGS', ['-D__STDC_CONSTANT_MACROS', '-D__STDC_LIMIT_MACROS', '-msse', '-mfpmath=sse', '-ffast-math', '-Wall'])
17     conf.env.append_value('CXXFLAGS', ['-DDVDOMATIC_VERSION="%s"' % VERSION])
18
19     conf.env.DEBUG_HASH = conf.options.debug_hash
20
21     if conf.options.enable_debug:
22         conf.env.append_value('CXXFLAGS', '-g')
23     else:
24         conf.env.append_value('CXXFLAGS', '-O3')
25
26     if conf.options.ffmpeg_083:
27         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_FFMPEG_0_8_3')
28
29     conf.env.DISABLE_GUI = conf.options.disable_gui
30
31     conf.check_cfg(package = 'sigc++-2.0', args = '--cflags --libs', uselib_store = 'SIGC++', mandatory = True)
32     conf.check_cfg(package = 'libavformat', args = '--cflags --libs', uselib_store = 'AVFORMAT', mandatory = True)
33     conf.check_cfg(package = 'libavfilter', args = '--cflags --libs', uselib_store = 'AVFILTER', mandatory = True)
34     conf.check_cfg(package = 'libavcodec', args = '--cflags --libs', uselib_store = 'AVCODEC', mandatory = True)
35     conf.check_cfg(package = 'libavutil', args = '--cflags --libs', uselib_store = 'AVUTIL', mandatory = True)
36     conf.check_cfg(package = 'libswscale', args = '--cflags --libs', uselib_store = 'SWSCALE', mandatory = True)
37     conf.check_cfg(package = 'libpostproc', args = '--cflags --libs', uselib_store = 'POSTPROC', mandatory = True)
38     conf.check_cfg(package = 'sndfile', args = '--cflags --libs', uselib_store = 'SNDFILE', mandatory = True)
39     conf.check_cfg(package = 'libdcp', args = '--cflags --libs', uselib_store = 'DCP', mandatory = True)
40     conf.check_cfg(package = '', path = 'Magick++-config', args = '--cppflags --cxxflags --libs', uselib_store = 'MAGICK', mandatory = True)
41     conf.check_cc(msg = 'Checking for library libtiff', function_name = 'TIFFOpen', header_name = 'tiffio.h', lib = 'tiff', uselib_store = 'TIFF')
42     conf.check_cc(fragment  = """
43                               #include <stdio.h>\n
44                               #include <openjpeg.h>\n
45                               int main () {\n
46                               void* p = (void *) opj_image_create;\n
47                               return 0;\n
48                               }
49                               """, msg = 'Checking for library openjpeg', lib = 'openjpeg', uselib_store = 'OPENJPEG')
50
51     conf.check_cc(fragment  = """
52                               #include <libssh/libssh.h>\n
53                               int main () {\n
54                               ssh_session s = ssh_new ();\n
55                               return 0;\n
56                               }
57                               """, msg = 'Checking for library libssh', lib = 'ssh', uselib_store = 'SSH')
58                               
59     conf.check_cxx(fragment = """
60                               #include <boost/thread.hpp>\n
61                               int main() { boost::thread t (); }\n
62                               """, msg = 'Checking for boost threading library', lib = 'boost_thread', uselib_store = 'BOOST_THREAD')
63     conf.check_cxx(fragment = """
64                               #include <boost/filesystem.hpp>\n
65                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
66                               """, msg = 'Checking for boost filesystem library', libpath = '/usr/local/lib', lib = ['boost_filesystem', 'boost_system'], uselib_store = 'BOOST_FILESYSTEM')
67
68     conf.recurse('src')
69     conf.recurse('test')
70
71 def build(bld):
72     create_version_cc(VERSION)
73
74     bld.recurse('src')
75     bld.recurse('test')
76
77     d = { 'PREFIX' : '${PREFIX' }
78
79     obj = bld(features = 'subst')
80     obj.source = 'dvdomatic.desktop.in'
81     obj.target = 'dvdomatic.desktop'
82     obj.dict = d
83
84     bld.install_files('${PREFIX}/share/applications', 'dvdomatic.desktop')
85     for r in ['22x22', '32x32', '48x48', '64x64', '128x128']:
86         bld.install_files('${PREFIX}/share/icons/hicolor/%s/apps' % r, 'icons/%s/dvdomatic.png' % r)
87
88 def dist(ctx):
89     ctx.excl = 'TODO core *~ src/gtk/*~ src/lib/*~ .waf* build .git'
90
91 def create_version_cc(version):
92     cmd = "LANG= git log --abbrev HEAD^..HEAD ."
93     output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
94     o = output[0].decode('utf-8')
95     commit = o.replace ("commit ", "")[0:10]
96
97     try:
98         text =  '#include "version.h"\n'
99         text += 'char const * dvdomatic_git_commit = \"%s\";\n' % commit
100         text += 'char const * dvdomatic_version = \"%s\";\n' % version
101         print('Writing version information to src/lib/version.cc')
102         o = open('src/lib/version.cc', 'w')
103         o.write(text)
104         o.close()
105     except IOError:
106         print('Could not open src/lib/version.cc for writing\n')
107         sys.exit(-1)