about summary refs log tree commit diff
path: root/linuxthreads/Makefile
blob: a86aae7d5398c4df2a42b5a0ba294b05349f9910 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# Copyright (C) 1996-2001, 2002 Free Software Foundation, Inc.
# This file is part of the GNU C Library.

# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.

#
#	Sub-makefile for linuxthreads portion of the library.
#
subdir	:= linuxthreads

linuxthreads-version := $(shell sed -n 's/^.*$(subdir)-\([0-9.]*\).*$$/\1/p' \
				    Banner)

headers := pthread.h semaphore.h
distribute := internals.h queue.h restart.h spinlock.h smp.h tst-signal.sh \
	      tst-cancel-wrappers.sh libc-tsd.c

routines := forward alloca_cutoff libc-cancellation libc_pthread_init
shared-only-routines = forward

extra-libs := libpthread
extra-libs-others := $(extra-libs)

libpthread-routines := attr cancel condvar join manager mutex ptfork \
		       ptlongjmp pthread signals specific errno lockfile \
		       semaphore spinlock rwlock pt-machine \
		       oldsemaphore events getcpuclockid pspinlock barrier \
		       ptclock_gettime ptclock_settime sighandler \
		       pthandles libc-tls-loc pt-allocrtsig \
		       ptw-write ptw-read ptw-close ptw-fcntl ptw-accept \
		       ptw-connect ptw-recv ptw-recvfrom ptw-recvmsg \
		       ptw-send ptw-sendmsg ptw-sendto ptw-fsync ptw-lseek \
		       ptw-lseek64 ptw-llseek ptw-msync ptw-nanosleep \
		       ptw-open ptw-open64 ptw-pause ptw-pread ptw-pread64 \
		       ptw-pwrite ptw-pwrite64 ptw-tcdrain ptw-wait \
		       ptw-waitpid pt-system
# Don't generate deps for calls with no sources.  See sysdeps/unix/Makefile.
omit-deps = $(unix-syscalls:%=ptw-%)

libpthread-shared-only-routines = pt-allocrtsig

nodelete-yes = -Wl,--enable-new-dtags,-z,nodelete
initfirst-yes = -Wl,--enable-new-dtags,-z,initfirst
LDFLAGS-pthread.so = $(nodelete-$(have-z-nodelete)) \
		     $(initfirst-$(have-z-initfirst))

vpath %.c Examples

tst-cancel-ARGS = "$(objpfx)"
CFLAGS-tst-cancel.c = -fno-inline -fno-inline-functions

include ../Makeconfig

ifeq ($(build-shared),yes)
extra-objs += crti.o crtn.o
omit-deps += crti crtn

CFLAGS-pt-initfini.s = -g0 -fPIC -fno-inline-functions
endif

librt-tests = ex10 ex11
tests = ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9 $(librt-tests) ex12 ex13 joinrace \
	tststack $(tests-nodelete-$(have-z-nodelete)) ecmutex ex14 ex15 ex16 \
	ex17 ex18 tst-cancel tst-context bug-sleep \
	tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \
	tst-cancel6
test-srcs = tst-signal
# These tests are linked with libc before libpthread
tests-reverse += tst-cancel5

ifeq ($(build-static),yes)
tests += tststatic tst-static-locale
tests-static += tststatic tst-static-locale
endif

ifeq (yes,$(build-shared))
tests-nodelete-yes = unload
endif

include ../Rules

extra-B-pthread.so = -B$(common-objpfx)linuxthreads/
$(objpfx)libpthread.so: $(objpfx)crti.o $(objpfx)crtn.o
$(objpfx)libpthread.so: +preinit += $(objpfx)crti.o
$(objpfx)libpthread.so: +postinit += $(objpfx)crtn.o

znodelete-yes = -DHAVE_Z_NODELETE
CFLAGS-mutex.c += -D__NO_WEAK_PTHREAD_ALIASES
CFLAGS-specific.c += -D__NO_WEAK_PTHREAD_ALIASES
CFLAGS-pthread.c += -D__NO_WEAK_PTHREAD_ALIASES $(znodelete-$(have-z-nodelete))
CFLAGS-ptfork.c += -D__NO_WEAK_PTHREAD_ALIASES
CFLAGS-cancel.c += -D__NO_WEAK_PTHREAD_ALIASES -D_RPC_THREAD_SAFE_
CFLAGS-unload.c += -DPREFIX=\"$(objpfx)\"
CFLAGS-sighandler.c += $(exceptions)

ifeq (yes,$(versioning))
-include $(common-objpfx)tls.make
libc-ok-for-link = $(use-thread)
else
libc-ok-for-link = yes
endif

ifeq (no,$(libc-ok-for-link))
# These hacks are necessary to let us link against a libc.so that exports
# the symbols _errno, _h_errno, and _res.  Those symbols are accessible
# in libc at runtime (dynamic linkable), but are not exported at link time
# so that applications cannot link against them.  However, libpthread.so
# needs to link against them for its __errno_location et al functions to
# find the locations that libc's symbols resolve to.  We cannot do this
# with aliases in libc.so(GLIBC_PRIVATE), because we need to refer to an
# executable's symbols when it defines them with copy relocs.
libc-link.so = $(objpfx)libc.so

$(objpfx)libc_pic_lite.a: $(common-objpfx)libc_pic.a
	cp $< $@T
	$(AR) d $@T errno.os herrno.os res_libc.os
	mv -f $@T $@

extra-objs += libc-tsd.os
$(objpfx)libc_pic_lite.os: $(objpfx)libc_pic_lite.a $(objpfx)libc-tsd.os
	$(LINK.o) -nostdlib -nostartfiles -r -o $@ \
		  $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^

$(objpfx)libc.so: $(elfobjdir)/soinit.os \
		  $(objpfx)libc_pic_lite.os \
		  $(elfobjdir)/sofini.os \
		  $(elfobjdir)/interp.os $(elfobjdir)/ld.so
	$(build-shlib)

generated += libc_pic_lite.a libc_pic_lite.os libc.so
else
libc-link.so = $(common-objpfx)libc.so
endif

# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
# This ensures they will load libc.so for needed symbols if loaded by
# a statically-linked program that hasn't already loaded it.
$(objpfx)libpthread.so: $(libc-link.so) $(common-objpfx)libc_nonshared.a

# Make sure we link with the thread library.
ifeq ($(build-shared),yes)
$(addprefix $(objpfx), \
  $(filter-out $(tests-static) $(tests-reverse) unload, \
    $(tests) $(test-srcs))): $(objpfx)libpthread.so
# $(objpfx)../libc.so is used instead of $(common-objpfx)libc.so,
# since otherwise libpthread.so comes before libc.so when linking.
$(addprefix $(objpfx), $(tests-reverse)): \
  $(objpfx)../libc.so $(objpfx)libpthread.so
$(addprefix $(objpfx),$(librt-tests)): $(common-objpfx)rt/librt.so
$(objpfx)unload: $(common-objpfx)dlfcn/libdl.so
$(objpfx)unload.out: $(objpfx)libpthread.so
else
$(addprefix $(objpfx),$(tests) $(test-srcs)): $(objpfx)libpthread.a
$(addprefix $(objpfx),$(librt-tests)): $(common-objpfx)rt/librt.a
endif
ifeq ($(build-bounded),yes)
$(tests:%=$(objpfx)%-bp): $(objpfx)libpthread_b.a
$(librt-tests:%=$(objpfx)%-bp): $(common-objpfx)rt/librt_b.a
endif

ifeq ($(build-static),yes)
$(addprefix $(objpfx), $(tests-static)): $(objpfx)libpthread.a
endif

ifeq ($(build-shared),yes)
vpath pt-initfini.c $(full_config_sysdirs)

$(objpfx)pt-initfini.s: pt-initfini.c
	$(compile.c) -S $(CFLAGS-pt-initfini.s) -finhibit-size-directive \
		$(patsubst -f%,-fno-%,$(exceptions)) -o $@

# We only have one kind of startup code files.  Static binaries and
# shared libraries are build using the PIC version.
$(objpfx)crti.S: $(objpfx)pt-initfini.s
	sed -n -e '1,/@HEADER_ENDS/p' \
	       -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
	       -e '/@TRAILER_BEGINS/,$$p' $< > $@
$(objpfx)crtn.S: $(objpfx)pt-initfini.s
	sed -n -e '1,/@HEADER_ENDS/p' \
	       -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
	       -e '/@TRAILER_BEGINS/,$$p' $< > $@

$(objpfx)defs.h: $(objpfx)pt-initfini.s
	sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
		$(AWK) -f ../csu/defs.awk > $@

$(objpfx)crti.o: $(objpfx)crti.S $(objpfx)defs.h
	$(compile.S) -g0 $(ASFLAGS-.os) -o $@

$(objpfx)crtn.o: $(objpfx)crtn.S $(objpfx)defs.h
	$(compile.S) -g0 $(ASFLAGS-.os) -o $@

generated += crti.S crtn.S defs.h pt-initfini.s
endif

ifeq (yes,$(build-static-nss))
otherlibs += $(nssobjdir)/libnss_files.a $(resolvobjdir)/libnss_dns.a \
             $(resolvobjdir)/libresolv.a
endif

ifeq (no,$(cross-compiling))
ifeq (yes,$(build-shared))
tests: $(objpfx)tst-signal.out $(objpfx)tst-cancel-wrappers.out
$(objpfx)tst-signal.out: tst-signal.sh $(objpfx)tst-signal
	$(SHELL) -e $< $(common-objpfx) > $@
$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh
	$(SHELL) $< $(common-objpfx)/libc_pic.a \
		    $(common-objpfx)/libc.a \
		    $(objpfx)/libpthread_pic.a \
		    $(objpfx)/libpthread.a > $@
endif
endif