blob: 158bcae2d00fbcee123ccf2514bc48013dba479c [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001# Makefile for uClibc NPTL
2#
3# Copyright (C) 2005-2006 Steven J. Hill <sjhill@realitydiluted.com>
4#
5# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6#
7
8subdirs += libpthread/nptl
9
10libpthread_DIR = $(top_srcdir)libpthread/nptl
11libpthread_OUT = $(top_builddir)libpthread/nptl
12
13include $(libpthread_DIR)/sysdeps/Makefile.in
14
15libc-shared-routines-y = forward.c libc-cancellation.c
16libc-static-routines-y = alloca_cutoff.c libc-cancellation.c
17libpthread-shared-only-routines-y = version.c
18libpthread-static-only-routines-y = pthread_atfork.c
19libpthread-routines- += $(notdir $(wildcard $(libpthread_DIR)/gen_*.c)) # dummy generated files
20libpthread-routines- += allocatestack.c # dummy included by pthread_create.c
21libpthread-routines- += pthread_mutex_getprioceiling.c pthread_mutex_setprioceiling.c # XXX: delete those or use them!
22libpthread-routines-$(UCLIBC_HAS_RESOLVER_SUPPORT) += res.c
23libpthread-routines-$(UCLIBC_SUSV4_LEGACY) += pthread_getconcurrency.c \
24 pthread_setconcurrency
25libpthread_CSRC = $(filter-out $(libpthread-routines-) \
26 $(libc-shared-routines-y) \
27 $(libc-static-routines-y) \
28 $(libpthread-shared-only-routines-y) \
29 $(libpthread-static-only-routines-y) \
30 $(notdir $(libpthread_OBJS:.o=.c)), \
31 $(notdir $(wildcard $(libpthread_DIR)/*.c)))
32
33libpthread_OBJS += $(addprefix $(libpthread_OUT)/,$(libpthread_CSRC:.c=.o))
34libpthread-so-y += $(addprefix $(libpthread_OUT)/,$(libpthread-shared-only-routines-y:.c=.oS))
35libpthread-so-y += $(libpthread_OBJS:.o=.oS)
36libpthread-nonshared-y := $(addprefix $(libpthread_OUT)/,$(libpthread-static-only-routines-y:.c=.oS))
37libpthread-static-y := $(addprefix $(libpthread_OUT)/,$(libpthread-static-only-routines-y:.c=.o))
38libpthread-static-y += $(libpthread_OBJS)
39ifeq ($(DOPIC),y)
40libpthread-a-y := $(libpthread-static-y:.o=.os)
41else
42libpthread-a-y := $(libpthread-static-y)
43endif
44
45libc-shared-routines-y := $(filter-out $(notdir $(libpthread_libc_OBJS:.o=.c)), $(libc-shared-routines-y))
46libc-static-routines-y := $(filter-out $(notdir $(libpthread_libc_OBJS:.o=.c)), $(libc-static-routines-y))
47libc-shared-routines-y := $(addprefix $(libpthread_OUT)/,$(libc-shared-routines-y:.c=.oS))
48libc-static-routines-y := $(addprefix $(libpthread_OUT)/,$(libc-static-routines-y:.c=.o))
49libc-shared-y += $(libc-shared-routines-y) $(libpthread_libc_OBJS:.o=.oS)
50ifeq ($(DOPIC),y)
51libc-static-y += $(libc-static-routines-y:.o=.os) $(libpthread_libc_a_OBJS:.o=.os) $(libpthread_ld_tls_COBJ:.o=.os)
52else
53libc-static-y += $(libc-static-routines-y) $(libpthread_libc_a_OBJS) $(libpthread_ld_tls_COBJ)
54endif
55
56librt-pt-routines-y := $(patsubst %.c,$(libpthread_pthread_OUT)/%.o,$(filter-out $(notdir $(libpthread_librt_OBJS:.o=.c)), $(librt-pt-routines-y)))
57librt-pt-shared-only-routines-y := $(patsubst %.c,$(libpthread_pthread_OUT)/%.o,$(filter-out $(notdir $(libpthread_librt_OBJS:.o=.c)), $(librt-pt-shared-only-routines-y)))
58librt_OBJS = $(libpthread_librt_OBJS) $(librt-pt-routines-y)
59ifeq ($(DOPIC),y)
60librt-a-y += $(librt_OBJS:.o=.os)
61else
62librt-a-y += $(librt_OBJS)
63endif
64librt-so-y += $(librt_OBJS:.o=.oS) $(librt-pt-shared-only-routines-y:.o=.oS)
65
66ifeq ($(UCLIBC_CTOR_DTOR),y)
67START_FILE-libpthread.so := $(top_builddir)libpthread/nptl/sysdeps/pthread/pt-crti.o
68END_FILE-libpthread.so := $(top_builddir)libpthread/nptl/sysdeps/pthread/pt-crtn.o
69LDFLAGS-libpthread.so += -nostartfiles
70$(top_builddir)lib/libpthread.so: | $(START_FILE-libpthread.so) $(END_FILE-libpthread.so)
71endif
72
73libpthread_FULL_NAME := libpthread-$(VERSION).so
74lib-a-$(UCLIBC_HAS_THREADS) += $(top_builddir)lib/libpthread.a
75lib-so-$(UCLIBC_HAS_THREADS) += $(top_builddir)lib/libpthread.so
76
77$(top_builddir)lib/libpthread.so: $(libpthread_OUT)/libpthread_so.a $(libc.depend) $(libdl.depend) $(top_builddir)lib/libpthread_nonshared.a
78 $(call link.so,$(libpthread_FULL_NAME),$(ABI_VERSION))
79 $(Q)cat $(top_srcdir)extra/scripts/format.lds > $@.tmp
80 $(Q)echo "GROUP ( $(notdir $@).$(ABI_VERSION) libpthread_nonshared.a )" >> $@.tmp
81 $(Q)mv $@.tmp $@
82
83ifeq ($(PTHREADS_DEBUG_SUPPORT),y)
84$(libpthread_OUT)/libpthread_so.a: STRIP_FLAGS:=$(STRIP_FLAGS:-x=-X --strip-debug)
85endif
86$(libpthread_OUT)/libpthread_so.a: $(libpthread-so-y)
87 $(Q)$(RM) $@
88 $(do_ar)
89
90$(top_builddir)lib/libpthread.a: $(libpthread-a-y)
91 $(Q)$(INSTALL) -d $(dir $@)
92 $(Q)$(RM) $@
93 $(do_ar)
94
95#
96# Create 'pthread-errnos.h' header file.
97#
98CFLAGS-gen_pthread-errnos.c = -S
99
100$(libpthread_OUT)/gen_pthread-errnos.c: $(libpthread_DIR)/pthread-errnos.sym | $(libpthread_OUT)
101 $(do_awk) $(top_srcdir)extra/scripts/gen-as-const.awk $< > $@
102
103$(libpthread_OUT)/gen_pthread-errnos.s: $(libpthread_OUT)/gen_pthread-errnos.c | headers
104 $(compile.c)
105libpthread-generated-y += $(libpthread_OUT)/gen_pthread-errnos.s
106$(libpthread_OUT)/pthread-errnos.h: $(libpthread_OUT)/gen_pthread-errnos.s
107 $(do_sed) $(PTHREAD_GENERATE_MANGLE) $< > $@
108 @if test ! -s $@ ; then rm -f $@ ; false ; fi
109
110pregen-headers-$(UCLIBC_HAS_THREADS_NATIVE) += $(libpthread_OUT)/pthread-errnos.h
111
112headers-$(UCLIBC_HAS_THREADS_NATIVE) += $(nptl_headers_bootstrap)
113
114libpthread_H := $(addprefix $(top_builddir)include/,semaphore.h)
115libpthread_include_H := $(addprefix $(top_builddir)include/,pthread.h)
116libpthread_include_BITS_H := $(addprefix $(top_builddir)include/bits/,libc-lock.h stdio-lock.h)
117libpthread_include_STD_IMPL_OS_ARCH_BITS_H := $(addprefix $(top_builddir)include/bits/,pthreadtypes.h semaphore.h)
118
119$(libpthread_include_STD_IMPL_OS_ARCH_BITS_H): $(top_builddir)include/bits/%:
120 $(do_ln) $(call rel_srcdir)$(PTDIR)/sysdeps/unix/sysv/linux/$(TARGET_ARCH)/bits/$(@F) $@
121$(libpthread_include_BITS_H): $(top_builddir)include/bits/%:
122 $(do_ln) $(call rel_srcdir)$(PTDIR)/sysdeps/pthread/bits/$(@F) $@
123$(libpthread_include_H): $(top_builddir)include/%:
124 $(do_ln) $(call rel_srcdir)$(PTDIR)/sysdeps/pthread/$(@F) $@
125$(libpthread_H): $(top_builddir)include/%:
126 $(do_ln) $(call rel_srcdir)$(PTDIR)/$(@F) $@
127
128nptl_headers_bootstrap = $(libpthread_H) $(libpthread_include_H) $(libpthread_include_BITS_H) $(libpthread_include_STD_IMPL_OS_ARCH_BITS_H)
129
130objclean-y += CLEAN_libpthread/nptl
131headers_clean-y += HEADERCLEAN_libpthread/nptl
132
133HEADERCLEAN_libpthread/nptl:
134 $(do_rm) $(nptl_headers_bootstrap) \
135 $(addprefix $(libpthread_OUT)/gen_pthread-errnos., c s) \
136 $(libpthread_OUT)/pthread-errnos.h
137
138CLEAN_libpthread/nptl:
139 $(do_rm) $(addprefix $(libpthread_OUT)/*., o os oS a)
140
141ifeq ($(PTHREADS_DEBUG_SUPPORT),y)
142LDFLAGS-libpthread.so += $(LDFLAGS_NOSTRIP) -Wl,-z,defs
143else
144LDFLAGS-libpthread.so += $(LDFLAGS)
145endif
146
147LDFLAGS-libpthread.so += $(top_builddir)lib/$(UCLIBC_LDSO_NAME)-$(VERSION).so $(top_builddir)lib/libdl-$(VERSION).so \
148 -Wl,-z,nodelete,-z,initfirst,-init=__pthread_initialize_minimal_internal
149
150LIBS-libpthread.so := $(LIBS)
151
152CFLAGS-nptl = -DNOT_IN_libc -DIS_IN_libpthread $(SSP_ALL_CFLAGS)
153
154# Since cancellation handling is in large parts handled using exceptions
155# we have to compile some files with exception handling enabled, some
156# even with asynchronous unwind tables.
157
158# init.c contains sigcancel_handler().
159CFLAGS-init.c = -fexceptions -fasynchronous-unwind-tables
160# The unwind code itself,
161CFLAGS-unwind.c = -fexceptions
162CFLAGS-unwind-forcedunwind.c = -fexceptions -fasynchronous-unwind-tables
163
164# The following three functions must be async-cancel safe.
165CFLAGS-pthread_cancel.c = -fexceptions -fasynchronous-unwind-tables
166CFLAGS-pthread_setcancelstate.c = -fexceptions -fasynchronous-unwind-tables
167CFLAGS-pthread_setcanceltype.c = -fexceptions -fasynchronous-unwind-tables
168
169# These are internal functions which similar functionality as setcancelstate
170# and setcanceltype.
171CFLAGS-cancellation.c = -fasynchronous-unwind-tables
172CFLAGS-libc-cancellation.c = -fasynchronous-unwind-tables
173
174# Calling pthread_exit() must cause the registered cancel handlers to
175# be executed. Therefore exceptions have to be thrown through this
176# function.
177CFLAGS-pthread_exit.c = -fexceptions
178
179# Among others, __pthread_unwind is forwarded. This function must handle
180# exceptions.
181CFLAGS-forward.c = -fexceptions
182
183# The following are cancellation points. Some of the functions can
184# block and therefore temporarily enable asynchronous cancellation.
185# Those must be compiled asynchronous unwind tables.
186CFLAGS-pthread_testcancel.c = -fexceptions
187CFLAGS-pthread_join.c = -fexceptions -fasynchronous-unwind-tables
188CFLAGS-pthread_timedjoin.c = -fexceptions -fasynchronous-unwind-tables
189CFLAGS-pthread_once.c = $(uses-callbacks) -fexceptions \
190 -fasynchronous-unwind-tables
191CFLAGS-pthread_cond_wait.c = -fexceptions -fasynchronous-unwind-tables
192CFLAGS-pthread_cond_timedwait.c = -fexceptions -fasynchronous-unwind-tables
193CFLAGS-sem_wait.c = -fexceptions -fasynchronous-unwind-tables
194CFLAGS-sem_timedwait.c = -fexceptions -fasynchronous-unwind-tables
195
196# These are the function wrappers we have to duplicate here.
197CFLAGS-fcntl.c = -fexceptions -fasynchronous-unwind-tables
198CFLAGS-lockf.c = -fexceptions
199CFLAGS-pread.c = -fexceptions -fasynchronous-unwind-tables
200CFLAGS-pread64.c = -fexceptions -fasynchronous-unwind-tables
201CFLAGS-pwrite.c = -fexceptions -fasynchronous-unwind-tables
202CFLAGS-pwrite64.c = -fexceptions -fasynchronous-unwind-tables
203CFLAGS-wait.c = -fexceptions -fasynchronous-unwind-tables
204CFLAGS-waitpid.c = -fexceptions -fasynchronous-unwind-tables
205CFLAGS-sigwait.c = -fexceptions -fasynchronous-unwind-tables
206CFLAGS-msgrcv.c = -fexceptions -fasynchronous-unwind-tables
207CFLAGS-msgsnd.c = -fexceptions -fasynchronous-unwind-tables
208CFLAGS-tcdrain.c = -fexceptions -fasynchronous-unwind-tables
209
210CFLAGS-pt-system.c = -fexceptions -I$(top_srcdir)libc/stdlib
211
212#
213# The rest of this file is uClibc specific.
214#
215CFLAGS-pthread_barrier_init.c = -D_GNU_SOURCE
216CFLAGS-pthread_barrier_destroy.c = -D_GNU_SOURCE
217CFLAGS-pthread_barrierattr_init.c = -D_GNU_SOURCE
218CFLAGS-pthread_barrierattr_destroy.c = -D_GNU_SOURCE
219CFLAGS-pthread_barrierattr_getpshared.c = -D_GNU_SOURCE
220CFLAGS-pthread_barrierattr_setpshared.c = -D_GNU_SOURCE
221CFLAGS-sem_open.c = -D_GNU_SOURCE
222
223CFLAGS-OMIT-alloca_cutoff.c = $(CFLAGS-nptl)
224CFLAGS-OMIT-forward.c = $(CFLAGS-nptl)
225CFLAGS-OMIT-libc-lowlevelock.c = $(CFLAGS-nptl)
226CFLAGS-OMIT-libc-cancellation.c = $(CFLAGS-nptl)