summaryrefslogtreecommitdiff
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
commit2bf44dfd4f429cf7b1ae4e4c042dd369e8c842e5 (patch)
tree0a8964127c35bd31bdaa467333e58d0b937914ab
parent331a32358715ff022133ec021156cd72886b7fdd (diff)
downloadpkgsrc-2bf44dfd4f429cf7b1ae4e4c042dd369e8c842e5.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.
-rw-r--r--mk/bsd.pkg.mk6
-rw-r--r--mk/pthread.buildlink3.mk71
-rw-r--r--mk/pthread.builtin.mk74
3 files changed, 101 insertions, 50 deletions
diff --git a/mk/bsd.pkg.mk b/mk/bsd.pkg.mk
index efde626582f..1b45f4de652 100644
--- a/mk/bsd.pkg.mk
+++ b/mk/bsd.pkg.mk
@@ -1,4 +1,4 @@
-# $NetBSD: bsd.pkg.mk,v 1.1534 2004/11/12 02:05:20 tv Exp $
+# $NetBSD: bsd.pkg.mk,v 1.1535 2004/11/12 05:20:01 jlam Exp $
#
# This file is in the public domain.
#
@@ -475,10 +475,6 @@ MAKE_ENV+= CPP="${CPP}"
MAKE_ENV+= CXXFLAGS="${CXXFLAGS}"
.endif
-# export the flags needed to compile and link pthreaded code
-MAKE_ENV+= PTHREAD_CFLAGS="${PTHREAD_CFLAGS}"
-MAKE_ENV+= PTHREAD_LDFLAGS="${PTHREAD_LDFLAGS}"
-
TOUCH_FLAGS?= -f
# determine if we need a working patch(1).
diff --git a/mk/pthread.buildlink3.mk b/mk/pthread.buildlink3.mk
index 8e665c899f8..f6585ab4991 100644
--- a/mk/pthread.buildlink3.mk
+++ b/mk/pthread.buildlink3.mk
@@ -1,4 +1,4 @@
-# $NetBSD: pthread.buildlink3.mk,v 1.13 2004/11/10 18:46:07 jlam Exp $
+# $NetBSD: pthread.buildlink3.mk,v 1.14 2004/11/12 05:20:01 jlam Exp $
#
# The pthreads strategy for pkgsrc is to "bless" a particular pthread
# package as the Official Pthread Replacement (OPR). A package that uses
@@ -118,7 +118,8 @@ PTHREAD_OPTS?= # empty
#
.undef PTHREAD_TYPE
PREFER_NATIVE_PTHREADS?= YES
-.if exists(/usr/include/pthread.h) && ${PREFER_NATIVE_PTHREADS} == "YES"
+.if exists(/usr/include/pthread.h) && \
+ !empty(PREFER_NATIVE_PTHREADS:M[yY][eE][sS])
PTHREAD_TYPE= native
.else
. if !empty(PTHREAD_OPTS:Mnative)
@@ -141,52 +142,22 @@ PKG_SKIP_REASON= "${PKGNAME} requires a working pthreads implementation."
.endif
.if ${PTHREAD_TYPE} == "native"
-#
-# Link the native pthread libraries and headers into ${BUILDLINK_DIR}.
-#
-BUILDLINK_PREFIX.pthread= /usr
-BUILDLINK_LDFLAGS.pthread= # empty
-
-# only pass -pthread on platforms known to support it.
-. if ${OPSYS} == "FreeBSD" || ${OPSYS} == "Linux" || ${OPSYS} == "NetBSD"
-BUILDLINK_CFLAGS.pthread= -pthread
-. else
-BUILDLINK_CFLAGS.pthread= # empty
-. 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 exists(/usr/lib/libpthread.so) || exists(/lib/libpthread.so)
-BUILDLINK_LDADD.pthread= -lpthread
-. elif exists(/usr/lib/libc_r.so)
-BUILDLINK_LDADD.pthread= -lc_r
-# In OpenBSD there is no libpthread.so, just libpthread.so.X.X.
-. elif ${OPSYS} == "OpenBSD"
-_CHECK_LIBPTH!= \
- if ${TEST} -f /usr/lib/libpthread.so.*; then \
- ${ECHO} "yes"; \
- else \
- ${ECHO} "no"; \
- fi
-. if ${_CHECK_LIBPTH} == "yes"
-BUILDLINK_LDADD.pthread= -lpthread
-. endif
-. else
-BUILDLINK_LDADD.pthread= # empty
-. endif
-
+BUILDLINK_PACKAGES:= ${BUILDLINK_PACKAGES:Npthread}
+BUILDLINK_PACKAGES+= pthread
+BUILDLINK_BUILTIN_MK.pthread= ../../mk/pthread.builtin.mk
.elif ${PTHREAD_TYPE} == "${_PKG_PTHREAD}"
. if exists(${_PKG_PTHREAD_BUILDLINK3_MK})
. if !empty(_PKG_PTHREAD_DEPENDS)
BUILDLINK_DEPENDS.${_PKG_PTHREAD}+= ${_PKG_PTHREAD_DEPENDS}
. endif
-BUILDLINK_PREFIX.pthread= ${BUILDLINK_PREFIX.${_PKG_PTHREAD}}
-BUILDLINK_CFLAGS.pthread= ${BUILDLINK_CFLAGS.${_PKG_PTHREAD}}
-BUILDLINK_LDFLAGS.pthread= ${BUILDLINK_LDFLAGS.${_PKG_PTHREAD}}
-BUILDLINK_LDADD.pthread= -lpthread
. include "${_PKG_PTHREAD_BUILDLINK3_MK}"
+BUILDLINK_PREFIX.pthread= ${BUILDLINK_PREFIX.${_PKG_PTHREAD}}
+BUILDLINK_CFLAGS.pthread= ${BUILDLINK_CFLAGS.${_PKG_PTHREAD}}
+BUILDLINK_CPPFLAGS.${_PKG_PTHREAD}?= -D_REENTRANT
+BUILDLINK_CPPFLAGS.pthread= ${BUILDLINK_CPPFLAGS.${_PKG_PTHREAD}}
+BUILDLINK_LDFLAGS.pthread= ${BUILDLINK_LDFLAGS.${_PKG_PTHREAD}}
+BUILDLINK_LIBS.${_PKG_PTHREAD}?= -lpthread
+BUILDLINK_LIBS.pthread= ${BUILDLINK_LIBS.${_PKG_PTHREAD}}
. else
PKG_SKIP_REASON= "${PKGNAME} needs pthreads, but ${_PKG_PTHREAD_BUILDLINK3_MK} is missing."
. endif
@@ -194,13 +165,23 @@ PKG_SKIP_REASON= "${PKGNAME} needs pthreads, but ${_PKG_PTHREAD_BUILDLINK3_MK} i
.if !empty(PTHREAD_BUILDLINK3_MK:M+)
#
-# Define user-visible PTHREAD_CFLAGS and PTHREAD_LDFLAGS as compiler
-# options used to compile/link pthreaded code.
+# Define user-visible PTHREAD_{CFLAGS,LDFLAGS,LIBS} as compiler options
+# used to compile/link pthreaded code.
#
PTHREAD_CFLAGS= ${BUILDLINK_CFLAGS.pthread}
-PTHREAD_LDFLAGS= ${BUILDLINK_LDFLAGS.pthread} ${BUILDLINK_LDADD.pthread}
+PTHREAD_CFLAGS+= ${BUILDLINK_CPPFLAGS.pthread}
+PTHREAD_LDFLAGS= ${BUILDLINK_LDFLAGS.pthread}
+PTHREAD_LDFLAGS+= ${PTHREAD_LIBS} # XXX This should be removed!
+PTHREAD_LIBS= ${BUILDLINK_LIBS.pthread}
+CONFIGURE_ENV+= PTHREAD_CFLAGS="${PTHREAD_CFLAGS}"
+CONFIGURE_ENV+= PTHREAD_LDFLAGS="${PTHREAD_LDFLAGS}"
+CONFIGURE_ENV+= PTHREAD_LIBS="${PTHREAD_LIBS}"
+MAKE_ENV+= PTHREAD_CFLAGS="${PTHREAD_CFLAGS}"
+MAKE_ENV+= PTHREAD_LDFLAGS="${PTHREAD_LDFLAGS}"
+MAKE_ENV+= PTHREAD_LIBS="${PTHREAD_LIBS}"
PTHREADBASE= ${BUILDLINK_PREFIX.pthread}
CONFIGURE_ENV+= PTHREADBASE=${PTHREADBASE}
MAKE_ENV+= PTHREADBASE=${PTHREADBASE}
+
.endif # PTHREAD_BUILDLINK3_MK
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