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