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