Detect pthread support by compiling a test program with the -pthread switch, not just check for the header file.
--- a/src/core/wscript Sat Jan 24 18:47:47 2009 +0000
+++ b/src/core/wscript Sat Jan 24 19:25:33 2009 +0000
@@ -9,7 +9,30 @@
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 <pthread.h>
+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 @@
'unix-system-mutex.cc',
'unix-system-condition.cc',
])
+ core.uselib = 'PTHREAD'
headers.source.extend([
'system-mutex.h',
'system-thread.h',