summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2014-04-27 09:05:07 +0200
committerwm4 <wm4@nowhere>2014-04-30 11:45:31 +0200
commit9993fd8888a408be17424bed0908f85522aa9467 (patch)
tree8dee8124e84f1ab091ef5a64c524843e802794d6
parentd9c3a51d877433a548c365fa144158d1c09bb6f3 (diff)
downloadmpv-9993fd8888a408be17424bed0908f85522aa9467.tar.bz2
mpv-9993fd8888a408be17424bed0908f85522aa9467.tar.xz
build: use -pthread when available
Our code currently tries to link -lpthread and adds stuff like -D_REENTRANT based on the target platform. GCC actually supports to just pass a -pthread compiler and linker flag that will automatically enable threading and define the correct symbols for the platform, so let's try to just use that as our first choice. clang also supports -pthread but it must be used only as a compiler flag, so we also take care of that scenario with this commit.
-rw-r--r--waftools/checks/custom.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/waftools/checks/custom.py b/waftools/checks/custom.py
index ce9735435d..20b18675db 100644
--- a/waftools/checks/custom.py
+++ b/waftools/checks/custom.py
@@ -8,7 +8,20 @@ __all__ = ["check_pthreads", "check_iconv", "check_lua", "check_oss_4front",
pthreads_program = load_fragment('pthreads.c')
+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
+
def check_pthreads(ctx, dependency_identifier):
+ if check_pthread_flag(ctx, dependency_identifier):
+ return True
platform_cflags = {
'linux': '-D_REENTRANT',
'freebsd': '-D_THREAD_SAFE',