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