5375ae430c0e0fa2947a025530513c51ae354ffe
[dcpomatic.git] / src / tools / wscript
1 #
2 #    Copyright (C) 2012-2020 Carl Hetherington <cth@carlh.net>
3 #
4 #    This file is part of DCP-o-matic.
5 #
6 #    DCP-o-matic is free software; you can redistribute it and/or modify
7 #    it under the terms of the GNU General Public License as published by
8 #    the Free Software Foundation; either version 2 of the License, or
9 #    (at your option) any later version.
10 #
11 #    DCP-o-matic is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 import os
21 import glob
22 from waflib import Logs
23 import i18n
24
25
26 def description(tool, variant):
27     descriptions = {
28         'dcpomatic': 'DCP-o-matic',
29         'dcpomatic_batch': 'DCP-o-matic Batch Converter',
30         'dcpomatic_server': 'DCP-o-matic Encode Server',
31         'dcpomatic_kdm': 'DCP-o-matic KDM Creator',
32         'dcpomatic_player': 'DCP-o-matic Player',
33         'dcpomatic_playlist': 'DCP-o-matic Playlist Editor',
34         'dcpomatic_combiner': 'DCP-o-matic Combiner',
35         'dcpomatic_verifier': 'DCP-o-matic Verifier',
36     }
37     return descriptions[tool] if tool in descriptions else tool
38
39
40 def make_rc(tool, icon, variant):
41     filename = f'build/src/tools/{tool}.rc'
42     with open(filename, 'w') as rc:
43         if tool == 'dcpomatic_disk_writer':
44             print('#include "winuser.h"', file=rc)
45             print('1 RT_MANIFEST "dcpomatic2_disk_writer.exe.manifest"', file=rc)
46             with open("build/src/tools/dcpomatic2_disk_writer.exe.manifest", "w") as manifest:
47                 print("""
48 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
49 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
50     <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="dcpomatic2_disk_writer" type="win32"/> 
51     <description>DCP-o-matic Disk Writer</description> 
52     <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
53             <security>
54                     <requestedPrivileges>
55                             <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
56                     </requestedPrivileges>
57             </security>
58     </trustInfo>
59 </assembly>""", file=manifest)
60         else:
61             print(f"""
62 id ICON "../../graphics/windows/{icon}"
63 #include "wx-3.1/wx/msw/wx.rc"
64 VS_VERSION_INFO VERSIONINFO
65  FILEVERSION    0,0,0,2
66  PRODUCTVERSION 0,0,0,2
67  FILEFLAGSMASK 0x3fL
68  #ifdef _DEBUG
69  FILEFLAGS 0x1L
70  #else
71  FILEFLAGS 0x0L
72  #endif
73  FILEOS 0x4L
74  FILETYPE 0x1L
75  FILESUBTYPE 0x0L
76 {{
77     BLOCK "StringFileInfo"
78     {{
79         BLOCK "040904b0"
80         {{
81             VALUE "FileDescription", "{description(tool, variant)}\\0"
82         }}
83     }}
84     BLOCK "VarFileInfo"
85     {{
86         VALUE "Translation", 0x409, 1200
87     }}
88 }}
89     """, file=rc)
90     return filename
91
92 def configure(conf):
93     if conf.env.TARGET_WINDOWS_64 or conf.env.TARGET_WINDOWS_32:
94         conf.env.append_value('CXXFLAGS', ['-mconsole'])
95         conf.env.append_value('LINKFLAGS', ['-mconsole'])
96
97 def build(bld):
98     uselib =  'BOOST_THREAD BOOST_DATETIME DCP XMLSEC CXML XMLPP AVFORMAT AVFILTER AVCODEC '
99     uselib += 'AVUTIL SWSCALE SWRESAMPLE POSTPROC CURL BOOST_FILESYSTEM SSH ZIP CAIROMM FONTCONFIG PANGOMM SUB '
100     uselib += 'SNDFILE SAMPLERATE BOOST_REGEX ICU NETTLE RTAUDIO PNG JPEG LEQM_NRT '
101
102     if bld.env.ENABLE_DISK:
103         if bld.env.TARGET_LINUX:
104             uselib += 'POLKIT '
105         uselib += 'LWEXT4 NANOMSG '
106
107     if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32:
108         uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE WINSOCK2 OLE32 DSOUND WINMM KSUSER SETUPAPI UUID '
109     if bld.env.TARGET_LINUX:
110         uselib += 'DL '
111
112     cli_tools = ['dcpomatic_cli', 'dcpomatic_server_cli', 'server_test', 'dcpomatic_kdm_cli', 'dcpomatic_create', 'dcpomatic_map']
113     if bld.env.ENABLE_DISK and not bld.env.DISABLE_GUI:
114         cli_tools.append('dcpomatic_disk_writer')
115
116     try:
117         os.makedirs('build/src/tools')
118     except:
119         pass
120
121     for t in cli_tools:
122         obj = bld(features='cxx cxxprogram')
123         obj.uselib = uselib
124         obj.includes = ['..']
125         obj.use    = ['libdcpomatic2']
126         obj.source = '%s.cc' % t
127         if (bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32) and t == 'dcpomatic_disk_writer':
128             obj.source += f' ../../{make_rc(t, None, bld.env.VARIANT)}'
129             # Prevent a console window opening when we start dcpomatic2_disk_writer
130             obj.env.append_value('LINKFLAGS', '-Wl,-subsystem,windows')
131         obj.target = t.replace('dcpomatic', 'dcpomatic2')
132         if t == 'server_test':
133             obj.install_path = None
134
135     gui_tools = []
136     if not bld.env.DISABLE_GUI:
137         gui_tools = ['dcpomatic',
138                      'dcpomatic_batch',
139                      'dcpomatic_server',
140                      'dcpomatic_kdm',
141                      'dcpomatic_player',
142                      'dcpomatic_playlist',
143                      'dcpomatic_combiner',
144                      'dcpomatic_editor',
145                      'dcpomatic_verifier']
146         if bld.env.ENABLE_DISK:
147             gui_tools.append('dcpomatic_disk')
148
149     for t in gui_tools:
150         obj = bld(features='cxx cxxprogram')
151         obj.uselib = uselib
152         if bld.env.BUILD_STATIC or bld.env.TARGET_LINUX:
153             obj.uselib += ' GTK'
154         obj.uselib += ' WXWIDGETS'
155         if not bld.env.TARGET_OSX:
156             obj.uselib += ' GL GLU'
157         if bld.env.TARGET_LINUX:
158             obj.uselib += ' X11'
159         if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32:
160             obj.uselib += ' GLEW'
161         obj.includes = ['..']
162         obj.use    = ['libdcpomatic2', 'libdcpomatic2-wx']
163         obj.source = '%s.cc' % t
164         if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32:
165             obj.source += f' ../../{make_rc(t, t.replace("dcpomatic", "dcpomatic2") + ".ico", bld.env.VARIANT)}'
166         obj.target = t.replace('dcpomatic', 'dcpomatic2')
167
168     i18n.po_to_mo(os.path.join('src', 'tools'), 'dcpomatic2', bld)
169
170 def pot(bld):
171     cc = """
172          dcpomatic_batch.cc
173          dcpomatic.cc
174          dcpomatic_combiner.cc
175          dcpomatic_disk.cc
176          dcpomatic_editor.cc
177          dcpomatic_kdm.cc
178          dcpomatic_server.cc
179          dcpomatic_player.cc
180          dcpomatic_playlist.cc
181          dcpomatic_server.cc
182          """
183     i18n.pot(os.path.join('src', 'tools'), cc, 'dcpomatic')
184
185 def pot_merge(bld):
186     i18n.pot_merge(os.path.join('src', 'tools'), 'dcpomatic')