1 # Makefile for uClibc NPTL
3 # Copyright (C) 2005-2006 Steven J. Hill <sjhill@realitydiluted.com>
5 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8 subdirs += libpthread/nptl/sysdeps/$(TARGET_ARCH) \
9 libpthread/nptl/sysdeps/unix/sysv/linux \
10 libpthread/nptl/sysdeps/pthread
12 libpthread-routines-y = init vars events version \
13 pthread_create pthread_exit pthread_detach \
14 pthread_join pthread_tryjoin pthread_timedjoin \
15 pthread_self pthread_equal pthread_yield \
16 pthread_getconcurrency pthread_setconcurrency \
17 pthread_getschedparam pthread_setschedparam \
18 pthread_setschedprio \
19 pthread_attr_init pthread_attr_destroy \
20 pthread_attr_getdetachstate pthread_attr_setdetachstate \
21 pthread_attr_getguardsize pthread_attr_setguardsize \
22 pthread_attr_getschedparam pthread_attr_setschedparam \
23 pthread_attr_getschedpolicy pthread_attr_setschedpolicy \
24 pthread_attr_getinheritsched \
25 pthread_attr_setinheritsched \
26 pthread_attr_getscope pthread_attr_setscope \
27 pthread_attr_getstackaddr pthread_attr_setstackaddr \
28 pthread_attr_getstacksize pthread_attr_setstacksize \
29 pthread_attr_getstack pthread_attr_setstack \
31 pthread_mutex_init pthread_mutex_destroy \
32 pthread_mutex_lock pthread_mutex_trylock \
33 pthread_mutex_timedlock pthread_mutex_unlock \
34 pthread_mutex_consistent \
35 pthread_mutexattr_init pthread_mutexattr_destroy \
36 pthread_mutexattr_getpshared \
37 pthread_mutexattr_setpshared \
38 pthread_mutexattr_getrobust \
39 pthread_mutexattr_setrobust \
40 pthread_mutexattr_getprotocol \
41 pthread_mutexattr_setprotocol \
42 pthread_mutexattr_getprioceiling \
43 pthread_mutexattr_setprioceiling \
44 pthread_mutexattr_gettype pthread_mutexattr_settype \
45 pthread_rwlock_init pthread_rwlock_destroy \
46 pthread_rwlock_rdlock pthread_rwlock_timedrdlock \
47 pthread_rwlock_wrlock pthread_rwlock_timedwrlock \
48 pthread_rwlock_tryrdlock pthread_rwlock_trywrlock \
49 pthread_rwlock_unlock \
50 pthread_rwlockattr_init pthread_rwlockattr_destroy \
51 pthread_rwlockattr_getpshared \
52 pthread_rwlockattr_setpshared \
53 pthread_rwlockattr_getkind_np \
54 pthread_rwlockattr_setkind_np \
55 pthread_cond_init pthread_cond_destroy \
56 pthread_cond_wait pthread_cond_timedwait \
57 pthread_cond_signal pthread_cond_broadcast \
58 pthread_condattr_init pthread_condattr_destroy \
59 pthread_condattr_getpshared pthread_condattr_setpshared \
60 pthread_condattr_getclock pthread_condattr_setclock \
61 pthread_spin_init pthread_spin_destroy \
62 pthread_spin_lock pthread_spin_trylock \
64 pthread_barrier_init pthread_barrier_destroy \
65 pthread_barrier_wait \
66 pthread_barrierattr_init pthread_barrierattr_destroy \
67 pthread_barrierattr_getpshared \
68 pthread_barrierattr_setpshared \
69 pthread_key_create pthread_key_delete \
70 pthread_getspecific pthread_setspecific \
71 pthread_sigmask pthread_kill \
72 pthread_cancel pthread_testcancel \
73 pthread_setcancelstate pthread_setcanceltype \
76 pthread_getcpuclockid \
77 pthread_clock_gettime pthread_clock_settime \
78 sem_init sem_destroy \
79 sem_open sem_close sem_unlink \
81 sem_wait sem_trywait sem_timedwait sem_post \
82 cleanup cleanup_defer cleanup_compat \
83 cleanup_defer_compat unwind \
84 pt-longjmp pt-cleanup\
88 ptw-write ptw-read ptw-close ptw-fcntl ptw-accept \
89 ptw-connect ptw-recv ptw-recvfrom ptw-recvmsg ptw-send \
90 ptw-sendmsg ptw-sendto ptw-fsync ptw-lseek ptw-llseek \
91 ptw-msync ptw-nanosleep ptw-open ptw-open64 ptw-pause \
92 ptw-pread ptw-pread64 ptw-pwrite ptw-pwrite64 \
93 ptw-tcdrain ptw-wait ptw-waitpid ptw-msgrcv ptw-msgsnd \
96 flockfile ftrylockfile funlockfile \
99 pthread_kill_other_threads \
100 pthread_getaffinity pthread_setaffinity \
101 pthread_attr_getaffinity pthread_attr_setaffinity \
102 cleanup_routine unwind-forcedunwind
103 libpthread-routines-$(findstring y,$(UCLIBC_HAS_IPV4)$(UCLIBC_HAS_IPV6)) += res
105 libpthread-shared-only-routines = version pt-allocrtsig unwind-forcedunwind
107 ifeq ($(TARGET_ARCH),x86_64)
108 libpthread-routines-y := $(filter-out cancellation,$(libpthread-routines-y))
111 CFLAGS-pthread_atfork.c = -DNOT_IN_libc
113 # Since cancellation handling is in large parts handled using exceptions
114 # we have to compile some files with exception handling enabled, some
115 # even with asynchronous unwind tables.
117 # init.c contains sigcancel_handler().
118 CFLAGS-init.c = -fexceptions -fasynchronous-unwind-tables
119 # The unwind code itself,
120 CFLAGS-unwind.c = -fexceptions
121 CFLAGS-unwind-forcedunwind.c = -fexceptions -fasynchronous-unwind-tables
123 # The following three functions must be async-cancel safe.
124 CFLAGS-pthread_cancel.c = -fexceptions -fasynchronous-unwind-tables
125 CFLAGS-pthread_setcancelstate.c = -fexceptions -fasynchronous-unwind-tables
126 CFLAGS-pthread_setcanceltype.c = -fexceptions -fasynchronous-unwind-tables
128 # These are internal functions which similar functionality as setcancelstate
130 CFLAGS-cancellation.c = -fasynchronous-unwind-tables
131 CFLAGS-libc-cancellation.c = -fasynchronous-unwind-tables
133 # Calling pthread_exit() must cause the registered cancel handlers to
134 # be executed. Therefore exceptions have to be thrown through this
136 CFLAGS-pthread_exit.c = -fexceptions
138 # Among others, __pthread_unwind is forwarded. This function must handle
140 CFLAGS-forward.c = -fexceptions
142 # The following are cancellation points. Some of the functions can
143 # block and therefore temporarily enable asynchronous cancellation.
144 # Those must be compiled asynchronous unwind tables.
145 CFLAGS-pthread_testcancel.c = -fexceptions
146 CFLAGS-pthread_join.c = -fexceptions -fasynchronous-unwind-tables
147 CFLAGS-pthread_timedjoin.c = -fexceptions -fasynchronous-unwind-tables
148 CFLAGS-pthread_once.c = $(uses-callbacks) -fexceptions \
149 -fasynchronous-unwind-tables
150 CFLAGS-pthread_cond_wait.c = -fexceptions -fasynchronous-unwind-tables
151 CFLAGS-pthread_cond_timedwait.c = -fexceptions -fasynchronous-unwind-tables
152 CFLAGS-sem_wait.c = -fexceptions -fasynchronous-unwind-tables
153 CFLAGS-sem_timedwait.c = -fexceptions -fasynchronous-unwind-tables
155 # These are the function wrappers we have to duplicate here.
156 CFLAGS-fcntl.c = -fexceptions -fasynchronous-unwind-tables
157 CFLAGS-lockf.c = -fexceptions
158 CFLAGS-pread.c = -fexceptions -fasynchronous-unwind-tables
159 CFLAGS-pread64.c = -fexceptions -fasynchronous-unwind-tables
160 CFLAGS-pwrite.c = -fexceptions -fasynchronous-unwind-tables
161 CFLAGS-pwrite64.c = -fexceptions -fasynchronous-unwind-tables
162 CFLAGS-wait.c = -fexceptions -fasynchronous-unwind-tables
163 CFLAGS-waitpid.c = -fexceptions -fasynchronous-unwind-tables
164 CFLAGS-sigwait.c = -fexceptions -fasynchronous-unwind-tables
165 CFLAGS-msgrcv.c = -fexceptions -fasynchronous-unwind-tables
166 CFLAGS-msgsnd.c = -fexceptions -fasynchronous-unwind-tables
167 CFLAGS-tcdrain.c = -fexceptions -fasynchronous-unwind-tables
169 CFLAGS-pt-system.c = -fexceptions -I./libc/stdlib
172 # The rest of this file is uClibc specific.
174 CFLAGS-pthread_barrier_init.c = -D_GNU_SOURCE
175 CFLAGS-pthread_barrier_destroy.c = -D_GNU_SOURCE
176 CFLAGS-pthread_barrierattr_init.c = -D_GNU_SOURCE
177 CFLAGS-pthread_barrierattr_destroy.c = -D_GNU_SOURCE
178 CFLAGS-pthread_barrierattr_getpshared.c = -D_GNU_SOURCE
179 CFLAGS-pthread_barrierattr_setpshared.c = -D_GNU_SOURCE
180 CFLAGS-sem_open.c = -D_GNU_SOURCE
182 CFLAGS-nptl = -DNOT_IN_libc=1 -DIS_IN_libpthread=1 $(SSP_ALL_CFLAGS)
184 CFLAGS-OMIT-alloca_cutoff.c = -DNOT_IN_libc=1 -DIS_IN_libpthread=1
185 CFLAGS-OMIT-forward.c = -DNOT_IN_libc=1 -DIS_IN_libpthread=1
186 CFLAGS-OMIT-libc-lowlevelock.c = -DNOT_IN_libc=1 -DIS_IN_libpthread=1
187 CFLAGS-OMIT-libc-cancellation.c = -DNOT_IN_libc=1 -DIS_IN_libpthread=1
189 libpthread-os-routines = pthread_yield
190 libpthread-misc-routines = pthread_rwlock_rdlock pthread_rwlock_timedrdlock \
191 pthread_rwlock_wrlock pthread_rwlock_timedwrlock \
192 pthread_rwlock_unlock pthread_cond_wait \
193 pthread_cond_timedwait pthread_cond_signal \
194 pthread_cond_broadcast pthread_spin_init \
195 pthread_spin_destroy pthread_spin_lock \
196 pthread_spin_trylock pthread_spin_unlock \
197 pthread_barrier_init pthread_barrier_destroy \
198 pthread_barrier_wait pthread_sigmask \
199 pthread_kill pthread_once \
200 pthread_getcpuclockid sem_wait \
201 sem_trywait sem_timedwait \
202 sem_post pt-longjmp \
203 lowlevellock pt-vfork \
204 ptw-close ptw-read ptw-write \
205 ptw-fcntl ptw-accept ptw-connect \
206 ptw-recv ptw-recvfrom ptw-recvmsg \
207 ptw-send ptw-sendmsg ptw-sendto \
208 ptw-fsync ptw-lseek ptw-llseek \
209 ptw-msync ptw-nanosleep ptw-open \
210 ptw-open64 ptw-pause ptw-pread \
211 ptw-pread64 ptw-pwrite ptw-pwrite64 \
212 ptw-tcdrain ptw-wait ptw-waitpid \
213 ptw-msgrcv ptw-msgsnd ptw-sigwait \
214 pt-raise flockfile ftrylockfile \
215 funlockfile sigaction \
216 pthread_getaffinity \
217 pthread_setaffinity \
218 pthread_attr_getaffinity \
219 pthread_attr_setaffinity \
222 ifeq ($(PTHREADS_DEBUG_SUPPORT),y)
223 LDFLAGS-libpthread.so := $(LDFLAGS_NOSTRIP) -Wl,-z,defs
225 LDFLAGS-libpthread.so := $(LDFLAGS)
228 LDFLAGS-libpthread.so += $(top_builddir)lib/$(UCLIBC_LDSO_NAME)-$(VERSION).so $(top_builddir)lib/libdl-$(VERSION).so -Wl,-z,nodelete,-z,initfirst,-init=__pthread_initialize_minimal_internal
230 LIBS-libpthread.so := $(LIBS)
232 ifneq ($(UCLIBC_CTOR_DTOR),y)
233 START_FILE-libpthread.so := $(top_builddir)/libpthread/nptl/sysdeps/pthread/crti.o $(SHARED_START_FILES)
234 END_FILE-libpthread.so := $(SHARED_END_FILES) $(top_builddir)/libpthread/nptl/sysdeps/pthread/crtn.o
237 libpthread_FULL_NAME := libpthread-$(VERSION).so
239 PTHREAD_DIR := $(top_srcdir)libpthread/nptl
240 PTHREAD_OUT := $(top_builddir)libpthread/nptl
242 libpthread_static_SRC := pthread_atfork
244 libpthread_a_SRC = $(patsubst %, $(PTHREAD_DIR)/%.c, \
245 $(filter-out $(libpthread-os-routines) \
246 $(libpthread-misc-routines) \
247 $(libpthread-shared-only-routines), \
248 $(libpthread-routines-y)))
249 libpthread_so_SRC = $(patsubst %, $(PTHREAD_DIR)/%.c, \
250 $(filter-out $(libpthread-os-routines) \
251 $(libpthread-misc-routines), $(libpthread-routines-y)))
253 ifeq ($(TARGET_ARCH),x86_64)
254 libc-static-y += $(patsubst %.c, $(PTHREAD_OUT)/%.o, alloca_cutoff.c)
255 libc-shared-y += $(patsubst %.c, $(PTHREAD_OUT)/%.oS, forward.c)
257 libc-static-y += $(patsubst %.c, $(PTHREAD_OUT)/%.o, alloca_cutoff.c \
259 libc-shared-y += $(patsubst %.c, $(PTHREAD_OUT)/%.oS, forward.c \
263 libpthread-nonshared-y += $(patsubst %,$(PTHREAD_OUT)/%.oS,$(libpthread_static_SRC))
267 libpthread-a-y := $(patsubst $(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.os,$(libpthread_a_SRC))
269 libpthread-a-y := $(patsubst $(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.o,$(libpthread_a_SRC))
272 libpthread-so-y := $(patsubst $(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.oS,$(libpthread_so_SRC))
273 libpthread-static-y += $(patsubst $(PTHREAD_DIR)/%.c,$(PTHREAD_OUT)/%.o,$(libpthread_a_SRC) $(libpthread_static_SRC))
275 objclean-y += CLEAN_libpthread/nptl
276 headers_clean-y += HEADERCLEAN_libpthread/nptl
278 -include $(PTHREAD_DIR)/sysdeps/generic/Makefile.in
279 -include $(PTHREAD_DIR)/sysdeps/pthread/Makefile.in
280 -include $(PTHREAD_DIR)/sysdeps/$(TARGET_ARCH)/Makefile.arch
281 -include $(PTHREAD_DIR)/sysdeps/unix/sysv/linux/Makefile.in
282 -include $(PTHREAD_DIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/Makefile.arch
284 lib-a-$(UCLIBC_HAS_THREADS) += $(top_builddir)lib/libpthread.a
285 lib-so-$(UCLIBC_HAS_THREADS) += $(top_builddir)lib/libpthread.so
287 $(top_builddir)lib/libpthread.so: $(PTHREAD_OUT)/libpthread_so.a $(libc.depend) $(libdl.depend) $(top_builddir)lib/libpthread_nonshared.a
288 $(call link.so,$(libpthread_FULL_NAME),$(ABI_VERSION))
289 $(Q)cat $(top_srcdir)extra/scripts/format.lds > $@.tmp
290 $(Q)echo "GROUP ( $(notdir $@).$(ABI_VERSION) libpthread_nonshared.a )" >> $@.tmp
293 ifeq ($(PTHREADS_DEBUG_SUPPORT),y)
294 $(PTHREAD_OUT)/libpthread_so.a: STRIP_FLAGS:=$(STRIP_FLAGS:-x=-X --strip-debug)
296 $(PTHREAD_OUT)/libpthread_so.a: $(libpthread-so-y)
300 $(top_builddir)lib/libpthread.a: $(libpthread-a-y)
301 $(Q)$(INSTALL) -d $(dir $@)
306 # Create 'pthread-errnos.h' header file.
308 CFLAGS-pthread-errnos.c = -S
310 $(PTHREAD_OUT)/pthread-errnos.c: $(PTHREAD_DIR)/pthread-errnos.sym
311 $(do_awk) $(top_srcdir)extra/scripts/gen-as-const.awk $< > $@
313 $(PTHREAD_OUT)/pthread-errnos.s: $(PTHREAD_OUT)/pthread-errnos.c
316 $(PTHREAD_OUT)/pthread-errnos.h: $(PTHREAD_OUT)/pthread-errnos.s
317 $(do_sed) -n "s/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$\/#define \1 \2/p" $< > $@
319 pregen-headers-$(UCLIBC_HAS_THREADS_NATIVE) += $(PTHREAD_OUT)/pthread-errnos.h
321 headers-$(UCLIBC_HAS_THREADS_NATIVE) += $(nptl_headers_bootstrap)
323 $(top_builddir)include/pthread.h:
324 $(do_ln) ../$(PTDIR)/sysdeps/pthread/$(@F) $(top_builddir)$@
325 $(top_builddir)include/semaphore.h:
326 $(do_ln) ../$(PTDIR)/$(@F) $(top_builddir)$@
327 $(top_builddir)include/bits/semaphore.h: | include/bits
328 $(do_ln) ../../$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/bits/$(@F) $(top_builddir)$@
329 $(top_builddir)include/bits/pthreadtypes.h: | include/bits
330 $(do_ln) ../../$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/bits/$(@F) $(top_builddir)$@
331 $(top_builddir)include/bits/libc-lock.h: | include/bits
332 $(do_ln) ../../$(PTDIR)/sysdeps/pthread/bits/$(@F) $(top_builddir)$@
333 $(top_builddir)include/bits/stdio-lock.h: | include/bits
334 $(do_ln) ../../$(PTDIR)/sysdeps/pthread/bits/$(@F) $(top_builddir)$@
336 nptl_headers_bootstrap := $(top_builddir)include/pthread.h \
337 $(top_builddir)include/semaphore.h \
338 $(top_builddir)include/bits/semaphore.h \
339 $(top_builddir)include/bits/pthreadtypes.h \
340 $(top_builddir)include/bits/libc-lock.h \
341 $(top_builddir)include/bits/stdio-lock.h
344 HEADERCLEAN_libpthread/nptl:
345 $(do_rm) $(nptl_headers_bootstrap) \
346 $(addprefix $(PTHREAD_OUT)/pthread-errnos., c h s)
348 CLEAN_libpthread/nptl:
349 $(do_rm) $(addprefix $(PTHREAD_OUT)/*., o os oS a)