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