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