nobody cares about xpm anymore
[ardour.git] / gtk2_ardour / wscript
1 #!/usr/bin/env python
2 from waflib.extras import autowaf as autowaf
3 from waflib import Options, TaskGen
4 import waflib.Logs as Logs, waflib.Utils as Utils
5 import os
6 import shutil
7 import sys
8 import re
9 import time
10 from waflib.Task import Task
11 from waflib.Tools import winres
12 import subprocess
13 import glob
14 import copy
15
16 # Mandatory variables
17 top = '.'
18 out = 'build'
19
20 from waflib import TaskGen
21 @TaskGen.extension('.m')
22 def m_hook(self, node):
23         """Alias .m files to be compiled the same as .c files, gcc will do the right thing."""
24         return self.create_compiled_task('c', node)
25
26 path_prefix = 'gtk2_ardour/'
27
28 gtk2_ardour_sources = [
29         'about.cc',
30         'actions.cc',
31         'add_route_dialog.cc',
32         'ambiguous_file_dialog.cc',
33         'analysis_window.cc',
34         'ardour_button.cc',
35         'ardour_dialog.cc',
36         'ardour_display.cc',
37         'ardour_dropdown.cc',
38         'ardour_knob.cc',
39         'ardour_ui.cc',
40         'ardour_ui2.cc',
41         'ardour_ui_dependents.cc',
42         'ardour_ui_dialogs.cc',
43         'ardour_ui_ed.cc',
44         'ardour_ui_mixer.cc',
45         'ardour_ui_options.cc',
46         'ardour_window.cc',
47         'audio_clock.cc',
48         'audio_region_editor.cc',
49         'audio_region_view.cc',
50         'audio_streamview.cc',
51         'audio_time_axis.cc',
52         'automation_controller.cc',
53         'automation_line.cc',
54         'automation_region_view.cc',
55         'automation_streamview.cc',
56         'automation_time_axis.cc',
57         'axis_view.cc',
58         'big_clock_window.cc',
59         'bundle_manager.cc',
60         'button_joiner.cc',
61         'clock_group.cc',
62         'configinfo.cc',
63         'control_point.cc',
64         'control_point_dialog.cc',
65         'cursor_context.cc',
66         'curvetest.cc',
67         'debug.cc',
68         'duplicate_routes_dialog.cc',
69         'edit_note_dialog.cc',
70         'editing.cc',
71         'editor.cc',
72         'editor_actions.cc',
73         'editor_audio_import.cc',
74         'editor_pt_import.cc',
75         'editor_audiotrack.cc',
76         'editor_canvas.cc',
77         'editor_canvas_events.cc',
78         'editor_component.cc',
79         'editor_cursors.cc',
80         'editor_drag.cc',
81         'editor_route_groups.cc',
82         'editor_export_audio.cc',
83         'editor_group_tabs.cc',
84         'editor_keys.cc',
85         'editor_locations.cc',
86         'editor_markers.cc',
87         'editor_mixer.cc',
88         'editor_mouse.cc',
89         'editor_ops.cc',
90         'editor_regions.cc',
91         'editor_routes.cc',
92         'editor_rulers.cc',
93         'editor_selection.cc',
94         'editor_snapshots.cc',
95         'editor_summary.cc',
96         'editor_tempodisplay.cc',
97         'editor_timefx.cc',
98         'engine_dialog.cc',
99         'enums.cc',
100         'export_channel_selector.cc',
101         'export_dialog.cc',
102         'export_file_notebook.cc',
103         'export_filename_selector.cc',
104         'export_format_dialog.cc',
105         'export_format_selector.cc',
106         'export_preset_selector.cc',
107         'export_report.cc',
108         'export_timespan_selector.cc',
109         'fft.cc',
110         'fft_graph.cc',
111         'fft_result.cc',
112         'floating_text_entry.cc',
113         'sfdb_freesound_mootcher.cc',
114         'gain_meter.cc',
115         'generic_pluginui.cc',
116         'ghostregion.cc',
117         'global_port_matrix.cc',
118         'group_tabs.cc',
119         'gtk_pianokeyboard.c',
120         'gui_object.cc',
121         'insert_remove_time_dialog.cc',
122         'instrument_selector.cc',
123         'interthread_progress_window.cc',
124         'io_selector.cc',
125         'hit.cc',
126         'keyboard.cc',
127         'keyeditor.cc',
128         'latency_gui.cc',
129         'led.cc',
130         'level_meter.cc',
131         'location_ui.cc',
132         'lua_script_manager.cc',
133         'luainstance.cc',
134         'luawindow.cc',
135         'main.cc',
136         'main_clock.cc',
137         'marker.cc',
138         'midi_automation_line.cc',
139         'midi_channel_dialog.cc',
140         'midi_channel_selector.cc',
141         'midi_cut_buffer.cc',
142         'midi_export_dialog.cc',
143         'midi_list_editor.cc',
144         'midi_port_dialog.cc',
145         'midi_region_view.cc',
146         'midi_scroomer.cc',
147         'midi_selection.cc',
148         'midi_streamview.cc',
149         'midi_time_axis.cc',
150         'midi_tracer.cc',
151         'midi_velocity_dialog.cc',
152         'missing_file_dialog.cc',
153         'missing_plugin_dialog.cc',
154         'mixer_actor.cc',
155         'mixer_group_tabs.cc',
156         'mixer_strip.cc',
157         'mixer_ui.cc',
158         'meterbridge.cc',
159         'meter_strip.cc',
160         'meter_patterns.cc',
161         'monitor_section.cc',
162         'monitor_selector.cc',
163         'mono_panner.cc',
164         'mono_panner_editor.cc',
165         'mouse_cursors.cc',
166         'nag.cc',
167         'new_plugin_preset_dialog.cc',
168         'normalize_dialog.cc',
169         'note.cc',
170         'note_base.cc',
171         'note_player.cc',
172         'note_select_dialog.cc',
173         'nsm.cc',
174         'nsmclient.cc',
175         'option_editor.cc',
176         'opts.cc',
177         'panner2d.cc',
178         'panner_editor.cc',
179         'panner_interface.cc',
180         'panner_ui.cc',
181         'patch_change.cc',
182         'piano_roll_header.cc',
183         'pingback.cc',
184         'playlist_selector.cc',
185         'plugin_eq_gui.cc',
186         'plugin_pin_dialog.cc',
187         'plugin_selector.cc',
188         'plugin_ui.cc',
189         'port_group.cc',
190         'port_insert_ui.cc',
191         'port_matrix.cc',
192         'port_matrix_body.cc',
193         'port_matrix_column_labels.cc',
194         'port_matrix_component.cc',
195         'port_matrix_grid.cc',
196         'port_matrix_labels.cc',
197         'port_matrix_row_labels.cc',
198         'processor_box.cc',
199         'patch_change_dialog.cc',
200         'progress_reporter.cc',
201         'prompter.cc',
202         'public_editor.cc',
203         'quantize_dialog.cc',
204         'rc_option_editor.cc',
205         'region_editor.cc',
206         'region_gain_line.cc',
207         'region_layering_order_editor.cc',
208         'region_selection.cc',
209         'region_view.cc',
210         'return_ui.cc',
211         'rhythm_ferret.cc',
212         'route_group_dialog.cc',
213         'route_group_menu.cc',
214         'route_params_ui.cc',
215         'route_processor_selection.cc',
216         'route_time_axis.cc',
217         'route_ui.cc',
218         'ruler_dialog.cc',
219         'save_as_dialog.cc',
220         'search_path_option.cc',
221         'script_selector.cc',
222         'selection.cc',
223         'selection_memento.cc',
224         'send_ui.cc',
225         'session_dialog.cc',
226         'session_import_dialog.cc',
227         'session_metadata_dialog.cc',
228         'session_option_editor.cc',
229         'sfdb_ui.cc',
230         'shuttle_control.cc',
231         'soundcloud_export_selector.cc',
232         'splash.cc',
233         'speaker_dialog.cc',
234         'startup.cc',
235         'step_editor.cc',
236         'step_entry.cc',
237         'stereo_panner.cc',
238         'stereo_panner_editor.cc',
239         'streamview.cc',
240         'strip_silence_dialog.cc',
241         'sys_ex.cc',
242         'tape_region_view.cc',
243         'tempo_dialog.cc',
244         'tempo_lines.cc',
245         'theme_manager.cc',
246         'time_axis_view.cc',
247         'time_axis_view_item.cc',
248         'time_fx_dialog.cc',
249         'time_info_box.cc',
250         'time_selection.cc',
251         'timers.cc',
252         'tooltips.cc',
253         'track_selection.cc',
254         'track_view_list.cc',
255         'transform_dialog.cc',
256         'transpose_dialog.cc',
257         'ui_config.cc',
258         'utils.cc',
259         'verbose_cursor.cc',
260         'visibility_group.cc',
261         'window_manager.cc',
262 # video-timeline related sources:
263         'video_image_frame.cc',
264         'add_video_dialog.cc',
265         'editor_videotimeline.cc',
266         'video_timeline.cc',
267         'video_monitor.cc',
268         'transcode_ffmpeg.cc',
269         'transcode_video_dialog.cc',
270         'video_server_dialog.cc',
271         'utils_videotl.cc',
272         'export_video_dialog.cc',
273         'export_video_infobox.cc',
274         'video_tool_paths.cc'
275 ]
276
277 def enoify (major, minor):
278     # Code names based on
279     # https://en.wikipedia.org/wiki/Brian_Eno_discography
280     #
281     # sort Studio albums + Collaborative albums + Compilation albums by Month/Year.
282     # (no Singles, no EPs, no Video Albums, no Production)
283     if major == 3:
284         return "\\n\\\"E-No\\\""
285     elif major == 4:
286         if minor == 0:
287             return "\\n\\\"No Pussyfooting\\\""
288         elif minor == 1:
289             return "\\n\\\"Here Come the Warm Jets\\\""
290         elif minor == 2:
291             return "\\n\\\"Taking Tiger Mountain\\\""
292         elif minor == 3:
293             return "\\n\\\"Lady June's Linguistic Leprosy\\\""
294         elif minor == 4:
295             return "\\n\\\"Discreet Music\\\""
296         elif minor == 5:
297             return "\\n\\\"Another Green World\\\""
298         elif minor == 6:
299             return "\\n\\\"Evening Star\\\""
300         elif minor == 7:
301             return "\\n\\\"Cluster and Eno\\\""
302         elif minor == 8:
303             return "\\n\\\"Before and After Science\\\""
304     return "\\\"\\\""
305
306 def options(opt):
307     autowaf.set_options(opt)
308
309 def configure(conf):
310     conf.load('misc')
311     conf.load('compiler_cxx')
312     autowaf.configure(conf)
313
314     # TODO: Insert a sanity check for on OS X to ensure CoreAudio is present
315
316     autowaf.check_pkg(conf, 'fftw3f', uselib_store='FFTW3F',
317                       mandatory=True)
318     autowaf.check_pkg(conf, 'fftw3f', uselib_store='FFTW35F',
319                       atleast_version='3.3.5', mandatory=False)
320     autowaf.check_pkg(conf, 'flac', uselib_store='FLAC',
321                       atleast_version='1.2.1')
322     autowaf.check_pkg(conf, 'gthread-2.0', uselib_store='GTHREAD',
323                       atleast_version='2.10.1')
324     autowaf.check_pkg(conf, 'gtk+-2.0', uselib_store='GTK',
325                       atleast_version='2.18')
326     autowaf.check_pkg(conf, 'gtkmm-2.4', uselib_store='GTKMM',
327                       atleast_version='2.18')
328     autowaf.check_pkg(conf, 'ogg', uselib_store='OGG', atleast_version='1.1.2')
329     autowaf.check_pkg(conf, 'x11', uselib_store='X11', atleast_version='1.1', mandatory=False)
330     autowaf.check_pkg(conf, 'fontconfig', uselib_store='FONTCONFIG')
331
332
333     if sys.platform == 'darwin':
334         retval = conf.run_c_code (code='#include <AppKit/NSWindow.h>\n\
335         int main(void) { (void) NSWindowWillStartLiveResizeNotification; return 0; }\n',
336                                   env = conf.env.derive (),
337                                   features = [ 'c' ],
338                                   compiler = 'cc',
339                                   compile_filename='test.m',
340                                   mandatory = False,
341             )
342
343         if retval == 0:
344             autowaf.display_msg (conf, 'Checking for Cocoa live resizing constants', 'ok')
345             conf.define ('HAVE_COCOA_LIVE_RESIZING', 1)
346         else:
347             autowaf.display_msg (conf, 'Checking for Cocoa live resizing constants', 'too old - AU plugin windows will be fixed size')
348
349     conf.write_config_header('gtk2ardour-config.h', remove=False)
350
351     bak = conf.env['define_key']
352     conf.define('VERSIONSTRING', str (conf.env['VERSION']))
353     conf.define('CODENAME', enoify(int(conf.env['MAJOR']), int(conf.env['MINOR'])))
354     conf.env['define_key'] = ['VERSIONSTRING', 'CODENAME' ]
355     conf.write_config_header('gtk2ardour-version.h')
356     conf.env['define_key'] = bak;
357
358     # Boost headers
359     autowaf.check_header(conf, 'cxx', 'boost/shared_ptr.hpp')
360     autowaf.check_header(conf, 'cxx', 'boost/weak_ptr.hpp')
361
362 # Add a waf `feature' to allow compilation of things using winegcc
363 from waflib.TaskGen import feature
364 @feature("wine")
365 def set_winegcc(self):
366     self.env.LINK_CXX = self.env.LINK_CC = 'wineg++'
367     self.env.CC = 'winegcc'
368
369 def _doPyp(infileName, deps = False):
370     outStr = ''
371     out = []
372     re_spaces = re.compile("\s+")
373
374     if infileName == '-':
375         fd = sys.stdin
376     else:
377         fd = open(infileName)
378     inLines = fd.readlines()
379     if fd != sys.stdin:
380         fd.close()
381
382
383     for line in inLines:
384         bits = re_spaces.split(line)
385         if bits[0] == '##include':
386             incName = bits[1]
387             if (deps):
388                 out += [ incName ]
389             else:
390                 # assume included file comes from same place as source file
391                 incName = os.path.join (os.path.dirname (infileName), incName);
392                 outStr += _doPyp(incName)
393         else:
394             if not deps:
395                 outStr += line
396
397     # done
398     if deps:
399         return out
400     else:
401         return outStr
402
403 def include_processor(task):
404     infileName = task.inputs[0].srcpath()
405     outfileName = os.path.join(out, task.outputs[0].bldpath())
406     fdOut = open (outfileName, "w")
407     fdOut.write (_doPyp(infileName))
408     fdOut.close ()
409
410
411 def build_color_scheme(path, prefix):
412     f = open (path, 'r')
413     color_scheme = ''
414     for line in f:
415         if re.search ('^#@color', line):
416             line.strip() # remove newline
417             words = line.split()
418             if len(color_scheme):
419                 color_scheme += ';'
420             color_scheme += prefix
421             color_scheme += '_'
422             color_scheme += words[1]
423             color_scheme += ':'
424             color_scheme += words[2]
425     f.close()
426     return color_scheme
427
428 def build(bld):
429
430     VERSION = "%s.%s" % (bld.env['MAJOR'], bld.env['MINOR'])
431     I18N_PACKAGE = 'gtk2_ardour' + bld.env['MAJOR']
432
433     # Tool to dump lua-bindings (of gtk2ardour + libs)
434     if re.search ("linux", sys.platform) != None and bld.env['LUABINDINGDOC']:
435         obj = bld (features = 'cxx c cxxprogram')
436         obj.install_path = None
437         obj.source    = list(gtk2_ardour_sources)
438         obj.target    = 'luadoc'
439         obj.includes  = ['.', '../libs']
440         obj.ldflags   = ['-no-undefined']
441         obj.use       = [
442                 'libpbd',
443                 'libardour',
444                 'libardour_cp',
445                 'libtimecode',
446                 'libmidipp',
447                 'libgtkmm2ext',
448                 'libcanvas',
449                 'libptformat',
450                 ]
451         obj.defines = [
452                 'NOMAIN',
453                 'PACKAGE="' + I18N_PACKAGE + '"',
454                 'DATA_DIR="' + os.path.normpath(bld.env['DATADIR']) + '"',
455                 'CONFIG_DIR="' + os.path.normpath(bld.env['SYSCONFDIR']) + '"',
456                 'LOCALEDIR="' + os.path.normpath(bld.env['LOCALEDIR']) + '"',
457                 ]
458         obj.linkflags = ''
459         obj.uselib    = 'UUID FLAC FONTCONFIG GLIBMM GTHREAD GTK OGG CURL DL GTKMM CANVAS FFTW3F LO TAGLIB XML '
460         obj.source += [ 'luadoc.cc', 'bundle_env_linux.cc' ]
461         if bld.is_defined('HAVE_SUIL'):
462             obj.source += [ 'lv2_plugin_ui.cc' ]
463             obj.use += [ 'SUIL' ]
464         if bld.is_defined('LXVST_SUPPORT'):
465             obj.source += [ 'vst_plugin_ui.cc' ]
466             obj.source += [ 'linux_vst_gui_support.cc', 'lxvst_plugin_ui.cc' ]
467             obj.defines += [ 'LXVST_SUPPORT' ]
468             obj.use += [ 'X11' ]
469
470
471     if bld.is_defined('WINDOWS_VST_SUPPORT') and bld.env['build_target'] != 'mingw':
472         # Windows VST support w/wine
473         # If we require VST support we build a stub main() and the FST library
474         # here using winegcc, and link it to the GTK front-end library
475         obj = bld (features = 'cxx c cxxprogram wine')
476         obj.source = ( '../libs/fst/vstwin.c', '../vst/winmain.c' )
477         #
478         # XXX do we really need to explicitly link to all of these for the wine executable?
479         #
480         obj.use          = [ 'libpbd',
481                              'libmidipp',
482                              'libardour',
483                              'libardour_cp',
484                              'libtimecode',
485                              'libmidipp',
486                              'libgtk2_ardour',
487                              'libgtkmm2ext',
488                              'libcanvas',
489                              'libptformat',
490                              ]
491         obj.target = 'ardour-' + str (bld.env['VERSION']) + '-vst.exe.so'
492         obj.includes  = [ '../libs/fst', '.' ]
493         obj.linkflags = ['-mwindows', '-Wl,--export-dynamic']
494         obj.linkflags += bld.env['LDFLAGS']
495         obj.defines = ['_POSIX_SOURCE', 'USE_WS_PREFIX']
496         obj.install_path = bld.env['DLLDIR']
497         # end of the wine executable
498
499         # now the shared library containing the GTK GUI for ardour
500         obj = bld (features = 'cxx c cxxshlib')
501         # operate on copy to avoid adding sources twice
502         obj.source    = list(gtk2_ardour_sources)
503         obj.includes  = [ '../libs/fst', '.' ]
504         obj.name      = 'libgtk2_ardour'
505         obj.target    = 'gtk2_ardour'
506         obj.cflags  = [ '-fPIC' ]
507
508     else:
509         # just the normal executable version of the GTK GUI
510         if bld.env['build_target'] == 'mingw':
511             obj = bld (features = 'cxx c cxxprogram winres')
512         else:
513             obj = bld (features = 'cxx c cxxprogram')
514         # operate on copy to avoid adding sources twice
515         obj.source    = list(gtk2_ardour_sources)
516         obj.target = 'ardour-' + str (bld.env['VERSION'])
517         obj.includes = ['.']
518         obj.ldflags = ['-no-undefined']
519
520         if bld.is_defined('WINDOWS_VST_SUPPORT'):
521         # Windows VST support mingw
522             obj.includes += [ '../libs/fst' ]
523
524     # at this point, "obj" refers to either the normal native executable
525     # OR the shared library built for use with wine on linux.
526
527     obj.use      = [ 'libpbd',
528                      'libardour',
529                      'libardour_cp',
530                      'libtimecode',
531                      'libmidipp',
532                      'libgtkmm2ext',
533                      'libcanvas',
534                      'libptformat',
535                      ]
536
537     obj.defines = [
538         'PACKAGE="' + I18N_PACKAGE + '"',
539         'DATA_DIR="' + os.path.normpath(bld.env['DATADIR']) + '"',
540         'CONFIG_DIR="' + os.path.normpath(bld.env['SYSCONFDIR']) + '"',
541         'LOCALEDIR="' + os.path.normpath(bld.env['LOCALEDIR']) + '"',
542         ]
543     obj.install_path = bld.env['DLLDIR']
544     obj.linkflags    = ''
545     obj.uselib       = 'UUID FLAC FONTCONFIG GLIBMM GTHREAD GTK OGG CURL DL GTKMM CANVAS FFTW3F LO TAGLIB XML '
546
547     if sys.platform == 'darwin':
548         obj.uselib += ' AUDIOUNITS OSX '
549         obj.use    += ' libappleutility'
550         obj.source += [ 'cocoacarbon.mm', 'bundle_env_cocoa.cc' ]
551     elif bld.env['build_target'] == 'mingw':
552         obj.source += [ 'bundle_env_mingw.cc' ]
553         obj.source += [ 'windows_icon.rc' ]
554     else:
555         obj.source += [ 'bundle_env_linux.cc' ]
556
557     obj.includes += ['../libs']
558
559     obj.use += 'libptformat'
560
561     if bld.env['build_target'] == 'mingw':
562         obj.linkflags += ' -mwindows'
563
564     if bld.is_defined('HAVE_SUIL'):
565         obj.source += [ 'lv2_plugin_ui.cc' ]
566         obj.use += [ 'SUIL' ]
567
568     if bld.is_defined('HAVE_FFTW35F') and bld.env['build_target'] != 'mingw':
569         bld.env['LIB_FFTW3F'] += ['fftw3f_threads']
570
571     if bld.is_defined('NEED_INTL'):
572         obj.linkflags += ' -lintl'
573
574     if bld.is_defined('WINDOWS_VST_SUPPORT'):
575         obj.source += [ 'windows_vst_plugin_ui.cc' ]
576         obj.defines += [ 'WINDOWS_VST_SUPPORT' ]
577         if bld.env['build_target'] != 'mingw':
578             obj.use += [ 'X11' ]
579
580     if bld.is_defined('LXVST_SUPPORT'):
581         obj.source += [ 'linux_vst_gui_support.cc', 'lxvst_plugin_ui.cc' ]
582         obj.defines += [ 'LXVST_SUPPORT' ]
583         obj.use += [ 'X11' ]
584
585     if bld.is_defined('WINDOWS_VST_SUPPORT') or bld.is_defined('LXVST_SUPPORT'):
586         obj.source += [ 'vst_plugin_ui.cc' ]
587
588     if bld.is_defined('PHONE_HOME'):
589         obj.defines += [ 'PHONE_HOME' ]
590
591     if bld.is_defined('HAVE_COREAUDIO'):
592         TaskGen.task_gen.mappings['.mm'] = TaskGen.task_gen.mappings['.cc']
593         obj.use += ' libappleutility '
594
595     if bld.is_defined('AUDIOUNIT_SUPPORT'):
596         obj.source += [ 'au_pluginui.mm' ]
597
598     # Wrappers
599
600     wrapper_subst_dict = {
601             'INSTALL_PREFIX' : bld.env['PREFIX'],
602             'LIBDIR'         : os.path.normpath(bld.env['DLLDIR']),
603             'DATADIR'        : os.path.normpath(bld.env['DATADIR']),
604             'CONFDIR'        : os.path.normpath(bld.env['CONFDIR']),
605             'LIBS'           : 'build/libs',
606             'VERSION'        : str (bld.env['VERSION']),
607             'EXECUTABLE'     : 'build/gtk2_ardour/ardour-' + str (bld.env['VERSION'])
608     }
609
610     def set_subst_dict(obj, dict):
611         for i in dict:
612             setattr(obj, i, dict[i])
613
614     obj              = bld(features = 'subst')
615     obj.source       = 'ardev_common.sh.in'
616     obj.target       = 'ardev_common_waf.sh'
617     obj.chmod        = Utils.O755
618     obj.dict         = wrapper_subst_dict
619     set_subst_dict(obj, wrapper_subst_dict)
620
621     obj              = bld(features = 'subst')
622     obj.source       = 'ardour.sh.in'
623     obj.target       = 'ardour' + str (bld.env['MAJOR'])
624     obj.chmod        = Utils.O755
625     obj.dict         = wrapper_subst_dict
626     obj.install_path = bld.env['BINDIR']
627     set_subst_dict(obj, wrapper_subst_dict)
628
629     if bld.is_defined('WINDOWS_VST_SUPPORT'):
630         obj              = bld(features = 'subst')
631         obj.source       = '../vst/ardourvst.in'
632         obj.target       = 'ardourvst' + str (bld.env['MAJOR'])
633         obj.chmod        = Utils.O755
634         obj.dict         = wrapper_subst_dict
635         obj.install_path = bld.env['BINDIR']
636         set_subst_dict(obj, wrapper_subst_dict)
637
638     # Font configuration
639
640     font_subst_dict = {}
641     font_sizes      = {}
642     base_font       = ""
643
644     # Set up font sizes
645     if sys.platform == 'darwin':
646         basefont = ""
647         font_sizes = {
648                 'SMALLER' : '9',
649                 'SMALL' : '10',
650                 'NORMAL' : '11',
651                 'BIG' : '13',
652                 'BIGGER' : '17',
653                 'LARGE' : '18',
654                 'LARGER' : '28',
655                 'HUGER' : '36',
656                 'MASSIVE' : '60',
657         }
658
659         # There is no acceptable monospace font available on older versions of OS X
660         # and no API on those versions to load TTF files that will work with
661         # GTK/fontconfig/pango.
662         #
663         # In addition, the ArdourMono font gets clipped for some reason on OS X
664         #
665         # Moreover, Lucida Grande just seems to work even though it is not monospace
666         # so just use it.
667         #
668         font_names = {
669             'MONOSPACE' : 'Monaco',
670             'CLOCKFONT' : 'Lucida Grande',
671         }
672     else: # Linux/X11 fonts
673         basefont = '' # unspecified - use system defaults
674         font_sizes = {
675                 'SMALLER' : '6',
676                 'SMALL' : '7',
677                 'NORMAL' : '8',
678                 'BIG' : '11',
679                 'BIGGER' : '13.5',
680                 'LARGE' : '14.5',
681                 'LARGER' : '19',
682                 'HUGER' : '27',
683                 'MASSIVE' : '48',
684         }
685         font_names = {
686                 'MONOSPACE' : 'ArdourMono',
687                 'CLOCKFONT' : 'ArdourMono',
688         }
689
690     # Set up font substitution dictionary
691     # @FONT_XXXX@
692     for style in ['', 'BOLD', 'ITALIC']:
693         for sizename,points in iter(font_sizes.items()):
694             if (len (style)):
695                 key = "_".join (['FONT',style,sizename])
696                 fontstyle = " ".join ([basefont,style.lower(),points])
697             else:
698                 key = "_".join (['FONT',sizename])
699                 fontstyle = " ".join ([basefont,points])
700
701             font_subst_dict[key] = fontstyle
702
703     # @FONT_SIZE_XXXX@
704     for sizename,points in iter(font_sizes.items()):
705             key = "_".join (['FONT_SIZE',sizename])
706             font_subst_dict[key] = points
707
708     # various font names, eg @BOLD_MONOSPACE@
709     for font_sym,text in iter(font_names.items()):
710         key = font_sym
711         font_subst_dict[key] = text
712
713     # RC file
714
715     obj              = bld(features = 'subst')
716     obj.source       = [ 'clearlooks.rc.in' ]
717     obj.target       = 'clearlooks.rc'
718     obj.install_path = bld.env['CONFDIR']
719     set_subst_dict(obj, font_subst_dict)
720
721     obj              = bld(features = 'subst')
722     obj.source       = [ 'default_ui_config.in' ]
723     obj.target       = 'default_ui_config'
724     obj.install_path = bld.env['CONFDIR']
725     set_subst_dict(obj, font_subst_dict)
726
727     # Menus
728     menus_argv = []
729     if sys.platform == 'darwin':
730         menus_argv = [ '-E', '-P', '-D__APPLE__', '-' ]
731     else:
732         menus_argv = [ '-E', '-P' ]
733
734     if bld.is_defined('PTFORMAT'):
735         menus_argv += [ '-DPTFORMAT' ]
736
737     # always build all versions of the menu definitions
738     # so that we can try them out with different program builds.
739     for program in [ 'ardour', 'trx' ]:
740         obj = bld(features = 'command-output')
741         obj.command = 'cpp'
742         obj.command_is_external = True
743         obj.no_inputs = True
744         obj.argv = menus_argv
745         obj.dep_vars = ['PTFORMAT', 'GTKOSX', 'WINDOWS']
746         obj.stdin = program + '.menus.in'
747         obj.stdout = program + '.menus'
748         bld.install_files (bld.env['CONFDIR'], program + '.menus')
749
750     # Freedesktop
751     freedesktop_subst_dict = {
752                     'ARDOUR_EXEC' : str (bld.env['lwrcase_dirname']),
753                     'ARDOUR_ICON' : str (bld.env['lwrcase_dirname']),
754                     'VERSION': str (bld.env['VERSION']),
755     }
756
757     if bld.env['FREEDESKTOP']:
758         obj              = bld(features = 'subst')
759         obj.source       = 'ardour.desktop.in'
760         obj.target       = str (bld.env['lwrcase_dirname']) + '.desktop'
761         obj.chmod        = Utils.O644
762         obj.dict         = freedesktop_subst_dict
763         set_subst_dict(obj, freedesktop_subst_dict)
764
765         obj              = bld(features = 'subst')
766         obj.source       = 'ardour-mime-info.xml'
767         obj.target       = 'ardour.xml'
768         obj.chmod        = Utils.O644
769
770         # build appdata with translations
771         appdata_i18n_mo(bld)
772         appdata_i18n_xmlin(bld)
773         obj              = bld(features = 'subst')
774         obj.source       = 'ardour.appdata.xml.in'
775         obj.target       = str (bld.env['lwrcase_dirname']) + '.appdata.xml'
776         obj.chmod        = Utils.O644
777         obj.dict         = freedesktop_subst_dict
778         set_subst_dict(obj, freedesktop_subst_dict)
779
780     # Keybindings
781
782     # NATIVE ARDOUR BINDING FILES
783     # explicitly state the use of perl here so that it works on windows too
784     # 
785     a_rule = 'perl ../tools/fmt-bindings --platform="%s" --winkey="%s" --accelmap ${SRC[0].abspath()} >${TGT}' % (sys.platform, bld.env['WINDOWS_KEY'] )
786     for b in [ 'ardour' ] :
787         obj = bld(
788             target = b + '.keys',
789             source = [ b + '.keys.in', 'mixer.bindings', 'processor_box.bindings', 'step_editing.bindings', 'monitor.bindings' ],
790             rule = a_rule
791             )
792         obj.install_path = bld.env['CONFDIR']
793         
794     # Icons/Images
795     bld.install_files(os.path.join (bld.env['DATADIR'], 'icons'), bld.path.ant_glob('icons/*.png'))
796     bld.install_files(bld.env['DATADIR'], 'ArdourMono.ttf')
797
798     # Application/Product specific resources (icon, splash)
799     pgmname = Options.options.program_name;
800     bld.install_files(os.path.join(bld.env['DATADIR'], 'resources'), bld.path.ant_glob('resources/' + pgmname + '*'))
801
802     if bld.env['build_target'] == 'mingw':
803         # These icons need to overwrite the files already installed in the icons
804         # directory above. Do this in the external packaging scripts for now.
805         #bld.install_files(os.path.join (bld.env['DATADIR'], 'icons'), bld.path.ant_glob('icons/cursor_square/*.png'))
806         bld.install_files(os.path.join (bld.env['DATADIR'], 'icons'), 'icons/cursor_square/hotspots')
807
808     # Default UI configuration
809     bld.install_files(bld.env['CONFDIR'], 'default_ui_config')
810     # Color Themes
811     bld.install_files(bld.env['CONFDIR'], 'dark.colors')
812
813     # Default export stuff
814     bld.install_files(os.path.join(bld.env['CONFDIR'], 'export'), bld.path.ant_glob('export/*.format'))
815
816     # i18n
817     if bld.is_defined('ENABLE_NLS'):
818         mo_files = bld.path.ant_glob('po/*.mo')
819         for mo in mo_files:
820             lang = os.path.basename(mo.srcpath()).replace('.mo', '')
821             bld.install_as (os.path.join(os.path.normpath(bld.env['LOCALEDIR']), lang, 'LC_MESSAGES', I18N_PACKAGE + '.mo'),
822                             mo)
823
824 def i18n(bld):
825         I18N_PACKAGE = 'gtk2_ardour' + bld.env['MAJOR']
826         autowaf.build_i18n(bld, top, 'gtk2_ardour', I18N_PACKAGE, gtk2_ardour_sources,
827                            'Paul Davis')
828         appdata_i18n_pot(bld)
829         appdata_i18n_po(bld)
830
831 def i18n_pot(bld):
832         I18N_PACKAGE = 'gtk2_ardour' + bld.env['MAJOR']
833         autowaf.build_i18n_pot(bld, top, 'gtk2_ardour', I18N_PACKAGE, gtk2_ardour_sources,
834                                'Paul Davis')
835         appdata_i18n_pot(bld)
836
837 def i18n_po(bld):
838         I18N_PACKAGE = 'gtk2_ardour' + bld.env['MAJOR']
839         autowaf.build_i18n_po(bld, top, 'gtk2_ardour', I18N_PACKAGE, gtk2_ardour_sources,
840                               'Paul Davis')
841         appdata_i18n_po(bld)
842
843 def i18n_mo(bld):
844         I18N_PACKAGE = 'gtk2_ardour' + bld.env['MAJOR']
845         autowaf.build_i18n_mo(bld, top, 'gtk2_ardour', I18N_PACKAGE, gtk2_ardour_sources,
846                               'Paul Davis')
847
848 def appdata_i18n_pot(bld):
849     potfile = os.path.join(bld.top_dir, 'gtk2_ardour', 'appdata',
850             'ardour.appdata.pot')
851     if bld.cmd == 'build':
852         Logs.info('Generating pot file from Ardour appdata')
853         itsfile = os.path.join(bld.top_dir, 'tools', 'as-metainfo.its')
854         adsource = os.path.join(bld.top_dir, 'gtk2_ardour',
855                 'ardour.appdata.xml.in.in')
856         Logs.info('Updating ' + potfile)
857         subprocess.call(('itstool', '-i', itsfile, '-o', potfile, adsource))
858     elif bld.cmd == 'clean' and os.path.exists(potfile):
859         Logs.info('Removing Ardour appdata pot file')
860         os.remove(potfile)
861
862 def appdata_i18n_po(bld):
863     autowaf.build_i18n_po(bld, bld.top_dir, os.path.join(
864         'gtk2_ardour', 'appdata'), 'ardour.appdata', 'dummy', 'dummy')
865
866 def appdata_i18n_mo(bld):
867     autowaf.build_i18n_mo(bld, bld.top_dir, os.path.join(
868         'gtk2_ardour', 'appdata'), 'ardour.appdata', 'dummy', 'dummy')
869
870 def appdata_i18n_xmlin(bld):
871     adxmlinfile = os.path.join(bld.top_dir, 'gtk2_ardour',
872             'ardour.appdata.xml.in')
873     if bld.cmd == 'build':
874         itsfile = os.path.join(bld.top_dir, 'tools', 'as-metainfo.its')
875         adxmlininfile = os.path.join(bld.top_dir, 'gtk2_ardour',
876                 'ardour.appdata.xml.in.in')
877         mo_glob = os.path.join(bld.top_dir, 'gtk2_ardour', 'appdata', 'po', '*.mo')
878         mo_files = glob.glob(mo_glob)
879         Logs.info('Generating ' + adxmlinfile)
880         subprocess.call(['itstool', '-i', itsfile, '-o', adxmlinfile,
881             '-j', adxmlininfile] + mo_files)
882     elif bld.cmd == 'clean' and os.path.exists(adxmlinfile):
883         Logs.info('Removing ' + adxmlinfile)
884         os.remove(adxmlinfile)