Tweak installer .exe name.
[dcpomatic.git] / wscript
1 import subprocess
2 import os
3
4 APPNAME = 'dvdomatic'
5 VERSION = '0.30pre'
6
7 def options(opt):
8     opt.load('compiler_cxx')
9     opt.load('winres')
10     opt.add_option('--debug-hash', action='store_true', default = False, help = 'print hashes of data at various points')
11     opt.add_option('--enable-debug', action='store_true', default = False, help = 'build with debugging information and without optimisation')
12     opt.add_option('--disable-gui', action='store_true', default = False, help = 'disable building of GUI tools')
13     opt.add_option('--disable-player', action='store_true', default = False, help = 'disable building of the player components')
14     opt.add_option('--ffmpeg-083', action='store_true', default = False, help = 'Use FFmpeg version in Ubuntu 12.04')
15     opt.add_option('--target-windows', action='store_true', default = False, help = 'set up to do a cross-compile to Windows')
16
17 def configure(conf):
18     conf.load('compiler_cxx')
19     conf.load('winres')
20
21     conf.env.append_value('CXXFLAGS', ['-D__STDC_CONSTANT_MACROS', '-msse', '-mfpmath=sse', '-ffast-math', '-fno-strict-aliasing', '-Wall', '-Wno-attributes'])
22     conf.env.append_value('CXXFLAGS', ['-DDVDOMATIC_VERSION="%s"' % VERSION])
23
24     if conf.options.target_windows:
25         conf.env.append_value('CXXFLAGS', ['-DDVDOMATIC_WINDOWS'])
26         conf.env.append_value('LINKFLAGS', '-mwindows')
27         conf.options.disable_player = True
28         conf.check(lib = 'ws2_32', uselib_store = 'WINSOCK2', msg = "Checking for library winsock2")
29         boost_lib_suffix = '-mt'
30         boost_thread = 'boost_thread_win32-mt'
31     else:
32         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_POSIX')
33         boost_lib_suffix = ''
34         boost_thread = 'boost_thread'
35
36     conf.env.DEBUG_HASH = conf.options.debug_hash
37     conf.env.TARGET_WINDOWS = conf.options.target_windows
38     conf.env.DISABLE_GUI = conf.options.disable_gui
39     conf.env.DISABLE_PLAYER = conf.options.disable_player
40     conf.env.VERSION = VERSION
41
42     if conf.options.disable_player:
43         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_DISABLE_PLAYER')
44
45     if conf.options.enable_debug:
46         conf.env.append_value('CXXFLAGS', '-g')
47     else:
48         conf.env.append_value('CXXFLAGS', '-O3')
49
50     if conf.options.ffmpeg_083:
51         conf.env.append_value('CXXFLAGS', '-DDVDOMATIC_FFMPEG_0_8_3')
52
53     conf.check_cfg(package = 'sigc++-2.0', args = '--cflags --libs', uselib_store = 'SIGC++', mandatory = True)
54     conf.check_cfg(package = 'libavformat', args = '--cflags --libs', uselib_store = 'AVFORMAT', mandatory = True)
55     conf.check_cfg(package = 'libavfilter', args = '--cflags --libs', uselib_store = 'AVFILTER', mandatory = True)
56     conf.check_cfg(package = 'libavcodec', args = '--cflags --libs', uselib_store = 'AVCODEC', mandatory = True)
57     conf.check_cfg(package = 'libavutil', args = '--cflags --libs', uselib_store = 'AVUTIL', mandatory = True)
58     conf.check_cfg(package = 'libswscale', args = '--cflags --libs', uselib_store = 'SWSCALE', mandatory = True)
59     conf.check_cfg(package = 'libpostproc', args = '--cflags --libs', uselib_store = 'POSTPROC', mandatory = True)
60     conf.check_cfg(package = 'sndfile', args = '--cflags --libs', uselib_store = 'SNDFILE', mandatory = True)
61     conf.check_cfg(package = 'libdcp', args = '--cflags --libs', uselib_store = 'DCP', mandatory = True)
62     conf.check_cfg(package = 'glib-2.0', args = '--cflags --libs', uselib_store = 'GLIB', mandatory = True)
63     conf.check_cfg(package = '', path = 'Magick++-config', args = '--cppflags --cxxflags --libs', uselib_store = 'MAGICK', mandatory = True)
64     conf.check_cc(msg = 'Checking for library libtiff', function_name = 'TIFFOpen', header_name = 'tiffio.h', lib = 'tiff', uselib_store = 'TIFF')
65     conf.check_cc(fragment  = """
66                               #include <stdio.h>\n
67                               #include <openjpeg.h>\n
68                               int main () {\n
69                               void* p = (void *) opj_image_create;\n
70                               return 0;\n
71                               }
72                               """, msg = 'Checking for library openjpeg', lib = 'openjpeg', uselib_store = 'OPENJPEG')
73
74     conf.check_cc(fragment  = """
75                               #include <libssh/libssh.h>\n
76                               int main () {\n
77                               ssh_session s = ssh_new ();\n
78                               return 0;\n
79                               }
80                               """, msg = 'Checking for library libssh', mandatory = False, lib = 'ssh', uselib_store = 'SSH')
81
82     conf.check_cxx(fragment = """
83                               #include <boost/thread.hpp>\n
84                               int main() { boost::thread t (); }\n
85                               """, msg = 'Checking for boost threading library',
86                               lib = [boost_thread, 'boost_system%s' % boost_lib_suffix],
87                               uselib_store = 'BOOST_THREAD')
88
89     conf.check_cxx(fragment = """
90                               #include <boost/filesystem.hpp>\n
91                               int main() { boost::filesystem::copy_file ("a", "b"); }\n
92                               """, msg = 'Checking for boost filesystem library',
93                               libpath = '/usr/local/lib',
94                               lib = ['boost_filesystem%s' % boost_lib_suffix, 'boost_system%s' % boost_lib_suffix],
95                               uselib_store = 'BOOST_FILESYSTEM')
96
97     conf.check_cc(fragment = """
98                              #include <glib.h>
99                              int main() { g_format_size (1); }
100                              """, msg = 'Checking for g_format_size ()',
101                              uselib = 'GLIB',
102                              define_name = 'HAVE_G_FORMAT_SIZE',
103                              mandatory = False)
104
105     conf.recurse('src')
106     conf.recurse('test')
107
108 def build(bld):
109     create_version_cc(VERSION)
110
111     bld.recurse('src')
112     bld.recurse('test')
113     if bld.env.TARGET_WINDOWS:
114         bld.recurse('windows')
115
116     d = { 'PREFIX' : '${PREFIX' }
117
118     obj = bld(features = 'subst')
119     obj.source = 'dvdomatic.desktop.in'
120     obj.target = 'dvdomatic.desktop'
121     obj.dict = d
122
123     bld.install_files('${PREFIX}/share/applications', 'dvdomatic.desktop')
124     for r in ['22x22', '32x32', '48x48', '64x64', '128x128']:
125         bld.install_files('${PREFIX}/share/icons/hicolor/%s/apps' % r, 'icons/%s/dvdomatic.png' % r)
126
127 def dist(ctx):
128     ctx.excl = 'TODO core *~ src/gtk/*~ src/lib/*~ .waf* build .git'
129
130 def create_version_cc(version):
131     if os.path.exists('.git'):
132         cmd = "LANG= git log --abbrev HEAD^..HEAD ."
133         output = subprocess.Popen(cmd, shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE).communicate()[0].splitlines()
134         o = output[0].decode('utf-8')
135         commit = o.replace ("commit ", "")[0:10]
136     else:
137         commit = 'release'
138
139     try:
140         text =  '#include "version.h"\n'
141         text += 'char const * dvdomatic_git_commit = \"%s\";\n' % commit
142         text += 'char const * dvdomatic_version = \"%s\";\n' % version
143         print('Writing version information to src/lib/version.cc')
144         o = open('src/lib/version.cc', 'w')
145         o.write(text)
146         o.close()
147     except IOError:
148         print('Could not open src/lib/version.cc for writing\n')
149         sys.exit(-1)
150