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