summaryrefslogtreecommitdiff
path: root/mk/pthread.builtin.mk
diff options
context:
space:
mode:
authorjlam <jlam@pkgsrc.org>2004-11-12 05:20:01 +0000
committerjlam <jlam@pkgsrc.org>2004-11-12 05:20:01 +0000
commit153b3f00b765cb8f2a28c7e20a4cd4ecf1b35404 (patch)
tree0a8964127c35bd31bdaa467333e58d0b937914ab /mk/pthread.builtin.mk
parente5817e65a2d360eb1089f384601e69ec0a54c16e (diff)
downloadpkgsrc-153b3f00b765cb8f2a28c7e20a4cd4ecf1b35404.tar.gz
(1) Split out the native (built-in) pthread detection in
pthread.buildlink3.mk into a separate file, pthread.builtin.mk, that is handled using the usual builtin.mk logic. (2) If pthread.buildlink3.mk is included by a package Makefile, then automatically add the necessary compiler and linker flags to compile and link pthread-enabled/reentrant code. For native pthreads, this means passing -pthread to the compiler and linker. For the userland pthread replacement, we pass -D_REENTRANT and -lpthread instead. (3) Add PTHREAD_{CFLAGS,LDFLAGS,LIBS} in both CONFIGURE_ENV and MAKE_ENV when pthread.buildlink3.mk is included so that the configure and build processes can use these values. Remove these definitions from bsd.pkg.mk since PTHREAD_* variables are all declared within pthread.buildlink3.mk. XXX For now, PTHREAD_LDFLAGS is a superset of PTHREAD_LIBS until XXX packages that use use PTHREAD_LDFLAGS can be fixed.
Diffstat (limited to 'mk/pthread.builtin.mk')
-rw-r--r--mk/pthread.builtin.mk74
1 files changed, 74 insertions, 0 deletions
diff --git a/mk/pthread.builtin.mk b/mk/pthread.builtin.mk
new file mode 100644
index 00000000000..ce64509228a
--- /dev/null
+++ b/mk/pthread.builtin.mk
@@ -0,0 +1,74 @@
+# $NetBSD: pthread.builtin.mk,v 1.1 2004/11/12 05:20:02 jlam Exp $
+
+.if !defined(_BLNK_LIBPTHREAD_FOUND)
+_BLNK_LIBPTHREAD_FOUND!= \
+ if ${TEST} "`${ECHO} /usr/lib/libpthread.*`" = "/usr/lib/libpthread.*"; then \
+ ${ECHO} "no"; \
+ elif ${TEST} "`${ECHO} /lib/libpthread.*`" = "/lib/libpthread.*"; then \
+ ${ECHO} "no"; \
+ else \
+ ${ECHO} "yes"; \
+ fi
+BUILDLINK_VARS+= _BLNK_LIBPTHREAD_FOUND
+.endif
+.if !defined(_BLNK_LIBC_R_FOUND)
+_BLNK_LIBC_R_FOUND!= \
+ if ${TEST} "`${ECHO} /usr/lib/libc_r.*`" = "/usr/lib/libc_r.*"; then \
+ ${ECHO} "no"; \
+ else \
+ ${ECHO} "yes"; \
+ fi
+BUILDLINK_VARS+= _BLNK_LIBC_R_FOUND
+.endif
+
+.if !defined(IS_BUILTIN.pthread)
+IS_BUILTIN.pthread= no
+. if exists(/usr/include/pthread.h)
+IS_BUILTIN.pthread= yes
+. endif
+BUILDLINK_VARS+= IS_BUILTIN.pthread
+.endif # IS_BUILTIN.pthread
+
+# We ignore the value of PREFER_PKGSRC and PREFER_NATIVE. Whether we
+# prefer one or the other is dependent on the value of
+# PREFER_NATIVE_PTHREADS, which is yes/no.
+#
+.if !empty(PREFER_NATIVE_PTHREADS:M[yY][eE][sS])
+USE_BUILTIN.pthread= ${IS_BUILTIN.pthread}
+.else
+USE_BUILTIN.pthread= no
+.endif
+
+CHECK_BUILTIN.pthread?= no
+.if !empty(CHECK_BUILTIN.pthread:M[nN][oO])
+
+.if !empty(USE_BUILTIN.pthread:M[yY][eE][sS])
+BUILDLINK_PREFIX.pthread= /usr
+BUILDLINK_LDFLAGS.pthread= # empty
+
+# only pass -pthread on platforms known to support it.
+# XXX
+# XXX This should really be a check for GCC!
+# XXX
+. if ${OPSYS} == "FreeBSD" || ${OPSYS} == "Linux" || ${OPSYS} == "NetBSD"
+BUILDLINK_CFLAGS.pthread+= -pthread
+BUILDLINK_LDFLAGS.pthread+= -pthread
+. else
+BUILDLINK_CPPFLAGS.pthread+= -D_REENTRANT
+. endif
+
+# Handle systems which have pthreads functions in libc_r such as
+# FreeBSD 5.x, or fall back to libc if we don't find libc_r.
+#
+. if ${OPSYS} == "NetBSD"
+BUILDLINK_LIBS.pthread= # empty
+. elif !empty(_BLNK_LIBPTHREAD_FOUND:M[yY][eE][sS])
+BUILDLINK_LIBS.pthread= -lpthread
+. elif !empty(_BLNK_LIBC_R_FOUND:M[yY][eE][sS])
+BUILDLINK_LIBS.pthread= -lc_r
+. else
+BUILDLINK_LIBS.pthread= # empty
+. endif
+.endif # USE_BUILTIN.pthread
+
+.endif # CHECK_BUILTIN.pthread