Makefile revision 1.95
11.95Sbrad#	$NetBSD: Makefile,v 1.95 2019/09/22 18:45:20 brad 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.35Schristos# XXX: This crappy poke at libc's internals needs to be fixed.
401.35SchristosCPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${.CURDIR}/../libc
411.35Schristos
421.85Spooka# providing alternative MI implementations for creating an lwp is
431.85Spooka# possible by setting PTHREAD_MAKELWP.  Currently, alternatives are
441.85Spooka# set by the rumprun software stacks (see repo.rumpkernel.org)
451.85SpookaPTHREAD_MAKELWP?=	pthread_makelwp_netbsd.c
461.9Sthorpej
471.9Sthorpej#
481.9Sthorpej# NOTE: When you create a new file for libpthread, make sure that pthread.c
491.9Sthorpej# gets a reference to a symbol in that file.  Otherwise, Unix's stupid static
501.9Sthorpej# library semantics will end up discarding potentially important objects.
511.9Sthorpej#
521.9SthorpejSRCS=	pthread.c 
531.18SnathanwSRCS+=	pthread_attr.c
541.9SthorpejSRCS+=	pthread_barrier.c
551.85Spooka# used by rumprun-posix to work around symbol collisions
561.85Spooka.if ${PTHREAD_CANCELSTUB:Uyes} != "no"
571.9SthorpejSRCS+=	pthread_cancelstub.c
581.85Spooka.endif
591.9SthorpejSRCS+=	pthread_cond.c
601.86SchristosSRCS+=	pthread_getcpuclockid.c
611.9SthorpejSRCS+=	pthread_lock.c 
621.85SpookaSRCS+=	${PTHREAD_MAKELWP}
631.40SadSRCS+=	pthread_misc.c
641.9SthorpejSRCS+=	pthread_mutex.c
651.74SjoergSRCS+=	pthread_once.c
661.9SthorpejSRCS+=	pthread_rwlock.c
671.9SthorpejSRCS+=	pthread_specific.c
681.42SadSRCS+=	pthread_spin.c
691.21SnathanwSRCS+=	pthread_tsd.c
701.26SchristosSRCS+=	res_state.c
711.91Sthorpej.PATH: ${.CURDIR}/../librt
721.11SchristosSRCS+=	sem.c
731.9Sthorpej# Architecture-dependent files
741.56Sad.if exists(${ARCHDIR}/pthread_md.S)
751.56SadSRCS+= pthread_md.S
761.9Sthorpej.endif
771.82Smatt.if exists(${ARCHDIR}/Makefile.inc)
781.82Smatt.include "${ARCHDIR}/Makefile.inc"
791.82Smatt.endif
801.21Snathanw
811.79Sapb# The PTHREAD__COMPAT flag builds a libpthread that can be dropped
821.79Sapb# into a NetBSD 2/3/4 chroot with a NetBSD 5 or later kernel.
831.79Sapb# This makes threading work in the chroot, no other modifications
841.79Sapb# required.
851.79Sapb#
861.53Sad.if defined(PTHREAD__COMPAT)
871.53SadSRCS+=		pthread_compat.c
881.53Sad.PATH.c:	${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic
891.53Sad.PATH.S:	${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic
901.53Sad.PATH.c:	${.CURDIR}/../../common/lib/libc/atomic
911.53Sad.PATH.c:	${.CURDIR}/../libc/misc
921.53Sad.include "../../common/lib/libc/arch/${ARCHSUBDIR}/atomic/Makefile.inc"
931.53Sad.endif
941.53Sad
951.76SjoergALIGN_FUNCTIONS=	${${ACTIVE_CC} == "gcc":? -falign-functions=32 :}
961.76Sjoerg
971.21Snathanw# The TSD routines are used in the implementation of profiling, and so
981.21Snathanw# can't be profiled themselves.
991.88SchsCOPTS.pthread_specific.c+=	${ALIGN_FUNCTIONS}
1001.21Snathanwpthread_specific.po: pthread_specific.o
1011.25Slukem	${_MKTARGET_CREATE}
1021.21Snathanw	cp pthread_specific.o pthread_specific.po
1031.21Snathanw
1041.72SchristosCOPTS.pthread.c += -Wno-stack-protector -Wno-format-nonliteral
1051.72SchristosCOPTS.pthread_attr.c += -Wno-format-nonliteral
1061.45Sjnemeth
1071.52SrmindMAN+=	affinity.3 pthread.3 \
1081.48Syamt	pthread_attr.3 \
1091.58Sjruoho	pthread_attr_get_np.3 \
1101.60Sjruoho	pthread_attr_getdetachstate.3 \
1111.62Sjruoho	pthread_attr_getguardsize.3 \
1121.63Sjruoho	pthread_attr_getinheritsched.3 \
1131.48Syamt	pthread_attr_getname_np.3 \
1141.64Sjruoho	pthread_attr_getschedparam.3 \
1151.59Sjruoho	pthread_attr_getscope.3 \
1161.61Sjruoho	pthread_attr_getstack.3 \
1171.48Syamt	pthread_attr_setcreatesuspend_np.3 \
1181.66Srmind	pthread_barrier.3 pthread_barrierattr.3 \
1191.17Snathanw	pthread_cancel.3 pthread_cleanup_push.3 \
1201.66Srmind	pthread_cond.3 pthread_condattr.3 \
1211.66Srmind	pthread_create.3 pthread_detach.3 pthread_equal.3 \
1221.73Syamt	pthread_curcpu_np.3 \
1231.48Syamt	pthread_exit.3 \
1241.86Schristos	pthread_getcpuclockid.3 \
1251.48Syamt	pthread_getname_np.3 \
1261.48Syamt	pthread_getspecific.3 pthread_join.3 \
1271.69Sjruoho	pthread_key_create.3 pthread_kill.3 \
1281.66Srmind	pthread_mutex.3 pthread_mutexattr.3 \
1291.66Srmind	pthread_once.3 pthread_rwlock.3 pthread_rwlockattr.3 \
1301.17Snathanw	pthread_schedparam.3 pthread_self.3 \
1311.69Sjruoho	pthread_sigmask.3 pthread_spin.3 \
1321.51Srmind	pthread_suspend_np.3 pthread_testcancel.3
1331.17Snathanw
1341.70SchristosMLINKS+=	pthread_attr_get_np.3 pthread_getattr_np.3
1351.52SrmindMLINKS+=	affinity.3 pthread_setaffinity_np.3
1361.52SrmindMLINKS+=	affinity.3 pthread_getaffinity_np.3
1371.57Sjruoho
1381.17SnathanwMLINKS+=	pthread_attr.3 pthread_attr_init.3
1391.17SnathanwMLINKS+=	pthread_attr.3 pthread_attr_destroy.3
1401.59Sjruoho
1411.60SjruohoMLINKS+=	pthread_attr_getdetachstate.3 pthread_attr_setdetachstate.3
1421.62SjruohoMLINKS+=	pthread_attr_getguardsize.3 pthread_attr_setguardsize.3
1431.63SjruohoMLINKS+=	pthread_attr_getinheritsched.3 pthread_attr_setinheritsched.3
1441.68SjruohoMLINKS+=	pthread_attr_getname_np.3 pthread_attr_setname_np.3
1451.67Sjruoho
1461.67SjruohoMLINKS+=	pthread_attr_getschedparam.3 pthread_attr_setschedparam.3 \
1471.67Sjruoho		pthread_attr_getschedparam.3 pthread_attr_getschedpolicy.3 \
1481.67Sjruoho		pthread_attr_getschedparam.3 pthread_attr_setschedpolicy.3
1491.67Sjruoho
1501.59SjruohoMLINKS+=	pthread_attr_getscope.3 pthread_attr_setscope.3
1511.67Sjruoho
1521.61SjruohoMLINKS+=	pthread_attr_getstack.3 pthread_attr_setstack.3 \
1531.61Sjruoho		pthread_attr_getstack.3 pthread_attr_getstacksize.3 \
1541.61Sjruoho		pthread_attr_getstack.3 pthread_attr_setstacksize.3 \
1551.61Sjruoho		pthread_attr_getstack.3 pthread_attr_getstackaddr.3 \
1561.61Sjruoho		pthread_attr_getstack.3 pthread_attr_setstackaddr.3
1571.57Sjruoho
1581.66SrmindMLINKS+=	pthread_cleanup_push.3 pthread_cleanup_pop.3
1591.66Srmind
1601.66SrmindMLINKS+=	pthread_barrier.3 pthread_barrier_init.3
1611.66SrmindMLINKS+=	pthread_barrier.3 pthread_barrier_destroy.3
1621.66SrmindMLINKS+=	pthread_barrier.3 pthread_barrier_wait.3
1631.66Srmind
1641.32SpeterMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_init.3
1651.32SpeterMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_destroy.3
1661.87SchristosMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_getpshared.3
1671.87SchristosMLINKS+=	pthread_barrierattr.3 pthread_barrierattr_setpshared.3
1681.66Srmind
1691.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_init.3
1701.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_destroy.3
1711.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_broadcast.3
1721.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_wait.3
1731.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_signal.3
1741.66SrmindMLINKS+=	pthread_cond.3 pthread_cond_timedwait.3
1751.66Srmind
1761.17SnathanwMLINKS+=	pthread_condattr.3 pthread_condattr_init.3
1771.17SnathanwMLINKS+=	pthread_condattr.3 pthread_condattr_destroy.3
1781.78SriastradMLINKS+=	pthread_condattr.3 pthread_condattr_setclock.3
1791.87SchristosMLINKS+=	pthread_condattr.3 pthread_condattr_getclock.3
1801.87SchristosMLINKS+=	pthread_condattr.3 pthread_condattr_getpshared.3
1811.87SchristosMLINKS+=	pthread_condattr.3 pthread_condattr_setpshared.3
1821.66Srmind
1831.68SjruohoMLINKS+=	pthread_getname_np.3 pthread_setname_np.3
1841.69SjruohoMLINKS+=	pthread_getspecific.3 pthread_setspecific.3
1851.69SjruohoMLINKS+=	pthread_key_create.3 pthread_key_delete.3
1861.68Sjruoho
1871.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_init.3
1881.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_destroy.3
1891.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_lock.3
1901.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_trylock.3
1911.66SrmindMLINKS+=	pthread_mutex.3 pthread_mutex_unlock.3
1921.87SchristosMLINKS+=	pthread_mutex.3 pthread_mutex_timedlock.3
1931.87SchristosMLINKS+=	pthread_mutex.3	pthread_mutex_getprioceiling.3
1941.87SchristosMLINKS+=	pthread_mutex.3	pthread_mutex_setprioceiling.3 
1951.66Srmind
1961.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_init.3
1971.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_destroy.3
1981.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_getpshared.3
1991.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_setpshared.3
2001.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_settype.3
2011.17SnathanwMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_gettype.3
2021.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_getprotocol.3
2031.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_setprotocol.3
2041.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_getprioceiling.3
2051.87SchristosMLINKS+=	pthread_mutexattr.3 pthread_mutexattr_setprioceiling.3	
2061.66Srmind
2071.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_init.3
2081.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_destroy.3
2091.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_rdlock.3
2101.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_wrlock.3
2111.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_unlock.3
2121.66Srmind
2131.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_timedrdlock.3
2141.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_timedwrlock.3
2151.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_tryrdlock.3
2161.66SrmindMLINKS+=	pthread_rwlock.3 pthread_rwlock_trywrlock.3
2171.66Srmind
2181.17SnathanwMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_init.3
2191.17SnathanwMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_destroy.3
2201.87SchristosMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_getpshared.3
2211.87SchristosMLINKS+=	pthread_rwlockattr.3 pthread_rwlockattr_setpshared.3
2221.66Srmind
2231.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_init.3
2241.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_destroy.3
2251.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_lock.3
2261.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_trylock.3
2271.66SrmindMLINKS+=	pthread_spin.3 pthread_spin_unlock.3
2281.66Srmind
2291.17SnathanwMLINKS+=	pthread_schedparam.3 pthread_setschedparam.3
2301.17SnathanwMLINKS+=	pthread_schedparam.3 pthread_getschedparam.3
2311.23SchristosMLINKS+=	pthread_suspend_np.3 pthread_resume_np.3
2321.17SnathanwMLINKS+=	pthread_testcancel.3 pthread_setcancelstate.3
2331.17SnathanwMLINKS+=	pthread_testcancel.3 pthread_setcanceltype.3
2341.9Sthorpej
2351.92Skamil# ISO C threads (ISO/IEC 9899:2011)
2361.92Skamil
2371.92SkamilSRCS+=		call_once.c cnd.c mtx.c thrd.c tss.c
2381.92SkamilMAN+=		threads.3 call_once.3 cnd.3 mtx.3 thrd.3 tss.3
2391.92Skamil
2401.92SkamilMLINKS+=	call_once.3 ONCE_FLAG_INIT.3
2411.92SkamilMLINKS+=	call_once.3 once_flag.3
2421.92Skamil
2431.92SkamilMLINKS+=	cnd.3 cnd_broadcast.3
2441.92SkamilMLINKS+=	cnd.3 cnd_destroy.3
2451.92SkamilMLINKS+=	cnd.3 cnd_init.3
2461.92SkamilMLINKS+=	cnd.3 cnd_signal.3
2471.92SkamilMLINKS+=	cnd.3 cnd_timedwait.3
2481.92SkamilMLINKS+=	cnd.3 cnd_wait.3
2491.92Skamil
2501.92SkamilMLINKS+=	mtx.3 mtx_destroy.3
2511.92SkamilMLINKS+=	mtx.3 mtx_init.3
2521.92SkamilMLINKS+=	mtx.3 mtx_lock.3
2531.92SkamilMLINKS+=	mtx.3 mtx_timedlock.3
2541.92SkamilMLINKS+=	mtx.3 mtx_trylock.3
2551.92SkamilMLINKS+=	mtx.3 mtx_unlock.3
2561.92Skamil
2571.92SkamilMLINKS+=	thrd.3 thrd_create.3
2581.92SkamilMLINKS+=	thrd.3 thrd_current.3
2591.92SkamilMLINKS+=	thrd.3 thrd_detach.3
2601.92SkamilMLINKS+=	thrd.3 thrd_equal.3
2611.92SkamilMLINKS+=	thrd.3 thrd_exit.3
2621.92SkamilMLINKS+=	thrd.3 thrd_join.3
2631.92SkamilMLINKS+=	thrd.3 thrd_sleep.3
2641.92SkamilMLINKS+=	thrd.3 thrd_yield.3
2651.92Skamil
2661.92SkamilMLINKS+=	tss.3 TSS_DTOR_ITERATIONS.3
2671.92SkamilMLINKS+=	tss.3 tss_create.3
2681.92SkamilMLINKS+=	tss.3 tss_delete.3
2691.92SkamilMLINKS+=	tss.3 tss_get.3
2701.92SkamilMLINKS+=	tss.3 tss_set.3
2711.92Skamil
2721.92SkamilINCS+=		threads.h
2731.92Skamil
2741.93Smaya# PR lib/54001: create libpthread.a as a single large object, with all the
2751.93Smaya# symbols in one section. ensures that if any libpthread function is used,
2761.93Smaya# you get all of them from libpthread, and not the libc stubs.
2771.93Smaya#
2781.93Smaya# This makes -lpthread equivalent to -Wl,--whole-archive -lpthread
2791.93Smaya
2801.93Smaya__archivebuild: .USE
2811.93Smaya	${_MKTARGET_BUILD}
2821.93Smaya	@rm -f ${.TARGET}
2831.93Smaya	${LD} -r -o ${.TARGET}.o `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
2841.93Smaya	${AR} ${_ARFL} ${.TARGET} ${.TARGET}.o
2851.93Smaya
2861.94SmayaCLEANFILES+=	${_LIBS:=.o}
2871.93Smaya
2881.1Sproven.include <bsd.lib.mk>
2891.1Sproven
2901.9Sthorpej.else
2911.9Sthorpej
2921.9Sthorpej.include <bsd.man.mk>
2931.10Sthorpej.include <bsd.files.mk>
2941.10Sthorpej.include <bsd.inc.mk>
2951.9Sthorpej
2961.9Sthorpej.endif
2971.9Sthorpej
2981.9Sthorpej# WARNS=2 sets -Wcast-qual. This causes problems for one of
2991.9Sthorpej# pthread_setspecific() and pthread_getspecific(), since the constness
3001.9Sthorpej# of the argument to setspecific() has to be discarded *somewhere*
3011.9Sthorpej# before returning it from getspecific().
3021.77SmattCWARNFLAGS+= -Wno-cast-qual
303