From 4c0ffdacf0215a67a6e007a0f014928d59eeaf4b Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sat, 24 Jan 2009 19:25:33 +0000 Subject: [PATCH] Detect pthread support by compiling a test program with the -pthread switch, not just check for the header file. --- src/core/wscript | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/core/wscript b/src/core/wscript index 879a4c997..b12cb9311 100644 --- a/src/core/wscript +++ b/src/core/wscript @@ -9,7 +9,30 @@ def configure(conf): conf.check(header_name='signal.h', define_name='HAVE_SIGNAL_H') - conf.env['ENABLE_THREADING'] = conf.check(header_name='pthread.h', define_name='HAVE_PTHREAD_H') + # Check for POSIX threads + test_env = conf.env.copy() + test_env.append_value('LINKFLAGS', '-pthread') + test_env.append_value('CXXFLAGS', '-pthread') + test_env.append_value('CCFLAGS', '-pthread') + fragment = """ +#include +int main () +{ + pthread_mutex_t m; + pthread_mutex_init (&m, NULL); + return 0; +} + """ + have_pthread = conf.check(header_name='pthread.h', define_name='HAVE_PTHREAD_H', + env=test_env, fragment=fragment, + errmsg='Could not find pthread support (build/config.log for details)', + mandatory=False) + if have_pthread: + conf.env['CXXFLAGS_PTHREAD'] = '-pthread' + conf.env['CCFLAGS_PTHREAD'] = '-pthread' + conf.env['LINKFLAGS_PTHREAD'] = '-pthread' + + conf.env['ENABLE_THREADING'] = have_pthread conf.report_optional_feature("Threading", "Threading Primitives", conf.env['ENABLE_THREADING'], @@ -112,6 +135,7 @@ def build(bld): 'unix-system-mutex.cc', 'unix-system-condition.cc', ]) + core.uselib = 'PTHREAD' headers.source.extend([ 'system-mutex.h', 'system-thread.h',