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')
60 help='Enable debug symbols',
61 conf_dest
='BUILD_DEBUG',
67 help='Enable devmode', # enable warnings and treat them as errors
68 conf_dest
='BUILD_DEVMODE',
72 db
= opt
.add_auto_option(
74 help='Use Berkeley DB (metadata)')
75 db
.check(header_name
='db.h')
78 # this must be called before the configure phase
79 opt
.apply_auto_options_hack()
81 def display_feature(conf
, msg
, build
):
83 conf
.msg(msg
, 'yes', color
='GREEN')
85 conf
.msg(msg
, 'no', color
='YELLOW')
88 conf
.load('compiler_c')
89 conf
.load('waf_autooptions')
91 conf
.env
['JACK_API_VERSION'] = JACK_API_VERSION
93 flags
= WafToolchainFlags(conf
)
95 if Options
.options
.libdir
:
96 conf
.env
['LIBDIR'] = Options
.options
.libdir
98 conf
.env
['LIBDIR'] = conf
.env
['PREFIX'] + '/lib64'
100 if Options
.options
.pkgconfigdir
:
101 conf
.env
['PKGCONFDIR'] = Options
.options
.pkgconfigdir
103 conf
.env
['PKGCONFDIR'] = conf
.env
['LIBDIR'] + '/pkgconfig'
105 conf
.env
['JACK_DRIVER_DIR'] = os
.path
.normpath(
106 os
.path
.join(conf
.env
['PREFIX'],
109 conf
.env
['JACK_INTERNAL_DIR'] = os
.path
.normpath(
110 os
.path
.join(conf
.env
['PREFIX'],
113 conf
.define('JACK_DRIVER_DIR', conf
.env
['JACK_DRIVER_DIR'])
114 conf
.define('JACK_INTERNAL_DIR', conf
.env
['JACK_INTERNAL_DIR'])
116 conf
.check_cfg(package
='expat', args
='--cflags --libs')
117 conf
.env
['LIB_M'] = ['m']
119 flags
.add_c('-std=gnu99')
120 if conf
.env
['BUILD_DEVMODE']:
121 flags
.add_c(['-Wall', '-Wextra'])
122 flags
.add_c('-Wpedantic')
123 flags
.add_c('-Werror')
124 flags
.add_c(['-Wno-variadic-macros', '-Wno-gnu-zero-variadic-macro-arguments'])
126 # https://wiki.gentoo.org/wiki/Modern_C_porting
127 if conf
.env
['CC'] == 'clang':
128 flags
.add_c('-Wno-unknown-argumemt')
129 flags
.add_c('-Werror=implicit-function-declaration')
130 flags
.add_c('-Werror=incompatible-function-pointer-types')
131 flags
.add_c('-Werror=deprecated-non-prototype')
132 flags
.add_c('-Werror=strict-prototypes')
133 if int(conf
.env
['CC_VERSION'][0]) < 16:
134 flags
.add_c('-Werror=implicit-int')
136 flags
.add_c('-Wno-unknown-warning-option')
137 flags
.add_c('-Werror=implicit-function-declaration')
138 flags
.add_c('-Werror=implicit-int')
139 flags
.add_c('-Werror=incompatible-pointer-types')
140 flags
.add_c('-Werror=strict-prototypes')
141 if conf
.env
['BUILD_DEBUG']:
142 flags
.add_c(['-O0', '-g', '-fno-omit-frame-pointer'])
145 conf
.define('JACK_THREAD_STACK_TOUCH', 500000)
146 conf
.define('jack_protocol_version', 24)
147 conf
.define('JACK_SHM_TYPE', 'System V')
148 conf
.define('USE_POSIX_SHM', 0)
149 conf
.define('DEFAULT_TMP_DIR', '/dev/shm')
150 conf
.define('JACK_SEMAPHORE_KEY', 0x282929)
151 conf
.define('JACK_DEFAULT_DRIVER', 'dummy')
152 conf
.define('JACK_VERSION', VERSION
)
153 conf
.define('LIBDIR', conf
.env
['LIBDIR'])
154 conf
.write_config_header('config.h', remove
=False)
158 version_msg
= APPNAME
+ "-" + VERSION
159 if os
.access('version.h', os
.R_OK
):
160 data
= open('version.h').read()
161 m
= re
.match(r
'^#define GIT_VERSION "([^"]*)"$', data
)
163 version_msg
+= " exported from " + m
.group(1)
164 elif os
.access('.git', os
.R_OK
):
165 version_msg
+= " git revision will be checked and eventually updated during build"
168 conf
.msg('Install prefix', conf
.env
['PREFIX'], color
='CYAN')
169 conf
.msg('Library directory', conf
.all_envs
['']['LIBDIR'], color
='CYAN')
170 conf
.msg('Drivers directory', conf
.env
['JACK_DRIVER_DIR'], color
='CYAN')
171 conf
.msg('Internal clients directory', conf
.env
['JACK_INTERNAL_DIR'], color
='CYAN')
173 display_feature(conf
, 'Build debuggable binaries', conf
.env
['BUILD_DEBUG'])
176 ('C compiler flags', ['CFLAGS', 'CPPFLAGS']),
177 ('Linker flags', ['LINKFLAGS', 'LDFLAGS'])
179 for name
, vars in tool_flags
:
182 flags
+= conf
.all_envs
[''][var
]
183 conf
.msg(name
, repr(flags
), color
='NORMAL')
185 conf
.summarize_auto_options()
190 bld
= self
.generator
.bld
191 header
= self
.outputs
[0].abspath()
192 if os
.access('./version.h', os
.R_OK
):
193 header
= os
.path
.join(os
.getcwd(), out
, "version.h")
194 shutil
.copy('./version.h', header
)
195 data
= open(header
).read()
196 m
= re
.match(r
'^#define GIT_VERSION "([^"]*)"$', data
)
198 self
.ver
= m
.group(1)
199 Logs
.pprint('BLUE', "tarball from git revision " + self
.ver
)
204 if bld
.srcnode
.find_node('.git'):
205 self
.ver
= bld
.cmd_and_log("LANG= git rev-parse HEAD", quiet
=Context
.BOTH
).splitlines()[0]
206 if bld
.cmd_and_log("LANG= git diff-index --name-only HEAD", quiet
=Context
.BOTH
).splitlines():
209 Logs
.pprint('BLUE', "git revision " + self
.ver
)
213 fi
= open(header
, 'w')
214 fi
.write('#define GIT_VERSION "%s"\n' % self
.ver
)
219 bld(rule
=git_ver
, target
='version.h', update_outputs
=True, always
=True, ext_out
=['.h'])
229 clientlib
= bld(features
=['c', 'cshlib'])
230 clientlib
.defines
= 'HAVE_CONFIG_H'
231 clientlib
.includes
= includes
232 clientlib
.target
= 'jack'
233 clientlib
.vnum
= bld
.env
['JACK_API_VERSION']
234 clientlib
.install_path
= '${LIBDIR}'
235 clientlib
.use
= ['M', 'DB']
238 "libjack/intclient.c",
239 "libjack/messagebuffer.c",
242 "libjack/midiport.c",
243 "libjack/ringbuffer.c",
247 "libjack/transclient.c",
250 "libjack/metadata.c",
254 '${PREFIX}/include/jack',
274 # process jack.pc.in -> jack.pc
279 install_path
='${PKGCONFDIR}',
280 JACK_VERSION
=VERSION
,
281 INCLUDEDIR
=os
.path
.normpath(bld
.env
['PREFIX'] + '/include'),
282 CLIENTLIB
=clientlib
.target
,
285 serverlib
= bld(features
=['c', 'cshlib'])
286 serverlib
.defines
= ['HAVE_CONFIG_H', 'LIBJACKSERVER']
287 serverlib
.includes
= includes
288 serverlib
.target
= 'jackserver'
289 serverlib
.vnum
= bld
.env
['JACK_API_VERSION']
290 serverlib
.install_path
= '${LIBDIR}'
291 serverlib
.use
= ['M', 'DB']
294 'server/clientengine.c',
295 'server/transengine.c',
296 'server/controlapi.c',
297 'libjack/systemtest.c',
298 'libjack/sanitycheck.c',
301 'libjack/intclient.c',
302 'libjack/messagebuffer.c',
305 'libjack/midiport.c',
306 'libjack/ringbuffer.c',
310 'libjack/transclient.c',
313 "libjack/metadata.c",
316 # process jackserver.pc.in -> jackserver.pc
319 source
='jackserver.pc.in',
320 target
='jackserver.pc',
321 install_path
='${PKGCONFDIR}',
322 JACK_VERSION
=VERSION
,
323 INCLUDEDIR
=os
.path
.normpath(bld
.env
['PREFIX'] + '/include'),
324 SERVERLIB
=serverlib
.target
,
328 features
=['c', 'cshlib'],
329 defines
=['HAVE_CONFIG_H'],
333 install_path
='${JACK_DRIVER_DIR}/')
334 driver
.env
['cshlib_PATTERN'] = '%s.so'
335 driver
.source
= ['drivers/dummy/dummy_driver.c']
338 features
=['c', 'cshlib'],
339 defines
=['HAVE_CONFIG_H'],
341 use
= ['ALSA', 'serverlib'],
343 install_path
='${JACK_DRIVER_DIR}/')
344 driver
.env
['cshlib_PATTERN'] = '%s.so'
346 'drivers/alsa/alsa_driver.c',
347 'drivers/alsa/generic_hw.c',
348 'drivers/alsa/memops.c',
349 'drivers/alsa/hammerfall.c',
350 'drivers/alsa/hdsp.c',
351 'drivers/alsa/ice1712.c',
352 'drivers/alsa/usx2y.c',
353 # 'drivers/am/alsa_rawmidi.c',
354 # 'drivers/am/alsa_seqmidi.c',
358 features
=['c', 'cshlib'],
359 defines
=['HAVE_CONFIG_H'],
363 install_path
='${JACK_DRIVER_DIR}/')
364 driver
.env
['cshlib_PATTERN'] = '%s.so'
365 driver
.source
= ['drivers/oss/oss_driver.c']
368 # features=['c', 'cshlib'],
369 # defines=['HAVE_CONFIG_H'],
371 # use = ['ALSA', 'serverlib'],
372 # target='alsa_midi',
373 # install_path='${JACK_DRIVER_DIR}/')
374 # driver.env['cshlib_PATTERN'] = '%s.so'
376 # 'drivers/am/alsa_rawmidi.c',
377 # 'drivers/am/alsa_seqmidi.c',
378 # 'drivers/am/alsa_midi_driver.c',