4 from __future__
import print_function
11 from waflib
import Logs
, Options
, TaskGen
, Context
, Utils
, Scripting
12 from waflib
.Build
import BuildContext
, CleanContext
, InstallContext
, UninstallContext
13 from waftoolchainflags
import WafToolchainFlags
18 # these variables are mandatory ('/' are converted automatically)
22 def display_feature(conf
, msg
, build
):
24 conf
.msg(msg
, 'yes', color
='GREEN')
26 conf
.msg(msg
, 'no', color
='YELLOW')
29 if type(self
) == Scripting
.Dist
:
30 header
= "./gitversion.h"
33 bld
= self
.generator
.bld
34 header
= self
.outputs
[0].abspath()
35 if os
.access('./gitversion.h', os
.R_OK
):
36 #header = os.path.join(os.getcwd(), out, "version.h")
37 shutil
.copy('./gitversion.h', header
)
38 data
= open(header
).read()
39 m
= re
.match(r
'^#define GIT_VERSION "([^"]*)"$', data
)
42 Logs
.pprint('BLUE', "tarball from git revision " + self
.ver
)
47 if os
.access('./.git', os
.R_OK
):
48 self
.ver
= bld
.cmd_and_log("LANG= git rev-parse HEAD", quiet
=Context
.BOTH
).splitlines()[0]
49 if bld
.cmd_and_log("LANG= git diff-index --name-only HEAD", quiet
=Context
.BOTH
).splitlines():
52 Logs
.pprint('BLUE', "git revision " + self
.ver
)
56 fi
= open(header
, 'w')
57 fi
.write('#define GIT_VERSION "%s"\n' % self
.ver
)
60 def display_msg(conf
, msg
="", status
= None, color
= None):
62 #Logs.pprint(msg, status, color)
63 conf
.msg(msg
, status
, color
=color
)
65 Logs
.pprint('NORMAL', msg
)
67 def display_raw_text(conf
, text
, color
= 'NORMAL'):
68 Logs
.pprint(color
, text
, sep
= '')
70 def display_line(conf
, text
, color
= 'NORMAL'):
71 Logs
.pprint(color
, text
, sep
= os
.linesep
)
74 # options provided by the modules
75 opt
.load('compiler_c')
76 opt
.load('waf-autooptions')
80 help='Enable devmode', # enable warnings and treat them as errors
81 conf_dest
='BUILD_DEVMODE',
84 opt
.add_option('--debug', action
='store_true', default
=False, help='Build debuggable binaries')
86 opt
.add_option('--enable-pkg-config-dbus-service-dir', action
='store_true', default
=False, help='force D-Bus service install dir to be one returned by pkg-config')
87 opt
.add_option('--disable-dbus', action
='store_true', default
=False, help="Don't enable D-Bus support even if required dependencies are present")
88 opt
.add_option('--mandir', help="Manpage directory [Default: <prefix>/share/man]")
91 conf
.load('compiler_c')
92 conf
.load('waf-autooptions')
94 conf
.check_cfg(package
='alsa', mandatory
=True, args
='--cflags --libs')
95 conf
.check_cfg(package
='jack', vnum
="0.109.0", mandatory
=True, args
='--cflags --libs')
97 if not Options
.options
.disable_dbus
:
98 conf
.check_cfg(package
='dbus-1', mandatory
=False, args
='--cflags --libs')
99 conf
.env
['DBUS_ENABLED'] = 'LIB_DBUS-1' in conf
.env
101 conf
.env
['DBUS_ENABLED'] = False
103 if conf
.env
['DBUS_ENABLED']:
104 dbus_dir
= conf
.check_cfg(package
='dbus-1', args
='--variable=session_bus_services_dir', msg
="Retrieving D-Bus services dir")
108 dbus_dir
= dbus_dir
.strip()
109 conf
.env
['DBUS_SERVICES_DIR_REAL'] = dbus_dir
111 if Options
.options
.enable_pkg_config_dbus_service_dir
:
112 conf
.env
['DBUS_SERVICES_DIR'] = dbus_dir
114 conf
.env
['DBUS_SERVICES_DIR'] = os
.path
.join(os
.path
.normpath(conf
.env
['PREFIX']), 'share', 'dbus-1', 'services')
116 conf
.env
['LIB_DL'] = ['dl']
117 conf
.env
['LIB_PTHREAD'] = ['pthread']
119 # conf.c is the only user of expat and its build is disabled
120 #conf.check_header('expat.h', mandatory=True)
121 #conf.env['LIB_EXPAT'] = ['expat']
123 conf
.check(header_name
='getopt.h', mandatory
=True)
125 if Options
.options
.mandir
:
126 conf
.env
['MANDIR'] = Options
.options
.mandir
128 conf
.env
['MANDIR'] = conf
.env
['PREFIX'] + '/share/man'
130 conf
.define('A2J_VERSION', VERSION
)
131 conf
.write_config_header('config.h')
134 if os
.access('gitversion.h', os
.R_OK
):
135 data
= open('gitversion.h', 'r').read()
136 m
= re
.match(r
'^#define GIT_VERSION "([^"]*)"$', data
)
140 flags
= WafToolchainFlags(conf
)
141 flags
.add_c('-std=gnu99')
142 if conf
.env
['BUILD_DEVMODE']:
143 flags
.add_c(['-Wall', '-Wextra'])
144 #flags.add_c('-Wpedantic')
145 flags
.add_c('-Werror')
146 flags
.add_c(['-Wno-variadic-macros', '-Wno-gnu-zero-variadic-macro-arguments'])
148 # https://wiki.gentoo.org/wiki/Modern_C_porting
149 if conf
.env
['CC'] == 'clang':
150 flags
.add_c('-Wno-unknown-argumemt')
151 flags
.add_c('-Werror=implicit-function-declaration')
152 flags
.add_c('-Werror=incompatible-function-pointer-types')
153 flags
.add_c('-Werror=deprecated-non-prototype')
154 flags
.add_c('-Werror=strict-prototypes')
155 if int(conf
.env
['CC_VERSION'][0]) < 16:
156 flags
.add_c('-Werror=implicit-int')
158 flags
.add_c('-Wno-unknown-warning-option')
159 flags
.add_c('-Werror=implicit-function-declaration')
160 flags
.add_c('-Werror=implicit-int')
161 flags
.add_c('-Werror=incompatible-pointer-types')
162 flags
.add_c('-Werror=strict-prototypes')
163 if Options
.options
.debug
:
164 flags
.add_c(['-O0', '-g', '-fno-omit-frame-pointer'])
170 display_msg(conf
, "==================")
171 version_msg
= "a2jmidid-" + VERSION
173 version_msg
+= " exported from " + gitrev
175 version_msg
+= " git revision will checked and eventually updated during build"
179 display_msg(conf
, "Install prefix", conf
.env
['PREFIX'], 'CYAN')
180 display_feature(conf
, 'Build debuggable binaries', Options
.options
.debug
)
183 ('C compiler flags', ['CFLAGS', 'CPPFLAGS']),
184 ('Linker flags', ['LINKFLAGS', 'LDFLAGS'])
186 for name
, vars in tool_flags
:
189 flags
+= conf
.all_envs
[''][var
]
190 conf
.msg(name
, repr(flags
), color
='NORMAL')
192 if conf
.env
['DBUS_ENABLED']:
193 have_dbus_status
= "yes"
195 have_dbus_status
= "no"
196 display_msg(conf
, "D-Bus support", have_dbus_status
)
197 if conf
.env
['DBUS_ENABLED']:
198 display_msg(conf
, 'D-Bus service install directory', conf
.env
['DBUS_SERVICES_DIR'], 'CYAN')
199 if conf
.env
['DBUS_SERVICES_DIR'] != dbus_dir
:
201 display_line(conf
, "WARNING: D-Bus session services directory as reported by pkg-config is", 'RED')
202 display_raw_text(conf
, "WARNING:", 'RED')
203 display_line(conf
, conf
.env
['DBUS_SERVICES_DIR_REAL'], 'CYAN')
204 display_line(conf
, 'WARNING: but service file will be installed in', 'RED')
205 display_raw_text(conf
, "WARNING:", 'RED')
206 display_line(conf
, conf
.env
['DBUS_SERVICES_DIR'], 'CYAN')
207 display_line(conf
, 'WARNING: You may need to adjust your D-Bus configuration after installing ladish', 'RED')
208 display_line(conf
, 'WARNING: You can override dbus service install directory', 'RED')
209 display_line(conf
, 'WARNING: with --enable-pkg-config-dbus-service-dir option to this script', 'RED')
214 target
='gitversion.h',
219 prog
= bld(features
=['c', 'cprogram'])
233 if bld
.env
['DBUS_ENABLED']:
234 prog
.source
.append('dbus.c')
235 prog
.source
.append('dbus_iface_introspectable.c')
236 prog
.source
.append('dbus_iface_control.c')
238 prog
.includes
= '.' # make waf dependency tracking work
239 prog
.target
= 'a2jmidid'
240 prog
.use
= ['ALSA', 'JACK', 'DL', 'PTHREAD']
241 if bld
.env
['DBUS_ENABLED']:
242 prog
.use
.append('DBUS-1')
243 prog
.defines
= ["HAVE_GITVERSION_H"]
245 prog
= bld(features
=['c', 'cprogram'])
246 prog
.source
= 'a2jmidi_bridge.c'
247 prog
.target
= 'a2jmidi_bridge'
248 prog
.use
= ['ALSA', 'JACK']
250 prog
= bld(features
=['c', 'cprogram'])
251 prog
.source
= 'j2amidi_bridge.c'
252 prog
.target
= 'j2amidi_bridge'
253 prog
.use
= ['ALSA', 'JACK']
255 if bld
.env
['DBUS_ENABLED']:
256 # process org.gna.home.a2jmidid.service.in -> org.gna.home.a2jmidid.service
257 obj
= bld(features
='subst')
258 obj
.source
= 'org.gna.home.a2jmidid.service.in'
259 obj
.target
= 'org.gna.home.a2jmidid.service'
260 obj
.install_path
= '${DBUS_SERVICES_DIR}/'
261 obj
.bindir
= bld
.env
['PREFIX'] + '/bin'
264 os
.path
.join(bld
.env
['PREFIX'], 'bin', 'a2j_control'),
268 os
.path
.join(bld
.env
['PREFIX'], 'bin', 'a2j'),
279 if bld
.env
['DBUS_ENABLED']:
280 man_pages
.append("a2j.1")
281 man_pages
.append("a2j_control.1")
283 for i
in range(len(man_pages
)):
284 man_pages
[i
] = "man/" + man_pages
[i
]
286 bld
.install_files(os
.path
.join(bld
.env
['MANDIR'], 'man1'), man_pages
)