]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makerules
Switch gettimeofday from INTUSE to libc_hidden_proto.
[thirdparty/glibc.git] / Makerules
CommitLineData
4962050e 1# Copyright (C) 1991-2012 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.
96ifeq ($(versioning),yes)
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
109endif # $(versioning) = yes
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
1c68c264
RM
220# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
221# patterns matching sysdep directories whose assembly source files should
222# be suppressed.
223ifdef inhibit-sysdep-asm
16cd816f
RM
224define check-inhibit-asm
225case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) asm= ;; esac;
1c68c264 226endef
1c68c264
RM
227endif
228
e0a3ed4f 229-include $(common-objpfx)sysd-rules
1c68c264
RM
230ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
231# The value of $(+sysdep_dirs) the sysd-rules was computed for
232# differs from the one we are using now. So force a rebuild of sysd-rules.
233sysd-rules-force = FORCE
234FORCE:
235endif
e0a3ed4f 236$(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
708ef8a4
RM
237 $(sysdep-makefiles) $(sysdep-makeconfigs) \
238 $(sysd-rules-force)
1c68c264
RM
239 -@rm -f $@T
240 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
e0a3ed4f
RM
241 for dir in $(config-sysdirs); do \
242 case "$$dir" in \
243 /*) ;; \
244 *) dir="\$$(..)$$dir" ;; \
245 esac; \
8b728fa3 246 asm='.S'; \
16cd816f
RM
247 $(check-inhibit-asm) \
248 for o in $(all-object-suffixes); do \
249 set $(subst :, ,$(sysd-rules-patterns)); \
250 while [ $$# -ge 2 ]; do \
251 t=$$1; shift; \
252 d=$$1; shift; \
253 v=$${t%%%}; [ x"$$v" = x ] || v="\$$($${v}CPPFLAGS)"; \
254 for s in $$asm .c; do \
255 echo "\$$(objpfx)$$t$$o: $$dir/$$d$$s \$$(before-compile)"; \
256 echo " \$$(compile-command$$s) $$v"; \
257 done; \
258 done; \
259 done; \
260 echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force)"; \
261 echo " \$$(do-install)"; \
1c68c264
RM
262 done; \
263 echo 'sysd-rules-done = t') > $@T
264 mv -f $@T $@
265
266ifndef sysd-rules-done
267# Don't do deps until this exists, because it provides rules to make the deps.
268no_deps=t
269endif
270
b6ab06ce
UD
271define o-iterator-doit
272$(objpfx)%$o: %.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: %.c $(before-compile); $$(compile-command.c)
279endef
280object-suffixes-left := $(all-object-suffixes)
281include $(o-iterator)
282
7735afa2
UD
283define o-iterator-doit
284$(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
285endef
286object-suffixes-left := $(all-object-suffixes)
287include $(o-iterator)
288
b6ab06ce
UD
289# Omit the objpfx rules when building in the source tree, because
290# objpfx is empty and so these rules just override the ones above.
291ifdef objpfx
292# Define first rules to find the source files in $(objpfx).
293# Generated source files will end up there.
294define o-iterator-doit
295$(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
296endef
297object-suffixes-left := $(all-object-suffixes)
298include $(o-iterator)
299
b6ab06ce
UD
300define o-iterator-doit
301$(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
302endef
303object-suffixes-left := $(all-object-suffixes)
304include $(o-iterator)
305endif
306
1c68c264
RM
307# Generate version maps, but wait until sysdep-subdirs is known
308ifeq ($(sysd-sorted-done),t)
309ifeq ($(versioning),yes)
310-include $(common-objpfx)sysd-versions
311$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
312common-generated += $(version-maps)
313postclean-generated += sysd-versions Versions.all abi-versions.h \
314 Versions.def.v.i Versions.def.v Versions.v.i Versions.v
315
316ifndef avoid-generated
e0a3ed4f 317ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
1c68c264
RM
318sysd-versions-force = FORCE
319FORCE:
320endif
321# See %.v/%.v.i implicit rules in Makeconfig.
322$(common-objpfx)Versions.def.v.i: $(..)Versions.def \
323 $(wildcard $(add-ons:%=$(..)%/Versions.def))
324$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
325 $(common-objpfx)soversions.i \
326 $(common-objpfx)Versions.def.v
9d0547ce
RM
327 { while read which lib version setname; do \
328 test x"$$which" = xDEFAULT || continue; \
1c68c264
RM
329 test -z "$$setname" || echo "$$lib : $$setname"; \
330 done < $(word 2,$^); \
331 cat $(word 3,$^); \
332 } | LC_ALL=C $(AWK) -f $< > $@T
333 mv -f $@T $@
334# See %.v/%.v.i implicit rules in Makeconfig.
e0a3ed4f 335$(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
1c68c264
RM
336 $(wildcard $(sysdirs:%=%/Versions)) \
337 $(common-objpfx)abi-versions.h \
338 $(sysd-versions-force)
339$(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
340 $(common-objpfx)Versions.v \
341 $(..)scripts/versions.awk
e0a3ed4f 342 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
1c68c264
RM
343 cat $(word 2,$^) \
344 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
345 -v move_if_change='$(move-if-change)' \
346 -f $(word 3,$^); \
347 ) > $@T
348 mv -f $@T $@
349endif # avoid-generated
350endif # $(versioning) = yes
351endif # sysd-sorted-done
352
d73f5331 353# Generate .dT files as we compile.
b9608428 354compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
d73f5331 355compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
d73f5331 356compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
7735afa2 357compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
1c68c264 358
656416c9
AS
359# Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
360# track system includes here, they may spuriously trigger an install rule,
361# and would cause the check-local-headers test to fail.
362native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
363
1c68c264
RM
364# GCC can grok options after the file name, and it looks nicer that way.
365compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
7735afa2 366compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
073e82bf
RM
367compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
368 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
369COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
370 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
1c68c264 371
1c68c264
RM
372# We need this for the output to go in the right place. It will default to
373# empty if make was configured to work with a cc that can't grok -c and -o
374# together. You can't compile the C library with such a compiler.
375OUTPUT_OPTION = -o $@
376
377# We need the $(CFLAGS) to be in there to have the right predefines during
378# the dependency run for C sources. But having it for assembly sources can
379# get the wrong predefines.
f4281cc4 380S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
d73f5331 381
1c68c264
RM
382define +make-deps
383$(make-target-directory)
384$(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
b710b53d
RM
385 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
386's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
387$(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
1c68c264
RM
388mv -f $(@:.d=.T) $@ $(generate-md5)
389endef
d73f5331 390
1c68c264
RM
391ifneq (,$(objpfx))
392# Continuation lines here are dangerous because they introduce spaces!
393define sed-remove-objpfx
394-e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
395-e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
396endef
397endif
398\f
399# Modify the list of routines we build for different targets
400
0269750c 401ifeq (yes,$(build-shared))
1c68c264
RM
402ifndef libc.so-version
403# Undefine this because it can't work when we libc.so is unversioned.
404static-only-routines =
405endif
406endif
407
408# Bounded pointer thunks are only built for *.ob
409elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
410
411elide-routines.oS += $(filter-out $(static-only-routines),\
412 $(routines) $(aux) $(sysdep_routines)) \
413 $(elide-bp-thunks)
414elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
415
416# If we have versioned code we don't need the old versions in any of the
417# static libraries.
418elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
419elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
420elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
421elide-routines.ob += $(shared-only-routines)
422\f
423# Shared library building.
424
425ifeq (yes,$(build-shared))
426
427# Reference map file only when versioning is selected and a map file name
428# is given.
429ifeq ($(versioning),yes)
430map-file = $(firstword $($(@F:.so=-map)) \
431 $(addprefix $(common-objpfx), \
432 $(filter $(@F:.so=.map),$(version-maps))))
433load-map-file = $(map-file:%=-Wl,--version-script=%)
434endif
435
436# Pattern rule to build a shared object from an archive of PIC objects.
437# This must come after the installation rules so Make doesn't try to
438# build shared libraries in place from the installed *_pic.a files.
439# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
440# on other shared objects.
441lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
1c68c264
RM
442 $(build-shlib)
443
1c68c264 444define build-shlib-helper
a7f7b879 445$(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
73398a44 446 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
1c68c264
RM
447 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
448 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
449 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
450 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
451 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
452endef
1c68c264 453
f781ef40
RM
454ifeq (yes,$(use-default-link))
455# If the linker is good enough, we can let it use its default linker script.
456shlib-lds =
457shlib-lds-flags =
458else
1c68c264
RM
459# binutils only position loadable notes into the first page for binaries,
460# not for shared objects
20792f99 461$(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
358cad7c 462 $(LINK.o) -shared -Wl,-O1 \
c1e781ae 463 -nostdlib -nostartfiles \
358cad7c
RM
464 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
465 -Wl,--verbose 2>&1 | \
466 sed > $@T \
467 -e '/^=========/,/^=========/!d;/^=========/d' \
71213dc2
UD
468 $(if $(filter yes,$(have-hash-style)), \
469 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
470 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
471 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
472 , \
473 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
474 ) \
358cad7c 475 -e 's/^.*\*(\.dynbss).*$$/& \
20792f99 476 PROVIDE(__start___libc_freeres_ptrs = .); \
358cad7c 477 *(__libc_freeres_ptrs) \
ed20b3d9 478 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
561bcb80 479 -e 's@^.*\*(\.jcr).*$$@& \
db2f05ba
RM
480 PROVIDE(__start___libc_subfreeres = .);\
481 __libc_subfreeres : { *(__libc_subfreeres) }\
482 PROVIDE(__stop___libc_subfreeres = .);\
483 PROVIDE(__start___libc_atexit = .);\
484 __libc_atexit : { *(__libc_atexit) }\
485 PROVIDE(__stop___libc_atexit = .);\
486 PROVIDE(__start___libc_thread_subfreeres = .);\
487 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
561bcb80
RM
488 PROVIDE(__stop___libc_thread_subfreeres = .);\
489 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
decd4e50 490 test -s $@T
358cad7c
RM
491 mv -f $@T $@
492common-generated += shlib.lds
493
2d4fa81e
RM
494shlib-lds = $(common-objpfx)shlib.lds
495shlib-lds-flags = -T $(shlib-lds)
f781ef40 496endif
2d4fa81e 497
358cad7c 498define build-shlib
2d4fa81e 499$(build-shlib-helper) -o $@ $(shlib-lds-flags) \
1c68c264 500 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
1c68c264 501endef
1c68c264 502
1c68c264
RM
503define build-module-helper
504$(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
1a379ea0 505 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
1c68c264
RM
506 -B$(csu-objpfx) $(load-map-file) \
507 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
508 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
509endef
1c68c264
RM
510
511# This macro is similar to build-shlib but it does not define a soname
512# and it does not depend on the destination name to start with `lib'.
1c68c264
RM
513# binutils only position loadable notes into the first page for binaries,
514# not for shared objects
515define build-module
2d4fa81e 516$(build-module-helper) -o $@ $(shlib-lds-flags) \
1c68c264 517 $(csu-objpfx)abi-note.o $(build-module-objlist)
1c68c264 518endef
d9266ea0 519define build-module-asneeded
2d4fa81e 520$(build-module-helper) -o $@ $(shlib-lds-flags) \
d9266ea0
UD
521 $(csu-objpfx)abi-note.o \
522 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
523endef
1c68c264
RM
524
525build-module-helper-objlist = \
526 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
358cad7c 527 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
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
1c68c264
RM
570# Use our own special initializer and finalizer files for libc.so.
571$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
1b74661a 572 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
1c68c264 573 $(elfobjdir)/sofini.os \
358cad7c 574 $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
2d4fa81e 575 $(shlib-lds)
1c68c264
RM
576 $(build-shlib)
577ifeq ($(versioning),yes)
578$(common-objpfx)libc.so: $(common-objpfx)libc.map
579endif
580common-generated += libc.so libc_pic.os
581ifdef libc.so-version
582$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
583 $(make-link)
584common-generated += libc.so$(libc.so-version)
585endif
586endif
1c68c264
RM
587\f
588# Figure out the source filenames in this directory.
589
590override sources := $(addsuffix .c,\
591 $(filter-out $(elided-routines),\
592 $(routines) $(aux) \
593 $(sysdep_routines)))
594sysdep_routines := $(sysdep_routines)
595
596headers := $(headers) $(sysdep_headers)
597
598# This is the list of all object files, gotten by
599# replacing every ".c" in `sources' with a ".o".
600# We also add bounded-pointer thunks, which are later
601# elided for all suffixes except for `.ob'.
602override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
603 $(patsubst %,$(bppfx)%.o,\
604 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
605
606
607# The makefile may define $(extra-libs) with `libfoo libbar'
608# to build libfoo.a et al from the modules listed in $(libfoo-routines).
609ifdef extra-libs
610# extra-lib.mk is included once for each extra lib to define rules
611# to build it, and to add its objects to the various variables.
612# During its evaluation, $(lib) is set to the name of the library.
613extra-libs-left := $(extra-libs)
614include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
615endif
b30542fb
UD
616
617
aed48a2a
RM
618# The makefile may define $(modules-names) to build additional modules.
619# These are built with $(build-module), except any in $(modules-names-nobuild).
b30542fb
UD
620ifdef modules-names
621# extra-lib.mk is included once for each extra lib to define rules
622# to build it, and to add its objects to the various variables.
623# During its evaluation, $(lib) is set to the name of the library.
624extra-modules-left := $(modules-names)
625include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
aed48a2a
RM
626
627extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
628$(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
2d4fa81e 629 $(objpfx)%.os $(shlib-lds) \
aed48a2a
RM
630 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
631 $(build-module)
b30542fb 632endif
1c68c264
RM
633\f
634+depfiles := $(sources:.c=.d) \
635 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
5bd66283 636 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
376e973a 637 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
1c68c264
RM
638 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
639ifeq ($(build-programs),yes)
640+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
641endif
642+depfiles := $(addprefix $(objpfx),\
643 $(filter-out $(addsuffix .d,$(omit-deps)),\
9ae10332 644 $(+depfiles)))
d73f5331
RM
645all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
646+depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
647 $(wildcard $(all-dt-files:.dt=.d))
648
649# This is a funny rule in that it removes its input file.
650%.d: %.dt
651 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
652 mv -f $(@:.d=.T) $@ && \
653 rm -f $<
9ae10332
RM
654
655# Avoid the .h.d files for any .sym files whose .h files don't exist yet.
656# They will be generated when they're needed, and trying too early won't work.
657+gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
658+depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
659 $(+gen-as-const)))
1c68c264
RM
660
661ifdef +depfiles
662ifneq ($(no_deps),t)
663-include $(+depfiles)
664endif
665endif
666\f\f
667# Maximize efficiency by minimizing the number of rules.
668.SUFFIXES: # Clear the suffix list. We don't use suffix rules.
669# Don't define any builtin rules.
670MAKEFLAGS := $(MAKEFLAGS)r
671
672# Generic rule for making directories.
673%/:
674# mkdir isn't smart enough to strip a trailing /.
5dfeae0e
UD
675# We always require a mkdir which supports the -p option to avoid error
676# messages in case of races.
677 mkdir -p $(@:%/=%)
1c68c264
RM
678\f
679# Make sure that object files are not removed
680# when they are intermediates between sources and library members.
681.PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
682
683# Make sure that the parent library archive is never removed.
684.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
685\f
686# Use the verbose option of ar and tar when not running silently.
687ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
688verbose := v
689else # -s
690verbose :=
691endif # not -s
692
693ARFLAGS := r$(verbose)
694CREATE_ARFLAGS := cru$(verbose)
695\f
696# This makes all the object files in the parent library archive.
697
698.PHONY: lib lib-noranlib
699lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
700lib-noranlib: libobjs
701
702# For object-suffix $o, the list of objects with that suffix.
703# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
704o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
705 $(elide-routines$o)),\
706 $(objects))) \
707 $(addprefix $(objpfx),$(o-objects$o))
708
709others: $(addprefix $(objpfx),$(install-lib))
710
711ifndef objects
712
713# Create the stamp$o files to keep the parent makefile happy.
714subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
715$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
716 $(make-target-directory)
717 rm -f $@; > $@
718else
719
720# Define explicit rules to update each $(objpfx)stamp.SUFFIX
721# timestamp file; these rules (one explicit rule is generated for each
722# object suffix) write a list of objects to update in the stamp file.
723# The parent will then actually add them all to the archive in the
724# archive rule, below.
725define o-iterator-doit
726$(objpfx)stamp$o: $(o-objects); $$(do-stamp)
727endef
728define do-stamp
d8f6e441 729$(make-target-directory)
1c68c264
RM
730echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
731mv -f $@T $@
732endef
733object-suffixes-left := $(object-suffixes-for-libc)
734include $(o-iterator)
735
736endif
737
738# Now define explicit rules to build the library archives; these depend
739# on the stamp files built above.
740define o-iterator-doit
741$(common-objpfx)$(patsubst %,$(libtype$o),c): \
742 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
743endef
744define do-makelib
745cd $(common-objdir) && \
746$(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
1c68c264
RM
747endef
748subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
749subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
750ifndef subdir
751$(subdirs-stamps): subdir_lib;
752endif
753object-suffixes-left = $(object-suffixes-for-libc)
754include $(o-iterator)
755
756
757# This makes all the object files.
758.PHONY: objects objs libobjs extra-objs
759objects objs: libobjs extra-objs
760libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
761extra-objs: $(addprefix $(objpfx),$(extra-objs))
762
763# Canned sequence for building an extra library archive.
764define build-extra-lib
765$(patsubst %/,cd % &&,$(objpfx)) \
766$(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
767 $(patsubst $(objpfx)%,%,$^)
1c68c264
RM
768endef
769\f
770# Installation.
771
772.PHONY: force-install
773force-install:
774
775# $(install-lib) are installed from the object directory into $(libdir);
776# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
80d4c3b0
RM
777# unless they also appear in $(non-lib.a). $(install-data) are installed as
778# they are into $(datadir). $(headers) are installed as they are in
1c68c264
RM
779# $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
780# are installed from the object directory into $(bindir), $(bindir) and
80d4c3b0
RM
781# $(sbindir), respectively. $(install-others) and $(install-others-programs)
782# are absolute path names of files to install; rules to install them are
783# defined elsewhere.
1c68c264
RM
784
785# The simple library name to install libc.a under.
786# This could be defined by a sysdep Makefile.
787ifndef libc-name
788libc-name := c
789endif
790
791define do-install
792$(make-target-directory)
793$(INSTALL_DATA) $< $@
794endef
795
796# Make the target directory if it doesn't exist, using the `mkinstalldirs'
797# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
798define make-target-directory
799$(addprefix $(..)./scripts/mkinstalldirs ,\
800 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
801endef
802
803# Any directory (parent or subdir) should install libc.a; this way
804# "make install" in a subdir is guaranteed to install everything it changes.
805installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
806 $(inst_libdir)/$(patsubst %,$(libtype$o),\
807 $(libprefix)$(libc-name)))
808install: $(installed-libcs)
809$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
810 $(make-target-directory)
811 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
1c68c264
RM
812
813define do-install-program
814$(make-target-directory)
815$(INSTALL_PROGRAM) $< $@.new
816mv -f $@.new $@
817endef
818
819define do-install-script
820$(make-target-directory)
821$(INSTALL_SCRIPT) $< $@.new
822mv -f $@.new $@
823endef
824
825install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
826install-lib := $(filter-out %.so %_pic.a,$(install-lib))
827
828ifeq (yes,$(build-shared))
829# Find which .so's have versions.
830versioned := $(strip $(foreach so,$(install-lib.so),\
831 $(patsubst %,$(so),$($(so)-version))))
832
833install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
834install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
835
cc8bfce9
RM
836# For versioned libraries, we install three files:
837# $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
838# $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
839# $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
7a0c303e 840V := $(firstword $($(subdir)-version) $(version))
cc8bfce9
RM
841install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
842 $(foreach L,$(install-lib.so-versioned),\
843 $(inst_libdir)/$L \
7a0c303e 844 $(inst_slibdir)/$(L:.so=)-$V.so \
cc8bfce9 845 $(inst_slibdir)/$L$($L-version))
1c68c264
RM
846
847# Install all the unversioned shared libraries.
848$(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
849 $(objpfx)%.so $(+force)
850 $(do-install-program)
851
852ifneq ($(findstring -s,$(LN_S)),)
853define make-link
854rm -f $@.new
855$(SHELL) $(..)scripts/rellns-sh $< $@.new
856mv -f $@.new $@
857endef
858else
859# If we have no symbolic links don't bother with rellns-sh.
860define make-link
861rm -f $@.new
862$(LN_S) $< $@.new
863mv -f $@.new $@
864endef
865endif
866
867ifeq (yes,$(build-shared))
868ifeq (no,$(cross-compiling))
869symbolic-link-prog := $(common-objpfx)elf/sln
870symbolic-link-list := $(common-objpfx)elf/symlink.list
871define make-shlib-link
872echo $(<F) $@ >> $(symbolic-link-list)
873endef
874else # cross-compiling
875# We need a definition that can be used by elf/Makefile's install rules.
876symbolic-link-prog = $(LN_S)
877endif
878endif
879ifndef make-shlib-link
880define make-shlib-link
881rm -f $@
882$(LN_S) $(<F) $@
883endef
884endif
885
886ifdef libc.so-version
887# For a library specified to be version N, install three files:
888# libc.so -> libc.so.N (e.g. libc.so.6)
889# libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
890
891$(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
892 $(+force)
893 $(make-shlib-link)
894$(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
895 $(do-install-program)
896install: $(inst_slibdir)/libc.so$(libc.so-version)
897
898# This fragment of linker script gives the OUTPUT_FORMAT statement
899# for the configuration we are building. We put this statement into
900# the linker scripts we install for -lc et al so that they will not be
901# used by a link for a different format on a multi-architecture system.
902$(common-objpfx)format.lds: $(..)scripts/output-format.sed \
903 $(common-objpfx)config.make \
904 $(common-objpfx)config.h $(..)Makerules
5c550700
RM
905ifneq (unknown,$(output-format))
906 echo > $@.new 'OUTPUT_FORMAT($(output-format))'
907else
1c68c264
RM
908 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
909 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
910 | sed -n -f $< > $@.new
5e9b6af4 911 test -s $@.new
1c68c264 912 rm -f $@.so
5c550700 913endif
1c68c264
RM
914 mv -f $@.new $@
915common-generated += format.lds
916
917ifndef subdir
918# What we install as libc.so for programs to link against is in fact a
919# link script. It contains references for the various libraries we need.
920# The libc.so object is not complete since some functions are only defined
921# in libc_nonshared.a.
922# We need to use absolute paths since otherwise local copies (if they exist)
923# of the files are taken by the linker.
924install: $(inst_libdir)/libc.so
925$(inst_libdir)/libc.so: $(common-objpfx)format.lds \
926 $(common-objpfx)libc.so$(libc.so-version) \
927 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
928 $(libprefix)$(libc-name)) \
929 $(+force)
930 (echo '/* GNU ld script';\
931 echo ' Use the shared library, but some functions are only in';\
932 echo ' the static library, so try that secondarily. */';\
933 cat $<; \
934 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
935 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
c440fa75 936 ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1c68c264
RM
937 ) > $@.new
938 mv -f $@.new $@
939
940endif
941
942else
943install: $(inst_slibdir)/libc.so
944$(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
945 $(do-install-program)
946endif
947
948ifneq (,$(versioned))
949# Produce three sets of rules as above for all the smaller versioned libraries.
950
951define o-iterator-doit
952$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
953endef
2afbfec4
RM
954object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
955ifneq (,$(object-suffixes-left))
1c68c264 956include $(o-iterator)
2afbfec4 957endif
1c68c264
RM
958
959# Make symlinks in the build directory, because the versioned names might
960# be referenced by a DT_NEEDED in another library.
961define o-iterator-doit
962$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
963endef
964object-suffixes-left := $(versioned)
965include $(o-iterator)
966
967generated += $(foreach o,$(versioned),$o$($o-version))
968
969ifeq (,$($(subdir)-version))
970define o-iterator-doit
971$(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
972 $(+force);
973 $$(make-shlib-link)
974endef
975object-suffixes-left := $(versioned)
976include $(o-iterator)
977
978define o-iterator-doit
979$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
980 $$(do-install-program)
981endef
982object-suffixes-left := $(versioned)
983include $(o-iterator)
984else
985define o-iterator-doit
986$(inst_slibdir)/$o$($o-version): \
987 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
988 $$(make-shlib-link)
989endef
990object-suffixes-left := $(versioned)
991include $(o-iterator)
992
993define o-iterator-doit
994$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
995 $$(do-install-program)
996endef
997object-suffixes-left := $(versioned)
998include $(o-iterator)
999endif
1000endif
1001
1002define do-install-so
1003$(do-install-program)
1004$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1005 $(filter-out %.so,$@))
1006endef
1007
1008so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1009$(foreach v,$(so-versions),\
1010 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1011 $(+force)
1012 $(do-install-so)
1013$(foreach v,$(so-versions),\
1014 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1015 $(do-install-so)
1016endif
1017
1018ifdef install-bin
1019$(addprefix $(inst_bindir)/,$(install-bin)): \
1020 $(inst_bindir)/%: $(objpfx)% $(+force)
1021 $(do-install-program)
1022endif
1023ifdef install-bin-script
1024$(addprefix $(inst_bindir)/,$(install-bin-script)): \
1025 $(inst_bindir)/%: $(objpfx)% $(+force)
1026 $(do-install-script)
1027endif
1028ifdef install-rootsbin
1029$(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1030 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1031 $(do-install-program)
1032endif
1033ifdef install-sbin
1034$(addprefix $(inst_sbindir)/,$(install-sbin)): \
1035 $(inst_sbindir)/%: $(objpfx)% $(+force)
1036 $(do-install-program)
1037endif
1038ifdef install-lib
1039install-lib.a := $(filter lib%.a,$(install-lib))
1040install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1041ifdef install-lib-non.a
1042$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1043 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1044 $(do-install)
1045endif
1046ifdef install-lib.a
1047$(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1048 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1049 $(do-install)
1c68c264
RM
1050endif
1051endif
1052ifdef install-data
1053$(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1054 $(do-install)
1055endif
1056headers := $(strip $(headers))
1057ifdef headers
f0cf0902
RM
1058# This implicit rule installs headers from the source directory.
1059# It may be ignored in preference to rules from sysd-rules to find
1060# headers in the sysdeps tree.
1061$(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1c68c264 1062 $(do-install)
4962050e
JM
1063$(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1064 $(do-install)
f0cf0902
RM
1065$(inst_includedir)/%.h: %.h $(+force)
1066 $(do-install)
1067$(inst_includedir)/%.h: $(..)include/%.h $(+force)
1068 $(do-install)
1069headers-nonh := $(filter-out %.h,$(headers))
1070ifdef headers-nonh
1071$(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1072 % $(+force)
1073 $(do-install)
1074endif # headers-nonh
1c68c264
RM
1075endif # headers
1076
1077.PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1078 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1079 install-data-nosubdir install-headers-nosubdir
1080install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1081install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1082install-rootsbin-nosubdir: \
1083 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1084install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1085install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1086 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1087 $(addprefix $(libprefix),$(install-lib-non.a)))
1088install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1089install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1090install-others-nosubdir: $(install-others)
80d4c3b0 1091install-others-programs-nosubdir: $(install-others-programs)
1c68c264
RM
1092
1093# We need all the `-nosubdir' targets so that `install' in the parent
1094# doesn't depend on several things which each iterate over the subdirs.
1095# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1096# subroutine. Then in the parent `install-FOO' also causes subdir makes.
1097install-%:: install-%-nosubdir ;
1098
1099.PHONY: install install-no-libc.a-nosubdir
80d4c3b0 1100install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1c68c264 1101 install-lib-nosubdir install-others-nosubdir
80d4c3b0
RM
1102ifeq ($(build-programs),yes)
1103install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1104 install-rootsbin-nosubdir install-sbin-nosubdir \
1105 install-others-programs-nosubdir
1c68c264
RM
1106endif
1107install: install-no-libc.a-nosubdir
1108\f
c1820385 1109# Command to compile $< using the native libraries.
1c68c264
RM
1110define native-compile
1111$(make-target-directory)
1c68c264 1112$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
2ed8cda2 1113 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1c68c264
RM
1114endef
1115
1c68c264 1116# We always want to use configuration definitions.
2ed8cda2
JM
1117ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1118 -DIS_IN_build -include $(common-objpfx)config.h
1c68c264
RM
1119
1120# Support the GNU standard name for this target.
1121.PHONY: check
1122check: tests
1123# Special target to run tests which cannot be run unconditionally.
1124# Maintainers should use this target.
1125.PHONY: xcheck
1126xcheck: xtests
1127
1128all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1129ifneq (,$(all-nonlib))
7735afa2 1130cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1c68c264 1131lib := nonlib
7735afa2 1132include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1c68c264
RM
1133endif
1134
1135# The include magic above causes those files to use this variable for flags.
1136CPPFLAGS-nonlib = -DNOT_IN_libc=1
1137
1138
1139ifeq ($(versioning),yes)
1140# Generate normalized lists of symbols, versions, and data sizes.
1141# This is handy for checking against existing library binaries.
1142
1143%.symlist: $(..)scripts/abilist.awk %.dynsym
1144 LC_ALL=C $(AWK) -f $^ > $@T
1145 mv -f $@T $@
1146
1147%.dynsym: %.so
1148 $(OBJDUMP) --dynamic-syms $< > $@T
1149 mv -f $@T $@
1150
8dbd5d7b
DM
1151vpath %.abilist $(+sysdep_dirs)
1152
a65ef2ae
AJ
1153# The .PRECIOUS rule prevents the files built by an implicit rule whose
1154# target pattern is %.symlist from being considered "intermediate files"
1155# and automatically removed. We only want these files to be removed by
1156# 'make clean', which is handled by the 'generated' variable.
1157.PRECIOUS: %.symlist
1158generated += $(extra-libs:=.symlist)
1159
8dbd5d7b 1160check-abi-%: $(common-objpfx)config.make %.abilist $(objpfx)%.symlist
9ae10332 1161 $(check-abi)
8dbd5d7b 1162check-abi-%: $(common-objpfx)config.make %.abilist $(common-objpfx)%.symlist
9ae10332
RM
1163 $(check-abi)
1164define check-abi
ecf0ebfb 1165 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^)
9ae10332 1166endef
1c68c264 1167
8dbd5d7b 1168update-abi-%: $(objpfx)%.symlist %.abilist
9ae10332 1169 $(update-abi)
8dbd5d7b 1170update-abi-%: $(common-objpfx)%.symlist %.abilist
9ae10332 1171 $(update-abi)
9ae10332 1172define update-abi
8dbd5d7b
DM
1173@if cmp -s $^ 2> /dev/null; \
1174 then \
1175 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1176 else cp -f $^; \
1177 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
9ae10332
RM
1178 fi
1179endef
1c68c264
RM
1180
1181.PHONY: update-abi check-abi
1182update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1183check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1184ifdef subdir
1185subdir_check-abi: check-abi
1186subdir_update-abi: update-abi
1187else
1188check-abi: subdir_check-abi
1189update-abi: subdir_update-abi
1190endif
1191
1c68c264
RM
1192ifeq ($(subdir),elf)
1193check-abi: check-abi-libc
1194update-abi: update-abi-libc
1195common-generated += libc.symlist
1196endif
1197
fd54683c 1198ifeq ($(build-shared),yes)
94659495
RM
1199ifdef subdir
1200tests: check-abi
1201endif
1202endif
1203
1c68c264 1204endif
aad08dba 1205
e0a3ed4f
RM
1206# These will have been set by sysdeps/posix/Makefile.
1207L_tmpnam ?= 1
1208TMP_MAX ?= 0
1209L_ctermid ?= 1
1210L_cuserid ?= 1
1211
9ae10332
RM
1212stdio_lim = $(common-objpfx)bits/stdio_lim.h
1213
1214$(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1215$(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1216 $(common-objpfx)config.make
1217 $(make-target-directory)
7cd72ad3
RM
1218 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1219 echo '#define _LIBC 1'; \
1220 echo '#include "$(..)misc/sys/uio.h"'; } | \
1221 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
61653dfb 1222 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
7cd72ad3
RM
1223 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1224 $(@:st=dT) > $(@:st=dt)
1225 mv -f $(@:st=dt) $(@:st=d)
9ae10332
RM
1226 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1227 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1228 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1229 fopen_max=$${fopen_max:-16}; \
1230 filename_max=$${filename_max:-1024}; \
7cd72ad3 1231 if [ -z "$$iov_max" ]; then \
9ae10332
RM
1232 define_iov_max="# undef IOV_MAX"; \
1233 else \
1234 define_iov_max="# define IOV_MAX $$iov_max"; \
1235 fi; \
1236 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1237 -e "s/@FILENAME_MAX@/$$filename_max/" \
1238 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1239 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1240 -e "s/@L_ctermid@/$(L_ctermid)/" \
1241 -e "s/@L_cuserid@/$(L_cuserid)/" \
1242 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1243 $< > $(@:st=h.new)
1244 $(move-if-change) $(@:st=h.new) $(@:st=h)
1245# Remove these last so that they can be examined if something went wrong.
1246 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1247 touch $@
1248# Get dependencies.
1249ifndef no_deps
1250-include $(stdio_lim:h=d)
1251endif
1252common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1c68c264 1253\f
1c68c264
RM
1254FORCE:
1255
1c68c264
RM
1256.PHONY: echo-headers
1257echo-headers:
1258 @echo $(headers)
1259
220addf7
RM
1260%.bz2: %; bzip2 -9vk $<
1261%.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
6cfe8609 1262%.xz: %; xz -9evk $<
1c68c264
RM
1263\f
1264# Common cleaning targets.
1265
1266.PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1267clean: common-clean
1268mostlyclean: common-mostlyclean
1269
1270do-tests-clean:
1271 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1272 $(test-srcs)) \
1273 $(addsuffix -bp.out,$(tests) $(xtests) \
1274 $(test-srcs)))
1275
1276# Remove the object files.
1277common-mostlyclean:
1278 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1279 $(others) $(sysdep-others) stubs \
1280 $(addsuffix .o,$(tests) $(xtests) \
1281 $(test-srcs) $(others) \
1282 $(sysdep-others)) \
1283 $(addsuffix -bp,$(tests) $(xtests) \
1284 $(test-srcs)) \
1285 $(addsuffix .out,$(tests) $(xtests) \
1286 $(test-srcs)) \
1287 $(addsuffix -bp.out,$(tests) $(xtests) \
1288 $(test-srcs)))
376e973a
UD
1289 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1290 $(install-lib) $(install-lib.so) \
1c68c264
RM
1291 $(install-lib.so:%.so=%_pic.a))
1292 -rm -f core
1293 -rm -f $(objpfx)rtld-*.os
1294 $(rmobjs)
1295define rmobjs
1296$(foreach o,$(object-suffixes-for-libc),
1297-rm -f $(objpfx)stamp$o $(o-objects))
1298endef
1299
1300# Also remove the dependencies and generated source files.
1301common-clean: common-mostlyclean
d73f5331
RM
1302 -rm -f $(addprefix $(objpfx),$(generated))
1303 -rm -f $(objpfx)*.d $(objpfx)*.dt
1c68c264
RM
1304 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1305 -rm -f $(addprefix $(common-objpfx),$(common-generated))
e5a6e567 1306 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1c68c264
RM
1307\f
1308# Produce a file `stubs' which contains `#define __stub_FUNCTION'
1309# for each function which is a stub. We grovel over all the .d files
1310# looking for references to <stub-tag.h>. Then we grovel over each
1311# referenced source file to see what stub function it defines.
1312
1313ifdef objpfx
1314.PHONY: stubs # The parent Makefile calls this target.
1315stubs: $(objpfx)stubs
1316endif
561bcb80
RM
1317objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1318 $(addprefix $(objpfx),$(extra-objs))
1319$(objpfx)stubs: $(objs-for-stubs)
1320ifneq (,$(strip $(objs-for-stubs)))
ae46b677 1321 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
561bcb80 1322 $(AWK) '/\.gnu\.glibc-stub\./ { \
92ad15a8 1323 sub(/\.gnu\.glibc-stub\./, "", $$2); \
561bcb80
RM
1324 stubs[$$2] = 1; } \
1325 END { for (s in stubs) print "#define __stub_" s }' > $@T
1c68c264 1326 mv -f $@T $@
f291538f
RM
1327else
1328 > $@
1329endif
1c68c264 1330\f
1c68c264
RM
1331ifneq (,$(strip $(gpl2lgpl)))
1332ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1333# Snarf from the master source and frob the copying notice.
1334$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1335 sed -f $^ > $@-tmp
1336# So I don't edit them by mistake.
1337 chmod a-w $@-tmp
1338 mv -f $@-tmp $@
1c68c264
RM
1339endif
1340endif
1341
1342# Local Variables:
1343# mode: makefile
1344# End: