Write file descriptions to .exe files for the Windows task manager.
[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     }
36     return descriptions[tool] if tool in descriptions else tool
37
38
39 def make_rc(tool, icon, variant):
40     filename = f'build/src/tools/{tool}.rc'
41     with open(filename, 'w') as rc:
42         if tool == 'dcpomatic_disk_writer':
43             print('#include "winuser.h"', file=rc)
44             print('1 RT_MANIFEST "dcpomatic2_disk_writer.exe.manifest"', file=rc)
45             with open("build/src/tools/dcpomatic2_disk_writer.exe.manifest", "w") as manifest:
46                 print("""
47 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
48 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
49     <assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="dcpomatic2_disk_writer" type="win32"/> 
50     <description>DCP-o-matic Disk Writer</description> 
51     <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
52             <security>
53                     <requestedPrivileges>
54                             <requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
55                     </requestedPrivileges>
56             </security>
57     </trustInfo>
58 </assembly>""", file=manifest)
59         else:
60             print(f"""
61 id ICON "../../graphics/windows/{icon}"
62 #include "wx-3.1/wx/msw/wx.rc"'
63 VS_VERSION_INFO VERSIONINFO
64  FILEVERSION    0,0,0,2
65  PRODUCTVERSION 0,0,0,2
66  FILEFLAGSMASK 0x3fL
67  #ifdef _DEBUG
68  FILEFLAGS 0x1L
69  #else
70  FILEFLAGS 0x0L
71  #endif
72  FILEOS 0x4L
73  FILETYPE 0x1L
74  FILESUBTYPE 0x0L
75 {{
76     BLOCK "StringFileInfo"
77     {{
78         BLOCK "040904b0"
79         {{
80             VALUE "FileDescription", "{description(tool, variant)}\\0"
81         }}
82     }}
83     BLOCK "VarFileInfo"
84     {{
85         VALUE "Translation", 0x409, 1200
86     }}
87 }}
88     """, file=rc)
89     return filename
90
91 def configure(conf):
92     if conf.env.TARGET_WINDOWS_64 or conf.env.TARGET_WINDOWS_32:
93         conf.env.append_value('CXXFLAGS', ['-mconsole'])
94         conf.env.append_value('LINKFLAGS', ['-mconsole'])
95
96 def build(bld):
97     uselib =  'BOOST_THREAD BOOST_DATETIME DCP XMLSEC CXML XMLPP AVFORMAT AVFILTER AVCODEC '
98     uselib += 'AVUTIL SWSCALE SWRESAMPLE POSTPROC CURL BOOST_FILESYSTEM SSH ZIP CAIROMM FONTCONFIG PANGOMM SUB '
99     uselib += 'SNDFILE SAMPLERATE BOOST_REGEX ICU NETTLE RTAUDIO PNG JPEG LEQM_NRT '
100
101     if bld.env.ENABLE_DISK:
102         if bld.env.TARGET_LINUX:
103             uselib += 'POLKIT '
104         uselib += 'LWEXT4 NANOMSG '
105
106     if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32:
107         uselib += 'WINSOCK2 DBGHELP SHLWAPI MSWSOCK BOOST_LOCALE WINSOCK2 OLE32 DSOUND WINMM KSUSER SETUPAPI UUID '
108     if bld.env.TARGET_LINUX:
109         uselib += 'DL '
110
111     cli_tools = ['dcpomatic_cli', 'dcpomatic_server_cli', 'server_test', 'dcpomatic_kdm_cli', 'dcpomatic_create', 'dcpomatic_map']
112     if bld.env.ENABLE_DISK and not bld.env.DISABLE_GUI:
113         cli_tools.append('dcpomatic_disk_writer')
114
115     try:
116         os.makedirs('build/src/tools')
117     except:
118         pass
119
120     for t in cli_tools:
121         obj = bld(features='cxx cxxprogram')
122         obj.uselib = uselib
123         obj.includes = ['..']
124         obj.use    = ['libdcpomatic2']
125         obj.source = '%s.cc' % t
126         if (bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32) and t == 'dcpomatic_disk_writer':
127             obj.source += f' ../../{make_rc(t, None, bld.env.VARIANT)}'
128             # Prevent a console window opening when we start dcpomatic2_disk_writer
129             obj.env.append_value('LINKFLAGS', '-Wl,-subsystem,windows')
130         obj.target = t.replace('dcpomatic', 'dcpomatic2')
131         if t == 'server_test':
132             obj.install_path = None
133
134     gui_tools = []
135     if not bld.env.DISABLE_GUI:
136         gui_tools = ['dcpomatic',
137                      'dcpomatic_batch',
138                      'dcpomatic_server',
139                      'dcpomatic_kdm',
140                      'dcpomatic_player',
141                      'dcpomatic_playlist',
142                      'dcpomatic_combiner',
143                      'dcpomatic_editor',
144                      'dcpomatic_verifier']
145         if bld.env.ENABLE_DISK:
146             gui_tools.append('dcpomatic_disk')
147
148     for t in gui_tools:
149         obj = bld(features='cxx cxxprogram')
150         obj.uselib = uselib
151         if bld.env.BUILD_STATIC or bld.env.TARGET_LINUX:
152             obj.uselib += ' GTK'
153         obj.uselib += ' WXWIDGETS'
154         if not bld.env.TARGET_OSX:
155             obj.uselib += ' GL GLU'
156         if bld.env.TARGET_LINUX:
157             obj.uselib += ' X11'
158         if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32:
159             obj.uselib += ' GLEW'
160         obj.includes = ['..']
161         obj.use    = ['libdcpomatic2', 'libdcpomatic2-wx']
162         obj.source = '%s.cc' % t
163         if bld.env.TARGET_WINDOWS_64 or bld.env.TARGET_WINDOWS_32:
164             obj.source += f' ../../{make_rc(t, t.replace("dcpomatic", "dcpomatic2") + ".ico", bld.env.VARIANT)}'
165         obj.target = t.replace('dcpomatic', 'dcpomatic2')
166
167     i18n.po_to_mo(os.path.join('src', 'tools'), 'dcpomatic2', bld)
168
169 def pot(bld):
170     cc = """
171          dcpomatic_batch.cc
172          dcpomatic.cc
173          dcpomatic_combiner.cc
174          dcpomatic_disk.cc
175          dcpomatic_editor.cc
176          dcpomatic_kdm.cc
177          dcpomatic_server.cc
178          dcpomatic_player.cc
179          dcpomatic_playlist.cc
180          dcpomatic_server.cc
181          """
182     i18n.pot(os.path.join('src', 'tools'), cc, 'dcpomatic')
183
184 def pot_merge(bld):
185     i18n.pot_merge(os.path.join('src', 'tools'), 'dcpomatic')