Release 3.6
[gmidimonitor.git] / wscript
blob6458e8851bfd2b8ce80f917978728e8e8caefeae
1 #! /usr/bin/env python
2 # encoding: utf-8
4 import os, Logs, Options
6 top = '.'
7 out = 'build'
8 APPNAME='gmidimonitor'
9 VERSION='3.6'
11 optfeatures = {
12 'jack': {'description': 'JACK MIDI support',
13 'site': 'http://jackaudio.org/'},
14 'alsa': {'description': 'ALSA MIDI support',
15 'site': 'http://www.alsa-project.org/'},
16 'lash': {'description': 'LASH support',
17 'site': 'http://www.nongnu.org/lash/',
18 'package': 'lash-1.0'},
21 def display_line(text = ""):
22 Logs.pprint('NORMAL', text)
24 def display_value(ctx, text, value, color = 'NORMAL'):
25 ctx.msg(text, value, color)
27 def display_feature(ctx, opt):
28 if optfeatures[opt]['build']:
29 color = 'GREEN'
30 else:
31 color = 'YELLOW'
33 display_value(ctx, optfeatures[opt]['description'], optfeatures[opt]['status'], color)
35 def add_cflag(ctx, flag):
36 ctx.env.append_unique('CXXFLAGS', flag)
37 ctx.env.append_unique('CFLAGS', flag)
39 def add_linkflag(ctx, flag):
40 ctx.env.append_unique('LINKFLAGS', flag)
42 def add_opt_feature(opt, feature, help):
43 help = "Whether to build " + help + ", possible values: 'yes', 'no' and 'auto'. Default is 'auto'."
44 opt.add_option('--' + feature, type='choice', choices=['auto', 'yes', 'no'], default='auto', help=help)
46 def options(opt):
47 opt.load('compiler_c')
48 for k, v in optfeatures.items():
49 add_opt_feature(opt, k, v['description'])
51 def check_opt_packages(ctx):
52 for opt, v in optfeatures.items():
53 site = v['site']
54 try:
55 package = v['package']
56 except KeyError:
57 package = opt
59 value = getattr(Options.options, opt)
60 if value == 'no':
61 optfeatures[opt]['build'] = False
62 optfeatures[opt]['status'] = 'disabled (requested)'
63 else:
64 mandatory = value == 'yes'
65 if mandatory:
66 errmsg = 'not found, check ' + site
67 else:
68 errmsg = 'not found'
69 optfeatures[opt]['build'] = bool(ctx.check_cfg(package = package, mandatory = mandatory, args = '--cflags --libs', errmsg = errmsg))
70 if optfeatures[opt]['build']:
71 if mandatory:
72 optfeatures[opt]['status'] = 'enabled (requested)'
73 else:
74 optfeatures[opt]['status'] = 'enabled (auto)'
75 else:
76 optfeatures[opt]['status'] = 'disabled, package ' + package + ' not found, check ' + site
78 ctx.env['BUILD_' + opt.upper()] = optfeatures[opt]['build']
80 def configure(ctx):
81 ctx.load('compiler_c')
83 ctx.check_cfg(
84 package = 'gtk+-2.0',
85 errmsg = "not installed, see http://www.gtk.org/",
86 args = '--cflags --libs')
88 ctx.check_cfg(
89 package = 'gthread-2.0',
90 errmsg = "not installed, see http://www.gtk.org/",
91 args = '--cflags --libs')
93 ctx.check_cfg(
94 package = 'gmodule-2.0',
95 errmsg = "not installed, see http://www.gtk.org/",
96 args = '--cflags --libs')
98 check_opt_packages(ctx)
100 if not optfeatures['jack']['build'] and not optfeatures['alsa']['build']:
101 display_line()
102 display_feature(ctx, 'alsa')
103 display_feature(ctx, 'jack')
104 ctx.fatal("Neither JACK nor ALSA is available")
106 ctx.env['DATA_DIR'] = os.path.normpath(os.path.join(ctx.env['PREFIX'], 'share', APPNAME))
108 add_cflag(ctx, '-Wall')
109 #add_cflag(ctx, '-Wuninitialized')
110 #add_cflag(ctx, '-O3')
111 #add_cflag(ctx, '-g')
112 #add_linkflag(ctx, '-g')
114 display_line()
115 display_line('==================')
116 display_value(ctx, 'Prefix', ctx.env['PREFIX'])
117 display_feature(ctx, 'jack')
118 display_feature(ctx, 'alsa')
119 display_feature(ctx, 'lash')
120 display_line('==================')
121 display_line()
123 ctx.define('PACKAGE_VERSION', VERSION)
124 ctx.define('APPNAME', APPNAME)
125 ctx.define('DATA_DIR', ctx.env['DATA_DIR'])
126 ctx.write_config_header('config.h')
128 def build(ctx):
129 source = [
130 "main.c",
131 "about.c",
132 "path.c",
133 "gm.c",
134 "log.c",
135 "memory_atomic.c",
136 "sysex.c",
138 uselib = ['GTK+-2.0', 'GTHREAD-2.0', 'GMODULE-2.0']
140 if ctx.env['BUILD_JACK']:
141 source.append("jack.c")
142 uselib.append('JACK')
144 if ctx.env['BUILD_ALSA']:
145 source.append("alsa.c")
146 uselib.append('ALSA')
148 if ctx.env['BUILD_LASH']:
149 uselib.append('LASH-1.0')
151 ctx.program(
152 source = source,
153 features = 'c cprogram',
154 includes = ".",
155 target = 'gmidimonitor',
156 uselib = uselib,
159 ctx.install_files('${DATA_DIR}', 'gmidimonitor.ui')