]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makerules
.
[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' \
71213dc2
UD
490 $(if $(filter yes,$(have-hash-style)), \
491 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
492 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
493 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
494 , \
495 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
496 ) \
358cad7c 497 -e 's/^.*\*(\.dynbss).*$$/& \
20792f99 498 PROVIDE(__start___libc_freeres_ptrs = .); \
358cad7c 499 *(__libc_freeres_ptrs) \
ed20b3d9 500 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
561bcb80 501 -e 's@^.*\*(\.jcr).*$$@& \
db2f05ba
RM
502 PROVIDE(__start___libc_subfreeres = .);\
503 __libc_subfreeres : { *(__libc_subfreeres) }\
504 PROVIDE(__stop___libc_subfreeres = .);\
505 PROVIDE(__start___libc_atexit = .);\
506 __libc_atexit : { *(__libc_atexit) }\
507 PROVIDE(__stop___libc_atexit = .);\
508 PROVIDE(__start___libc_thread_subfreeres = .);\
509 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
561bcb80
RM
510 PROVIDE(__stop___libc_thread_subfreeres = .);\
511 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
358cad7c
RM
512 mv -f $@T $@
513common-generated += shlib.lds
514
515define build-shlib
516$(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
1c68c264 517 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
1c68c264
RM
518endef
519else
520ifneq (,$(findstring aix,$(config-os)))
521define build-shlib
522$(build-shlib-helper) \
523 -o $@ \
524 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
525 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
526endef
527define build-shlib
528$(build-shlib-helper) \
529 $(build-shlib-objlist)
530endef
531endif
532endif
533
534ifneq (,$(findstring aix,$(config-os)))
535define build-module-helper
536$(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
537 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
538 $(load-map-file) \
539 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
540 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
541endef
542else
543define build-module-helper
544$(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
1a379ea0 545 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
1c68c264
RM
546 -B$(csu-objpfx) $(load-map-file) \
547 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
548 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
549endef
550endif
551
552# This macro is similar to build-shlib but it does not define a soname
553# and it does not depend on the destination name to start with `lib'.
554ifeq (yes,$(elf))
555# binutils only position loadable notes into the first page for binaries,
556# not for shared objects
557define build-module
358cad7c 558$(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
1c68c264 559 $(csu-objpfx)abi-note.o $(build-module-objlist)
1c68c264 560endef
d9266ea0
UD
561define build-module-asneeded
562$(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
563 $(csu-objpfx)abi-note.o \
564 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
565endef
1c68c264
RM
566else
567ifneq (,$(findstring aix,$(config-os)))
568define build-module
569$(build-module-helper) \
570 -o $@ \
571 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
572 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
573endef
574else
575define build-module
576define build-module
577$(build-module-helper) \
578 -o $@ \
579 $(build-module-objlist)
580endef
581endif
582endif
583
584build-module-helper-objlist = \
585 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
358cad7c 586 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
1c68c264
RM
587whole-archive := -Wl,--whole-archive
588
589build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
590build-shlib-objlist = $(build-module-helper-objlist) \
591 $(LDLIBS-$(@F:lib%.so=%).so)
592
593# Don't try to use -lc when making libc.so itself.
594# Also omits crti.o and crtn.o, which we do not want
595# since we define our own `.init' section specially.
596LDFLAGS-c.so = -nostdlib -nostartfiles
cbdb12de
UD
597# But we still want to link libc.so against $(libc.so-gnulib).
598LDLIBS-c.so += $(libc.so-gnulib)
1c68c264
RM
599# Give libc.so an entry point and make it directly runnable itself.
600LDFLAGS-c.so += -e __libc_main
4df8c11d
UD
601# If lazy relocation is disabled add the -z now flag.
602ifeq ($(bind-now),yes)
603LDFLAGS-c.so += -Wl,-z,now
604endif
1c68c264
RM
605# Pre-link the objects of libc_pic.a so that we can locally resolve
606# COMMON symbols before we link against ld.so. This is because ld.so
607# contains some of libc_pic.a already, which will prevent the COMMONs
608# from being allocated in libc.so, which introduces evil dependencies
609# between libc.so and ld.so, which can make it impossible to upgrade.
610ifeq ($(elf),yes)
611$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
612 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
613 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
1c68c264
RM
614# Use our own special initializer and finalizer files for libc.so.
615$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
616 $(common-objpfx)libc_pic.os \
617 $(elfobjdir)/sofini.os \
358cad7c
RM
618 $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
619 $(common-objpfx)shlib.lds
1c68c264
RM
620 $(build-shlib)
621ifeq ($(versioning),yes)
622$(common-objpfx)libc.so: $(common-objpfx)libc.map
623endif
624common-generated += libc.so libc_pic.os
625ifdef libc.so-version
626$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
627 $(make-link)
628common-generated += libc.so$(libc.so-version)
629endif
630endif
631else
632ifneq (,$(findstring aix,$(config-os)))
633$(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
634 @rm -f $@
635 (echo '#!'; \
636 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
637 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
638 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
639 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
640 -bE:$(common-objpfx)syscalls.exp \
641 -bI:$(common-objpfx)syscalls.exp \
642 -L$(common-objpfx) -o $@ $^
643# AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
644 cp $@ $(common-objpfx)shr.o
645 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
646endif
647endif
648\f
649# Figure out the source filenames in this directory.
650
651override sources := $(addsuffix .c,\
652 $(filter-out $(elided-routines),\
653 $(routines) $(aux) \
654 $(sysdep_routines)))
655sysdep_routines := $(sysdep_routines)
656
657headers := $(headers) $(sysdep_headers)
658
659# This is the list of all object files, gotten by
660# replacing every ".c" in `sources' with a ".o".
661# We also add bounded-pointer thunks, which are later
662# elided for all suffixes except for `.ob'.
663override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
664 $(patsubst %,$(bppfx)%.o,\
665 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
666
667
668# The makefile may define $(extra-libs) with `libfoo libbar'
669# to build libfoo.a et al from the modules listed in $(libfoo-routines).
670ifdef extra-libs
671# extra-lib.mk is included once for each extra lib to define rules
672# to build it, and to add its objects to the various variables.
673# During its evaluation, $(lib) is set to the name of the library.
674extra-libs-left := $(extra-libs)
675include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
676endif
b30542fb
UD
677
678
aed48a2a
RM
679# The makefile may define $(modules-names) to build additional modules.
680# These are built with $(build-module), except any in $(modules-names-nobuild).
b30542fb
UD
681ifdef modules-names
682# extra-lib.mk is included once for each extra lib to define rules
683# to build it, and to add its objects to the various variables.
684# During its evaluation, $(lib) is set to the name of the library.
685extra-modules-left := $(modules-names)
686include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
aed48a2a
RM
687
688extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
689$(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
fe60d146 690 $(objpfx)%.os $(common-objpfx)shlib.lds \
aed48a2a
RM
691 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
692 $(build-module)
b30542fb 693endif
1c68c264
RM
694\f
695+depfiles := $(sources:.c=.d) \
696 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
376e973a 697 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
1c68c264
RM
698 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
699ifeq ($(build-programs),yes)
700+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
701endif
702+depfiles := $(addprefix $(objpfx),\
703 $(filter-out $(addsuffix .d,$(omit-deps)),\
9ae10332 704 $(+depfiles)))
d73f5331
RM
705all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
706+depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
707 $(wildcard $(all-dt-files:.dt=.d))
708
709# This is a funny rule in that it removes its input file.
710%.d: %.dt
711 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
712 mv -f $(@:.d=.T) $@ && \
713 rm -f $<
9ae10332
RM
714
715# Avoid the .h.d files for any .sym files whose .h files don't exist yet.
716# They will be generated when they're needed, and trying too early won't work.
717+gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
718+depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
719 $(+gen-as-const)))
1c68c264
RM
720
721ifdef +depfiles
722ifneq ($(no_deps),t)
723-include $(+depfiles)
724endif
725endif
726\f\f
727# Maximize efficiency by minimizing the number of rules.
728.SUFFIXES: # Clear the suffix list. We don't use suffix rules.
729# Don't define any builtin rules.
730MAKEFLAGS := $(MAKEFLAGS)r
731
732# Generic rule for making directories.
733%/:
734# mkdir isn't smart enough to strip a trailing /.
735 mkdir $(@:%/=%)
736\f
737# Make sure that object files are not removed
738# when they are intermediates between sources and library members.
739.PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
740
741# Make sure that the parent library archive is never removed.
742.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
743\f
744# Use the verbose option of ar and tar when not running silently.
745ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
746verbose := v
747else # -s
748verbose :=
749endif # not -s
750
751ARFLAGS := r$(verbose)
752CREATE_ARFLAGS := cru$(verbose)
753\f
754# This makes all the object files in the parent library archive.
755
756.PHONY: lib lib-noranlib
757lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
758lib-noranlib: libobjs
759
760# For object-suffix $o, the list of objects with that suffix.
761# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
762o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
763 $(elide-routines$o)),\
764 $(objects))) \
765 $(addprefix $(objpfx),$(o-objects$o))
766
767others: $(addprefix $(objpfx),$(install-lib))
768
769ifndef objects
770
771# Create the stamp$o files to keep the parent makefile happy.
772subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
773$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
774 $(make-target-directory)
775 rm -f $@; > $@
776else
777
778# Define explicit rules to update each $(objpfx)stamp.SUFFIX
779# timestamp file; these rules (one explicit rule is generated for each
780# object suffix) write a list of objects to update in the stamp file.
781# The parent will then actually add them all to the archive in the
782# archive rule, below.
783define o-iterator-doit
784$(objpfx)stamp$o: $(o-objects); $$(do-stamp)
785endef
786define do-stamp
d8f6e441 787$(make-target-directory)
1c68c264
RM
788echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
789mv -f $@T $@
790endef
791object-suffixes-left := $(object-suffixes-for-libc)
792include $(o-iterator)
793
794endif
795
796# Now define explicit rules to build the library archives; these depend
797# on the stamp files built above.
798define o-iterator-doit
799$(common-objpfx)$(patsubst %,$(libtype$o),c): \
800 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
801endef
802define do-makelib
803cd $(common-objdir) && \
804$(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
805$(RANLIB) $@
806endef
807subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
808subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
809ifndef subdir
810$(subdirs-stamps): subdir_lib;
811endif
812object-suffixes-left = $(object-suffixes-for-libc)
813include $(o-iterator)
814
815
816# This makes all the object files.
817.PHONY: objects objs libobjs extra-objs
818objects objs: libobjs extra-objs
819libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
820extra-objs: $(addprefix $(objpfx),$(extra-objs))
821
822# Canned sequence for building an extra library archive.
823define build-extra-lib
824$(patsubst %/,cd % &&,$(objpfx)) \
825$(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
826 $(patsubst $(objpfx)%,%,$^)
827$(RANLIB) $@
828endef
829\f
830# Installation.
831
832.PHONY: force-install
833force-install:
834
835# $(install-lib) are installed from the object directory into $(libdir);
836# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
837# unless they also appear in $(non-lib.a). $(install-data) are installed
838# as they are into $(datadir). $(headers) are installed as they are in
839# $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
840# are installed from the object directory into $(bindir), $(bindir) and
841# $(sbindir), respectively. $(install-others) are absolute path names of
842# files to install; rules to install them are defined elsewhere.
843
844# The simple library name to install libc.a under.
845# This could be defined by a sysdep Makefile.
846ifndef libc-name
847libc-name := c
848endif
849
850define do-install
851$(make-target-directory)
852$(INSTALL_DATA) $< $@
853endef
854
855# Make the target directory if it doesn't exist, using the `mkinstalldirs'
856# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
857define make-target-directory
858$(addprefix $(..)./scripts/mkinstalldirs ,\
859 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
860endef
861
862# Any directory (parent or subdir) should install libc.a; this way
863# "make install" in a subdir is guaranteed to install everything it changes.
864installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
865 $(inst_libdir)/$(patsubst %,$(libtype$o),\
866 $(libprefix)$(libc-name)))
867install: $(installed-libcs)
868$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
869 $(make-target-directory)
870 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
871# Running ranlib after installing makes the __.SYMDEF time stamp up to
872# date, which avoids messages from some linkers.
873 $(RANLIB) $@
874
875define do-install-program
876$(make-target-directory)
877$(INSTALL_PROGRAM) $< $@.new
878mv -f $@.new $@
879endef
880
881define do-install-script
882$(make-target-directory)
883$(INSTALL_SCRIPT) $< $@.new
884mv -f $@.new $@
885endef
886
887install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
888install-lib := $(filter-out %.so %_pic.a,$(install-lib))
889
890ifeq (yes,$(build-shared))
891# Find which .so's have versions.
892versioned := $(strip $(foreach so,$(install-lib.so),\
893 $(patsubst %,$(so),$($(so)-version))))
894
895install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
896install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
897
cc8bfce9
RM
898# For versioned libraries, we install three files:
899# $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
900# $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
901# $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
7a0c303e 902V := $(firstword $($(subdir)-version) $(version))
cc8bfce9
RM
903install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
904 $(foreach L,$(install-lib.so-versioned),\
905 $(inst_libdir)/$L \
7a0c303e 906 $(inst_slibdir)/$(L:.so=)-$V.so \
cc8bfce9 907 $(inst_slibdir)/$L$($L-version))
1c68c264
RM
908
909# Install all the unversioned shared libraries.
910$(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
911 $(objpfx)%.so $(+force)
912 $(do-install-program)
913
914ifneq ($(findstring -s,$(LN_S)),)
915define make-link
916rm -f $@.new
917$(SHELL) $(..)scripts/rellns-sh $< $@.new
918mv -f $@.new $@
919endef
920else
921# If we have no symbolic links don't bother with rellns-sh.
922define make-link
923rm -f $@.new
924$(LN_S) $< $@.new
925mv -f $@.new $@
926endef
927endif
928
929ifeq (yes,$(build-shared))
930ifeq (no,$(cross-compiling))
931symbolic-link-prog := $(common-objpfx)elf/sln
932symbolic-link-list := $(common-objpfx)elf/symlink.list
933define make-shlib-link
934echo $(<F) $@ >> $(symbolic-link-list)
935endef
936else # cross-compiling
937# We need a definition that can be used by elf/Makefile's install rules.
938symbolic-link-prog = $(LN_S)
939endif
940endif
941ifndef make-shlib-link
942define make-shlib-link
943rm -f $@
944$(LN_S) $(<F) $@
945endef
946endif
947
948ifdef libc.so-version
949# For a library specified to be version N, install three files:
950# libc.so -> libc.so.N (e.g. libc.so.6)
951# libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
952
953$(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
954 $(+force)
955 $(make-shlib-link)
956$(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
957 $(do-install-program)
958install: $(inst_slibdir)/libc.so$(libc.so-version)
959
960# This fragment of linker script gives the OUTPUT_FORMAT statement
961# for the configuration we are building. We put this statement into
962# the linker scripts we install for -lc et al so that they will not be
963# used by a link for a different format on a multi-architecture system.
964$(common-objpfx)format.lds: $(..)scripts/output-format.sed \
965 $(common-objpfx)config.make \
966 $(common-objpfx)config.h $(..)Makerules
967 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
968 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
969 | sed -n -f $< > $@.new
970 rm -f $@.so
971 mv -f $@.new $@
972common-generated += format.lds
973
974ifndef subdir
975# What we install as libc.so for programs to link against is in fact a
976# link script. It contains references for the various libraries we need.
977# The libc.so object is not complete since some functions are only defined
978# in libc_nonshared.a.
979# We need to use absolute paths since otherwise local copies (if they exist)
980# of the files are taken by the linker.
981install: $(inst_libdir)/libc.so
982$(inst_libdir)/libc.so: $(common-objpfx)format.lds \
983 $(common-objpfx)libc.so$(libc.so-version) \
984 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
985 $(libprefix)$(libc-name)) \
986 $(+force)
987 (echo '/* GNU ld script';\
988 echo ' Use the shared library, but some functions are only in';\
989 echo ' the static library, so try that secondarily. */';\
990 cat $<; \
991 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
992 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
c440fa75 993 ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1c68c264
RM
994 ) > $@.new
995 mv -f $@.new $@
996
997endif
998
999else
1000install: $(inst_slibdir)/libc.so
1001$(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1002 $(do-install-program)
1003endif
1004
1005ifneq (,$(versioned))
1006# Produce three sets of rules as above for all the smaller versioned libraries.
1007
1008define o-iterator-doit
1009$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1010endef
2afbfec4
RM
1011object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1012ifneq (,$(object-suffixes-left))
1c68c264 1013include $(o-iterator)
2afbfec4 1014endif
1c68c264
RM
1015
1016# Make symlinks in the build directory, because the versioned names might
1017# be referenced by a DT_NEEDED in another library.
1018define o-iterator-doit
1019$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1020endef
1021object-suffixes-left := $(versioned)
1022include $(o-iterator)
1023
1024generated += $(foreach o,$(versioned),$o$($o-version))
1025
1026ifeq (,$($(subdir)-version))
1027define o-iterator-doit
1028$(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1029 $(+force);
1030 $$(make-shlib-link)
1031endef
1032object-suffixes-left := $(versioned)
1033include $(o-iterator)
1034
1035define o-iterator-doit
1036$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1037 $$(do-install-program)
1038endef
1039object-suffixes-left := $(versioned)
1040include $(o-iterator)
1041else
1042define o-iterator-doit
1043$(inst_slibdir)/$o$($o-version): \
1044 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1045 $$(make-shlib-link)
1046endef
1047object-suffixes-left := $(versioned)
1048include $(o-iterator)
1049
1050define o-iterator-doit
1051$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1052 $$(do-install-program)
1053endef
1054object-suffixes-left := $(versioned)
1055include $(o-iterator)
1056endif
1057endif
1058
1059define do-install-so
1060$(do-install-program)
1061$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1062 $(filter-out %.so,$@))
1063endef
1064
1065so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1066$(foreach v,$(so-versions),\
1067 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1068 $(+force)
1069 $(do-install-so)
1070$(foreach v,$(so-versions),\
1071 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1072 $(do-install-so)
1073endif
1074
1075ifdef install-bin
1076$(addprefix $(inst_bindir)/,$(install-bin)): \
1077 $(inst_bindir)/%: $(objpfx)% $(+force)
1078 $(do-install-program)
1079endif
1080ifdef install-bin-script
1081$(addprefix $(inst_bindir)/,$(install-bin-script)): \
1082 $(inst_bindir)/%: $(objpfx)% $(+force)
1083 $(do-install-script)
1084endif
1085ifdef install-rootsbin
1086$(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1087 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1088 $(do-install-program)
1089endif
1090ifdef install-sbin
1091$(addprefix $(inst_sbindir)/,$(install-sbin)): \
1092 $(inst_sbindir)/%: $(objpfx)% $(+force)
1093 $(do-install-program)
1094endif
1095ifdef install-lib
1096install-lib.a := $(filter lib%.a,$(install-lib))
1097install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1098ifdef install-lib-non.a
1099$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1100 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1101 $(do-install)
1102endif
1103ifdef install-lib.a
1104$(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1105 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1106 $(do-install)
1107 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1108endif
1109endif
1110ifdef install-data
1111$(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1112 $(do-install)
1113endif
1114headers := $(strip $(headers))
1115ifdef headers
f0cf0902
RM
1116# This implicit rule installs headers from the source directory.
1117# It may be ignored in preference to rules from sysd-rules to find
1118# headers in the sysdeps tree.
1119$(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1c68c264 1120 $(do-install)
f0cf0902
RM
1121$(inst_includedir)/%.h: %.h $(+force)
1122 $(do-install)
1123$(inst_includedir)/%.h: $(..)include/%.h $(+force)
1124 $(do-install)
1125headers-nonh := $(filter-out %.h,$(headers))
1126ifdef headers-nonh
1127$(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1128 % $(+force)
1129 $(do-install)
1130endif # headers-nonh
1c68c264
RM
1131endif # headers
1132
1133.PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1134 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1135 install-data-nosubdir install-headers-nosubdir
1136install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1137install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1138install-rootsbin-nosubdir: \
1139 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1140install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1141install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1142 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1143 $(addprefix $(libprefix),$(install-lib-non.a)))
1144install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1145install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1146install-others-nosubdir: $(install-others)
1147
1148# We need all the `-nosubdir' targets so that `install' in the parent
1149# doesn't depend on several things which each iterate over the subdirs.
1150# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1151# subroutine. Then in the parent `install-FOO' also causes subdir makes.
1152install-%:: install-%-nosubdir ;
1153
1154.PHONY: install install-no-libc.a-nosubdir
1155ifeq ($(build-programs),yes)
1156install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1157 install-bin-nosubdir install-bin-script-nosubdir \
1158 install-lib-nosubdir install-others-nosubdir \
1159 install-rootsbin-nosubdir install-sbin-nosubdir
1160else
1161install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1162 install-lib-nosubdir install-others-nosubdir
1163endif
1164install: install-no-libc.a-nosubdir
1165\f
1166# Command to compile $< in $(objdir) using the native libraries.
1167define native-compile
1168$(make-target-directory)
1169$(patsubst %/,cd % &&,$(objpfx)) \
1170$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1171 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1172endef
1173
1174# Command to compile $< in $(common-objdir) using the native libraries.
1175# We must cd to $(objdir) anyway so that $(..)config.h is valid.
1176define common-objdir-compile
1177$(patsubst %/,cd % &&,$(objpfx)) \
1178$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1179 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1180endef
1181
1182# We always want to use configuration definitions.
1183# Note that this is only used for commands running in $(objpfx).
1184ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1185
1186# Support the GNU standard name for this target.
1187.PHONY: check
1188check: tests
1189# Special target to run tests which cannot be run unconditionally.
1190# Maintainers should use this target.
1191.PHONY: xcheck
1192xcheck: xtests
1193
1194all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1195ifneq (,$(all-nonlib))
7735afa2 1196cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1c68c264 1197lib := nonlib
7735afa2 1198include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1c68c264
RM
1199endif
1200
1201# The include magic above causes those files to use this variable for flags.
1202CPPFLAGS-nonlib = -DNOT_IN_libc=1
1203
1204
1205ifeq ($(versioning),yes)
1206# Generate normalized lists of symbols, versions, and data sizes.
1207# This is handy for checking against existing library binaries.
1208
1209%.symlist: $(..)scripts/abilist.awk %.dynsym
1210 LC_ALL=C $(AWK) -f $^ > $@T
1211 mv -f $@T $@
1212
1213%.dynsym: %.so
1214 $(OBJDUMP) --dynamic-syms $< > $@T
1215 mv -f $@T $@
1216
1c68c264 1217check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
9ae10332
RM
1218 $(..)abilist/%.abilist $(objpfx)%.symlist
1219 $(check-abi)
1220check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1221 $(..)abilist/%.abilist $(common-objpfx)%.symlist
1222 $(check-abi)
1223define check-abi
1c68c264 1224 LC_ALL=C \
9ae10332 1225 $(AWK) -f $< -v 'config=$(check-abi-config)' \
d2e75f65 1226 $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1c68c264 1227 $(filter %.abilist,$^) \
2dd18ce2 1228 | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
9ae10332 1229endef
fd54683c
RM
1230ifeq ($(enable-check-abi),warn)
1231check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1232endif
1c68c264 1233
643931fb 1234ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
0e56981e 1235-include $(common-objpfx)tls.make
32c075e1
JJ
1236config-tls := notls
1237ifeq ($(use-tls),yes)
fd54683c 1238config-tls := tls
32c075e1 1239endif
fd54683c
RM
1240ifeq ($(use-thread),yes)
1241config-tls := thread
1242endif
9ae10332 1243check-abi-config := \
fd54683c 1244 $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
9ae10332
RM
1245endif
1246
1247update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1248 $(objpfx)%.symlist
1249 $(update-abi)
1250update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1251 $(common-objpfx)%.symlist
1252 $(update-abi)
1c68c264 1253ifndef update-abi-config
9ae10332 1254define update-abi
1c68c264 1255 @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
9ae10332 1256endef
1c68c264 1257else
9ae10332 1258define update-abi
fd54683c 1259LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
9ae10332
RM
1260 > $(..)abilist/$*.abilist.new
1261@if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1262 then rm -f $(..)abilist/$*.abilist.new; \
1263 echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1264 else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1265 echo '*** Now check $*.abilist changes for correctness ***'; \
1266 fi
1267endef
1c68c264
RM
1268endif
1269
1270.PHONY: update-abi check-abi
1271update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1272check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1273ifdef subdir
1274subdir_check-abi: check-abi
1275subdir_update-abi: update-abi
1276else
1277check-abi: subdir_check-abi
1278update-abi: subdir_update-abi
1279endif
1280
1c68c264
RM
1281ifeq ($(subdir),elf)
1282check-abi: check-abi-libc
1283update-abi: update-abi-libc
1284common-generated += libc.symlist
1285endif
1286
fd54683c
RM
1287ifeq ($(build-shared),yes)
1288ifneq ($(enable-check-abi),no)
94659495
RM
1289ifdef subdir
1290tests: check-abi
1291endif
1292endif
fd54683c 1293endif
94659495 1294
1c68c264 1295endif
aad08dba 1296
e0a3ed4f
RM
1297# These will have been set by sysdeps/posix/Makefile.
1298L_tmpnam ?= 1
1299TMP_MAX ?= 0
1300L_ctermid ?= 1
1301L_cuserid ?= 1
1302
9ae10332
RM
1303stdio_lim = $(common-objpfx)bits/stdio_lim.h
1304
1305$(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1306$(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1307 $(common-objpfx)config.make
1308 $(make-target-directory)
7cd72ad3
RM
1309 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1310 echo '#define _LIBC 1'; \
1311 echo '#include "$(..)misc/sys/uio.h"'; } | \
1312 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1313 $(+includes) -xc - -o $(@:st=hT)
1314 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1315 $(@:st=dT) > $(@:st=dt)
1316 mv -f $(@:st=dt) $(@:st=d)
9ae10332
RM
1317 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1318 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1319 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1320 fopen_max=$${fopen_max:-16}; \
1321 filename_max=$${filename_max:-1024}; \
7cd72ad3 1322 if [ -z "$$iov_max" ]; then \
9ae10332
RM
1323 define_iov_max="# undef IOV_MAX"; \
1324 else \
1325 define_iov_max="# define IOV_MAX $$iov_max"; \
1326 fi; \
1327 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1328 -e "s/@FILENAME_MAX@/$$filename_max/" \
1329 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1330 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1331 -e "s/@L_ctermid@/$(L_ctermid)/" \
1332 -e "s/@L_cuserid@/$(L_cuserid)/" \
1333 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1334 $< > $(@:st=h.new)
1335 $(move-if-change) $(@:st=h.new) $(@:st=h)
1336# Remove these last so that they can be examined if something went wrong.
1337 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1338 touch $@
1339# Get dependencies.
1340ifndef no_deps
1341-include $(stdio_lim:h=d)
1342endif
1343common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1c68c264 1344\f
1c68c264
RM
1345FORCE:
1346
1c68c264
RM
1347.PHONY: echo-headers
1348echo-headers:
1349 @echo $(headers)
1350
220addf7
RM
1351%.bz2: %; bzip2 -9vk $<
1352%.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1c68c264
RM
1353\f
1354# Common cleaning targets.
1355
1356.PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1357clean: common-clean
1358mostlyclean: common-mostlyclean
1359
1360do-tests-clean:
1361 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1362 $(test-srcs)) \
1363 $(addsuffix -bp.out,$(tests) $(xtests) \
1364 $(test-srcs)))
1365
1366# Remove the object files.
1367common-mostlyclean:
1368 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1369 $(others) $(sysdep-others) stubs \
1370 $(addsuffix .o,$(tests) $(xtests) \
1371 $(test-srcs) $(others) \
1372 $(sysdep-others)) \
1373 $(addsuffix -bp,$(tests) $(xtests) \
1374 $(test-srcs)) \
1375 $(addsuffix .out,$(tests) $(xtests) \
1376 $(test-srcs)) \
1377 $(addsuffix -bp.out,$(tests) $(xtests) \
1378 $(test-srcs)))
376e973a
UD
1379 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1380 $(install-lib) $(install-lib.so) \
1c68c264
RM
1381 $(install-lib.so:%.so=%_pic.a))
1382 -rm -f core
1383 -rm -f $(objpfx)rtld-*.os
1384 $(rmobjs)
1385define rmobjs
1386$(foreach o,$(object-suffixes-for-libc),
1387-rm -f $(objpfx)stamp$o $(o-objects))
1388endef
1389
1390# Also remove the dependencies and generated source files.
1391common-clean: common-mostlyclean
d73f5331
RM
1392 -rm -f $(addprefix $(objpfx),$(generated))
1393 -rm -f $(objpfx)*.d $(objpfx)*.dt
1c68c264
RM
1394 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1395 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1c68c264
RM
1396\f
1397# Produce a file `stubs' which contains `#define __stub_FUNCTION'
1398# for each function which is a stub. We grovel over all the .d files
1399# looking for references to <stub-tag.h>. Then we grovel over each
1400# referenced source file to see what stub function it defines.
1401
1402ifdef objpfx
1403.PHONY: stubs # The parent Makefile calls this target.
1404stubs: $(objpfx)stubs
1405endif
561bcb80
RM
1406objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1407 $(addprefix $(objpfx),$(extra-objs))
1408$(objpfx)stubs: $(objs-for-stubs)
1409ifneq (,$(strip $(objs-for-stubs)))
ae46b677 1410 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
561bcb80
RM
1411 $(AWK) '/\.gnu\.glibc-stub\./ { \
1412 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1413 stubs[$$2] = 1; } \
1414 END { for (s in stubs) print "#define __stub_" s }' > $@T
1c68c264 1415 mv -f $@T $@
f291538f
RM
1416else
1417 > $@
1418endif
1c68c264 1419\f
1c68c264
RM
1420ifneq (,$(strip $(gpl2lgpl)))
1421ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1422# Snarf from the master source and frob the copying notice.
1423$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1424 sed -f $^ > $@-tmp
1425# So I don't edit them by mistake.
1426 chmod a-w $@-tmp
1427 mv -f $@-tmp $@
1428ifeq ($(with-cvs),yes)
1429 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1430endif
1431endif
1432endif
1433
1434# Local Variables:
1435# mode: makefile
1436# End: