]> git.ipfire.org Git - thirdparty/glibc.git/blame - linuxthreads/Makefile
* config.make.in (fno-unit-at-a-time): Define.
[thirdparty/glibc.git] / linuxthreads / Makefile
CommitLineData
bf293afe 1# Copyright (C) 1996-2002, 2003 Free Software Foundation, Inc.
5afdca00
UD
2# This file is part of the GNU C Library.
3
4# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
5# modify it under the terms of the GNU Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 2.1 of the License, or (at your option) any later version.
5afdca00
UD
8
9# The GNU C Library is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12# Lesser General Public License for more details.
5afdca00 13
41bdb6e2
AJ
14# You should have received a copy of the GNU Lesser General Public
15# License along with the GNU C Library; if not, write to the Free
16# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17# 02111-1307 USA.
5afdca00
UD
18
19#
20# Sub-makefile for linuxthreads portion of the library.
21#
22subdir := linuxthreads
23
5181d776
RM
24all: # Make this the default target; it will be defined in Rules.
25
7cabd57c
UD
26linuxthreads-version := $(shell sed -n 's/^.*$(subdir)-\([0-9.]*\).*$$/\1/p' \
27 Banner)
5afdca00 28
f8afba91 29headers := pthread.h semaphore.h
53da80ab 30distribute := internals.h queue.h restart.h spinlock.h smp.h tst-signal.sh \
82f81a90 31 tst-cancel-wrappers.sh libc-tsd.c
5afdca00 32
270d9d47 33routines := forward alloca_cutoff libc-cancellation libc_pthread_init
82f81a90 34shared-only-routines = forward
5afdca00
UD
35
36extra-libs := libpthread
37extra-libs-others := $(extra-libs)
970d0b1d 38install-lib-ldscripts := libpthread.so
5afdca00
UD
39
40libpthread-routines := attr cancel condvar join manager mutex ptfork \
9a197dcc
RM
41 ptlongjmp pthread pt-sigsuspend signals specific errno \
42 lockfile semaphore spinlock rwlock pt-machine \
3b5c1b57 43 oldsemaphore events getcpuclockid pspinlock barrier \
f0377954 44 ptclock_gettime ptclock_settime sighandler \
82f81a90
UD
45 pthandles libc-tls-loc pt-allocrtsig \
46 ptw-write ptw-read ptw-close ptw-fcntl ptw-accept \
47 ptw-connect ptw-recv ptw-recvfrom ptw-recvmsg \
48 ptw-send ptw-sendmsg ptw-sendto ptw-fsync ptw-lseek \
49 ptw-lseek64 ptw-llseek ptw-msync ptw-nanosleep \
50 ptw-open ptw-open64 ptw-pause ptw-pread ptw-pread64 \
51 ptw-pwrite ptw-pwrite64 ptw-tcdrain ptw-wait \
c86b0841 52 ptw-waitpid pt-system old_pthread_atfork pthread_atfork
645294eb
RM
53# Don't generate deps for calls with no sources. See sysdeps/unix/Makefile.
54omit-deps = $(unix-syscalls:%=ptw-%)
82f81a90
UD
55
56libpthread-shared-only-routines = pt-allocrtsig
c86b0841 57libpthread-static-only-routines = pthread_atfork
5afdca00 58
416d2de6
UD
59libpthread-nonshared = pthread_atfork
60
bf293afe
UD
61CFLAGS-pthread_atfork.c = -DNOT_IN_libc
62
0fb7851f 63nodelete-yes = -Wl,--enable-new-dtags,-z,nodelete
b71e7ce8
UD
64initfirst-yes = -Wl,--enable-new-dtags,-z,initfirst
65LDFLAGS-pthread.so = $(nodelete-$(have-z-nodelete)) \
66 $(initfirst-$(have-z-initfirst))
0fb7851f 67
0302fece 68vpath %.c Examples
e64911d1 69
7d4c3e67 70tst-cancel-ARGS = "$(objpfx)"
01d1a5b6 71CFLAGS-tst-cancel.c = -fno-inline -fno-inline-functions
7d4c3e67 72
ad7534c8
UD
73include ../Makeconfig
74
b71e7ce8 75ifeq ($(build-shared),yes)
416d2de6
UD
76others: $(objpfx)libpthread_nonshared.a
77endif
78
79$(objpfx)libpthread_nonshared.a: $(addprefix $(objpfx),$(addsuffix .os,$(libpthread-nonshared)))
80 $(AR) $(ARFLAGS) $@ $^
81
82ifeq ($(build-shared),yes)
83
4a2939f9
RM
84# Set the `multidir' variable by grabbing the variable from the compiler.
85# We do it once and save the result in a generated makefile.
86-include $(objpfx)multidir.mk
87$(objpfx)multidir.mk: $(common-objpfx)config.make
88 dir=`$(CC) $(CFLAGS) $(CPPFLAGS) -print-multi-directory`; \
89 echo "multidir := $$dir" > $@T
90 mv -f $@T $@
91generated += multidir.mk
92
93crti-objs := crti.o
94crtn-objs := crtn.o
95ifneq (,$(patsubst .,,$(multidir)))
96generated-dirs := $(firstword $(subst /, , $(multidir)))
97crti-objs += $(multidir)/crti.o
98crtn-objs += $(multidir)/crtn.o
99omit-deps += $(multidir)/crti $(multidir)/crtn
100endif
101extra-objs += $(crti-objs) $(crtn-objs)
cc6d371d 102omit-deps += crti crtn
b71e7ce8 103
49803108 104CFLAGS-pt-initfini.s = -g0 -fPIC -fno-inline-functions $(fno-unit-at-a-time)
b71e7ce8
UD
105endif
106
e64911d1 107librt-tests = ex10 ex11
64f6b8f3 108tests = ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 $(librt-tests) ex12 ex13 joinrace \
df4cada7 109 tststack $(tests-nodelete-$(have-z-nodelete)) ecmutex ex14 ex15 ex16 \
131fd126
UD
110 ex17 ex18 tst-cancel tst-context bug-sleep \
111 tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \
1b6f6a92 112 tst-cancel6 tst-cancel7 tst-cancel8 tst-popen tst-popen2 tst-attr1
de13e6e7 113test-srcs = tst-signal
131fd126
UD
114# These tests are linked with libc before libpthread
115tests-reverse += tst-cancel5
ad7534c8 116
67ee6db0 117ifeq ($(build-static),yes)
bf293afe
UD
118tests += tststatic tst-static-locale tst-cancel-static
119tests-static += tststatic tst-static-locale tst-cancel-static
67ee6db0
UD
120endif
121
ad7534c8
UD
122ifeq (yes,$(build-shared))
123tests-nodelete-yes = unload
e3a88560 124tests += tst-tls1 tst-_res1
ad7534c8 125endif
0302fece 126
e3a88560
UD
127modules-names = tst-_res1mod1 tst-_res1mod2 \
128 tst-tls1mod tst-tls1moda tst-tls1modb tst-tls1modc \
129 tst-tls1modd tst-tls1mode tst-tls1modf
0e9d6240
UD
130extra-objs += $(addsuffix .os,$(strip $(modules-names)))
131test-extras += $(modules-names)
132test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
133
e3a88560
UD
134tst-tls1mod.so-no-z-defs = yes
135tst-tls1moda.so-no-z-defs = yes
136tst-tls1modb.so-no-z-defs = yes
137tst-tls1modc.so-no-z-defs = yes
138tst-tls1modd.so-no-z-defs = yes
139tst-tls1mode.so-no-z-defs = yes
140tst-tls1modf.so-no-z-defs = yes
141
0e9d6240
UD
142$(test-modules): $(objpfx)%.so: $(objpfx)%.os $(common-objpfx)shlib.lds
143 $(build-module)
144
5181d776
RM
145ifeq ($(build-shared),yes)
146# Build all the modules even when not actually running test programs.
147tests: $(test-modules)
148endif
5afdca00 149
416d2de6
UD
150# What we install as libpthread.so for programs to link against is in fact a
151# link script. It contains references for the various libraries we need.
152# The libpthread.so object is not complete since some functions are only defined
153# in libpthread_nonshared.a.
154# We need to use absolute paths since otherwise local copies (if they exist)
155# of the files are taken by the linker.
156install: $(inst_libdir)/libpthread.so
157$(inst_libdir)/libpthread.so: $(common-objpfx)format.lds \
158 $(objpfx)libpthread.so$(libpthread.so-version) \
159 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
160 $(libprefix)pthread) \
161 $(+force)
162 (echo '/* GNU ld script';\
163 echo ' Use the shared library, but some functions are only in';\
164 echo ' the static library, so try that secondarily. */';\
165 cat $<; \
166 echo 'GROUP ( $(slibdir)/libpthread.so$(libpthread.so-version)' \
167 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)pthread)'\
168 ')' \
169 ) > $@.new
170 mv -f $@.new $@
171$(inst_libdir)/libpthread_nonshared.a: $(objpfx)libpthread_nonshared.a
172 $(do-install)
173
174
b71e7ce8 175extra-B-pthread.so = -B$(common-objpfx)linuxthreads/
4a2939f9
RM
176$(objpfx)libpthread.so: $(addprefix $(objpfx),$(crti-objs) $(crtn-objs))
177$(objpfx)libpthread.so: +preinit += $(addprefix $(objpfx),$(crti-objs))
178$(objpfx)libpthread.so: +postinit += $(addprefix $(objpfx),$(crtn-objs))
b71e7ce8 179
5ef50d00 180znodelete-yes = -DHAVE_Z_NODELETE
97dac76c
UD
181CFLAGS-mutex.c += -D__NO_WEAK_PTHREAD_ALIASES
182CFLAGS-specific.c += -D__NO_WEAK_PTHREAD_ALIASES
5ef50d00 183CFLAGS-pthread.c += -D__NO_WEAK_PTHREAD_ALIASES $(znodelete-$(have-z-nodelete))
97dac76c 184CFLAGS-ptfork.c += -D__NO_WEAK_PTHREAD_ALIASES
481b550f 185CFLAGS-cancel.c += -D__NO_WEAK_PTHREAD_ALIASES -D_RPC_THREAD_SAFE_
ad7534c8 186CFLAGS-unload.c += -DPREFIX=\"$(objpfx)\"
e07bb02a
UD
187CFLAGS-mutex.c += $(uses-callbacks)
188CFLAGS-sighandler.c += $(uses-callbacks)
97dac76c 189
53da80ab
RM
190ifeq (yes,$(versioning))
191-include $(common-objpfx)tls.make
192libc-ok-for-link = $(use-thread)
193else
194libc-ok-for-link = yes
195endif
196
197ifeq (no,$(libc-ok-for-link))
198# These hacks are necessary to let us link against a libc.so that exports
199# the symbols _errno, _h_errno, and _res. Those symbols are accessible
200# in libc at runtime (dynamic linkable), but are not exported at link time
201# so that applications cannot link against them. However, libpthread.so
202# needs to link against them for its __errno_location et al functions to
203# find the locations that libc's symbols resolve to. We cannot do this
204# with aliases in libc.so(GLIBC_PRIVATE), because we need to refer to an
205# executable's symbols when it defines them with copy relocs.
206libc-link.so = $(objpfx)libc.so
207
208$(objpfx)libc_pic_lite.a: $(common-objpfx)libc_pic.a
209 cp $< $@T
210 $(AR) d $@T errno.os herrno.os res_libc.os
211 mv -f $@T $@
212
213extra-objs += libc-tsd.os
214$(objpfx)libc_pic_lite.os: $(objpfx)libc_pic_lite.a $(objpfx)libc-tsd.os
215 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
216 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
217
bbd17455
UD
218# This trick leaves errno and h_errno undefined.
219libc.so-no-z-defs = yes
220
53da80ab
RM
221$(objpfx)libc.so: $(elfobjdir)/soinit.os \
222 $(objpfx)libc_pic_lite.os \
223 $(elfobjdir)/sofini.os \
224 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
225 $(build-shlib)
226
227generated += libc_pic_lite.a libc_pic_lite.os libc.so
228else
229libc-link.so = $(common-objpfx)libc.so
230endif
231
54c92465
UD
232include ../Rules
233
5afdca00
UD
234# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
235# This ensures they will load libc.so for needed symbols if loaded by
236# a statically-linked program that hasn't already loaded it.
733f25e6
UD
237# Depend on ld.so too to get proper versions of ld.so symbols.
238$(objpfx)libpthread.so: $(libc-link.so) $(common-objpfx)libc_nonshared.a \
239 $(if $(filter yes,$(elf)), $(elfobjdir)/ld.so)
0302fece
UD
240
241# Make sure we link with the thread library.
df455ccb 242ifeq ($(build-shared),yes)
67ee6db0 243$(addprefix $(objpfx), \
131fd126 244 $(filter-out $(tests-static) $(tests-reverse) unload, \
416d2de6
UD
245 $(tests) $(test-srcs))): $(objpfx)libpthread.so \
246 $(objpfx)libpthread_nonshared.a
131fd126
UD
247# $(objpfx)../libc.so is used instead of $(common-objpfx)libc.so,
248# since otherwise libpthread.so comes before libc.so when linking.
249$(addprefix $(objpfx), $(tests-reverse)): \
416d2de6
UD
250 $(objpfx)../libc.so $(objpfx)libpthread.so \
251 $(objpfx)libpthread_nonshared.a
c6696b79 252$(objpfx)../libc.so: $(common-objpfx)libc.so ;
e64911d1 253$(addprefix $(objpfx),$(librt-tests)): $(common-objpfx)rt/librt.so
ad7534c8 254$(objpfx)unload: $(common-objpfx)dlfcn/libdl.so
416d2de6 255$(objpfx)unload.out: $(objpfx)libpthread.so $(objpfx)libpthread_nonshared.a
df455ccb 256else
de13e6e7 257$(addprefix $(objpfx),$(tests) $(test-srcs)): $(objpfx)libpthread.a
e64911d1
GM
258$(addprefix $(objpfx),$(librt-tests)): $(common-objpfx)rt/librt.a
259endif
260ifeq ($(build-bounded),yes)
261$(tests:%=$(objpfx)%-bp): $(objpfx)libpthread_b.a
262$(librt-tests:%=$(objpfx)%-bp): $(common-objpfx)rt/librt_b.a
df455ccb 263endif
b71e7ce8 264
67ee6db0
UD
265ifeq ($(build-static),yes)
266$(addprefix $(objpfx), $(tests-static)): $(objpfx)libpthread.a
267endif
268
b71e7ce8
UD
269ifeq ($(build-shared),yes)
270vpath pt-initfini.c $(full_config_sysdirs)
271
272$(objpfx)pt-initfini.s: pt-initfini.c
273 $(compile.c) -S $(CFLAGS-pt-initfini.s) -finhibit-size-directive \
274 $(patsubst -f%,-fno-%,$(exceptions)) -o $@
275
276# We only have one kind of startup code files. Static binaries and
277# shared libraries are build using the PIC version.
278$(objpfx)crti.S: $(objpfx)pt-initfini.s
279 sed -n -e '1,/@HEADER_ENDS/p' \
280 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
281 -e '/@TRAILER_BEGINS/,$$p' $< > $@
cc6d371d
RM
282$(objpfx)crtn.S: $(objpfx)pt-initfini.s
283 sed -n -e '1,/@HEADER_ENDS/p' \
284 -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
285 -e '/@TRAILER_BEGINS/,$$p' $< > $@
b71e7ce8
UD
286
287$(objpfx)defs.h: $(objpfx)pt-initfini.s
288 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
289 $(AWK) -f ../csu/defs.awk > $@
290
eeae65e3
UD
291$(objpfx)crti.o: $(objpfx)crti.S $(objpfx)defs.h
292 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
293
294$(objpfx)crtn.o: $(objpfx)crtn.S $(objpfx)defs.h
b71e7ce8
UD
295 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
296
4a2939f9
RM
297ifneq ($(multidir),.)
298$(objpfx)$(multidir):
299 @mkdir -p $(objpfx)$(multidir)
300
301$(objpfx)$(multidir)/crti.o: $(objpfx)crti.o $(objpfx)$(multidir)
302 ln -f $< $@
303
304$(objpfx)$(multidir)/crtn.o: $(objpfx)crtn.o $(objpfx)$(multidir)
305 ln -f $< $@
306endif
307
cc6d371d 308generated += crti.S crtn.S defs.h pt-initfini.s
b71e7ce8 309endif
80ff3e34
AJ
310
311ifeq (yes,$(build-static-nss))
312otherlibs += $(nssobjdir)/libnss_files.a $(resolvobjdir)/libnss_dns.a \
313 $(resolvobjdir)/libresolv.a
314endif
de13e6e7 315
0e9d6240
UD
316ifeq (yes,$(build-shared))
317$(objpfx)tst-_res1mod2.so: $(objpfx)tst-_res1mod1.so
318$(objpfx)tst-_res1: $(objpfx)tst-_res1mod2.so $(shared-thread-library)
e3a88560
UD
319
320$(objpfx)tst-tls1: $(objpfx)tst-tls1mod.so $(shared-thread-library)
321
322tests: $(objpfx)tst-tls2.out
323$(objpfx)tst-tls2.out: tst-tls2.sh $(objpfx)tst-tls1 \
324 $(objpfx)tst-tls1moda.so $(objpfx)tst-tls1modb.so \
325 $(objpfx)tst-tls1modc.so $(objpfx)tst-tls1modd.so \
326 $(objpfx)tst-tls1mode.so $(objpfx)tst-tls1modf.so
327 $(SHELL) -e tst-tls2.sh $(common-objpfx) $(elf-objpfx) \
328 $(rtld-installed-name)
0e9d6240
UD
329endif
330
de13e6e7
UD
331ifeq (no,$(cross-compiling))
332ifeq (yes,$(build-shared))
82f81a90 333tests: $(objpfx)tst-signal.out $(objpfx)tst-cancel-wrappers.out
de13e6e7 334$(objpfx)tst-signal.out: tst-signal.sh $(objpfx)tst-signal
67ee6db0 335 $(SHELL) -e $< $(common-objpfx) > $@
82f81a90
UD
336$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh
337 $(SHELL) $< $(common-objpfx)/libc_pic.a \
338 $(common-objpfx)/libc.a \
339 $(objpfx)/libpthread_pic.a \
340 $(objpfx)/libpthread.a > $@
de13e6e7
UD
341endif
342endif