Makefile revision 1.97
11.97Slukem#	$NetBSD: Makefile,v 1.97 2023/07/14 23:28:01 lukem Exp $
21.9Sthorpej#
31.9Sthorpej
41.90SchristosNOSANITIZER=	# defined
51.75SmattWARNS?=	5
61.85SpookaLIB=	pthread
71.24Scl
81.9Sthorpej.include <bsd.own.mk>
91.9Sthorpej
101.95SbradUSE_SHLIBDIR=	yes
111.95Sbrad
121.55Smrg.if defined(PTHREAD_MACHINE_ARCH) && !empty(PTHREAD_MACHINE_ARCH) && \
131.55Smrg    exists(${.CURDIR}/arch/${PTHREAD_MACHINE_ARCH})
141.55SmrgARCHSUBDIR=	${PTHREAD_MACHINE_ARCH}
151.84Smatt.elif defined(PTHREAD_MACHINE_CPU) && !empty(PTHREAD_MACHINE_CPU) && \
161.84Smatt    exists(${.CURDIR}/arch/${PTHREAD_MACHINE_CPU})
171.84SmattARCHSUBDIR=	${PTHREAD_MACHINE_CPU}
181.55Smrg.elif exists(${.CURDIR}/arch/${MACHINE_ARCH})
191.9SthorpejARCHSUBDIR=	${MACHINE_ARCH}
201.9Sthorpej.elif exists(${.CURDIR}/arch/${MACHINE_CPU}) 
211.9SthorpejARCHSUBDIR=	${MACHINE_CPU}
221.9Sthorpej.else
231.9Sthorpej.BEGIN:
241.10Sthorpej	@echo "WARNING: no ARCHSUBDIR for ${MACHINE_ARCH}/${MACHINE_CPU}; skipping..."
251.9Sthorpej.endif
261.9Sthorpej
271.10SthorpejINCS=	pthread.h pthread_types.h pthread_queue.h
281.10SthorpejINCSDIR=/usr/include
291.10Sthorpej
301.9Sthorpej.if defined(ARCHSUBDIR)
311.9Sthorpej
321.9SthorpejARCHDIR=	${.CURDIR}/arch/${ARCHSUBDIR}
331.9Sthorpej.PATH:	${ARCHDIR}
341.9Sthorpej
351.80SchristosCPPFLAGS+=	-I${ARCHDIR} -I${.CURDIR} -I${.OBJDIR} -D_LIBC -D_REENTRANT
361.80SchristosCPPFLAGS+=	-I${.CURDIR}/../libc/include
371.80SchristosCPPFLAGS+=	-D__LIBPTHREAD_SOURCE__ -D__LIBC_THREAD_STUBS
381.9Sthorpej
391.96Sjoerg# Since <pthread.h> is not used, allow declaring pthread_create and
401.96Sjoerg# friends locally.
411.96SjoergCWARNFLAGS.clang+=	-Wno-builtin-requires-header
421.96Sjoerg
431.35Schristos# XXX: This crappy poke at libc's internals needs to be fixed.
441.35SchristosCPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${.CURDIR}/../libc
451.35Schristos
461.85Spooka# providing alternative MI implementations for creating an lwp is
471.85Spooka# possible by setting PTHREAD_MAKELWP.  Currently, alternatives are
481.97Slukem# set by the rumprun software stacks (see https://github.com/rumpkernel/rumprun )
491.85SpookaPTHREAD_MAKELWP?=	pthread_makelwp_netbsd.c
501.9Sthorpej
511.9Sthorpej#
521.9Sthorpej# NOTE: When you create a new file for libpthread, make sure that pthread.c
531.9Sthorpej# gets a reference to a symbol in that file.  Otherwise, Unix's stupid static
541.9Sthorpej# library semantics will end up discarding potentially important objects.
551.9Sthorpej#
561.9SthorpejSRCS=	pthread.c 
571.18SnathanwSRCS+=	pthread_attr.c
581.9SthorpejSRCS+=	pthread_barrier.c
591.85Spooka# used by rumprun-posix to work around symbol collisions
601.85Spooka.if ${PTHREAD_CANCELSTUB:Uyes} != "no"
611.9SthorpejSRCS+=	pthread_cancelstub.c
621.85Spooka.endif
631.9SthorpejSRCS+=	pthread_cond.c
641.86SchristosSRCS+=	pthread_getcpuclockid.c
651.9SthorpejSRCS+=	pthread_lock.c 
661.85SpookaSRCS+=	${PTHREAD_MAKELWP}
671.40SadSRCS+=	pthread_misc.c
681.9SthorpejSRCS+=	pthread_mutex.c
691.74SjoergSRCS+=	pthread_once.c
701.9SthorpejSRCS+=	pthread_rwlock.c
711.9SthorpejSRCS+=	pthread_specific.c
721.42SadSRCS+=	pthread_spin.c
731.21SnathanwSRCS+=	pthread_tsd.c
741.26SchristosSRCS+=	res_state.c
751.91Sthorpej.PATH: ${.CURDIR}/../librt
761.11SchristosSRCS+=	sem.c
771.9Sthorpej# Architecture-dependent files
781.56Sad.if exists(${ARCHDIR}/pthread_md.S)
791.56SadSRCS+= pthread_md.S
801.9Sthorpej.endif
811.82Smatt.if exists(${ARCHDIR}/Makefile.inc)
821.82Smatt.include "${ARCHDIR}/Makefile.inc"
831.82Smatt.endif
841.21Snathanw
851.79Sapb# The PTHREAD__COMPAT flag builds a libpthread that can be dropped
861.79Sapb# into a NetBSD 2/3/4 chroot with a NetBSD 5 or later kernel.
871.79Sapb# This makes threading work in the chroot, no other modifications
881.79Sapb# required.
891.79Sapb#
901.53Sad.if defined(PTHREAD__COMPAT)
911.53SadSRCS+=		pthread_compat.c
921.53Sad.PATH.c:	${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic
931.53Sad.PATH.S:	${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic
941.53Sad.PATH.c:	${.CURDIR}/../../common/lib/libc/atomic
951.53Sad.PATH.c:	${.CURDIR}/../libc/misc
961.53Sad.include "../../common/lib/libc/arch/${ARCHSUBDIR}/atomic/Makefile.inc"
971.53Sad.endif
981.53Sad
991.76SjoergALIGN_FUNCTIONS=	${${ACTIVE_CC} == "gcc":? -falign-functions=32 :}
1001.76Sjoerg
1011.21Snathanw# The TSD routines are used in the implementation of profiling, and so
1021.21Snathanw# can't be profiled themselves.
1031.88SchsCOPTS.pthread_specific.c+=	${ALIGN_FUNCTIONS}
1041.21Snathanwpthread_specific.po: pthread_specific.o
1051.25Slukem	${_MKTARGET_CREATE}
1061.21Snathanw	cp pthread_specific.o pthread_specific.po
1071.21Snathanw
1081.72SchristosCOPTS.pthread.c += -Wno-stack-protector -Wno-format-nonliteral
1091.72SchristosCOPTS.pthread_attr.c += -Wno-format-nonliteral
1101.45Sjnemeth
1111.52SrmindMAN+=	affinity.3 pthread.3 \
1121.48Syamt	pthread_attr.3 \
1131.58Sjruoho	pthread_attr_get_np.3 \
1141.60Sjruoho	pthread_attr_getdetachstate.3 \
1151.62Sjruoho	pthread_attr_getguardsize.3 \
1161.63Sjruoho	pthread_attr_getinheritsched.3 \
1171.48Syamt	pthread_attr_getname_np.3 \
1181.64Sjruoho	pthread_attr_getschedparam.3 \
1191.59Sjruoho	pthread_attr_getscope.3 \
1201.61Sjruoho	pthread_attr_getstack.3 \
1211.48Syamt	pthread_attr_setcreatesuspend_np.3 \
1221.66Srmind	pthread_barrier.3 pthread_barrierattr.3 \
1231.17Snathanw	pthread_cancel.3 pthread_cleanup_push.3 \
1241.66Srmind	pthread_cond.3 pthread_condattr.3 \
1251.66Srmind	pthread_create.3 pthread_detach.3 pthread_equal.3 \
1261.73Syamt	pthread_curcpu_np.3 \
1271.48Syamt	pthread_exit.3 \
1281.86Schristos	pthread_getcpuclockid.3 \
1291.48Syamt	pthread_getname_np.3 \
1301.48Syamt	pthread_getspecific.3 pthread_join.3 \
1311.69Sjruoho	pthread_key_create.3 pthread_kill.3 \
1321.66Srmind	pthread_mutex.3 pthread_mutexattr.3 \
1331.66Srmind	pthread_once.3 pthread_rwlock.3 pthread_rwlockattr.3 \
1341.17Snathanw	pthread_schedparam.3 pthread_self.3 \
1351.69Sjruoho	pthread_sigmask.3 pthread_spin.3 \
1361.51Srmind	pthread_suspend_np.3 pthread_testcancel.3
1371.17Snathanw
1381.70SchristosMLINKS+=	pthread_attr_get_np.3 pthread_getattr_np.3
1391.52SrmindMLINKS+=	affinity.3 pthread_setaffinity_np.3
1401.52SrmindMLINKS+=	affinity.3 pthread_getaffinity_np.3
1411.57Sjruoho
1421.17SnathanwMLINKS+=	pthread_attr.3 pthread_attr_init.3
1431.17SnathanwMLINKS+=	pthread_attr.3 pthread_attr_destroy.3
1441.59Sjruoho
1451.60SjruohoMLINKS+=	pthread_attr_getdetachstate.3 pthread_attr_setdetachstate.3
1461.62SjruohoMLINKS+=	pthread_attr_getguardsize.3 pthread_attr_setguardsize.3
1471.63SjruohoMLINKS+=	pthread_attr_getinheritsched.3 pthread_attr_setinheritsched.3
1481.68SjruohoMLINKS+=	pthread_attr_getname_np.3 pthread_attr_setname_np.3
1491.67Sjruoho
1501.67SjruohoMLINKS+=	pthread_attr_getschedparam.3 pthread_attr_setschedparam.3 \
1511.67Sjruoho		pthread_attr_getschedparam.3 pthread_attr_getschedpolicy.3 \
1521.67Sjruoho		pthread_attr_getschedparam.3 pthread_attr_setschedpolicy.3
1531.67Sjruoho
1541.59SjruohoMLINKS+=	pthread_attr_getscope.3 pthread_attr_setscope.3
1551.67Sjruoho
1561.61SjruohoMLINKS+=	pthread_attr_getstack.3 pthread_attr_setstack.3 \
1571.61Sjruoho		pthread_attr_getstack.3 pthread_attr_getstacksize.3 \
1581.61Sjruoho		pthread_attr_getstack.3 pthread_attr_setstacksize.3 \
1591.61Sjruoho		pthread_attr_getstack.3 pthread_attr_getstackaddr.3 \
1601.61Sjruoho		pthread_attr_getstack.3 pthread_attr_setstackaddr.3
1611.57Sjruoho
1621.66SrmindMLINKS+=	pthread_cleanup_push.3 pthread_cleanup_pop.3
1631.66Srmind
1641.66SrmindMLINKS+=	pthread_barrier.3 pthread_barrier_init.3
1651.66SrmindMLINKS+=	pthread_barrier.3 pthread_barrier_destroy.3
1661.66SrmindMLINKS+=	pthread_barrier.3 pthread_barrier_wait.3
1671.66Srmind
1681.32SpeterMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_init.3
1691.32SpeterMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_destroy.3
1701.87SchristosMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_getpshared.3
1711.87SchristosMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_setpshared.3
1721.66Srmind
1731.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_init.3
1741.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_destroy.3
1751.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_broadcast.3
1761.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_wait.3
1771.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_signal.3
1781.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_timedwait.3
1791.66Srmind
1801.17SnathanwMLINKS+=	pthread_condattr.3 pthread_condattr_init.3
1811.17SnathanwMLINKS+=	pthread_condattr.3 pthread_condattr_destroy.3
1821.78SriastradMLINKS+=	pthread_condattr.3 pthread_condattr_setclock.3
1831.87SchristosMLINKS+=	pthread_condattr.3 pthread_condattr_getclock.3
1841.87SchristosMLINKS+=	pthread_condattr.3 pthread_condattr_getpshared.3
1851.87SchristosMLINKS+=	pthread_condattr.3 pthread_condattr_setpshared.3
1861.66Srmind
1871.68SjruohoMLINKS+=	pthread_getname_np.3 pthread_setname_np.3
1881.69SjruohoMLINKS+=	pthread_getspecific.3 pthread_setspecific.3
1891.69SjruohoMLINKS+=	pthread_key_create.3 pthread_key_delete.3
1901.68Sjruoho
1911.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_init.3
1921.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_destroy.3
1931.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_lock.3
1941.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_trylock.3
1951.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_unlock.3
1961.87SchristosMLINKS+=	pthread_mutex.3 pthread_mutex_timedlock.3
1971.87SchristosMLINKS+=	pthread_mutex.3	pthread_mutex_getprioceiling.3
1981.87SchristosMLINKS+=	pthread_mutex.3	pthread_mutex_setprioceiling.3 
1991.66Srmind
2001.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_init.3
2011.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_destroy.3
2021.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_getpshared.3
2031.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_setpshared.3
2041.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_settype.3
2051.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_gettype.3
2061.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_getprotocol.3
2071.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_setprotocol.3
2081.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_getprioceiling.3
2091.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_setprioceiling.3	
2101.66Srmind
2111.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_init.3
2121.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_destroy.3
2131.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_rdlock.3
2141.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_wrlock.3
2151.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_unlock.3
2161.66Srmind
2171.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_timedrdlock.3
2181.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_timedwrlock.3
2191.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_tryrdlock.3
2201.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_trywrlock.3
2211.66Srmind
2221.17SnathanwMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_init.3
2231.17SnathanwMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_destroy.3
2241.87SchristosMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_getpshared.3
2251.87SchristosMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_setpshared.3
2261.66Srmind
2271.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_init.3
2281.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_destroy.3
2291.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_lock.3
2301.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_trylock.3
2311.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_unlock.3
2321.66Srmind
2331.17SnathanwMLINKS+=	pthread_schedparam.3 pthread_setschedparam.3
2341.17SnathanwMLINKS+=	pthread_schedparam.3 pthread_getschedparam.3
2351.23SchristosMLINKS+=	pthread_suspend_np.3 pthread_resume_np.3
2361.17SnathanwMLINKS+=	pthread_testcancel.3 pthread_setcancelstate.3
2371.17SnathanwMLINKS+=	pthread_testcancel.3 pthread_setcanceltype.3
2381.9Sthorpej
2391.92Skamil# ISO C threads (ISO/IEC 9899:2011)
2401.92Skamil
2411.92SkamilSRCS+=		call_once.c cnd.c mtx.c thrd.c tss.c
2421.92SkamilMAN+=		threads.3 call_once.3 cnd.3 mtx.3 thrd.3 tss.3
2431.92Skamil
2441.92SkamilMLINKS+=	call_once.3 ONCE_FLAG_INIT.3
2451.92SkamilMLINKS+=	call_once.3 once_flag.3
2461.92Skamil
2471.92SkamilMLINKS+=	cnd.3 cnd_broadcast.3
2481.92SkamilMLINKS+=	cnd.3 cnd_destroy.3
2491.92SkamilMLINKS+=	cnd.3 cnd_init.3
2501.92SkamilMLINKS+=	cnd.3 cnd_signal.3
2511.92SkamilMLINKS+=	cnd.3 cnd_timedwait.3
2521.92SkamilMLINKS+=	cnd.3 cnd_wait.3
2531.92Skamil
2541.92SkamilMLINKS+=	mtx.3 mtx_destroy.3
2551.92SkamilMLINKS+=	mtx.3 mtx_init.3
2561.92SkamilMLINKS+=	mtx.3 mtx_lock.3
2571.92SkamilMLINKS+=	mtx.3 mtx_timedlock.3
2581.92SkamilMLINKS+=	mtx.3 mtx_trylock.3
2591.92SkamilMLINKS+=	mtx.3 mtx_unlock.3
2601.92Skamil
2611.92SkamilMLINKS+=	thrd.3 thrd_create.3
2621.92SkamilMLINKS+=	thrd.3 thrd_current.3
2631.92SkamilMLINKS+=	thrd.3 thrd_detach.3
2641.92SkamilMLINKS+=	thrd.3 thrd_equal.3
2651.92SkamilMLINKS+=	thrd.3 thrd_exit.3
2661.92SkamilMLINKS+=	thrd.3 thrd_join.3
2671.92SkamilMLINKS+=	thrd.3 thrd_sleep.3
2681.92SkamilMLINKS+=	thrd.3 thrd_yield.3
2691.92Skamil
2701.92SkamilMLINKS+=	tss.3 TSS_DTOR_ITERATIONS.3
2711.92SkamilMLINKS+=	tss.3 tss_create.3
2721.92SkamilMLINKS+=	tss.3 tss_delete.3
2731.92SkamilMLINKS+=	tss.3 tss_get.3
2741.92SkamilMLINKS+=	tss.3 tss_set.3
2751.92Skamil
2761.92SkamilINCS+=		threads.h
2771.92Skamil
2781.93Smaya# PR lib/54001: create libpthread.a as a single large object, with all the
2791.93Smaya# symbols in one section. ensures that if any libpthread function is used,
2801.93Smaya# you get all of them from libpthread, and not the libc stubs.
2811.93Smaya#
2821.93Smaya# This makes -lpthread equivalent to -Wl,--whole-archive -lpthread
2831.93Smaya
2841.93Smaya__archivebuild: .USE
2851.93Smaya	${_MKTARGET_BUILD}
2861.93Smaya	@rm -f ${.TARGET}
2871.93Smaya	${LD} -r -o ${.TARGET}.o `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
2881.93Smaya	${AR} ${_ARFL} ${.TARGET} ${.TARGET}.o
2891.93Smaya
2901.94SmayaCLEANFILES+=	${_LIBS:=.o}
2911.93Smaya
2921.1Sproven.include <bsd.lib.mk>
2931.1Sproven
2941.9Sthorpej.else
2951.9Sthorpej
2961.9Sthorpej.include <bsd.man.mk>
2971.10Sthorpej.include <bsd.files.mk>
2981.10Sthorpej.include <bsd.inc.mk>
2991.9Sthorpej
3001.9Sthorpej.endif
3011.9Sthorpej
3021.9Sthorpej# WARNS=2 sets -Wcast-qual. This causes problems for one of
3031.9Sthorpej# pthread_setspecific() and pthread_getspecific(), since the constness
3041.9Sthorpej# of the argument to setspecific() has to be discarded *somewhere*
3051.9Sthorpej# before returning it from getspecific().
3061.77SmattCWARNFLAGS+= -Wno-cast-qual
307