1 # $NetBSD: Makefile,v 1.100 2025/04/07 16:07:05 rillig Exp $ 2 # 3 4 NOSANITIZER= # defined 5 WARNS?= 5 6 LIB= pthread 7 8 .include <bsd.own.mk> 9 10 USE_SHLIBDIR= yes 11 12 .if defined(PTHREAD_MACHINE_ARCH) && !empty(PTHREAD_MACHINE_ARCH) && \ 13 exists(${.CURDIR}/arch/${PTHREAD_MACHINE_ARCH}) 14 ARCHSUBDIR= ${PTHREAD_MACHINE_ARCH} 15 .elif defined(PTHREAD_MACHINE_CPU) && !empty(PTHREAD_MACHINE_CPU) && \ 16 exists(${.CURDIR}/arch/${PTHREAD_MACHINE_CPU}) 17 ARCHSUBDIR= ${PTHREAD_MACHINE_CPU} 18 .elif exists(${.CURDIR}/arch/${MACHINE_ARCH}) 19 ARCHSUBDIR= ${MACHINE_ARCH} 20 .elif exists(${.CURDIR}/arch/${MACHINE_CPU}) 21 ARCHSUBDIR= ${MACHINE_CPU} 22 .else 23 .BEGIN: 24 @echo "WARNING: no ARCHSUBDIR for ${MACHINE_ARCH}/${MACHINE_CPU}; skipping..." 25 .endif 26 27 INCS= pthread.h pthread_types.h pthread_queue.h 28 INCSDIR=/usr/include 29 30 .if defined(ARCHSUBDIR) 31 32 ARCHDIR= ${.CURDIR}/arch/${ARCHSUBDIR} 33 .PATH: ${ARCHDIR} 34 35 EXPSYM_SRCS+= pthread_mi.expsym 36 . if ${MACHINE_ARCH} == "alpha" || ${MACHINE_ARCH} == "hppa" 37 # PTHREAD__ASM_RASOPS 38 EXPSYM_SRCS+= pthread_md.expsym 39 . else 40 # !PTHREAD__ASM_RASOPS 41 # XXX These really shouldn't be exported. 42 EXPSYM_SRCS+= pthread_ras.expsym 43 . endif 44 45 LIB_EXPSYM= pthread.expsym 46 pthread.expsym: ${EXPSYM_SRCS} 47 ${_MKTARGET_CREATE} 48 LC_ALL=C sort -m ${.ALLSRC} >${.TARGET}.tmp && \ 49 ${MV} ${.TARGET}.tmp ${.TARGET} 50 CLEANFILES+= pthread.expsym pthread.expsym.tmp 51 52 CPPFLAGS+= -I${ARCHDIR} -I${.CURDIR} -I${.OBJDIR} -D_LIBC -D_REENTRANT 53 CPPFLAGS+= -I${.CURDIR}/../libc/include 54 CPPFLAGS+= -D__LIBPTHREAD_SOURCE__ -D__LIBC_THREAD_STUBS 55 56 # Since <pthread.h> is not used, allow declaring pthread_create and 57 # friends locally. 58 CWARNFLAGS.clang+= -Wno-builtin-requires-header 59 60 # XXX: This crappy poke at libc's internals needs to be fixed. 61 CPPFLAGS+=-I${NETBSDSRCDIR}/sys -I${.CURDIR}/../libc 62 63 # providing alternative MI implementations for creating an lwp is 64 # possible by setting PTHREAD_MAKELWP. Currently, alternatives are 65 # set by the rumprun software stacks (see https://github.com/rumpkernel/rumprun ) 66 PTHREAD_MAKELWP?= pthread_makelwp_netbsd.c 67 68 # 69 # NOTE: When you create a new file for libpthread, make sure that pthread.c 70 # gets a reference to a symbol in that file. Otherwise, Unix's stupid static 71 # library semantics will end up discarding potentially important objects. 72 # 73 SRCS= pthread.c 74 SRCS+= pthread_attr.c 75 SRCS+= pthread_barrier.c 76 # used by rumprun-posix to work around symbol collisions 77 .if ${PTHREAD_CANCELSTUB:Uyes} != "no" 78 SRCS+= pthread_cancelstub.c 79 .endif 80 SRCS+= pthread_cond.c 81 SRCS+= pthread_getcpuclockid.c 82 SRCS+= pthread_lock.c 83 SRCS+= ${PTHREAD_MAKELWP} 84 SRCS+= pthread_misc.c 85 SRCS+= pthread_mutex.c 86 SRCS+= pthread_once.c 87 SRCS+= pthread_rwlock.c 88 SRCS+= pthread_specific.c 89 SRCS+= pthread_spin.c 90 SRCS+= pthread_tsd.c 91 SRCS+= res_state.c 92 .PATH: ${.CURDIR}/../librt 93 SRCS+= sem.c 94 # Architecture-dependent files 95 .if exists(${ARCHDIR}/pthread_md.S) 96 SRCS+= pthread_md.S 97 .endif 98 .if exists(${ARCHDIR}/Makefile.inc) 99 .include "${ARCHDIR}/Makefile.inc" 100 .endif 101 102 # The PTHREAD__COMPAT flag builds a libpthread that can be dropped 103 # into a NetBSD 2/3/4 chroot with a NetBSD 5 or later kernel. 104 # This makes threading work in the chroot, no other modifications 105 # required. 106 # 107 .if defined(PTHREAD__COMPAT) 108 SRCS+= pthread_compat.c 109 .PATH.c: ${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic 110 .PATH.S: ${.CURDIR}/../../common/lib/libc/arch/${ARCHSUBDIR}/atomic 111 .PATH.c: ${.CURDIR}/../../common/lib/libc/atomic 112 .PATH.c: ${.CURDIR}/../libc/misc 113 .include "../../common/lib/libc/arch/${ARCHSUBDIR}/atomic/Makefile.inc" 114 .endif 115 116 ALIGN_FUNCTIONS= ${${ACTIVE_CC} == "gcc":? -falign-functions=32 :} 117 118 # The TSD routines are used in the implementation of profiling, and so 119 # can't be profiled themselves. 120 COPTS.pthread_specific.c+= ${ALIGN_FUNCTIONS} 121 pthread_specific.po: pthread_specific.o 122 ${_MKTARGET_CREATE} 123 cp pthread_specific.o pthread_specific.po 124 125 COPTS.pthread.c += -Wno-stack-protector -Wno-format-nonliteral 126 COPTS.pthread_attr.c += -Wno-format-nonliteral 127 128 LINTFLAGS+= -Ac11 # for _Atomic 129 130 MAN+= affinity.3 pthread.3 \ 131 pthread_attr.3 \ 132 pthread_attr_get_np.3 \ 133 pthread_attr_getdetachstate.3 \ 134 pthread_attr_getguardsize.3 \ 135 pthread_attr_getinheritsched.3 \ 136 pthread_attr_getname_np.3 \ 137 pthread_attr_getschedparam.3 \ 138 pthread_attr_getscope.3 \ 139 pthread_attr_getstack.3 \ 140 pthread_attr_setcreatesuspend_np.3 \ 141 pthread_barrier.3 pthread_barrierattr.3 \ 142 pthread_cancel.3 pthread_cleanup_push.3 \ 143 pthread_cond.3 pthread_condattr.3 \ 144 pthread_create.3 pthread_detach.3 pthread_equal.3 \ 145 pthread_curcpu_np.3 \ 146 pthread_exit.3 \ 147 pthread_getcpuclockid.3 \ 148 pthread_getname_np.3 \ 149 pthread_getspecific.3 pthread_join.3 \ 150 pthread_key_create.3 pthread_kill.3 \ 151 pthread_mutex.3 pthread_mutexattr.3 \ 152 pthread_once.3 pthread_rwlock.3 pthread_rwlockattr.3 \ 153 pthread_schedparam.3 pthread_self.3 \ 154 pthread_sigmask.3 pthread_spin.3 \ 155 pthread_suspend_np.3 pthread_testcancel.3 156 157 MLINKS+= pthread_attr_get_np.3 pthread_getattr_np.3 158 MLINKS+= affinity.3 pthread_setaffinity_np.3 159 MLINKS+= affinity.3 pthread_getaffinity_np.3 160 161 MLINKS+= pthread_attr.3 pthread_attr_init.3 162 MLINKS+= pthread_attr.3 pthread_attr_destroy.3 163 164 MLINKS+= pthread_attr_getdetachstate.3 pthread_attr_setdetachstate.3 165 MLINKS+= pthread_attr_getguardsize.3 pthread_attr_setguardsize.3 166 MLINKS+= pthread_attr_getinheritsched.3 pthread_attr_setinheritsched.3 167 MLINKS+= pthread_attr_getname_np.3 pthread_attr_setname_np.3 168 169 MLINKS+= pthread_attr_getschedparam.3 pthread_attr_setschedparam.3 \ 170 pthread_attr_getschedparam.3 pthread_attr_getschedpolicy.3 \ 171 pthread_attr_getschedparam.3 pthread_attr_setschedpolicy.3 172 173 MLINKS+= pthread_attr_getscope.3 pthread_attr_setscope.3 174 175 MLINKS+= pthread_attr_getstack.3 pthread_attr_setstack.3 \ 176 pthread_attr_getstack.3 pthread_attr_getstacksize.3 \ 177 pthread_attr_getstack.3 pthread_attr_setstacksize.3 \ 178 pthread_attr_getstack.3 pthread_attr_getstackaddr.3 \ 179 pthread_attr_getstack.3 pthread_attr_setstackaddr.3 180 181 MLINKS+= pthread_cleanup_push.3 pthread_cleanup_pop.3 182 183 MLINKS+= pthread_barrier.3 pthread_barrier_init.3 184 MLINKS+= pthread_barrier.3 pthread_barrier_destroy.3 185 MLINKS+= pthread_barrier.3 pthread_barrier_wait.3 186 187 MLINKS+= pthread_barrierattr.3 pthread_barrierattr_init.3 188 MLINKS+= pthread_barrierattr.3 pthread_barrierattr_destroy.3 189 MLINKS+= pthread_barrierattr.3 pthread_barrierattr_getpshared.3 190 MLINKS+= pthread_barrierattr.3 pthread_barrierattr_setpshared.3 191 192 MLINKS+= pthread_cond.3 pthread_cond_init.3 193 MLINKS+= pthread_cond.3 pthread_cond_destroy.3 194 MLINKS+= pthread_cond.3 pthread_cond_broadcast.3 195 MLINKS+= pthread_cond.3 pthread_cond_wait.3 196 MLINKS+= pthread_cond.3 pthread_cond_signal.3 197 MLINKS+= pthread_cond.3 pthread_cond_timedwait.3 198 199 MLINKS+= pthread_condattr.3 pthread_condattr_init.3 200 MLINKS+= pthread_condattr.3 pthread_condattr_destroy.3 201 MLINKS+= pthread_condattr.3 pthread_condattr_setclock.3 202 MLINKS+= pthread_condattr.3 pthread_condattr_getclock.3 203 MLINKS+= pthread_condattr.3 pthread_condattr_getpshared.3 204 MLINKS+= pthread_condattr.3 pthread_condattr_setpshared.3 205 206 MLINKS+= pthread_getname_np.3 pthread_setname_np.3 207 MLINKS+= pthread_getspecific.3 pthread_setspecific.3 208 MLINKS+= pthread_key_create.3 pthread_key_delete.3 209 210 MLINKS+= pthread_mutex.3 pthread_mutex_init.3 211 MLINKS+= pthread_mutex.3 pthread_mutex_destroy.3 212 MLINKS+= pthread_mutex.3 pthread_mutex_lock.3 213 MLINKS+= pthread_mutex.3 pthread_mutex_trylock.3 214 MLINKS+= pthread_mutex.3 pthread_mutex_unlock.3 215 MLINKS+= pthread_mutex.3 pthread_mutex_timedlock.3 216 MLINKS+= pthread_mutex.3 pthread_mutex_getprioceiling.3 217 MLINKS+= pthread_mutex.3 pthread_mutex_setprioceiling.3 218 219 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_init.3 220 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_destroy.3 221 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_getpshared.3 222 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_setpshared.3 223 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_settype.3 224 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_gettype.3 225 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_getprotocol.3 226 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_setprotocol.3 227 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_getprioceiling.3 228 MLINKS+= pthread_mutexattr.3 pthread_mutexattr_setprioceiling.3 229 230 MLINKS+= pthread_rwlock.3 pthread_rwlock_init.3 231 MLINKS+= pthread_rwlock.3 pthread_rwlock_destroy.3 232 MLINKS+= pthread_rwlock.3 pthread_rwlock_rdlock.3 233 MLINKS+= pthread_rwlock.3 pthread_rwlock_wrlock.3 234 MLINKS+= pthread_rwlock.3 pthread_rwlock_unlock.3 235 236 MLINKS+= pthread_rwlock.3 pthread_rwlock_timedrdlock.3 237 MLINKS+= pthread_rwlock.3 pthread_rwlock_timedwrlock.3 238 MLINKS+= pthread_rwlock.3 pthread_rwlock_tryrdlock.3 239 MLINKS+= pthread_rwlock.3 pthread_rwlock_trywrlock.3 240 241 MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_init.3 242 MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_destroy.3 243 MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_getpshared.3 244 MLINKS+= pthread_rwlockattr.3 pthread_rwlockattr_setpshared.3 245 246 MLINKS+= pthread_spin.3 pthread_spin_init.3 247 MLINKS+= pthread_spin.3 pthread_spin_destroy.3 248 MLINKS+= pthread_spin.3 pthread_spin_lock.3 249 MLINKS+= pthread_spin.3 pthread_spin_trylock.3 250 MLINKS+= pthread_spin.3 pthread_spin_unlock.3 251 252 MLINKS+= pthread_schedparam.3 pthread_setschedparam.3 253 MLINKS+= pthread_schedparam.3 pthread_getschedparam.3 254 MLINKS+= pthread_suspend_np.3 pthread_resume_np.3 255 MLINKS+= pthread_testcancel.3 pthread_setcancelstate.3 256 MLINKS+= pthread_testcancel.3 pthread_setcanceltype.3 257 258 # ISO C threads (ISO/IEC 9899:2011) 259 260 SRCS+= call_once.c cnd.c mtx.c thrd.c tss.c 261 MAN+= threads.3 call_once.3 cnd.3 mtx.3 thrd.3 tss.3 262 263 MLINKS+= call_once.3 ONCE_FLAG_INIT.3 264 MLINKS+= call_once.3 once_flag.3 265 266 MLINKS+= cnd.3 cnd_broadcast.3 267 MLINKS+= cnd.3 cnd_destroy.3 268 MLINKS+= cnd.3 cnd_init.3 269 MLINKS+= cnd.3 cnd_signal.3 270 MLINKS+= cnd.3 cnd_timedwait.3 271 MLINKS+= cnd.3 cnd_wait.3 272 273 MLINKS+= mtx.3 mtx_destroy.3 274 MLINKS+= mtx.3 mtx_init.3 275 MLINKS+= mtx.3 mtx_lock.3 276 MLINKS+= mtx.3 mtx_timedlock.3 277 MLINKS+= mtx.3 mtx_trylock.3 278 MLINKS+= mtx.3 mtx_unlock.3 279 280 MLINKS+= thrd.3 thrd_create.3 281 MLINKS+= thrd.3 thrd_current.3 282 MLINKS+= thrd.3 thrd_detach.3 283 MLINKS+= thrd.3 thrd_equal.3 284 MLINKS+= thrd.3 thrd_exit.3 285 MLINKS+= thrd.3 thrd_join.3 286 MLINKS+= thrd.3 thrd_sleep.3 287 MLINKS+= thrd.3 thrd_yield.3 288 289 MLINKS+= tss.3 TSS_DTOR_ITERATIONS.3 290 MLINKS+= tss.3 tss_create.3 291 MLINKS+= tss.3 tss_delete.3 292 MLINKS+= tss.3 tss_get.3 293 MLINKS+= tss.3 tss_set.3 294 295 INCS+= threads.h 296 297 # PR lib/54001: create libpthread.a as a single large object, with all the 298 # symbols in one section. ensures that if any libpthread function is used, 299 # you get all of them from libpthread, and not the libc stubs. 300 # 301 # This makes -lpthread equivalent to -Wl,--whole-archive -lpthread 302 303 __archivebuild: .USE 304 ${_MKTARGET_BUILD} 305 @rm -f ${.TARGET} 306 ${LD} -r -o ${.TARGET}.o `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}` 307 ${AR} ${_ARFL} ${.TARGET} ${.TARGET}.o 308 309 CLEANFILES+= ${_LIBS:=.o} 310 311 .include <bsd.lib.mk> 312 313 .else 314 315 .include <bsd.man.mk> 316 .include <bsd.files.mk> 317 .include <bsd.inc.mk> 318 319 .endif 320 321 # WARNS=2 sets -Wcast-qual. This causes problems for one of 322 # pthread_setspecific() and pthread_getspecific(), since the constness 323 # of the argument to setspecific() has to be discarded *somewhere* 324 # before returning it from getspecific(). 325 CWARNFLAGS+= -Wno-cast-qual 326