4 # Copyright (C) 2015-2018 Karl Linden <karl.j.linden@gmail.com>
5 # Copyleft (C) 2008-2022 Nedko Arnaudov
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 from __future__ import print_function
27 from waflib import Logs, Options, TaskGen
28 from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
30 # see also common/JackConstants.h
33 JACK_API_VERSION = '0.1.0'
35 # these variables are mandatory ('/' are converted automatically)
39 def display_feature(conf, msg, build):
41 conf.msg(msg, 'yes', color='GREEN')
43 conf.msg(msg, 'no', color='YELLOW')
47 # options provided by the modules
48 opt.load('compiler_cxx')
49 opt.load('compiler_c')
50 opt.load('autooptions')
57 help='HTML documentation directory [Default: <prefix>/share/jack-audio-connection-kit/reference/html/',
59 opt.add_option('--libdir', type='string', help='Library directory [Default: <prefix>/lib]')
60 opt.add_option('--pkgconfigdir', type='string', help='pkg-config file directory [Default: <libdir>/pkgconfig]')
61 opt.add_option('--mandir', type='string', help='Manpage directory [Default: <prefix>/share/man/man1]')
63 # options affecting binaries
68 help='Target platform for cross-compiling, e.g. cygwin or win32',
70 opt.add_option('--debug', action='store_true', default=False, dest='debug', help='Build debuggable binaries')
72 #opt.set_auto_options_define('HAVE_%s')
73 #opt.set_auto_options_style('yesno_and_hack')
75 # options with third party dependencies
76 #doxygen = opt.add_auto_option(
78 # help='Build doxygen documentation',
79 # conf_dest='BUILD_DOXYGEN_DOCS',
81 #doxygen.find_program('doxygen')
86 # this must be called before the configure phase
87 #opt.apply_auto_options_hack()
90 def detect_platform(conf):
91 # GNU/kFreeBSD and GNU/Hurd are treated as Linux
93 # ('KEY, 'Human readable name', ['strings', 'to', 'check', 'for'])
94 ('IS_LINUX', 'Linux', ['gnu0', 'gnukfreebsd', 'linux', 'posix']),
95 ('IS_FREEBSD', 'FreeBSD', ['freebsd']),
96 ('IS_MACOSX', 'MacOS X', ['darwin']),
97 ('IS_SUN', 'SunOS', ['sunos']),
98 ('IS_WINDOWS', 'Windows', ['cygwin', 'msys', 'win32'])
101 for key, name, strings in platforms:
102 conf.env[key] = False
104 conf.start_msg('Checking platform')
105 platform = Options.options.platform
106 for key, name, strings in platforms:
108 if platform.startswith(s):
110 conf.end_msg(name, color='CYAN')
115 conf.load('compiler_cxx')
116 conf.load('compiler_c')
118 detect_platform(conf)
120 conf.check_cfg(package='jackserver', uselib_store='JACKSERVER', args=["--cflags", "--libs"])
122 conf.check_cfg(package='expat', args='--cflags --libs')
124 conf.env.append_unique('CFLAGS', '-Wall')
125 conf.env.append_unique('CXXFLAGS', ['-Wall', '-Wno-invalid-offsetof'])
126 conf.env.append_unique('CXXFLAGS', '-std=gnu++11')
128 if conf.env['IS_FREEBSD']:
129 conf.check(lib='execinfo', uselib='EXECINFO', define_name='EXECINFO')
130 conf.check_cfg(package='libsysinfo', args='--cflags --libs')
132 if not conf.env['IS_MACOSX']:
133 conf.env.append_unique('LDFLAGS', '-Wl,--no-undefined')
135 conf.check(lib='aften', uselib='AFTEN', define_name='AFTEN')
138 + '#include <aften/aften.h>\n'
142 + 'AftenContext fAftenContext;\n'
143 + 'aften_set_defaults(&fAftenContext);\n'
144 + 'unsigned char *fb;\n'
145 + 'float *buf=new float[10];\n'
146 + 'int res = aften_encode_frame(&fAftenContext, fb, buf, 1);\n'
149 msg='Checking for aften_encode_frame()',
150 define_name='HAVE_AFTEN_NEW_API',
154 conf.env.append_unique('CXXFLAGS', '-Wno-deprecated-register')
156 conf.load('autooptions')
160 conf.env['LIB_PTHREAD'] = ['pthread']
161 conf.env['LIB_DL'] = ['dl']
162 conf.env['LIB_RT'] = ['rt']
163 conf.env['LIB_M'] = ['m']
164 conf.env['LIB_STDC++'] = ['stdc++']
165 conf.env['JACK_API_VERSION'] = JACK_API_VERSION
166 conf.env['JACK_VERSION'] = VERSION
168 conf.env['BINDIR'] = conf.env['PREFIX'] + '/bin'
170 if Options.options.htmldir:
171 conf.env['HTMLDIR'] = Options.options.htmldir
173 # set to None here so that the doxygen code can find out the highest
174 # directory to remove upon install
175 conf.env['HTMLDIR'] = None
177 if Options.options.libdir:
178 conf.env['LIBDIR'] = Options.options.libdir
180 conf.env['LIBDIR'] = conf.env['PREFIX'] + '/lib'
182 if Options.options.pkgconfigdir:
183 conf.env['PKGCONFDIR'] = Options.options.pkgconfigdir
185 conf.env['PKGCONFDIR'] = conf.env['LIBDIR'] + '/pkgconfig'
187 if Options.options.mandir:
188 conf.env['MANDIR'] = Options.options.mandir
190 conf.env['MANDIR'] = conf.env['PREFIX'] + '/share/man/man1'
192 if conf.env['BUILD_DEBUG']:
193 conf.env.append_unique('CXXFLAGS', '-g')
194 conf.env.append_unique('CFLAGS', '-g')
195 conf.env.append_unique('LINKFLAGS', '-g')
197 conf.write_config_header('config.h', remove=False)
200 print('LADI JACK ' + VERSION)
202 conf.msg('Install prefix', conf.env['PREFIX'], color='CYAN')
203 conf.msg('Library directory', conf.all_envs['']['LIBDIR'], color='CYAN')
204 display_feature(conf, 'Build debuggable binaries', conf.env['BUILD_DEBUG'])
207 ('C compiler flags', ['CFLAGS', 'CPPFLAGS']),
208 ('C++ compiler flags', ['CXXFLAGS', 'CPPFLAGS']),
209 ('Linker flags', ['LINKFLAGS', 'LDFLAGS'])
211 for name, vars in tool_flags:
214 flags += conf.all_envs[''][var]
215 conf.msg(name, repr(flags), color='NORMAL')
217 #conf.summarize_auto_options()
219 conf.msg('D-Bus service install directory', conf.env['DBUS_SERVICES_DIR'], color='CYAN')
221 if conf.env['DBUS_SERVICES_DIR'] != conf.env['DBUS_SERVICES_DIR_REAL']:
223 print(Logs.colors.RED + 'WARNING: D-Bus session services directory as reported by pkg-config is')
224 print(Logs.colors.RED + 'WARNING:', end=' ')
225 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR_REAL'])
226 print(Logs.colors.RED + 'WARNING: but service file will be installed in')
227 print(Logs.colors.RED + 'WARNING:', end=' ')
228 print(Logs.colors.CYAN + conf.env['DBUS_SERVICES_DIR'])
230 Logs.colors.RED + 'WARNING: You may need to adjust your D-Bus configuration after installing jackdbus'
232 print('WARNING: You can override dbus service install directory')
233 print('WARNING: with --enable-pkg-config-dbus-service-dir option to this script')
234 print(Logs.colors.NORMAL, end=' ')
239 # process subfolders from here
241 if bld.env['IS_LINUX'] or bld.env['IS_FREEBSD']:
245 if bld.env['BUILD_DOXYGEN_DOCS']:
246 html_build_dir = bld.path.find_or_declare('html').abspath()
250 source='doxyfile.in',
252 HTML_BUILD_DIR=html_build_dir,
253 SRCDIR=bld.srcnode.abspath(),
257 # There are two reasons for logging to doxygen.log and using it as
258 # target in the build rule (rather than html_build_dir):
259 # (1) reduce the noise when running the build
260 # (2) waf has a regular file to check for a timestamp. If the directory
261 # is used instead waf will rebuild the doxygen target (even upon
264 doxyfile = task.inputs[0].abspath()
265 logfile = task.outputs[0].abspath()
266 cmd = '%s %s &> %s' % (task.env['DOXYGEN'][0], doxyfile, logfile)
267 return task.exec_command(cmd)
275 # Determine where to install HTML documentation. Since share_dir is the
276 # highest directory the uninstall routine should remove, there is no
277 # better candidate for share_dir, but the requested HTML directory if
278 # --htmldir is given.
279 if bld.env['HTMLDIR']:
280 html_install_dir = bld.options.destdir + bld.env['HTMLDIR']
281 share_dir = html_install_dir
283 share_dir = bld.options.destdir + bld.env['PREFIX'] + '/share/jack-audio-connection-kit'
284 html_install_dir = share_dir + '/reference/html/'
286 if bld.cmd == 'install':
287 if os.path.isdir(html_install_dir):
288 Logs.pprint('CYAN', 'Removing old doxygen documentation installation...')
289 shutil.rmtree(html_install_dir)
290 Logs.pprint('CYAN', 'Removing old doxygen documentation installation done.')
291 Logs.pprint('CYAN', 'Installing doxygen documentation...')
292 shutil.copytree(html_build_dir, html_install_dir)
293 Logs.pprint('CYAN', 'Installing doxygen documentation done.')
294 elif bld.cmd == 'uninstall':
295 Logs.pprint('CYAN', 'Uninstalling doxygen documentation...')
296 if os.path.isdir(share_dir):
297 shutil.rmtree(share_dir)
298 Logs.pprint('CYAN', 'Uninstalling doxygen documentation done.')
299 elif bld.cmd == 'clean':
300 if os.access(html_build_dir, os.R_OK):
301 Logs.pprint('CYAN', 'Removing doxygen generated documentation...')
302 shutil.rmtree(html_build_dir)
303 Logs.pprint('CYAN', 'Removing doxygen generated documentation done.')
306 @TaskGen.extension('.mm')
307 def mm_hook(self, node):
308 """Alias .mm files to be compiled the same as .cpp files, gcc will do the right thing."""
309 return self.create_compiled_task('cxx', node)