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