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