CI: build on ubuntu 18.04 and ubuntu 22.04
[jackdbus.git] / wscript
blobabb585913b9f183a40fe79a2cee3eebda98e01ff
1 #! /usr/bin/python3
2 # encoding: utf-8
3 from __future__ import print_function
5 import os
6 import shutil
7 import sys
9 from waflib import Logs, Options, TaskGen
10 from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
12 # see also common/JackConstants.h
13 VERSION = '2.21'
14 APPNAME = 'jack'
15 JACK_API_VERSION = '0.1.0'
17 # these variables are mandatory ('/' are converted automatically)
18 top = '.'
19 out = 'build'
21 def display_feature(conf, msg, build):
22     if build:
23         conf.msg(msg, 'yes', color='GREEN')
24     else:
25         conf.msg(msg, 'no', color='YELLOW')
28 def options(opt):
29     # options provided by the modules
30     opt.load('compiler_cxx')
31     opt.load('compiler_c')
32     opt.load('autooptions')
34     # install directories
35     opt.add_option(
36         '--htmldir',
37         type='string',
38         default=None,
39         help='HTML documentation directory [Default: <prefix>/share/jack-audio-connection-kit/reference/html/',
40     )
41     opt.add_option('--libdir', type='string', help='Library directory [Default: <prefix>/lib]')
42     opt.add_option('--pkgconfigdir', type='string', help='pkg-config file directory [Default: <libdir>/pkgconfig]')
43     opt.add_option('--mandir', type='string', help='Manpage directory [Default: <prefix>/share/man/man1]')
45     # options affecting binaries
46     opt.add_option(
47         '--platform',
48         type='string',
49         default=sys.platform,
50         help='Target platform for cross-compiling, e.g. cygwin or win32',
51     )
52     opt.add_option('--debug', action='store_true', default=False, dest='debug', help='Build debuggable binaries')
54     #opt.set_auto_options_define('HAVE_%s')
55     #opt.set_auto_options_style('yesno_and_hack')
57     # options with third party dependencies
58     #doxygen = opt.add_auto_option(
59     #        'doxygen',
60     #        help='Build doxygen documentation',
61     #        conf_dest='BUILD_DOXYGEN_DOCS',
62     #        default=False)
63     #doxygen.find_program('doxygen')
65     # dbus options
66     opt.recurse('dbus')
68     # this must be called before the configure phase
69     #opt.apply_auto_options_hack()
72 def detect_platform(conf):
73     # GNU/kFreeBSD and GNU/Hurd are treated as Linux
74     platforms = [
75         # ('KEY, 'Human readable name', ['strings', 'to', 'check', 'for'])
76         ('IS_LINUX',   'Linux',   ['gnu0', 'gnukfreebsd', 'linux', 'posix']),
77         ('IS_FREEBSD', 'FreeBSD', ['freebsd']),
78         ('IS_MACOSX',  'MacOS X', ['darwin']),
79         ('IS_SUN',     'SunOS',   ['sunos']),
80         ('IS_WINDOWS', 'Windows', ['cygwin', 'msys', 'win32'])
81     ]
83     for key, name, strings in platforms:
84         conf.env[key] = False
86     conf.start_msg('Checking platform')
87     platform = Options.options.platform
88     for key, name, strings in platforms:
89         for s in strings:
90             if platform.startswith(s):
91                 conf.env[key] = True
92                 conf.end_msg(name, color='CYAN')
93                 break
96 def configure(conf):
97     conf.load('compiler_cxx')
98     conf.load('compiler_c')
100     detect_platform(conf)
102     conf.check_cfg(package='jackserver', uselib_store='JACKSERVER', args=["--cflags", "--libs"])
104     conf.check_cfg(package='expat', args='--cflags --libs')
106     conf.env.append_unique('CFLAGS', '-Wall')
107     conf.env.append_unique('CXXFLAGS', ['-Wall', '-Wno-invalid-offsetof'])
108     conf.env.append_unique('CXXFLAGS', '-std=gnu++11')
110     if conf.env['IS_FREEBSD']:
111         conf.check(lib='execinfo', uselib='EXECINFO', define_name='EXECINFO')
112         conf.check_cfg(package='libsysinfo', args='--cflags --libs')
114     if not conf.env['IS_MACOSX']:
115         conf.env.append_unique('LDFLAGS', '-Wl,--no-undefined')
116     else:
117         conf.check(lib='aften', uselib='AFTEN', define_name='AFTEN')
118         conf.check_cxx(
119             fragment=''
120             + '#include <aften/aften.h>\n'
121             + 'int\n'
122             + 'main(void)\n'
123             + '{\n'
124             + 'AftenContext fAftenContext;\n'
125             + 'aften_set_defaults(&fAftenContext);\n'
126             + 'unsigned char *fb;\n'
127             + 'float *buf=new float[10];\n'
128             + 'int res = aften_encode_frame(&fAftenContext, fb, buf, 1);\n'
129             + '}\n',
130             lib='aften',
131             msg='Checking for aften_encode_frame()',
132             define_name='HAVE_AFTEN_NEW_API',
133             mandatory=False)
135         # TODO
136         conf.env.append_unique('CXXFLAGS', '-Wno-deprecated-register')
138     conf.load('autooptions')
140     conf.recurse('dbus')
142     conf.env['LIB_PTHREAD'] = ['pthread']
143     conf.env['LIB_DL'] = ['dl']
144     conf.env['LIB_RT'] = ['rt']
145     conf.env['LIB_M'] = ['m']
146     conf.env['LIB_STDC++'] = ['stdc++']
147     conf.env['JACK_API_VERSION'] = JACK_API_VERSION
148     conf.env['JACK_VERSION'] = VERSION
150     conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin'
152     if Options.options.htmldir:
153         conf.env['HTMLDIR'] = Options.options.htmldir
154     else:
155         # set to None here so that the doxygen code can find out the highest
156         # directory to remove upon install
157         conf.env['HTMLDIR'] = None
159     if Options.options.libdir:
160         conf.env['LIBDIR'] = Options.options.libdir
161     else:
162         conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
164     if Options.options.pkgconfigdir:
165         conf.env['PKGCONFDIR'] = Options.options.pkgconfigdir
166     else:
167         conf.env['PKGCONFDIR'] = conf.env['LIBDIR'] + '/pkgconfig'
169     if Options.options.mandir:
170         conf.env['MANDIR'] = Options.options.mandir
171     else:
172         conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
174     if conf.env['BUILD_DEBUG']:
175         conf.env.append_unique('CXXFLAGS', '-g')
176         conf.env.append_unique('CFLAGS', '-g')
177         conf.env.append_unique('LINKFLAGS', '-g')
179     conf.write_config_header('config.h', remove=False)
181     print()
182     print('LADI JACK ' + VERSION)
184     conf.msg('Install prefix', conf.env['PREFIX'], color='CYAN')
185     conf.msg('Library directory', conf.all_envs['']['LIBDIR'], color='CYAN')
186     display_feature(conf, 'Build debuggable binaries', conf.env['BUILD_DEBUG'])
188     tool_flags = [
189         ('C compiler flags',   ['CFLAGS', 'CPPFLAGS']),
190         ('C++ compiler flags', ['CXXFLAGS', 'CPPFLAGS']),
191         ('Linker flags',       ['LINKFLAGS', 'LDFLAGS'])
192     ]
193     for name, vars in tool_flags:
194         flags = []
195         for var in vars:
196             flags += conf.all_envs[''][var]
197         conf.msg(name, repr(flags), color='NORMAL')
199     #conf.summarize_auto_options()
201     conf.msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], color='CYAN')
203     if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
204         print()
205         print(Logs.colors.RED + 'WARNING: D-Bus session services directory as reported by pkg-config is')
206         print(Logs.colors.RED + 'WARNING:', end=' ')
207         print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
208         print(Logs.colors.RED + 'WARNING: but service file will be installed in')
209         print(Logs.colors.RED + 'WARNING:', end=' ')
210         print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
211         print(
212             Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus'
213             )
214         print('WARNING: You can override dbus service install directory')
215         print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
216         print(Logs.colors.NORMAL, end=' ')
217     print()
220 def build(bld):
221     # process subfolders from here
223     if bld.env['IS_LINUX'] or bld.env['IS_FREEBSD']:
224         bld.recurse('man')
225     bld.recurse('dbus')
227     if bld.env['BUILD_DOXYGEN_DOCS']:
228         html_build_dir = bld.path.find_or_declare('html').abspath()
230         bld(
231             features='subst',
232             source='doxyfile.in',
233             target='doxyfile',
234             HTML_BUILD_DIR=html_build_dir,
235             SRCDIR=bld.srcnode.abspath(),
236             VERSION=VERSION
237         )
239         # There are two reasons for logging to doxygen.log and using it as
240         # target in the build rule (rather than html_build_dir):
241         # (1) reduce the noise when running the build
242         # (2) waf has a regular file to check for a timestamp. If the directory
243         #     is used instead waf will rebuild the doxygen target (even upon
244         #     install).
245         def doxygen(task):
246             doxyfile = task.inputs[0].abspath()
247             logfile = task.outputs[0].abspath()
248             cmd = '%s %s &> %s' % (task.env['DOXYGEN'][0], doxyfile, logfile)
249             return task.exec_command(cmd)
251         bld(
252             rule=doxygen,
253             source='doxyfile',
254             target='doxygen.log'
255         )
257         # Determine where to install HTML documentation. Since share_dir is the
258         # highest directory the uninstall routine should remove, there is no
259         # better candidate for share_dir, but the requested HTML directory if
260         # --htmldir is given.
261         if bld.env['HTMLDIR']:
262             html_install_dir = bld.options.destdir + bld.env['HTMLDIR']
263             share_dir = html_install_dir
264         else:
265             share_dir = bld.options.destdir + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
266             html_install_dir = share_dir + '/reference/html/'
268         if bld.cmd == 'install':
269             if os.path.isdir(html_install_dir):
270                 Logs.pprint('CYAN', 'Removing old doxygen documentation installation...')
271                 shutil.rmtree(html_install_dir)
272                 Logs.pprint('CYAN', 'Removing old doxygen documentation installation done.')
273             Logs.pprint('CYAN', 'Installing doxygen documentation...')
274             shutil.copytree(html_build_dir, html_install_dir)
275             Logs.pprint('CYAN', 'Installing doxygen documentation done.')
276         elif bld.cmd == 'uninstall':
277             Logs.pprint('CYAN', 'Uninstalling doxygen documentation...')
278             if os.path.isdir(share_dir):
279                 shutil.rmtree(share_dir)
280             Logs.pprint('CYAN', 'Uninstalling doxygen documentation done.')
281         elif bld.cmd == 'clean':
282             if os.access(html_build_dir, os.R_OK):
283                 Logs.pprint('CYAN', 'Removing doxygen generated documentation...')
284                 shutil.rmtree(html_build_dir)
285                 Logs.pprint('CYAN', 'Removing doxygen generated documentation done.')
288 @TaskGen.extension('.mm')
289 def mm_hook(self, node):
290     """Alias .mm files to be compiled the same as .cpp files, gcc will do the right thing."""
291     return self.create_compiled_task('cxx', node)