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