]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makerules
* sysdeps/x86_64/__longjmp.S: Also protect SP and BP.
[thirdparty/glibc.git] / Makerules
CommitLineData
9d0547ce 1# Copyright (C) 1991-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
1c68c264
RM
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
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.
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
12# Lesser General Public License for more details.
13
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.
18
19#
20# Common rules for making the GNU C library. This file is included
21# by the top-level Makefile and by all subdirectory makefiles
22# (through Rules).
23#
24ifneq (,)
25This makefile requires GNU Make.
26endif
27
28REQUIRED_MAKE_VERSION = 3.74
29REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
30
31ifneq ($(REQUIRED_MAKE_VERSION), \
32 $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33Wrong GNU Make version. See above for the version needed.
34endif
35
36
37ifdef subdir
38.. := ../
39endif # subdir
40
41# If `sources' was defined by the parent makefile, undefine it so
42# we will later get it from wildcard search in this directory.
43ifneq "$(findstring env,$(origin sources))" ""
44sources :=
45endif
46
47oPATH := $(PATH)
48PATH := this definition should take precedence over $(oPATH)
49ifeq ($(PATH),$(oPATH))
50You must not use the -e flag when building the GNU C library.
51else
52PATH := $(oPATH)
53endif
54\f
55ifndef +included-Makeconfig
56include $(..)Makeconfig
57endif
58
a334319f
UD
59# `configure' writes a definition of `config-sysdirs' in `config.make'.
60sysdirs = $(strip $(full_config_sysdirs))
61
62+sysdir_pfx = $(common-objpfx)
63
64export sysdirs := $(sysdirs)
65
66+sysdep_dirs := $(full_config_sysdirs)
67ifdef objdir
68+sysdep_dirs := $(objdir) $(+sysdep_dirs)
69endif
70
71# Add -I switches to get the right sysdep directories.
72# `+includes' in Makeconfig references $(+sysdep-includes).
73+sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
74
1c68c264
RM
75# This variable is used in ``include $(o-iterator)'' after defining
76# $(o-iterator-doit) to produce some desired rule using $o for the object
77# suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78# is produced for each object suffix in use.
79o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
80\f
81# Include any system-specific makefiles.
82
83# This is here so things in sysdep Makefiles can easily depend on foo.h as
84# appropriate and not worry about where foo.h comes from, which may be
85# system dependent and not known by that Makefile.
86vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87 $(+sysdep_dirs) $(..)))
88
89# The same is true for RPC source files.
90vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91 $(+sysdep_dirs) $(..)))
92
93# Some sysdep makefiles use this to distinguish being included here from
94# being included individually by a subdir makefile (hurd/Makefile needs this).
95in-Makerules := yes
96
a334319f 97sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
1c68c264
RM
98ifneq (,$(sysdep-makefiles))
99include $(sysdep-makefiles)
100endif
101
102
103# Reorder before-compile so that mach things come first, and hurd things
104# second, before all else. The mach and hurd subdirectories have many
105# generated header files which the much of rest of the library depends on,
106# so it is best to build them first (and mach before hurd, at that).
107before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
108 $(before-compile)) \
109 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
110 $(before-compile))
111
112# Even before that, we need abi-versions.h which is generated right here.
113ifeq ($(versioning),yes)
114ifndef avoid-generated
115before-compile := $(common-objpfx)abi-versions.h $(before-compile)
116$(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
117 $(common-objpfx)Versions.all
118 LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
119 mv -f $@T $@
120
121$(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
122 sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
123 $(common-objpfx)abi-versions.h > $@T
124 mv -f $@T $@
125endif # avoid-generated
126endif # $(versioning) = yes
127
d73f5331 128# Make sure the subdirectory for object files gets created.
1c68c264 129ifdef objpfx
d73f5331 130ifeq (,$(wildcard $(objpfx).))
1c68c264
RM
131before-compile += $(objpfx).
132$(objpfx).:
133 $(make-target-directory)
134endif
135endif
136
137# Remove existing files from `before-compile'. Things are added there when
138# they must exist for dependency generation to work right, but once they
139# exist there is no further need for every single file to depend on them,
140# and those gratuitous dependencies result in many gratuitous
141# recompilations.
142before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
143
144# Don't let any before-compile file be an intermediate and get removed.
145ifdef before-compile
146$(before-compile):
147endif
148
7f3a54bd
RM
149# We don't want $(common-objpfx) files to depend on miscellaneous stuff
150# in subdirs.
151ifdef subdir
152common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
153else
154common-before-compile = $(before-compile)
155endif
156
d73f5331 157ifndef subdir
1c68c264
RM
158# If a makefile needs to do something conditional on something that
159# can only be figured out from headers, write a FOO.make.c input
160# file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
161# to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
d73f5331
RM
162#
163# We only generate these in the top-level makefile, to avoid any weirdness
164# from subdir-specific makefile tweaks creeping in on an update.
7f3a54bd 165$(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
1c68c264
RM
166 rm -f $@T $@.dT
167 (echo '# Generated from $*.make.c by Makerules.'; \
a334319f 168 $(CC) $(CFLAGS) $(CPPFLAGS) -E $< \
7cd72ad3 169 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
1c68c264
RM
170 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
171 echo 'common-generated += $(@F)'; \
9ae10332
RM
172 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
173 rm -f $@.dT) > $@T
1c68c264 174 mv -f $@T $@
d73f5331 175endif
9ae10332 176
0e56981e 177ifdef subdir
7cd72ad3
RM
178sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
179 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
0e56981e 180else
7cd72ad3
RM
181sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
182 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
0e56981e 183endif
7f3a54bd
RM
184
185
0c7c6d53 186ifdef gen-as-const-headers
7f3a54bd
RM
187# Generating headers for assembly constants.
188# We need this defined early to get into before-compile before
189# it's used in sysd-rules, below.
190$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
191 %.sym $(common-before-compile)
192 $(AWK) -f $< $(filter %.sym,$^) \
1feda3ed
RM
193 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
194 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
195 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
196 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
197 rm -f $(@:.h.d=.h)T3
7f3a54bd
RM
198 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
199 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
200 rm -f $(@:.h=.h.d)T
201 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
202 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
203vpath %.sym $(sysdirs)
204before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
0c7c6d53
RM
205
206tests += test-as-const
207$(objpfx)test-as-const.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
208 $(gen-as-const-headers) \
209 $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
210 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
211 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
212 echo '#include "$(..)test-skeleton.c"') > $@T
213 mv -f $@T $@
214endif
1c68c264
RM
215\f
216# Generate an ordered list of implicit rules which find the source files in
217# each sysdep directory. The old method was to use vpath to search all the
218# sysdep directories. However, that had the problem that a .S file in a
219# later directory would be chosen over a .c file in an earlier directory,
220# which does not preserve the desired sysdeps ordering behavior.
221
1c68c264
RM
222# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
223# patterns matching sysdep directories whose assembly source files should
224# be suppressed.
225ifdef inhibit-sysdep-asm
226define open-check-inhibit-asm
227case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
228endef
229close-check-inhibit-asm = ;; esac ;
230endif
231
a334319f 232-include $(+sysdir_pfx)sysd-rules
1c68c264
RM
233ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
234# The value of $(+sysdep_dirs) the sysd-rules was computed for
235# differs from the one we are using now. So force a rebuild of sysd-rules.
236sysd-rules-force = FORCE
237FORCE:
238endif
a334319f
UD
239$(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
240 $(wildcard $(foreach dir,$(sysdirs),\
241 $(dir)/Makefile))\
242 $(sysd-rules-force)
1c68c264
RM
243 -@rm -f $@T
244 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
a334319f 245 for dir in $(config-sysdirs:%='$$(..)%'); do \
1c68c264
RM
246 for o in $(all-object-suffixes); do \
247 $(open-check-inhibit-asm) \
248 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
249 \$$(compile-command.S)"; \
250 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
251 \$$(compile-command.s)"; \
252 echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
253 \$$(compile-command.S)"; \
254 echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
255 \$$(compile-command.s)"; \
256 echo "\$$(objpfx)ptw-%$$o: $$dir/%.S \$$(before-compile); \
257 \$$(compile-command.S)"; \
258 echo "\$$(objpfx)ptw-%$$o: $$dir/%.s \$$(before-compile); \
259 \$$(compile-command.s)"; \
260 $(close-check-inhibit-asm) \
261 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
262 \$$(compile-command.c)"; \
263 echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
264 \$$(compile-command.c)"; \
265 echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
266 \$$(compile-command.c)"; \
267 done; \
a334319f
UD
268 echo "\$$(objpfx)m_%.S: $$dir/s_%.S; \$$(+make-include-of-dep)"; \
269 echo "\$$(objpfx)m_%.c: $$dir/s_%.c; \$$(+make-include-of-dep)"; \
1c68c264 270 done; \
b6ab06ce 271 echo "\$$(objpfx)m_%.c: s_%.c; \$$(+make-include-of-dep)"; \
1c68c264
RM
272 echo 'sysd-rules-done = t') > $@T
273 mv -f $@T $@
274
275ifndef sysd-rules-done
276# Don't do deps until this exists, because it provides rules to make the deps.
277no_deps=t
278endif
279
a334319f
UD
280# This is used by the m_%.[Sc] pattern rules in sysd-rules.
281define +make-include-of-dep
282echo '#include <$<>' > $@T
283mv -f $@T $@
0ecb606c 284endef
1c68c264 285
b6ab06ce
UD
286# It matters that this set of rules, for compiling from sources in
287# the current directory (the $srcdir/$subdir) come before the
288# generated sysdep rules in included from sysd-rules below. When
289# compiling in the source tree, generated sources go into the current
290# directory, and those should be chosen before any sources in sysdeps.
291define o-iterator-doit
292$(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
293endef
294object-suffixes-left := $(all-object-suffixes)
295include $(o-iterator)
296
297define o-iterator-doit
298$(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
299endef
300object-suffixes-left := $(all-object-suffixes)
301include $(o-iterator)
302
303define o-iterator-doit
304$(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
305endef
306object-suffixes-left := $(all-object-suffixes)
307include $(o-iterator)
308
309# Omit the objpfx rules when building in the source tree, because
310# objpfx is empty and so these rules just override the ones above.
311ifdef objpfx
312# Define first rules to find the source files in $(objpfx).
313# Generated source files will end up there.
314define o-iterator-doit
315$(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
316endef
317object-suffixes-left := $(all-object-suffixes)
318include $(o-iterator)
319
320define o-iterator-doit
321$(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
322endef
323object-suffixes-left := $(all-object-suffixes)
324include $(o-iterator)
325
326define o-iterator-doit
327$(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
328endef
329object-suffixes-left := $(all-object-suffixes)
330include $(o-iterator)
331endif
332
1c68c264
RM
333# Generate version maps, but wait until sysdep-subdirs is known
334ifeq ($(sysd-sorted-done),t)
335ifeq ($(versioning),yes)
336-include $(common-objpfx)sysd-versions
337$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
338common-generated += $(version-maps)
339postclean-generated += sysd-versions Versions.all abi-versions.h \
340 Versions.def.v.i Versions.def.v Versions.v.i Versions.v
341
342ifndef avoid-generated
a334319f 343ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
1c68c264
RM
344sysd-versions-force = FORCE
345FORCE:
346endif
347# See %.v/%.v.i implicit rules in Makeconfig.
348$(common-objpfx)Versions.def.v.i: $(..)Versions.def \
349 $(wildcard $(add-ons:%=$(..)%/Versions.def))
350$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
351 $(common-objpfx)soversions.i \
352 $(common-objpfx)Versions.def.v
9d0547ce
RM
353 { while read which lib version setname; do \
354 test x"$$which" = xDEFAULT || continue; \
1c68c264
RM
355 test -z "$$setname" || echo "$$lib : $$setname"; \
356 done < $(word 2,$^); \
357 cat $(word 3,$^); \
358 } | LC_ALL=C $(AWK) -f $< > $@T
359 mv -f $@T $@
360# See %.v/%.v.i implicit rules in Makeconfig.
a334319f 361$(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
1c68c264
RM
362 $(wildcard $(sysdirs:%=%/Versions)) \
363 $(common-objpfx)abi-versions.h \
364 $(sysd-versions-force)
365$(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
366 $(common-objpfx)Versions.v \
367 $(..)scripts/versions.awk
a334319f 368 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
1c68c264
RM
369 cat $(word 2,$^) \
370 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
371 -v move_if_change='$(move-if-change)' \
372 -f $(word 3,$^); \
373 ) > $@T
374 mv -f $@T $@
375endif # avoid-generated
376endif # $(versioning) = yes
377endif # sysd-sorted-done
378
d73f5331 379# Generate .dT files as we compile.
b9608428 380compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
d73f5331
RM
381compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
382compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
383compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
1c68c264
RM
384
385# GCC can grok options after the file name, and it looks nicer that way.
386compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
073e82bf
RM
387compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
388 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
389COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
390 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
1c68c264
RM
391COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
392
1c68c264
RM
393# We need this for the output to go in the right place. It will default to
394# empty if make was configured to work with a cc that can't grok -c and -o
395# together. You can't compile the C library with such a compiler.
396OUTPUT_OPTION = -o $@
397
398# We need the $(CFLAGS) to be in there to have the right predefines during
399# the dependency run for C sources. But having it for assembly sources can
400# get the wrong predefines.
f4281cc4 401S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
d73f5331 402
1c68c264
RM
403define +make-deps
404$(make-target-directory)
405$(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
b710b53d
RM
406 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
407's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
408$(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
1c68c264
RM
409mv -f $(@:.d=.T) $@ $(generate-md5)
410endef
d73f5331 411
1c68c264
RM
412ifneq (,$(objpfx))
413# Continuation lines here are dangerous because they introduce spaces!
414define sed-remove-objpfx
415-e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
416-e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
417endef
418endif
419\f
420# Modify the list of routines we build for different targets
421
422ifeq (yesyes,$(build-shared)$(elf))
423ifndef libc.so-version
424# Undefine this because it can't work when we libc.so is unversioned.
425static-only-routines =
426endif
427endif
428
429# Bounded pointer thunks are only built for *.ob
430elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
431
432elide-routines.oS += $(filter-out $(static-only-routines),\
433 $(routines) $(aux) $(sysdep_routines)) \
434 $(elide-bp-thunks)
435elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
436
437# If we have versioned code we don't need the old versions in any of the
438# static libraries.
439elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
440elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
441elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
442elide-routines.ob += $(shared-only-routines)
443\f
444# Shared library building.
445
446ifeq (yes,$(build-shared))
447
448# Reference map file only when versioning is selected and a map file name
449# is given.
450ifeq ($(versioning),yes)
451map-file = $(firstword $($(@F:.so=-map)) \
452 $(addprefix $(common-objpfx), \
453 $(filter $(@F:.so=.map),$(version-maps))))
454load-map-file = $(map-file:%=-Wl,--version-script=%)
455endif
456
457# Pattern rule to build a shared object from an archive of PIC objects.
458# This must come after the installation rules so Make doesn't try to
459# build shared libraries in place from the installed *_pic.a files.
460# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
461# on other shared objects.
462lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
463ifneq (,$(findstring aix,$(config-os)))
464 (echo '#!'; \
465 dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
466endif
467 $(build-shlib)
468
469ifeq ($(elf),yes)
470define build-shlib-helper
a7f7b879 471$(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
73398a44 472 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
1c68c264
RM
473 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
474 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
475 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
476 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
477 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
478endef
479else
480ifneq (,$(findstring aix,$(config-os)))
481define build-shlib-helper
482$(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
483 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
484 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
485 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
486 -L$(subst :, -L,$(rpath-link))
487endef
488else
489endif
490endif
491
492ifeq (yes,$(elf))
493# binutils only position loadable notes into the first page for binaries,
494# not for shared objects
20792f99 495$(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
358cad7c 496 $(LINK.o) -shared -Wl,-O1 \
c1e781ae 497 -nostdlib -nostartfiles \
358cad7c
RM
498 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
499 -Wl,--verbose 2>&1 | \
500 sed > $@T \
501 -e '/^=========/,/^=========/!d;/^=========/d' \
a334319f 502 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
358cad7c 503 -e 's/^.*\*(\.dynbss).*$$/& \
20792f99 504 PROVIDE(__start___libc_freeres_ptrs = .); \
358cad7c 505 *(__libc_freeres_ptrs) \
ed20b3d9 506 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
561bcb80 507 -e 's@^.*\*(\.jcr).*$$@& \
db2f05ba
RM
508 PROVIDE(__start___libc_subfreeres = .);\
509 __libc_subfreeres : { *(__libc_subfreeres) }\
510 PROVIDE(__stop___libc_subfreeres = .);\
511 PROVIDE(__start___libc_atexit = .);\
512 __libc_atexit : { *(__libc_atexit) }\
513 PROVIDE(__stop___libc_atexit = .);\
514 PROVIDE(__start___libc_thread_subfreeres = .);\
515 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
561bcb80
RM
516 PROVIDE(__stop___libc_thread_subfreeres = .);\
517 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
358cad7c
RM
518 mv -f $@T $@
519common-generated += shlib.lds
520
521define build-shlib
522$(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
1c68c264 523 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
1c68c264
RM
524endef
525else
526ifneq (,$(findstring aix,$(config-os)))
527define build-shlib
528$(build-shlib-helper) \
529 -o $@ \
530 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
531 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
532endef
533define build-shlib
534$(build-shlib-helper) \
535 $(build-shlib-objlist)
536endef
537endif
538endif
539
540ifneq (,$(findstring aix,$(config-os)))
541define build-module-helper
542$(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
543 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
544 $(load-map-file) \
545 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
546 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
547endef
548else
549define build-module-helper
550$(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
1a379ea0 551 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
1c68c264
RM
552 -B$(csu-objpfx) $(load-map-file) \
553 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
554 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
555endef
556endif
557
558# This macro is similar to build-shlib but it does not define a soname
559# and it does not depend on the destination name to start with `lib'.
560ifeq (yes,$(elf))
561# binutils only position loadable notes into the first page for binaries,
562# not for shared objects
563define build-module
358cad7c 564$(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
1c68c264 565 $(csu-objpfx)abi-note.o $(build-module-objlist)
1c68c264
RM
566endef
567else
568ifneq (,$(findstring aix,$(config-os)))
569define build-module
570$(build-module-helper) \
571 -o $@ \
572 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
573 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
574endef
575else
576define build-module
577define build-module
578$(build-module-helper) \
579 -o $@ \
580 $(build-module-objlist)
581endef
582endif
583endif
584
585build-module-helper-objlist = \
586 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
358cad7c 587 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
1c68c264
RM
588whole-archive := -Wl,--whole-archive
589
590build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
591build-shlib-objlist = $(build-module-helper-objlist) \
592 $(LDLIBS-$(@F:lib%.so=%).so)
593
594# Don't try to use -lc when making libc.so itself.
595# Also omits crti.o and crtn.o, which we do not want
596# since we define our own `.init' section specially.
597LDFLAGS-c.so = -nostdlib -nostartfiles
cbdb12de
UD
598# But we still want to link libc.so against $(libc.so-gnulib).
599LDLIBS-c.so += $(libc.so-gnulib)
1c68c264
RM
600# Give libc.so an entry point and make it directly runnable itself.
601LDFLAGS-c.so += -e __libc_main
4df8c11d
UD
602# If lazy relocation is disabled add the -z now flag.
603ifeq ($(bind-now),yes)
604LDFLAGS-c.so += -Wl,-z,now
605endif
1c68c264
RM
606# Pre-link the objects of libc_pic.a so that we can locally resolve
607# COMMON symbols before we link against ld.so. This is because ld.so
608# contains some of libc_pic.a already, which will prevent the COMMONs
609# from being allocated in libc.so, which introduces evil dependencies
610# between libc.so and ld.so, which can make it impossible to upgrade.
611ifeq ($(elf),yes)
612$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
613 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
614 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
1c68c264
RM
615# Use our own special initializer and finalizer files for libc.so.
616$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
617 $(common-objpfx)libc_pic.os \
618 $(elfobjdir)/sofini.os \
358cad7c
RM
619 $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
620 $(common-objpfx)shlib.lds
1c68c264
RM
621 $(build-shlib)
622ifeq ($(versioning),yes)
623$(common-objpfx)libc.so: $(common-objpfx)libc.map
624endif
625common-generated += libc.so libc_pic.os
626ifdef libc.so-version
627$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
628 $(make-link)
629common-generated += libc.so$(libc.so-version)
630endif
631endif
632else
633ifneq (,$(findstring aix,$(config-os)))
634$(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
635 @rm -f $@
636 (echo '#!'; \
637 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
638 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
639 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
640 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
641 -bE:$(common-objpfx)syscalls.exp \
642 -bI:$(common-objpfx)syscalls.exp \
643 -L$(common-objpfx) -o $@ $^
644# AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
645 cp $@ $(common-objpfx)shr.o
646 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
647endif
648endif
649\f
650# Figure out the source filenames in this directory.
651
652override sources := $(addsuffix .c,\
653 $(filter-out $(elided-routines),\
654 $(routines) $(aux) \
655 $(sysdep_routines)))
656sysdep_routines := $(sysdep_routines)
657
658headers := $(headers) $(sysdep_headers)
659
660# This is the list of all object files, gotten by
661# replacing every ".c" in `sources' with a ".o".
662# We also add bounded-pointer thunks, which are later
663# elided for all suffixes except for `.ob'.
664override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
665 $(patsubst %,$(bppfx)%.o,\
666 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
667
668
669# The makefile may define $(extra-libs) with `libfoo libbar'
670# to build libfoo.a et al from the modules listed in $(libfoo-routines).
671ifdef extra-libs
672# extra-lib.mk is included once for each extra lib to define rules
673# to build it, and to add its objects to the various variables.
674# During its evaluation, $(lib) is set to the name of the library.
675extra-libs-left := $(extra-libs)
676include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
677endif
b30542fb
UD
678
679
aed48a2a
RM
680# The makefile may define $(modules-names) to build additional modules.
681# These are built with $(build-module), except any in $(modules-names-nobuild).
b30542fb
UD
682ifdef modules-names
683# extra-lib.mk is included once for each extra lib to define rules
684# to build it, and to add its objects to the various variables.
685# During its evaluation, $(lib) is set to the name of the library.
686extra-modules-left := $(modules-names)
687include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
aed48a2a
RM
688
689extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
690$(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
fe60d146 691 $(objpfx)%.os $(common-objpfx)shlib.lds \
aed48a2a
RM
692 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
693 $(build-module)
b30542fb 694endif
1c68c264
RM
695\f
696+depfiles := $(sources:.c=.d) \
697 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
698 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
699ifeq ($(build-programs),yes)
700+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
701endif
702+depfiles := $(addprefix $(objpfx),\
703 $(filter-out $(addsuffix .d,$(omit-deps)),\
9ae10332 704 $(+depfiles)))
d73f5331
RM
705all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
706+depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
707 $(wildcard $(all-dt-files:.dt=.d))
708
709# This is a funny rule in that it removes its input file.
710%.d: %.dt
711 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
712 mv -f $(@:.d=.T) $@ && \
713 rm -f $<
9ae10332
RM
714
715# Avoid the .h.d files for any .sym files whose .h files don't exist yet.
716# They will be generated when they're needed, and trying too early won't work.
717+gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
718+depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
719 $(+gen-as-const)))
1c68c264
RM
720
721ifdef +depfiles
722ifneq ($(no_deps),t)
723-include $(+depfiles)
724endif
725endif
726\f\f
727# Maximize efficiency by minimizing the number of rules.
728.SUFFIXES: # Clear the suffix list. We don't use suffix rules.
729# Don't define any builtin rules.
730MAKEFLAGS := $(MAKEFLAGS)r
731
732# Generic rule for making directories.
733%/:
734# mkdir isn't smart enough to strip a trailing /.
735 mkdir $(@:%/=%)
736\f
737# Make sure that object files are not removed
738# when they are intermediates between sources and library members.
739.PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
740
741# Make sure that the parent library archive is never removed.
742.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
743\f
744# Use the verbose option of ar and tar when not running silently.
745ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
746verbose := v
747else # -s
748verbose :=
749endif # not -s
750
751ARFLAGS := r$(verbose)
752CREATE_ARFLAGS := cru$(verbose)
753\f
754# This makes all the object files in the parent library archive.
755
756.PHONY: lib lib-noranlib
757lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
758lib-noranlib: libobjs
759
760# For object-suffix $o, the list of objects with that suffix.
761# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
762o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
763 $(elide-routines$o)),\
764 $(objects))) \
765 $(addprefix $(objpfx),$(o-objects$o))
766
767others: $(addprefix $(objpfx),$(install-lib))
768
769ifndef objects
770
771# Create the stamp$o files to keep the parent makefile happy.
772subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
773$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
774 $(make-target-directory)
775 rm -f $@; > $@
776else
777
778# Define explicit rules to update each $(objpfx)stamp.SUFFIX
779# timestamp file; these rules (one explicit rule is generated for each
780# object suffix) write a list of objects to update in the stamp file.
781# The parent will then actually add them all to the archive in the
782# archive rule, below.
783define o-iterator-doit
784$(objpfx)stamp$o: $(o-objects); $$(do-stamp)
785endef
786define do-stamp
d8f6e441 787$(make-target-directory)
1c68c264
RM
788echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
789mv -f $@T $@
790endef
791object-suffixes-left := $(object-suffixes-for-libc)
792include $(o-iterator)
793
794endif
795
796# Now define explicit rules to build the library archives; these depend
797# on the stamp files built above.
798define o-iterator-doit
799$(common-objpfx)$(patsubst %,$(libtype$o),c): \
800 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
801endef
802define do-makelib
803cd $(common-objdir) && \
804$(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
805$(RANLIB) $@
806endef
807subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
808subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
809ifndef subdir
810$(subdirs-stamps): subdir_lib;
811endif
812object-suffixes-left = $(object-suffixes-for-libc)
813include $(o-iterator)
814
815
816# This makes all the object files.
817.PHONY: objects objs libobjs extra-objs
818objects objs: libobjs extra-objs
819libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
820extra-objs: $(addprefix $(objpfx),$(extra-objs))
821
822# Canned sequence for building an extra library archive.
823define build-extra-lib
824$(patsubst %/,cd % &&,$(objpfx)) \
825$(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
826 $(patsubst $(objpfx)%,%,$^)
827$(RANLIB) $@
828endef
829\f
830# Installation.
831
832.PHONY: force-install
833force-install:
834
835# $(install-lib) are installed from the object directory into $(libdir);
836# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
837# unless they also appear in $(non-lib.a). $(install-data) are installed
838# as they are into $(datadir). $(headers) are installed as they are in
839# $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
840# are installed from the object directory into $(bindir), $(bindir) and
841# $(sbindir), respectively. $(install-others) are absolute path names of
842# files to install; rules to install them are defined elsewhere.
843
844# The simple library name to install libc.a under.
845# This could be defined by a sysdep Makefile.
846ifndef libc-name
847libc-name := c
848endif
849
850define do-install
851$(make-target-directory)
852$(INSTALL_DATA) $< $@
853endef
854
855# Make the target directory if it doesn't exist, using the `mkinstalldirs'
856# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
857define make-target-directory
858$(addprefix $(..)./scripts/mkinstalldirs ,\
859 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
860endef
861
862# Any directory (parent or subdir) should install libc.a; this way
863# "make install" in a subdir is guaranteed to install everything it changes.
864installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
865 $(inst_libdir)/$(patsubst %,$(libtype$o),\
866 $(libprefix)$(libc-name)))
867install: $(installed-libcs)
868$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
869 $(make-target-directory)
870 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
871# Running ranlib after installing makes the __.SYMDEF time stamp up to
872# date, which avoids messages from some linkers.
873 $(RANLIB) $@
874
875define do-install-program
876$(make-target-directory)
877$(INSTALL_PROGRAM) $< $@.new
878mv -f $@.new $@
879endef
880
881define do-install-script
882$(make-target-directory)
883$(INSTALL_SCRIPT) $< $@.new
884mv -f $@.new $@
885endef
886
887install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
888install-lib := $(filter-out %.so %_pic.a,$(install-lib))
889
890ifeq (yes,$(build-shared))
891# Find which .so's have versions.
892versioned := $(strip $(foreach so,$(install-lib.so),\
893 $(patsubst %,$(so),$($(so)-version))))
894
895install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
896install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
897
cc8bfce9
RM
898# For versioned libraries, we install three files:
899# $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
900# $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
901# $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
7a0c303e 902V := $(firstword $($(subdir)-version) $(version))
cc8bfce9
RM
903install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
904 $(foreach L,$(install-lib.so-versioned),\
905 $(inst_libdir)/$L \
7a0c303e 906 $(inst_slibdir)/$(L:.so=)-$V.so \
cc8bfce9 907 $(inst_slibdir)/$L$($L-version))
1c68c264
RM
908
909# Install all the unversioned shared libraries.
910$(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
911 $(objpfx)%.so $(+force)
912 $(do-install-program)
913
914ifneq ($(findstring -s,$(LN_S)),)
915define make-link
916rm -f $@.new
917$(SHELL) $(..)scripts/rellns-sh $< $@.new
918mv -f $@.new $@
919endef
920else
921# If we have no symbolic links don't bother with rellns-sh.
922define make-link
923rm -f $@.new
924$(LN_S) $< $@.new
925mv -f $@.new $@
926endef
927endif
928
929ifeq (yes,$(build-shared))
930ifeq (no,$(cross-compiling))
931symbolic-link-prog := $(common-objpfx)elf/sln
932symbolic-link-list := $(common-objpfx)elf/symlink.list
933define make-shlib-link
934echo $(<F) $@ >> $(symbolic-link-list)
935endef
936else # cross-compiling
937# We need a definition that can be used by elf/Makefile's install rules.
938symbolic-link-prog = $(LN_S)
939endif
940endif
941ifndef make-shlib-link
942define make-shlib-link
943rm -f $@
944$(LN_S) $(<F) $@
945endef
946endif
947
948ifdef libc.so-version
949# For a library specified to be version N, install three files:
950# libc.so -> libc.so.N (e.g. libc.so.6)
951# libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
952
953$(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
954 $(+force)
955 $(make-shlib-link)
956$(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
957 $(do-install-program)
958install: $(inst_slibdir)/libc.so$(libc.so-version)
959
960# This fragment of linker script gives the OUTPUT_FORMAT statement
961# for the configuration we are building. We put this statement into
962# the linker scripts we install for -lc et al so that they will not be
963# used by a link for a different format on a multi-architecture system.
964$(common-objpfx)format.lds: $(..)scripts/output-format.sed \
965 $(common-objpfx)config.make \
966 $(common-objpfx)config.h $(..)Makerules
967 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
968 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
969 | sed -n -f $< > $@.new
970 rm -f $@.so
971 mv -f $@.new $@
972common-generated += format.lds
973
974ifndef subdir
975# What we install as libc.so for programs to link against is in fact a
976# link script. It contains references for the various libraries we need.
977# The libc.so object is not complete since some functions are only defined
978# in libc_nonshared.a.
979# We need to use absolute paths since otherwise local copies (if they exist)
980# of the files are taken by the linker.
981install: $(inst_libdir)/libc.so
982$(inst_libdir)/libc.so: $(common-objpfx)format.lds \
983 $(common-objpfx)libc.so$(libc.so-version) \
984 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
985 $(libprefix)$(libc-name)) \
986 $(+force)
987 (echo '/* GNU ld script';\
988 echo ' Use the shared library, but some functions are only in';\
989 echo ' the static library, so try that secondarily. */';\
990 cat $<; \
991 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
992 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
c440fa75 993 ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1c68c264
RM
994 ) > $@.new
995 mv -f $@.new $@
996
997endif
998
999else
1000install: $(inst_slibdir)/libc.so
1001$(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1002 $(do-install-program)
1003endif
1004
1005ifneq (,$(versioned))
1006# Produce three sets of rules as above for all the smaller versioned libraries.
1007
1008define o-iterator-doit
1009$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1010endef
2afbfec4
RM
1011object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1012ifneq (,$(object-suffixes-left))
1c68c264 1013include $(o-iterator)
2afbfec4 1014endif
1c68c264
RM
1015
1016# Make symlinks in the build directory, because the versioned names might
1017# be referenced by a DT_NEEDED in another library.
1018define o-iterator-doit
1019$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1020endef
1021object-suffixes-left := $(versioned)
1022include $(o-iterator)
1023
1024generated += $(foreach o,$(versioned),$o$($o-version))
1025
1026ifeq (,$($(subdir)-version))
1027define o-iterator-doit
1028$(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1029 $(+force);
1030 $$(make-shlib-link)
1031endef
1032object-suffixes-left := $(versioned)
1033include $(o-iterator)
1034
1035define o-iterator-doit
1036$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1037 $$(do-install-program)
1038endef
1039object-suffixes-left := $(versioned)
1040include $(o-iterator)
1041else
1042define o-iterator-doit
1043$(inst_slibdir)/$o$($o-version): \
1044 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1045 $$(make-shlib-link)
1046endef
1047object-suffixes-left := $(versioned)
1048include $(o-iterator)
1049
1050define o-iterator-doit
1051$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1052 $$(do-install-program)
1053endef
1054object-suffixes-left := $(versioned)
1055include $(o-iterator)
1056endif
1057endif
1058
1059define do-install-so
1060$(do-install-program)
1061$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1062 $(filter-out %.so,$@))
1063endef
1064
1065so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1066$(foreach v,$(so-versions),\
1067 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1068 $(+force)
1069 $(do-install-so)
1070$(foreach v,$(so-versions),\
1071 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1072 $(do-install-so)
1073endif
1074
1075ifdef install-bin
1076$(addprefix $(inst_bindir)/,$(install-bin)): \
1077 $(inst_bindir)/%: $(objpfx)% $(+force)
1078 $(do-install-program)
1079endif
1080ifdef install-bin-script
1081$(addprefix $(inst_bindir)/,$(install-bin-script)): \
1082 $(inst_bindir)/%: $(objpfx)% $(+force)
1083 $(do-install-script)
1084endif
1085ifdef install-rootsbin
1086$(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1087 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1088 $(do-install-program)
1089endif
1090ifdef install-sbin
1091$(addprefix $(inst_sbindir)/,$(install-sbin)): \
1092 $(inst_sbindir)/%: $(objpfx)% $(+force)
1093 $(do-install-program)
1094endif
1095ifdef install-lib
1096install-lib.a := $(filter lib%.a,$(install-lib))
1097install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1098ifdef install-lib-non.a
1099$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1100 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1101 $(do-install)
1102endif
1103ifdef install-lib.a
1104$(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1105 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1106 $(do-install)
1107 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1108endif
1109endif
1110ifdef install-data
1111$(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1112 $(do-install)
1113endif
1114headers := $(strip $(headers))
1115ifdef headers
a334319f 1116$(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1c68c264
RM
1117 $(do-install)
1118endif # headers
1119
1120.PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1121 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1122 install-data-nosubdir install-headers-nosubdir
1123install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1124install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1125install-rootsbin-nosubdir: \
1126 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1127install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1128install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1129 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1130 $(addprefix $(libprefix),$(install-lib-non.a)))
1131install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1132install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1133install-others-nosubdir: $(install-others)
1134
1135# We need all the `-nosubdir' targets so that `install' in the parent
1136# doesn't depend on several things which each iterate over the subdirs.
1137# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1138# subroutine. Then in the parent `install-FOO' also causes subdir makes.
1139install-%:: install-%-nosubdir ;
1140
1141.PHONY: install install-no-libc.a-nosubdir
1142ifeq ($(build-programs),yes)
1143install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1144 install-bin-nosubdir install-bin-script-nosubdir \
1145 install-lib-nosubdir install-others-nosubdir \
1146 install-rootsbin-nosubdir install-sbin-nosubdir
1147else
1148install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1149 install-lib-nosubdir install-others-nosubdir
1150endif
1151install: install-no-libc.a-nosubdir
1152\f
1153# Command to compile $< in $(objdir) using the native libraries.
1154define native-compile
1155$(make-target-directory)
1156$(patsubst %/,cd % &&,$(objpfx)) \
1157$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1158 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1159endef
1160
1161# Command to compile $< in $(common-objdir) using the native libraries.
1162# We must cd to $(objdir) anyway so that $(..)config.h is valid.
1163define common-objdir-compile
1164$(patsubst %/,cd % &&,$(objpfx)) \
1165$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1166 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1167endef
1168
1169# We always want to use configuration definitions.
1170# Note that this is only used for commands running in $(objpfx).
1171ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1172
1173# Support the GNU standard name for this target.
1174.PHONY: check
1175check: tests
1176# Special target to run tests which cannot be run unconditionally.
1177# Maintainers should use this target.
1178.PHONY: xcheck
1179xcheck: xtests
1180
1181all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1182ifneq (,$(all-nonlib))
a334319f 1183cpp-srcs-left = $(all-nonlib:=.c)
1c68c264 1184lib := nonlib
a334319f 1185include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
1c68c264
RM
1186endif
1187
1188# The include magic above causes those files to use this variable for flags.
1189CPPFLAGS-nonlib = -DNOT_IN_libc=1
1190
1191
1192ifeq ($(versioning),yes)
1193# Generate normalized lists of symbols, versions, and data sizes.
1194# This is handy for checking against existing library binaries.
1195
1196%.symlist: $(..)scripts/abilist.awk %.dynsym
1197 LC_ALL=C $(AWK) -f $^ > $@T
1198 mv -f $@T $@
1199
1200%.dynsym: %.so
1201 $(OBJDUMP) --dynamic-syms $< > $@T
1202 mv -f $@T $@
1203
1c68c264 1204check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
9ae10332
RM
1205 $(..)abilist/%.abilist $(objpfx)%.symlist
1206 $(check-abi)
1207check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1208 $(..)abilist/%.abilist $(common-objpfx)%.symlist
1209 $(check-abi)
1210define check-abi
1c68c264 1211 LC_ALL=C \
9ae10332 1212 $(AWK) -f $< -v 'config=$(check-abi-config)' \
d2e75f65 1213 $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1c68c264 1214 $(filter %.abilist,$^) \
2dd18ce2 1215 | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
9ae10332 1216endef
fd54683c
RM
1217ifeq ($(enable-check-abi),warn)
1218check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1219endif
1c68c264 1220
643931fb 1221ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
0e56981e 1222-include $(common-objpfx)tls.make
fd54683c
RM
1223config-tls := notls
1224ifeq ($(use-tls),yes)
1225config-tls := tls
1226endif
1227ifeq ($(use-thread),yes)
1228config-tls := thread
1229endif
9ae10332 1230check-abi-config := \
fd54683c 1231 $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
9ae10332
RM
1232endif
1233
1234update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1235 $(objpfx)%.symlist
1236 $(update-abi)
1237update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1238 $(common-objpfx)%.symlist
1239 $(update-abi)
1c68c264 1240ifndef update-abi-config
9ae10332 1241define update-abi
1c68c264 1242 @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
9ae10332 1243endef
1c68c264 1244else
9ae10332 1245define update-abi
fd54683c 1246LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
9ae10332
RM
1247 > $(..)abilist/$*.abilist.new
1248@if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1249 then rm -f $(..)abilist/$*.abilist.new; \
1250 echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1251 else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1252 echo '*** Now check $*.abilist changes for correctness ***'; \
1253 fi
1254endef
1c68c264
RM
1255endif
1256
1257.PHONY: update-abi check-abi
1258update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1259check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1260ifdef subdir
1261subdir_check-abi: check-abi
1262subdir_update-abi: update-abi
1263else
1264check-abi: subdir_check-abi
1265update-abi: subdir_update-abi
1266endif
1267
1c68c264
RM
1268ifeq ($(subdir),elf)
1269check-abi: check-abi-libc
1270update-abi: update-abi-libc
1271common-generated += libc.symlist
1272endif
1273
fd54683c
RM
1274ifeq ($(build-shared),yes)
1275ifneq ($(enable-check-abi),no)
94659495
RM
1276ifdef subdir
1277tests: check-abi
1278endif
1279endif
fd54683c 1280endif
94659495 1281
1c68c264 1282endif
aad08dba 1283
a334319f
UD
1284# There's no good place to put this - here will do.
1285ifeq ($(filter %posix, $(sysdirs)),)
1286L_tmpnam = 1
1287TMP_MAX = 0
1288L_ctermid = 1
1289L_cuserid = 1
1290else
1291L_tmpnam = 20
1292TMP_MAX = 238328
1293L_ctermid = 9
1294L_cuserid = 9
1295endif
9ae10332
RM
1296stdio_lim = $(common-objpfx)bits/stdio_lim.h
1297
1298$(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1299$(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1300 $(common-objpfx)config.make
1301 $(make-target-directory)
7cd72ad3
RM
1302 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1303 echo '#define _LIBC 1'; \
1304 echo '#include "$(..)misc/sys/uio.h"'; } | \
1305 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1306 $(+includes) -xc - -o $(@:st=hT)
1307 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1308 $(@:st=dT) > $(@:st=dt)
1309 mv -f $(@:st=dt) $(@:st=d)
9ae10332
RM
1310 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1311 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1312 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1313 fopen_max=$${fopen_max:-16}; \
1314 filename_max=$${filename_max:-1024}; \
7cd72ad3 1315 if [ -z "$$iov_max" ]; then \
9ae10332
RM
1316 define_iov_max="# undef IOV_MAX"; \
1317 else \
1318 define_iov_max="# define IOV_MAX $$iov_max"; \
1319 fi; \
1320 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1321 -e "s/@FILENAME_MAX@/$$filename_max/" \
1322 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1323 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1324 -e "s/@L_ctermid@/$(L_ctermid)/" \
1325 -e "s/@L_cuserid@/$(L_cuserid)/" \
1326 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1327 $< > $(@:st=h.new)
1328 $(move-if-change) $(@:st=h.new) $(@:st=h)
1329# Remove these last so that they can be examined if something went wrong.
1330 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1331 touch $@
1332# Get dependencies.
1333ifndef no_deps
1334-include $(stdio_lim:h=d)
1335endif
1336common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1c68c264 1337\f
a334319f
UD
1338.PHONY: TAGS
1339TAGS: $(objpfx)distinfo $(..)MakeTAGS
1340 $(MAKE) $(addprefix -f ,$^) $@
1341
1342$(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1343 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1c68c264
RM
1344FORCE:
1345
a334319f 1346
1c68c264
RM
1347.PHONY: echo-headers
1348echo-headers:
1349 @echo $(headers)
1350
220addf7
RM
1351%.bz2: %; bzip2 -9vk $<
1352%.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1c68c264
RM
1353\f
1354# Common cleaning targets.
1355
1356.PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1357clean: common-clean
1358mostlyclean: common-mostlyclean
1359
1360do-tests-clean:
1361 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1362 $(test-srcs)) \
1363 $(addsuffix -bp.out,$(tests) $(xtests) \
1364 $(test-srcs)))
1365
1366# Remove the object files.
1367common-mostlyclean:
1368 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1369 $(others) $(sysdep-others) stubs \
1370 $(addsuffix .o,$(tests) $(xtests) \
1371 $(test-srcs) $(others) \
1372 $(sysdep-others)) \
1373 $(addsuffix -bp,$(tests) $(xtests) \
1374 $(test-srcs)) \
1375 $(addsuffix .out,$(tests) $(xtests) \
1376 $(test-srcs)) \
1377 $(addsuffix -bp.out,$(tests) $(xtests) \
1378 $(test-srcs)))
a334319f
UD
1379 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1380 $(install-lib.so) \
1c68c264
RM
1381 $(install-lib.so:%.so=%_pic.a))
1382 -rm -f core
1383 -rm -f $(objpfx)rtld-*.os
1384 $(rmobjs)
1385define rmobjs
1386$(foreach o,$(object-suffixes-for-libc),
1387-rm -f $(objpfx)stamp$o $(o-objects))
1388endef
1389
1390# Also remove the dependencies and generated source files.
1391common-clean: common-mostlyclean
d73f5331
RM
1392 -rm -f $(addprefix $(objpfx),$(generated))
1393 -rm -f $(objpfx)*.d $(objpfx)*.dt
1c68c264
RM
1394 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1395 -rm -f $(addprefix $(common-objpfx),$(common-generated))
a334319f 1396 -rm -f $(objpfx)distinfo
1c68c264
RM
1397\f
1398# Produce a file `stubs' which contains `#define __stub_FUNCTION'
1399# for each function which is a stub. We grovel over all the .d files
1400# looking for references to <stub-tag.h>. Then we grovel over each
1401# referenced source file to see what stub function it defines.
1402
1403ifdef objpfx
1404.PHONY: stubs # The parent Makefile calls this target.
1405stubs: $(objpfx)stubs
1406endif
561bcb80
RM
1407objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1408 $(addprefix $(objpfx),$(extra-objs))
1409$(objpfx)stubs: $(objs-for-stubs)
1410ifneq (,$(strip $(objs-for-stubs)))
ae46b677 1411 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
561bcb80
RM
1412 $(AWK) '/\.gnu\.glibc-stub\./ { \
1413 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1414 stubs[$$2] = 1; } \
1415 END { for (s in stubs) print "#define __stub_" s }' > $@T
1c68c264 1416 mv -f $@T $@
f291538f
RM
1417else
1418 > $@
1419endif
1c68c264 1420\f
a334319f
UD
1421# This information is not used for making distributions any more.
1422# But it's used by MakeTAGS for making TAGS files and the .pot files.
1423$(objpfx)distinfo: Makefile $(..)Makerules \
1424 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1425 $(make-target-directory)
1426 $(distinfo-vars)
1427 mv -f $@.new $@
1428
1429define distinfo-vars
1430rm -f $@.new
1431echo > $@.new 'subdir := $(subdir)'
1432$(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1433 headers sysdep_headers distribute dont_distribute generated \
1434 others tests xtests test-srcs extra-libs versioned \
1435 $(extra-libs:%=%-routines) \
1436 $(addprefix install-,lib lib.so data bin bin-script sbin others),
1437echo >> $@.new '$(subdir)-$(var) := $($(var))'
1438echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1439endef
1440\f
1c68c264
RM
1441ifneq (,$(strip $(gpl2lgpl)))
1442ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1443# Snarf from the master source and frob the copying notice.
1444$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1445 sed -f $^ > $@-tmp
1446# So I don't edit them by mistake.
1447 chmod a-w $@-tmp
1448 mv -f $@-tmp $@
1449ifeq ($(with-cvs),yes)
1450 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1451endif
1452endif
1453endif
1454
1455# Local Variables:
1456# mode: makefile
1457# End: