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