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