2013-12-07 15:58:22 +00:00
|
|
|
from waftools.inflectors import DependencyInflector
|
2013-07-16 11:28:28 +00:00
|
|
|
from waftools.checks.generic import *
|
2013-11-29 08:01:14 +00:00
|
|
|
from waflib import Utils
|
|
|
|
import os
|
2013-07-16 11:28:28 +00:00
|
|
|
|
2014-01-02 19:34:14 +00:00
|
|
|
__all__ = ["check_pthreads", "check_iconv", "check_lua", "check_oss_4front",
|
|
|
|
"check_cocoa"]
|
2013-07-16 11:28:28 +00:00
|
|
|
|
|
|
|
pthreads_program = load_fragment('pthreads.c')
|
|
|
|
|
2014-04-27 07:05:07 +00:00
|
|
|
def check_pthread_flag(ctx, dependency_identifier):
|
|
|
|
checks = [
|
|
|
|
check_cc(fragment = pthreads_program, cflags = '-pthread'),
|
|
|
|
check_cc(fragment = pthreads_program, cflags = '-pthread',
|
|
|
|
linkflags = '-pthread') ]
|
|
|
|
|
|
|
|
for fn in checks:
|
|
|
|
if fn(ctx, dependency_identifier):
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2013-07-16 11:28:28 +00:00
|
|
|
def check_pthreads(ctx, dependency_identifier):
|
2014-04-27 07:05:07 +00:00
|
|
|
if check_pthread_flag(ctx, dependency_identifier):
|
|
|
|
return True
|
2013-07-16 11:28:28 +00:00
|
|
|
platform_cflags = {
|
|
|
|
'linux': '-D_REENTRANT',
|
|
|
|
'freebsd': '-D_THREAD_SAFE',
|
|
|
|
'netbsd': '-D_THREAD_SAFE',
|
|
|
|
'openbsd': '-D_THREAD_SAFE',
|
|
|
|
'win32': '-DPTW32_STATIC_LIB',
|
|
|
|
}.get(ctx.env.DEST_OS, '')
|
|
|
|
libs = ['pthreadGC2', 'pthread']
|
|
|
|
checkfn = check_cc(fragment=pthreads_program, cflags=platform_cflags)
|
2013-11-26 13:16:29 +00:00
|
|
|
checkfn_nocflags = check_cc(fragment=pthreads_program)
|
|
|
|
for fn in [checkfn, checkfn_nocflags]:
|
|
|
|
if check_libs(libs, fn)(ctx, dependency_identifier):
|
|
|
|
return True
|
|
|
|
return False
|
2013-07-16 11:28:28 +00:00
|
|
|
|
|
|
|
def check_iconv(ctx, dependency_identifier):
|
|
|
|
iconv_program = load_fragment('iconv.c')
|
|
|
|
libdliconv = " ".join(ctx.env.LIB_LIBDL + ['iconv'])
|
|
|
|
libs = ['iconv', libdliconv]
|
|
|
|
checkfn = check_cc(fragment=iconv_program)
|
|
|
|
return check_libs(libs, checkfn)(ctx, dependency_identifier)
|
|
|
|
|
|
|
|
def check_lua(ctx, dependency_identifier):
|
2013-11-23 14:45:38 +00:00
|
|
|
if ctx.dependency_satisfied('libquvi4'):
|
|
|
|
quvi_lib_storage = [ 'libquvi4' ]
|
2013-07-16 11:28:28 +00:00
|
|
|
additional_lua_test_header = '#include <quvi/quvi.h>'
|
|
|
|
additional_lua_test_code = load_fragment('lua_libquvi4.c')
|
2013-11-23 14:45:38 +00:00
|
|
|
elif ctx.dependency_satisfied('libquvi9'):
|
|
|
|
quvi_lib_storage = [ 'libquvi9' ]
|
2013-07-16 11:28:28 +00:00
|
|
|
additional_lua_test_header = '#include <quvi.h>'
|
|
|
|
additional_lua_test_code = load_fragment('lua_libquvi9.c')
|
|
|
|
else:
|
2013-11-23 14:45:38 +00:00
|
|
|
quvi_lib_storage = []
|
2013-07-16 11:28:28 +00:00
|
|
|
additional_lua_test_header = ''
|
|
|
|
additional_lua_test_code = ''
|
|
|
|
|
|
|
|
fragment = load_fragment('lua.c').format(
|
2013-11-23 14:45:38 +00:00
|
|
|
additional_lua_test_header=additional_lua_test_header,
|
|
|
|
additional_lua_test_code=additional_lua_test_code)
|
2013-07-16 11:28:28 +00:00
|
|
|
|
|
|
|
lua_versions = [
|
|
|
|
( '51', 'lua >= 5.1.0 lua < 5.2.0'),
|
|
|
|
( '51deb', 'lua5.1 >= 5.1.0'), # debian
|
2014-01-14 22:49:26 +00:00
|
|
|
( '51fbsd', 'lua-5.1 >= 5.1.0'), # FreeBSD
|
2013-07-16 11:28:28 +00:00
|
|
|
( 'luajit', 'luajit >= 2.0.0' ),
|
|
|
|
# assume all our dependencies (libquvi in particular) link with 5.1
|
|
|
|
( '52', 'lua >= 5.2.0' ),
|
|
|
|
( '52deb', 'lua5.2 >= 5.2.0'), # debian
|
2014-01-14 22:49:26 +00:00
|
|
|
( '52fbsd', 'lua-5.2 >= 5.2.0'), # FreeBSD
|
2013-07-16 11:28:28 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
if ctx.options.LUA_VER:
|
|
|
|
lua_versions = \
|
|
|
|
[lv for lv in lua_versions if lv[0] == ctx.options.LUA_VER]
|
|
|
|
|
|
|
|
for lua_version, pkgconfig_query in lua_versions:
|
2013-12-04 17:57:29 +00:00
|
|
|
if compose_checks(
|
2013-07-16 11:28:28 +00:00
|
|
|
check_pkg_config(pkgconfig_query, uselib_store=lua_version),
|
2013-11-23 15:03:48 +00:00
|
|
|
check_cc(fragment=fragment,
|
|
|
|
use=[lua_version] + quvi_lib_storage,
|
|
|
|
execute=True))(ctx, dependency_identifier):
|
2013-07-16 11:28:28 +00:00
|
|
|
# XXX: this is a bit of a hack, ask waf developers if I can copy
|
|
|
|
# the uselib_store to 'lua'
|
|
|
|
ctx.mark_satisfied(lua_version)
|
|
|
|
ctx.add_optional_message(dependency_identifier,
|
|
|
|
'version found: ' + lua_version)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2013-11-29 08:01:14 +00:00
|
|
|
def __get_osslibdir():
|
2013-11-26 20:32:38 +00:00
|
|
|
cmd = ['sh', '-c', '. /etc/oss.conf && echo $OSSLIBDIR']
|
|
|
|
p = Utils.subprocess.Popen(cmd, stdin=Utils.subprocess.PIPE,
|
|
|
|
stdout=Utils.subprocess.PIPE,
|
|
|
|
stderr=Utils.subprocess.PIPE)
|
|
|
|
return p.communicate()[0].decode().rstrip()
|
2013-07-16 11:28:28 +00:00
|
|
|
|
2013-11-29 08:01:14 +00:00
|
|
|
def check_oss_4front(ctx, dependency_identifier):
|
|
|
|
oss_libdir = __get_osslibdir()
|
2013-07-16 11:28:28 +00:00
|
|
|
|
2013-12-07 15:58:22 +00:00
|
|
|
# avoid false positive from native sys/soundcard.h
|
|
|
|
if not oss_libdir:
|
|
|
|
defkey = DependencyInflector(dependency_identifier).define_key()
|
|
|
|
ctx.undefine(defkey)
|
|
|
|
return False
|
|
|
|
|
2013-11-29 08:01:14 +00:00
|
|
|
soundcard_h = os.path.join(oss_libdir, "include/sys/soundcard.h")
|
|
|
|
include_dir = os.path.join(oss_libdir, "include")
|
2013-07-16 11:28:28 +00:00
|
|
|
|
2013-11-29 08:01:14 +00:00
|
|
|
fn = check_cc(header_name=soundcard_h,
|
|
|
|
defines=['PATH_DEV_DSP="/dev/dsp"',
|
|
|
|
'PATH_DEV_MIXER="/dev/mixer"'],
|
|
|
|
cflags='-I{0}'.format(include_dir),
|
|
|
|
fragment=load_fragment('oss_audio.c'))
|
2013-07-16 11:28:28 +00:00
|
|
|
|
2013-11-29 08:01:14 +00:00
|
|
|
return fn(ctx, dependency_identifier)
|
2014-01-02 19:34:14 +00:00
|
|
|
|
|
|
|
def check_cocoa(ctx, dependency_identifier):
|
|
|
|
fn = check_cc(
|
|
|
|
fragment = load_fragment('cocoa.m'),
|
|
|
|
compile_filename = 'test.m',
|
|
|
|
framework_name = ['Cocoa', 'IOKit', 'OpenGL'],
|
|
|
|
includes = ctx.srcnode.abspath(),
|
|
|
|
linkflags = '-fobjc-arc')
|
|
|
|
|
|
|
|
return fn(ctx, dependency_identifier)
|