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