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