11.103Sriastrad# $NetBSD: Makefile,v 1.103 2025/11/23 22:11:41 riastradh 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.98Srin.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.99SriastradEXPSYM_SRCS+= pthread_mi.expsym 361.99Sriastrad. if ${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH} == "hppa" 371.99Sriastrad# PTHREAD__ASM_RASOPS 381.99SriastradEXPSYM_SRCS+= pthread_md.expsym 391.99Sriastrad. else 401.99Sriastrad# !PTHREAD__ASM_RASOPS 411.99Sriastrad# XXX These really shouldn't be exported. 421.99SriastradEXPSYM_SRCS+= pthread_ras.expsym 431.99Sriastrad. endif 441.99Sriastrad 451.99SriastradLIB_EXPSYM= pthread.expsym 461.99Sriastradpthread.expsym: ${EXPSYM_SRCS} 471.99Sriastrad ${_MKTARGET_CREATE} 481.99Sriastrad LC_ALL=C sort -m ${.ALLSRC} >${.TARGET}.tmp && \ 491.99Sriastrad ${MV} ${.TARGET}.tmp ${.TARGET} 501.99SriastradCLEANFILES+= pthread.expsym pthread.expsym.tmp 511.99Sriastrad 521.80SchristosCPPFLAGS+= -I${ARCHDIR} -I${.CURDIR} -I${.OBJDIR} -D_LIBC -D_REENTRANT 531.80SchristosCPPFLAGS+= -I${.CURDIR}/../libc/include 541.80SchristosCPPFLAGS+= -D__LIBPTHREAD_SOURCE__ -D__LIBC_THREAD_STUBS 551.9Sthorpej 561.96Sjoerg# Since <pthread.h> is not used, allow declaring pthread_create and 571.96Sjoerg# friends locally. 581.96SjoergCWARNFLAGS.clang+= -Wno-builtin-requires-header 591.96Sjoerg 601.35Schristos# XXX: This crappy poke at libc's internals needs to be fixed. 611.35SchristosCPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${.CURDIR}/../libc 621.35Schristos 631.85Spooka# providing alternative MI implementations for creating an lwp is 641.85Spooka# possible by setting PTHREAD_MAKELWP. Currently, alternatives are 651.97Slukem# set by the rumprun software stacks (see https://github.com/rumpkernel/rumprun ) 661.85SpookaPTHREAD_MAKELWP?= pthread_makelwp_netbsd.c 671.9Sthorpej 681.103Sriastrad# Prevent unloading libpthread. 691.103Sriastrad# 701.103Sriastrad# libpthread provides strong definitions of some symbols defined weakly 711.103Sriastrad# by libc, such as pthread_mutex_lock (actually __libc_mutex_lock under 721.103Sriastrad# the hood), which are used in libraries that take locks for 731.103Sriastrad# thread-safety -- this way, in non-threaded applications, 741.103Sriastrad# pthread_mutex_lock is a cheap noop libc stub, while in threaded 751.103Sriastrad# applications, it's a real libpthread operation. If libpthread is 761.103Sriastrad# dlopened, the symbol might be lazily resolved _after_ it is dlopened 771.103Sriastrad# to point at libpthread; then it cannot be safely unloaded, because 781.103Sriastrad# there's no way to roll back symbol resolution. 791.103Sriastrad# 801.103Sriastrad# PR lib/59784: dlopening and dlclosing libpthread is broken 811.103Sriastrad# 821.103SriastradLDADD+= -Wl,-z,nodelete 831.103Sriastrad 841.9Sthorpej# 851.9Sthorpej# NOTE: When you create a new file for libpthread, make sure that pthread.c 861.9Sthorpej# gets a reference to a symbol in that file. Otherwise, Unix's stupid static 871.9Sthorpej# library semantics will end up discarding potentially important objects. 881.9Sthorpej# 891.98SrinSRCS= pthread.c 901.18SnathanwSRCS+= pthread_attr.c 911.9SthorpejSRCS+= pthread_barrier.c 921.85Spooka# used by rumprun-posix to work around symbol collisions 931.85Spooka.if ${PTHREAD_CANCELSTUB:Uyes} != "no" 941.9SthorpejSRCS+= pthread_cancelstub.c 951.85Spooka.endif 961.9SthorpejSRCS+= pthread_cond.c 971.86SchristosSRCS+= pthread_getcpuclockid.c 981.98SrinSRCS+= pthread_lock.c 991.85SpookaSRCS+= ${PTHREAD_MAKELWP} 1001.40SadSRCS+= pthread_misc.c 1011.9SthorpejSRCS+= pthread_mutex.c 1021.74SjoergSRCS+= pthread_once.c 1031.9SthorpejSRCS+= pthread_rwlock.c 1041.9SthorpejSRCS+= pthread_specific.c 1051.42SadSRCS+= pthread_spin.c 1061.21SnathanwSRCS+= pthread_tsd.c 1071.26SchristosSRCS+= res_state.c 1081.91Sthorpej.PATH: ${.CURDIR}/../librt 1091.11SchristosSRCS+= sem.c 1101.9Sthorpej# Architecture-dependent files 1111.56Sad.if exists(${ARCHDIR}/pthread_md.S) 1121.56SadSRCS+= pthread_md.S 1131.9Sthorpej.endif 1141.82Smatt.if exists(${ARCHDIR}/Makefile.inc) 1151.82Smatt.include "${ARCHDIR}/Makefile.inc" 1161.82Smatt.endif 1171.21Snathanw 1181.79Sapb# The PTHREAD__COMPAT flag builds a libpthread that can be dropped 1191.79Sapb# into a NetBSD 2/3/4 chroot with a NetBSD 5 or later kernel. 1201.79Sapb# This makes threading work in the chroot, no other modifications 1211.79Sapb# required. 1221.79Sapb# 1231.53Sad.if defined(PTHREAD__COMPAT) 1241.53SadSRCS+= pthread_compat.c 1251.53Sad.PATH.c: ${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic 1261.53Sad.PATH.S: ${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic 1271.53Sad.PATH.c: ${.CURDIR}/../../common/lib/libc/atomic 1281.53Sad.PATH.c: ${.CURDIR}/../libc/misc 1291.53Sad.include "../../common/lib/libc/arch/${ARCHSUBDIR}/atomic/Makefile.inc" 1301.53Sad.endif 1311.53Sad 1321.76SjoergALIGN_FUNCTIONS= ${${ACTIVE_CC} == "gcc":? -falign-functions=32 :} 1331.76Sjoerg 1341.21Snathanw# The TSD routines are used in the implementation of profiling, and so 1351.21Snathanw# can't be profiled themselves. 1361.88SchsCOPTS.pthread_specific.c+= ${ALIGN_FUNCTIONS} 1371.21Snathanwpthread_specific.po: pthread_specific.o 1381.25Slukem ${_MKTARGET_CREATE} 1391.21Snathanw cp pthread_specific.o pthread_specific.po 1401.21Snathanw 1411.102SchristosCOPTS.pthread.c += -Wno-stack-protector -Wno-format-nonliteral 1421.72SchristosCOPTS.pthread_attr.c += -Wno-format-nonliteral 1431.45Sjnemeth 1441.100SrilligLINTFLAGS+= -Ac11 # for _Atomic 1451.100Srillig 1461.52SrmindMAN+= affinity.3 pthread.3 \ 1471.48Syamt pthread_attr.3 \ 1481.58Sjruoho pthread_attr_get_np.3 \ 1491.60Sjruoho pthread_attr_getdetachstate.3 \ 1501.62Sjruoho pthread_attr_getguardsize.3 \ 1511.63Sjruoho pthread_attr_getinheritsched.3 \ 1521.48Syamt pthread_attr_getname_np.3 \ 1531.64Sjruoho pthread_attr_getschedparam.3 \ 1541.59Sjruoho pthread_attr_getscope.3 \ 1551.61Sjruoho pthread_attr_getstack.3 \ 1561.48Syamt pthread_attr_setcreatesuspend_np.3 \ 1571.66Srmind pthread_barrier.3 pthread_barrierattr.3 \ 1581.17Snathanw pthread_cancel.3 pthread_cleanup_push.3 \ 1591.66Srmind pthread_cond.3 pthread_condattr.3 \ 1601.66Srmind pthread_create.3 pthread_detach.3 pthread_equal.3 \ 1611.73Syamt pthread_curcpu_np.3 \ 1621.48Syamt pthread_exit.3 \ 1631.86Schristos pthread_getcpuclockid.3 \ 1641.48Syamt pthread_getname_np.3 \ 1651.48Syamt pthread_getspecific.3 pthread_join.3 \ 1661.69Sjruoho pthread_key_create.3 pthread_kill.3 \ 1671.66Srmind pthread_mutex.3 pthread_mutexattr.3 \ 1681.66Srmind pthread_once.3 pthread_rwlock.3 pthread_rwlockattr.3 \ 1691.17Snathanw pthread_schedparam.3 pthread_self.3 \ 1701.69Sjruoho pthread_sigmask.3 pthread_spin.3 \ 1711.51Srmind pthread_suspend_np.3 pthread_testcancel.3 1721.17Snathanw 1731.70SchristosMLINKS+= pthread_attr_get_np.3 pthread_getattr_np.3 1741.52SrmindMLINKS+= affinity.3 pthread_setaffinity_np.3 1751.52SrmindMLINKS+= affinity.3 pthread_getaffinity_np.3 1761.57Sjruoho 1771.17SnathanwMLINKS+= pthread_attr.3 pthread_attr_init.3 1781.17SnathanwMLINKS+= pthread_attr.3 pthread_attr_destroy.3 1791.59Sjruoho 1801.60SjruohoMLINKS+= pthread_attr_getdetachstate.3 pthread_attr_setdetachstate.3 1811.62SjruohoMLINKS+= pthread_attr_getguardsize.3 pthread_attr_setguardsize.3 1821.63SjruohoMLINKS+= pthread_attr_getinheritsched.3 pthread_attr_setinheritsched.3 1831.68SjruohoMLINKS+= pthread_attr_getname_np.3 pthread_attr_setname_np.3 1841.67Sjruoho 1851.67SjruohoMLINKS+= pthread_attr_getschedparam.3 pthread_attr_setschedparam.3 \ 1861.67Sjruoho pthread_attr_getschedparam.3 pthread_attr_getschedpolicy.3 \ 1871.67Sjruoho pthread_attr_getschedparam.3 pthread_attr_setschedpolicy.3 1881.67Sjruoho 1891.59SjruohoMLINKS+= pthread_attr_getscope.3 pthread_attr_setscope.3 1901.67Sjruoho 1911.61SjruohoMLINKS+= pthread_attr_getstack.3 pthread_attr_setstack.3 \ 1921.61Sjruoho pthread_attr_getstack.3 pthread_attr_getstacksize.3 \ 1931.61Sjruoho pthread_attr_getstack.3 pthread_attr_setstacksize.3 \ 1941.61Sjruoho pthread_attr_getstack.3 pthread_attr_getstackaddr.3 \ 1951.61Sjruoho pthread_attr_getstack.3 pthread_attr_setstackaddr.3 1961.57Sjruoho 1971.66SrmindMLINKS+= pthread_cleanup_push.3 pthread_cleanup_pop.3 1981.66Srmind 1991.66SrmindMLINKS+= pthread_barrier.3 pthread_barrier_init.3 2001.66SrmindMLINKS+= pthread_barrier.3 pthread_barrier_destroy.3 2011.66SrmindMLINKS+= pthread_barrier.3 pthread_barrier_wait.3 2021.66Srmind 2031.32SpeterMLINKS+= pthread_barrierattr.3 pthread_barrierattr_init.3 2041.32SpeterMLINKS+= pthread_barrierattr.3 pthread_barrierattr_destroy.3 2051.87SchristosMLINKS+= pthread_barrierattr.3 pthread_barrierattr_getpshared.3 2061.87SchristosMLINKS+= pthread_barrierattr.3 pthread_barrierattr_setpshared.3 2071.66Srmind 2081.66SrmindMLINKS+= pthread_cond.3 pthread_cond_init.3 2091.66SrmindMLINKS+= pthread_cond.3 pthread_cond_destroy.3 2101.66SrmindMLINKS+= pthread_cond.3 pthread_cond_broadcast.3 2111.66SrmindMLINKS+= pthread_cond.3 pthread_cond_wait.3 2121.66SrmindMLINKS+= pthread_cond.3 pthread_cond_signal.3 2131.66SrmindMLINKS+= pthread_cond.3 pthread_cond_timedwait.3 2141.66Srmind 2151.17SnathanwMLINKS+= pthread_condattr.3 pthread_condattr_init.3 2161.17SnathanwMLINKS+= pthread_condattr.3 pthread_condattr_destroy.3 2171.78SriastradMLINKS+= pthread_condattr.3 pthread_condattr_setclock.3 2181.87SchristosMLINKS+= pthread_condattr.3 pthread_condattr_getclock.3 2191.87SchristosMLINKS+= pthread_condattr.3 pthread_condattr_getpshared.3 2201.87SchristosMLINKS+= pthread_condattr.3 pthread_condattr_setpshared.3 2211.66Srmind 2221.68SjruohoMLINKS+= pthread_getname_np.3 pthread_setname_np.3 2231.69SjruohoMLINKS+= pthread_getspecific.3 pthread_setspecific.3 2241.69SjruohoMLINKS+= pthread_key_create.3 pthread_key_delete.3 2251.68Sjruoho 2261.66SrmindMLINKS+= pthread_mutex.3 pthread_mutex_init.3 2271.66SrmindMLINKS+= pthread_mutex.3 pthread_mutex_destroy.3 2281.66SrmindMLINKS+= pthread_mutex.3 pthread_mutex_lock.3 2291.66SrmindMLINKS+= pthread_mutex.3 pthread_mutex_trylock.3 2301.66SrmindMLINKS+= pthread_mutex.3 pthread_mutex_unlock.3 2311.87SchristosMLINKS+= pthread_mutex.3 pthread_mutex_timedlock.3 2321.87SchristosMLINKS+= pthread_mutex.3 pthread_mutex_getprioceiling.3 2331.98SrinMLINKS+= pthread_mutex.3 pthread_mutex_setprioceiling.3 2341.66Srmind 2351.17SnathanwMLINKS+= pthread_mutexattr.3 pthread_mutexattr_init.3 2361.17SnathanwMLINKS+= pthread_mutexattr.3 pthread_mutexattr_destroy.3 2371.87SchristosMLINKS+= pthread_mutexattr.3 pthread_mutexattr_getpshared.3 2381.87SchristosMLINKS+= pthread_mutexattr.3 pthread_mutexattr_setpshared.3 2391.17SnathanwMLINKS+= pthread_mutexattr.3 pthread_mutexattr_settype.3 2401.17SnathanwMLINKS+= pthread_mutexattr.3 pthread_mutexattr_gettype.3 2411.87SchristosMLINKS+= pthread_mutexattr.3 pthread_mutexattr_getprotocol.3 2421.87SchristosMLINKS+= pthread_mutexattr.3 pthread_mutexattr_setprotocol.3 2431.87SchristosMLINKS+= pthread_mutexattr.3 pthread_mutexattr_getprioceiling.3 2441.98SrinMLINKS+= pthread_mutexattr.3 pthread_mutexattr_setprioceiling.3 2451.66Srmind 2461.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_init.3 2471.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_destroy.3 2481.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_rdlock.3 2491.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_wrlock.3 2501.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_unlock.3 2511.66Srmind 2521.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_timedrdlock.3 2531.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_timedwrlock.3 2541.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_tryrdlock.3 2551.66SrmindMLINKS+= pthread_rwlock.3 pthread_rwlock_trywrlock.3 2561.66Srmind 2571.17SnathanwMLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_init.3 2581.17SnathanwMLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_destroy.3 2591.87SchristosMLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_getpshared.3 2601.87SchristosMLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_setpshared.3 2611.66Srmind 2621.66SrmindMLINKS+= pthread_spin.3 pthread_spin_init.3 2631.66SrmindMLINKS+= pthread_spin.3 pthread_spin_destroy.3 2641.66SrmindMLINKS+= pthread_spin.3 pthread_spin_lock.3 2651.66SrmindMLINKS+= pthread_spin.3 pthread_spin_trylock.3 2661.66SrmindMLINKS+= pthread_spin.3 pthread_spin_unlock.3 2671.66Srmind 2681.17SnathanwMLINKS+= pthread_schedparam.3 pthread_setschedparam.3 2691.17SnathanwMLINKS+= pthread_schedparam.3 pthread_getschedparam.3 2701.23SchristosMLINKS+= pthread_suspend_np.3 pthread_resume_np.3 2711.17SnathanwMLINKS+= pthread_testcancel.3 pthread_setcancelstate.3 2721.17SnathanwMLINKS+= pthread_testcancel.3 pthread_setcanceltype.3 2731.9Sthorpej 2741.92Skamil# ISO C threads (ISO/IEC 9899:2011) 2751.92Skamil 2761.92SkamilSRCS+= call_once.c cnd.c mtx.c thrd.c tss.c 2771.92SkamilMAN+= threads.3 call_once.3 cnd.3 mtx.3 thrd.3 tss.3 2781.92Skamil 2791.92SkamilMLINKS+= call_once.3 ONCE_FLAG_INIT.3 2801.92SkamilMLINKS+= call_once.3 once_flag.3 2811.92Skamil 2821.92SkamilMLINKS+= cnd.3 cnd_broadcast.3 2831.92SkamilMLINKS+= cnd.3 cnd_destroy.3 2841.92SkamilMLINKS+= cnd.3 cnd_init.3 2851.92SkamilMLINKS+= cnd.3 cnd_signal.3 2861.92SkamilMLINKS+= cnd.3 cnd_timedwait.3 2871.92SkamilMLINKS+= cnd.3 cnd_wait.3 2881.92Skamil 2891.92SkamilMLINKS+= mtx.3 mtx_destroy.3 2901.92SkamilMLINKS+= mtx.3 mtx_init.3 2911.92SkamilMLINKS+= mtx.3 mtx_lock.3 2921.92SkamilMLINKS+= mtx.3 mtx_timedlock.3 2931.92SkamilMLINKS+= mtx.3 mtx_trylock.3 2941.92SkamilMLINKS+= mtx.3 mtx_unlock.3 2951.92Skamil 2961.92SkamilMLINKS+= thrd.3 thrd_create.3 2971.92SkamilMLINKS+= thrd.3 thrd_current.3 2981.92SkamilMLINKS+= thrd.3 thrd_detach.3 2991.92SkamilMLINKS+= thrd.3 thrd_equal.3 3001.92SkamilMLINKS+= thrd.3 thrd_exit.3 3011.92SkamilMLINKS+= thrd.3 thrd_join.3 3021.92SkamilMLINKS+= thrd.3 thrd_sleep.3 3031.92SkamilMLINKS+= thrd.3 thrd_yield.3 3041.92Skamil 3051.92SkamilMLINKS+= tss.3 TSS_DTOR_ITERATIONS.3 3061.92SkamilMLINKS+= tss.3 tss_create.3 3071.92SkamilMLINKS+= tss.3 tss_delete.3 3081.92SkamilMLINKS+= tss.3 tss_get.3 3091.92SkamilMLINKS+= tss.3 tss_set.3 3101.92Skamil 3111.92SkamilINCS+= threads.h 3121.92Skamil 3131.93Smaya# PR lib/54001: create libpthread.a as a single large object, with all the 3141.93Smaya# symbols in one section. ensures that if any libpthread function is used, 3151.93Smaya# you get all of them from libpthread, and not the libc stubs. 3161.93Smaya# 3171.93Smaya# This makes -lpthread equivalent to -Wl,--whole-archive -lpthread 3181.93Smaya 3191.93Smaya__archivebuild: .USE 3201.93Smaya ${_MKTARGET_BUILD} 3211.93Smaya @rm -f ${.TARGET} 3221.93Smaya ${LD} -r -o ${.TARGET}.o `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}` 3231.93Smaya ${AR} ${_ARFL} ${.TARGET} ${.TARGET}.o 3241.93Smaya 3251.94SmayaCLEANFILES+= ${_LIBS:=.o} 3261.93Smaya 3271.1Sproven.include <bsd.lib.mk> 3281.1Sproven 3291.9Sthorpej.else 3301.9Sthorpej 3311.9Sthorpej.include <bsd.man.mk> 3321.10Sthorpej.include <bsd.files.mk> 3331.10Sthorpej.include <bsd.inc.mk> 3341.9Sthorpej 3351.9Sthorpej.endif 3361.9Sthorpej 3371.9Sthorpej# WARNS=2 sets -Wcast-qual. This causes problems for one of 3381.9Sthorpej# pthread_setspecific() and pthread_getspecific(), since the constness 3391.9Sthorpej# of the argument to setspecific() has to be discarded *somewhere* 3401.9Sthorpej# before returning it from getspecific(). 3411.77SmattCWARNFLAGS+= -Wno-cast-qual 342