4 # SPDX-FileCopyrightText: Copyright © 2023 Nedko Arnaudov
5 # SPDX-License-Identifier: GPL-3.0-or-later
7 from __future__
import print_function
10 from waflib
import Context
11 from waflib
import Logs
, Options
, TaskGen
, Utils
12 from waflib
.Build
import BuildContext
, CleanContext
, InstallContext
, UninstallContext
13 from waf_toolchain_flags
import WafToolchainFlags
16 JACK_VERSION_MAJOR
= 1
17 JACK_VERSION_MINOR
= 126
18 JACK_VERSION_PATCH
= 2
21 VERSION
= str(JACK_VERSION_MAJOR
) + '.' + str(JACK_VERSION_MINOR
) + '.' + str(JACK_VERSION_PATCH
)
23 # (LADI) shlib versions
25 # LADI/jack-1.121.4 : 0.1.28 (jack-major=1, api-revision=28)
26 # LADI/jack-2.23.0 : 0.2.23 (jack-major=2, jack-minor=23)
27 # LADI/PipeWire-0.3.376 : 0.3.376 (jack-major=3, pipewire-libversion-minor=376)
28 # jackaudio/jack1-0.121 : 0.0.28 (JACK_API_CURRENT=0:JACK_API_REVISION=28:JACK_API_AGE=0)
29 # jackaudio/jack2-1.9.22 : 0.1.0
30 # PipeWire/PipeWire-0.3.77 : 0.3.377 # PipeWire switched to 0.3.PWVER in pipewire-0.3.77
31 # PipeWire/PipeWire-0.3.76 : 0.376.0
33 # Keep major at 0, as the shlib major is part of standard ld.so loading magic
34 JACK_API_VERSION
= '0.' + str(JACK_VERSION_MAJOR
) + '.' + str(JACK_API_REVISION
)
36 # these variables are mandatory ('/' are converted automatically)
41 opt
.load('compiler_c')
42 opt
.load('waf_autooptions')
44 opt
.set_auto_options_define('HAVE_%s')
45 opt
.set_auto_options_style('yesno_and_hack')
47 opt
.add_option('--libdir', type='string', help='Library directory [Default: <prefix>/lib64]')
48 opt
.add_option('--pkgconfigdir', type='string', help='pkg-config file directory [Default: <libdir>/pkgconfig]')
50 alsa
= opt
.add_auto_option(
52 help='Enable ALSA driver',
53 conf_dest
='BUILD_DRIVER_ALSA')
55 package
='alsa >= 1.0.18',
56 args
='--cflags --libs')
58 oss
= opt
.add_auto_option(
60 help='Enable OSS driver',
62 conf_dest
='BUILD_DRIVER_OSS')
64 firewire
= opt
.add_auto_option(
66 help='Enable Firewire (FFADO) driver',
67 conf_dest
='BUILD_DRIVER_FFADO')
69 package
='libffado >= 1.999.17',
70 args
='--cflags --libs')
74 help='Enable debug symbols',
75 conf_dest
='BUILD_DEBUG',
81 help='Enable devmode', # enable warnings and treat them as errors
82 conf_dest
='BUILD_DEVMODE',
86 db
= opt
.add_auto_option(
88 help='Use Berkeley DB (metadata)')
89 db
.check(header_name
='db.h')
92 # this must be called before the configure phase
93 opt
.apply_auto_options_hack()
95 def display_feature(conf
, msg
, build
):
97 conf
.msg(msg
, 'yes', color
='GREEN')
99 conf
.msg(msg
, 'no', color
='YELLOW')
102 conf
.load('compiler_c')
103 conf
.load('waf_autooptions')
105 conf
.env
['JACK_API_VERSION'] = JACK_API_VERSION
107 flags
= WafToolchainFlags(conf
)
109 if Options
.options
.libdir
:
110 conf
.env
['LIBDIR'] = Options
.options
.libdir
112 conf
.env
['LIBDIR'] = conf
.env
['PREFIX'] + '/lib64'
114 if Options
.options
.pkgconfigdir
:
115 conf
.env
['PKGCONFDIR'] = Options
.options
.pkgconfigdir
117 conf
.env
['PKGCONFDIR'] = conf
.env
['LIBDIR'] + '/pkgconfig'
119 conf
.env
['JACK_DRIVER_DIR'] = os
.path
.normpath(
120 os
.path
.join(conf
.env
['PREFIX'],
123 conf
.env
['JACK_INTERNAL_DIR'] = os
.path
.normpath(
124 os
.path
.join(conf
.env
['PREFIX'],
127 conf
.define('JACK_DRIVER_DIR', conf
.env
['JACK_DRIVER_DIR'])
128 conf
.define('JACK_INTERNAL_DIR', conf
.env
['JACK_INTERNAL_DIR'])
130 conf
.check_cfg(package
='expat', args
='--cflags --libs')
131 conf
.env
['LIB_M'] = ['m']
133 flags
.add_c('-std=gnu99')
134 if conf
.env
['BUILD_DEVMODE']:
135 flags
.add_c(['-Wall', '-Wextra'])
136 flags
.add_c('-Wpedantic')
137 flags
.add_c('-Werror')
138 flags
.add_c(['-Wno-variadic-macros', '-Wno-gnu-zero-variadic-macro-arguments'])
140 # https://wiki.gentoo.org/wiki/Modern_C_porting
141 if conf
.env
['CC'] == 'clang':
142 flags
.add_c('-Wno-unknown-argumemt')
143 flags
.add_c('-Werror=implicit-function-declaration')
144 flags
.add_c('-Werror=incompatible-function-pointer-types')
145 flags
.add_c('-Werror=deprecated-non-prototype')
146 flags
.add_c('-Werror=strict-prototypes')
147 if int(conf
.env
['CC_VERSION'][0]) < 16:
148 flags
.add_c('-Werror=implicit-int')
150 flags
.add_c('-Wno-unknown-warning-option')
151 flags
.add_c('-Werror=implicit-function-declaration')
152 flags
.add_c('-Werror=implicit-int')
153 flags
.add_c('-Werror=incompatible-pointer-types')
154 flags
.add_c('-Werror=strict-prototypes')
155 if conf
.env
['BUILD_DEBUG']:
156 flags
.add_c(['-O0', '-g', '-fno-omit-frame-pointer'])
159 conf
.define('JACK_THREAD_STACK_TOUCH', 500000)
160 conf
.define('jack_protocol_version', 24)
161 conf
.define('JACK_SHM_TYPE', 'System V')
162 conf
.define('USE_POSIX_SHM', 0)
163 conf
.define('DEFAULT_TMP_DIR', '/dev/shm')
164 conf
.define('JACK_SEMAPHORE_KEY', 0x282929)
165 conf
.define('JACK_DEFAULT_DRIVER', 'dummy')
166 conf
.define('JACK_VERSION', VERSION
)
167 conf
.define('LIBDIR', conf
.env
['LIBDIR'])
168 conf
.write_config_header('config.h', remove
=False)
172 version_msg
= APPNAME
+ "-" + VERSION
173 if os
.access('version.h', os
.R_OK
):
174 data
= open('version.h').read()
175 m
= re
.match(r
'^#define GIT_VERSION "([^"]*)"$', data
)
177 version_msg
+= " exported from " + m
.group(1)
178 elif os
.access('.git', os
.R_OK
):
179 version_msg
+= " git revision will be checked and eventually updated during build"
182 conf
.msg('Install prefix', conf
.env
['PREFIX'], color
='CYAN')
183 conf
.msg('Library directory', conf
.all_envs
['']['LIBDIR'], color
='CYAN')
184 conf
.msg('Drivers directory', conf
.env
['JACK_DRIVER_DIR'], color
='CYAN')
185 conf
.msg('Internal clients directory', conf
.env
['JACK_INTERNAL_DIR'], color
='CYAN')
187 display_feature(conf
, 'Build debuggable binaries', conf
.env
['BUILD_DEBUG'])
190 ('C compiler flags', ['CFLAGS', 'CPPFLAGS']),
191 ('Linker flags', ['LINKFLAGS', 'LDFLAGS'])
193 for name
, vars in tool_flags
:
196 flags
+= conf
.all_envs
[''][var
]
197 conf
.msg(name
, repr(flags
), color
='NORMAL')
199 conf
.summarize_auto_options()
204 bld
= self
.generator
.bld
205 header
= self
.outputs
[0].abspath()
206 if os
.access('./version.h', os
.R_OK
):
207 header
= os
.path
.join(os
.getcwd(), out
, "version.h")
208 shutil
.copy('./version.h', header
)
209 data
= open(header
).read()
210 m
= re
.match(r
'^#define GIT_VERSION "([^"]*)"$', data
)
212 self
.ver
= m
.group(1)
213 Logs
.pprint('BLUE', "tarball from git revision " + self
.ver
)
218 if bld
.srcnode
.find_node('.git'):
219 self
.ver
= bld
.cmd_and_log("LANG= git rev-parse HEAD", quiet
=Context
.BOTH
).splitlines()[0]
220 if bld
.cmd_and_log("LANG= git diff-index --name-only HEAD", quiet
=Context
.BOTH
).splitlines():
223 Logs
.pprint('BLUE', "git revision " + self
.ver
)
227 fi
= open(header
, 'w')
228 fi
.write('#define GIT_VERSION "%s"\n' % self
.ver
)
233 bld(rule
=git_ver
, target
='version.h', update_outputs
=True, always
=True, ext_out
=['.h'])
243 clientlib
= bld(features
=['c', 'cshlib'])
244 clientlib
.defines
= 'HAVE_CONFIG_H'
245 clientlib
.includes
= includes
246 clientlib
.target
= 'jack'
247 clientlib
.vnum
= bld
.env
['JACK_API_VERSION']
248 clientlib
.install_path
= '${LIBDIR}'
249 clientlib
.use
= ['M', 'DB']
252 "libjack/intclient.c",
253 "libjack/messagebuffer.c",
256 "libjack/midiport.c",
257 "libjack/ringbuffer.c",
261 "libjack/transclient.c",
264 "libjack/metadata.c",
268 '${PREFIX}/include/jack',
288 # process jack.pc.in -> jack.pc
293 install_path
='${PKGCONFDIR}',
294 JACK_VERSION
=VERSION
,
295 INCLUDEDIR
=os
.path
.normpath(bld
.env
['PREFIX'] + '/include'),
296 CLIENTLIB
=clientlib
.target
,
299 serverlib
= bld(features
=['c', 'cshlib'])
300 serverlib
.defines
= ['HAVE_CONFIG_H', 'LIBJACKSERVER']
301 serverlib
.includes
= includes
302 serverlib
.target
= 'jackserver'
303 serverlib
.vnum
= bld
.env
['JACK_API_VERSION']
304 serverlib
.install_path
= '${LIBDIR}'
305 serverlib
.use
= ['M', 'DB']
308 'server/clientengine.c',
309 'server/transengine.c',
310 'server/controlapi.c',
311 'libjack/systemtest.c',
312 'libjack/sanitycheck.c',
315 'libjack/intclient.c',
316 'libjack/messagebuffer.c',
319 'libjack/midiport.c',
320 'libjack/ringbuffer.c',
324 'libjack/transclient.c',
327 "libjack/metadata.c",
330 # process jackserver.pc.in -> jackserver.pc
333 source
='jackserver.pc.in',
334 target
='jackserver.pc',
335 install_path
='${PKGCONFDIR}',
336 JACK_VERSION
=VERSION
,
337 INCLUDEDIR
=os
.path
.normpath(bld
.env
['PREFIX'] + '/include'),
338 SERVERLIB
=serverlib
.target
,
342 features
=['c', 'cshlib'],
343 defines
=['HAVE_CONFIG_H'],
347 install_path
='${JACK_DRIVER_DIR}/')
348 driver
.env
['cshlib_PATTERN'] = '%s.so'
349 driver
.source
= ['drivers/dummy/dummy_driver.c']
351 if bld
.env
['BUILD_DRIVER_ALSA']:
353 features
=['c', 'cshlib'],
354 defines
=['HAVE_CONFIG_H'],
356 use
= ['ALSA', 'serverlib'],
358 install_path
='${JACK_DRIVER_DIR}/')
359 driver
.env
['cshlib_PATTERN'] = '%s.so'
361 'drivers/alsa/alsa_driver.c',
362 'drivers/alsa/generic_hw.c',
363 'drivers/alsa/memops.c',
364 'drivers/alsa/hammerfall.c',
365 'drivers/alsa/hdsp.c',
366 'drivers/alsa/ice1712.c',
367 'drivers/alsa/usx2y.c',
368 # 'drivers/am/alsa_rawmidi.c',
369 # 'drivers/am/alsa_seqmidi.c',
372 if bld
.env
['BUILD_DRIVER_ALSA']:
374 features
=['c', 'cshlib'],
375 defines
=['HAVE_CONFIG_H'],
379 install_path
='${JACK_DRIVER_DIR}/')
380 driver
.env
['cshlib_PATTERN'] = '%s.so'
381 driver
.source
= ['drivers/oss/oss_driver.c']
383 if bld
.env
['BUILD_DRIVER_FFADO']:
385 features
=['c', 'cshlib'],
386 defines
=['HAVE_CONFIG_H'],
388 use
= ['LIBFFADO', 'serverlib'],
390 install_path
='${JACK_DRIVER_DIR}/')
391 driver
.env
['cshlib_PATTERN'] = '%s.so'
392 driver
.source
= ['drivers/firewire/ffado_driver.c']
395 # features=['c', 'cshlib'],
396 # defines=['HAVE_CONFIG_H'],
398 # use = ['ALSA', 'serverlib'],
399 # target='alsa_midi',
400 # install_path='${JACK_DRIVER_DIR}/')
401 # driver.env['cshlib_PATTERN'] = '%s.so'
403 # 'drivers/am/alsa_rawmidi.c',
404 # 'drivers/am/alsa_seqmidi.c',
405 # 'drivers/am/alsa_midi_driver.c',