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