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