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