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