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