]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makerules
Update.
[thirdparty/glibc.git] / Makerules
CommitLineData
951641e7 1# Copyright (C) 1991-1999,2000,01,02 Free Software Foundation, Inc.
28f540f4
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
41bdb6e2
AJ
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.
28f540f4
RM
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
41bdb6e2 12# Lesser General Public License for more details.
28f540f4 13
41bdb6e2
AJ
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.
28f540f4
RM
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
14bab8de 28REQUIRED_MAKE_VERSION = 3.74
6952e59e 29REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
14bab8de
UD
30
31ifneq ($(REQUIRED_MAKE_VERSION), \
54d79e99 32 $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
14bab8de
UD
33Wrong GNU Make version. See above for the version needed.
34endif
35
28f540f4
RM
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
28f540f4
RM
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'.
0a55a284 60sysdirs = $(strip $(full_config_sysdirs))
28f540f4
RM
61
62+sysdir_pfx = $(common-objpfx)
63
64export sysdirs := $(sysdirs)
65
0a55a284 66+sysdep_dirs := $(full_config_sysdirs)
28f540f4
RM
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))
dbdb6189 74
ceb2d9aa
UD
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))
28f540f4
RM
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.
6e953631 86vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
57ba7bb4 87 $(+sysdep_dirs) $(..)))
28f540f4 88
714a562f
UD
89# The same is true for RPC source files.
90vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91 $(+sysdep_dirs) $(..)))
92
28f540f4
RM
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
083973f3
RM
97sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98ifneq (,$(sysdep-makefiles))
99include $(sysdep-makefiles)
3bbceb12
RM
100endif
101
102
28f540f4
RM
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
361742ed
RM
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
deb7f0b4 118 LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
361742ed 119 mv -f $@T $@
c7414a8e
RM
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 $@
361742ed
RM
125endif # avoid-generated
126endif # $(versioning) = yes
127
128
28f540f4
RM
129# Remove existing files from `before-compile'. Things are added there when
130# they must exist for dependency generation to work right, but once they
131# exist there is no further need for every single file to depend on them,
132# and those gratuitous dependencies result in many gratuitous
133# recompilations.
134before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
135
136# Don't let any before-compile file be an intermediate and get removed.
137ifdef before-compile
138$(before-compile):
139endif
140\f
141# Generate an ordered list of implicit rules which find the source files in
142# each sysdep directory. The old method was to use vpath to search all the
143# sysdep directories. However, that had the problem that a .S file in a
144# later directory would be chosen over a .c file in an earlier directory,
145# which does not preserve the desired sysdeps ordering behavior.
146
147# When making the list of .d files to include, we can't know which ones
148# have source in .s files, and thus do not in fact need a .d file.
149# So we must define rules to make .d files for .s files.
150define make-dummy-dep
6e953631 151$(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
28f540f4 152endef
6e953631 153$(common-objpfx)dummy.d:
28f540f4
RM
154 echo '# .s files cannot contain includes, so they need no deps.' > $@
155
156# It matters that this set of rules, for compiling from sources in
157# the current directory (the $srcdir/$subdir) come before the
158# generated sysdep rules in included from sysd-rules below. When
159# compiling in the source tree, generated sources go into the current
160# directory, and those should be chosen before any sources in sysdeps.
ceb2d9aa
UD
161define o-iterator-doit
162$(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
163endef
3f62b69a 164object-suffixes-left := $(all-object-suffixes)
ceb2d9aa 165include $(o-iterator)
28f540f4 166$(objpfx)%.d: %.S $(before-compile); $(+make-deps)
ceb2d9aa
UD
167
168define o-iterator-doit
169$(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
170endef
3f62b69a 171object-suffixes-left := $(all-object-suffixes)
ceb2d9aa 172include $(o-iterator)
6e953631 173$(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
ceb2d9aa
UD
174
175define o-iterator-doit
176$(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
177endef
3f62b69a 178object-suffixes-left := $(all-object-suffixes)
ceb2d9aa 179include $(o-iterator)
28f540f4
RM
180$(objpfx)%.d: %.c $(before-compile); $(+make-deps)
181
182# Omit the objpfx rules when building in the source tree, because
183# objpfx is empty and so these rules just override the ones above.
184ifdef objpfx
185# Define first rules to find the source files in $(objpfx).
186# Generated source files will end up there.
ceb2d9aa
UD
187define o-iterator-doit
188$(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
189endef
3f62b69a 190object-suffixes-left := $(all-object-suffixes)
ceb2d9aa 191include $(o-iterator)
28f540f4 192$(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
ceb2d9aa
UD
193
194define o-iterator-doit
195$(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
196endef
3f62b69a 197object-suffixes-left := $(all-object-suffixes)
ceb2d9aa 198include $(o-iterator)
6e953631 199$(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
ceb2d9aa
UD
200
201define o-iterator-doit
202$(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
203endef
3f62b69a 204object-suffixes-left := $(all-object-suffixes)
ceb2d9aa 205include $(o-iterator)
28f540f4
RM
206$(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
207endif
208
209# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
210# patterns matching sysdep directories whose assembly source files should
211# be suppressed.
212ifdef inhibit-sysdep-asm
213define open-check-inhibit-asm
214case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
215endef
51f75302 216close-check-inhibit-asm = ;; esac ;
28f540f4
RM
217endif
218
555f3a39 219-include $(+sysdir_pfx)sysd-rules
57ba7bb4
UD
220ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
221# The value of $(+sysdep_dirs) the sysd-rules was computed for
273d56ce
RM
222# differs from the one we are using now. So force a rebuild of sysd-rules.
223sysd-rules-force = FORCE
224FORCE:
225endif
28f540f4
RM
226$(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
227 $(wildcard $(foreach dir,$(sysdirs),\
57ba7bb4 228 $(dir)/Makefile))\
273d56ce 229 $(sysd-rules-force)
28f540f4 230 -@rm -f $@T
57ba7bb4 231 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
9c4c0024 232 for dir in $(config-sysdirs:%='$$(..)%'); do \
795fbc9a 233 for o in $(all-object-suffixes); do \
51f75302
RM
234 $(open-check-inhibit-asm) \
235 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
236 \$$(compile-command.S)"; \
237 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
238 \$$(compile-command.s)"; \
239 $(close-check-inhibit-asm) \
240 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
241 \$$(compile-command.c)"; \
242 done; \
28f540f4 243 $(open-check-inhibit-asm) \
6e953631 244 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
51f75302 245 \$$(make-dummy-dep)"; \
28f540f4
RM
246 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
247 \$$(+make-deps)"; \
51f75302 248 $(close-check-inhibit-asm) \
28f540f4
RM
249 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
250 \$$(+make-deps)"; \
3bbceb12
RM
251 done; \
252 echo 'sysd-rules-done = t') > $@T
28f540f4
RM
253 mv -f $@T $@
254
3bbceb12
RM
255ifndef sysd-rules-done
256# Don't do deps until this exists, because it provides rules to make the deps.
257no_deps=t
258endif
259
7a68c94a 260# Generate version maps, but wait until sysdep-subdirs is known
c95527a1 261ifeq ($(sysd-sorted-done),t)
8eaaffde
UD
262ifeq ($(versioning),yes)
263-include $(common-objpfx)sysd-versions
4bae5567 264$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
bdb04ee8 265common-generated += $(version-maps)
951641e7
RM
266postclean-generated += sysd-versions Versions.all abi-versions.h \
267 Versions.def.v.i Versions.def.v Versions.v.i Versions.v
4bae5567 268
7a68c94a
UD
269ifndef avoid-generated
270ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
271sysd-versions-force = FORCE
272FORCE:
273endif
951641e7
RM
274# See %.v/%.v.i implicit rules in Makeconfig.
275$(common-objpfx)Versions.def.v.i: $(..)Versions.def \
276 $(wildcard $(add-ons:%=$(..)%/Versions.def))
361742ed 277$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
3c132532 278 $(common-objpfx)soversions.i \
951641e7 279 $(common-objpfx)Versions.def.v
3c132532
RM
280 { while read lib version setname; do \
281 test -z "$$setname" || echo "$$lib : $$setname"; \
282 done < $(word 2,$^); \
951641e7 283 cat $(word 3,$^); \
3c132532 284 } | LC_ALL=C $(AWK) -f $< > $@T
99c9e773 285 mv -f $@T $@
951641e7
RM
286# See %.v/%.v.i implicit rules in Makeconfig.
287$(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
288 $(wildcard $(sysdirs:%=%/Versions)) \
289 $(common-objpfx)abi-versions.h \
290 $(sysd-versions-force)
99c9e773 291$(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
951641e7
RM
292 $(common-objpfx)Versions.v \
293 $(..)scripts/versions.awk
cf197e41 294 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
951641e7 295 cat $(word 2,$^) \
480d827b
RM
296 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
297 -v move_if_change='$(move-if-change)' \
951641e7 298 -f $(word 3,$^); \
cf197e41 299 ) > $@T
8eaaffde 300 mv -f $@T $@
7a68c94a
UD
301endif # avoid-generated
302endif # $(versioning) = yes
c95527a1 303endif # sysd-sorted-done
3bbceb12 304
361742ed 305
28f540f4
RM
306ifndef compile-command.S
307compile-command.S = $(compile.S) $(OUTPUT_OPTION)
308endif
309ifndef compile-command.s
310compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
311endif
312ifndef compile-command.c
313compile-command.c = $(compile.c) $(OUTPUT_OPTION)
314endif
315
28f540f4 316# GCC can grok options after the file name, and it looks nicer that way.
28f540f4 317compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
f166d865
UD
318compile.S = \
319 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
320COMPILE.S = \
321 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
aeb72b16 322COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
28f540f4 323
0ca2a569 324# If we want to generate MD5 checksums for the sources do this now.
d2b9a50e
UD
325ifeq ($(md5),yes)
326generate-md5 = ; rm -f $(@:.d=.md5); \
327$(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
328sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
329else
330generate-md5 =
331endif
332
28f540f4
RM
333# We need this for the output to go in the right place. It will default to
334# empty if make was configured to work with a cc that can't grok -c and -o
335# together. You can't compile the C library with such a compiler.
336OUTPUT_OPTION = -o $@
28f540f4
RM
337
338S-CPPFLAGS = $(asm-CPPFLAGS)
339define +make-deps
6e953631 340$(make-target-directory)
28f540f4 341-@rm -f $@
60c96635 342$(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
795fbc9a
UD
343sed \
344-e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
51f75302 345$(sed-remove-objpfx) > $(@:.d=.T)
d2b9a50e 346mv -f $(@:.d=.T) $@ $(generate-md5)
28f540f4
RM
347endef
348ifneq (,$(objpfx))
215dbbb1
RM
349# Continuation lines here are dangerous because they introduce spaces!
350define sed-remove-objpfx
6e953631
UD
351-e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
352-e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
215dbbb1 353endef
28f540f4
RM
354endif
355\f
69b4c429
GM
356# Modify the list of routines we build for different targets
357
ad10cac8 358ifeq (yesyes,$(build-shared)$(elf))
69b4c429
GM
359ifndef libc.so-version
360# Undefine this because it can't work when we libc.so is unversioned.
361static-only-routines =
362endif
363endif
364
365# Bounded pointer thunks are only built for *.ob
366elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
367
368elide-routines.oS += $(filter-out $(static-only-routines),\
369 $(routines) $(aux) $(sysdep_routines)) \
370 $(elide-bp-thunks)
371elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
372
373# If we have versioned code we don't need the old versions in any of the
374# static libraries.
375elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
376elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
377elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
378elide-routines.ob += $(shared-only-routines)
379\f
5f0e6fc7
RM
380# Shared library building.
381
382ifeq (yes,$(build-shared))
383
ae1025be
UD
384# Reference map file only when versioning is selected and a map file name
385# is given.
386ifeq ($(versioning),yes)
a9ddb793
UD
387map-file = $(firstword $($(@F:.so=-map)) \
388 $(addprefix $(common-objpfx), \
389 $(filter $(@F:.so=.map),$(version-maps))))
b17277cf 390load-map-file = $(map-file:%=-Wl,--version-script=%)
ae1025be
UD
391endif
392
5f0e6fc7
RM
393# Pattern rule to build a shared object from an archive of PIC objects.
394# This must come after the installation rules so Make doesn't try to
395# build shared libraries in place from the installed *_pic.a files.
396# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
397# on other shared objects.
66715f83 398lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
ad10cac8
UD
399ifneq (,$(findstring aix,$(config-os)))
400 (echo '#!'; \
401 dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
402endif
40a55d20 403 $(build-shlib)
5f0e6fc7 404
ad10cac8 405ifeq ($(elf),yes)
a986484f 406define build-shlib-helper
74bd2300 407$(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
90feeaa2
UD
408 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
409 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
5f0e6fc7
RM
410 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
411 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
a986484f
UD
412 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
413endef
ad10cac8
UD
414else
415ifneq (,$(findstring aix,$(config-os)))
416define build-shlib-helper
994431ed 417$(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
ad10cac8
UD
418 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
419 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
420 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
421 -L$(subst :, -L,$(rpath-link))
422endef
423else
424endif
425endif
a986484f
UD
426
427ifeq (yes,$(elf))
428# binutils only position loadable notes into the first page for binaries,
429# not for shared objects
430define build-shlib
431$(build-shlib-helper) \
639c3248 432 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
a986484f
UD
433 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
434 sed -e '/^=========/,/^=========/!d;/^=========/d' \
435 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
b5d51280
UD
436 > $@.lds
437rm -f $@.new
438$(build-shlib-helper) -o $@ -T $@.lds \
c7414a8e 439 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
b5d51280 440rm -f $@.lds
a986484f
UD
441endef
442else
ad10cac8
UD
443ifneq (,$(findstring aix,$(config-os)))
444define build-shlib
445$(build-shlib-helper) \
446 -o $@ \
447 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
448 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
449endef
a986484f
UD
450define build-shlib
451$(build-shlib-helper) \
c7414a8e 452 $(build-shlib-objlist)
5f0e6fc7 453endef
a986484f 454endif
ad10cac8 455endif
a986484f 456
ad10cac8
UD
457ifneq (,$(findstring aix,$(config-os)))
458define build-module-helper
459$(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
460 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
461 $(load-map-file) \
462 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
463 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
464endef
465else
a986484f 466define build-module-helper
74bd2300 467$(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
a986484f
UD
468 -B$(csu-objpfx) $(load-map-file) \
469 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
470 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
471endef
ad10cac8 472endif
5f0e6fc7 473
5d003fb2
UD
474# This macro is similar to build-shlib but it does not define a soname
475# and it does not depend on the destination name to start with `lib'.
a986484f
UD
476ifeq (yes,$(elf))
477# binutils only position loadable notes into the first page for binaries,
478# not for shared objects
5d003fb2 479define build-module
a986484f 480$(build-module-helper) \
2f53aec9 481 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
a986484f
UD
482 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
483 sed -e '/^=========/,/^=========/!d;/^=========/d' \
484 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
2f53aec9
UD
485 > $@.lds
486rm -f $@.new
487$(build-module-helper) -o $@ -T $@.lds \
c7414a8e 488 $(csu-objpfx)abi-note.o $(build-module-objlist)
2f53aec9 489rm -f $@.lds
a986484f
UD
490endef
491else
ad10cac8
UD
492ifneq (,$(findstring aix,$(config-os)))
493define build-module
494$(build-module-helper) \
495 -o $@ \
496 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
497 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
498endef
499else
500define build-module
a986484f
UD
501define build-module
502$(build-module-helper) \
c7414a8e
RM
503 -o $@ \
504 $(build-module-objlist)
5d003fb2 505endef
a986484f 506endif
ad10cac8 507endif
5d003fb2 508
c7414a8e
RM
509build-module-helper-objlist = \
510 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
511 $(filter-out $(map-file) $(+preinit) $(+postinit),$^))
512whole-archive := -Wl,--whole-archive
513
514build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
515build-shlib-objlist = $(build-module-helper-objlist) \
516 $(LDLIBS-$(@F:lib%.so=%).so)
517
5f0e6fc7
RM
518# Don't try to use -lc when making libc.so itself.
519# Also omits crti.o and crtn.o, which we do not want
520# since we define our own `.init' section specially.
521LDFLAGS-c.so = -nostdlib -nostartfiles
9a0a462c 522# But we still want to link libc.so against $(gnulib).
2698e32c 523LDLIBS-c.so += $(gnulib)
5f0e6fc7
RM
524# Give libc.so an entry point and make it directly runnable itself.
525LDFLAGS-c.so += -e __libc_main
b93492aa
UD
526# Force the backward compatibility EH functions to be linked.
527LDFLAGS-c.so += -u __register_frame
da2d1bc5
UD
528# Pre-link the objects of libc_pic.a so that we can locally resolve
529# COMMON symbols before we link against ld.so. This is because ld.so
530# contains some of libc_pic.a already, which will prevent the COMMONs
531# from being allocated in libc.so, which introduces evil dependencies
532# between libc.so and ld.so, which can make it impossible to upgrade.
ad10cac8 533ifeq ($(elf),yes)
da2d1bc5
UD
534$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
535 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
49547c68 536 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
5f0e6fc7 537# Use our own special initializer and finalizer files for libc.so.
40a55d20 538$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
da2d1bc5 539 $(common-objpfx)libc_pic.os \
66715f83 540 $(elfobjdir)/sofini.os \
a9ddb793 541 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
5f0e6fc7 542 $(build-shlib)
a9ddb793
UD
543ifeq ($(versioning),yes)
544$(common-objpfx)libc.so: $(common-objpfx)libc.map
545endif
1b5fd830 546common-generated += libc.so libc_pic.os
d705269e
UD
547ifdef libc.so-version
548$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
549 $(make-link)
da2d1bc5 550common-generated += libc.so$(libc.so-version)
d705269e 551endif
5f0e6fc7 552endif
ad10cac8
UD
553else
554ifneq (,$(findstring aix,$(config-os)))
555$(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
556 @rm -f $@
557 (echo '#!'; \
558 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
559 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
560 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
561 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
562 -bE:$(common-objpfx)syscalls.exp \
563 -bI:$(common-objpfx)syscalls.exp \
564 -L$(common-objpfx) -o $@ $^
565# AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
566 cp $@ $(common-objpfx)shr.o
567 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
568endif
569endif
5f0e6fc7 570\f
28f540f4
RM
571# Figure out the source filenames in this directory.
572
ab95290c
UD
573override sources := $(addsuffix .c,\
574 $(filter-out $(elided-routines),\
575 $(routines) $(aux) \
5539d257 576 $(sysdep_routines)))
28f540f4
RM
577sysdep_routines := $(sysdep_routines)
578
e60062b7
RM
579headers := $(headers) $(sysdep_headers)
580
28f540f4
RM
581# This is the list of all object files, gotten by
582# replacing every ".c" in `sources' with a ".o".
28546617
GM
583# We also add bounded-pointer thunks, which are later
584# elided for all suffixes except for `.ob'.
585override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
586 $(patsubst %,$(bppfx)%.o,\
587 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
693e7b96
RM
588
589
693e7b96
RM
590# The makefile may define $(extra-libs) with `libfoo libbar'
591# to build libfoo.a et al from the modules listed in $(libfoo-routines).
592ifdef extra-libs
593# extra-lib.mk is included once for each extra lib to define rules
594# to build it, and to add its objects to the various variables.
595# During its evaluation, $(lib) is set to the name of the library.
596extra-libs-left := $(extra-libs)
597include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
598endif
28f540f4 599\f
eb406346
UD
600+depfiles := $(sources:.c=.d) \
601 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
c238ecf7 602 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
0413b54c 603ifeq ($(build-programs),yes)
414fd335 604+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
0413b54c 605endif
28f540f4
RM
606+depfiles := $(addprefix $(objpfx),\
607 $(filter-out $(addsuffix .d,$(omit-deps)),\
608 $(+depfiles)))
609
28f540f4 610ifdef +depfiles
28f540f4 611ifneq ($(no_deps),t)
555f3a39 612-include $(+depfiles)
deab9dea 613endif
28f540f4
RM
614endif
615\f\f
616# Maximize efficiency by minimizing the number of rules.
9756dfe1 617.SUFFIXES: # Clear the suffix list. We don't use suffix rules.
f649c201
UD
618# Don't define any builtin rules.
619MAKEFLAGS := $(MAKEFLAGS)r
28f540f4
RM
620
621# Generic rule for making directories.
622%/:
623# mkdir isn't smart enough to strip a trailing /.
624 mkdir $(@:%/=%)
625\f
626# Make sure that object files are not removed
627# when they are intermediates between sources and library members.
9afc8a59 628.PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
28f540f4
RM
629
630# Make sure that the parent library archive is never removed.
51f75302 631.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
28f540f4
RM
632\f
633# Use the verbose option of ar and tar when not running silently.
634ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
635verbose := v
636else # -s
637verbose :=
638endif # not -s
639
640ARFLAGS := r$(verbose)
f38931a9 641CREATE_ARFLAGS := cru$(verbose)
28f540f4
RM
642\f
643# This makes all the object files in the parent library archive.
644
97a47867 645.PHONY: lib lib-noranlib
ae9b308c 646lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
b22fc5f5 647lib-noranlib: libobjs
51f75302 648
564210fe
RM
649# For object-suffix $o, the list of objects with that suffix.
650# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
651o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
652 $(elide-routines$o)),\
916c1395
GM
653 $(objects))) \
654 $(addprefix $(objpfx),$(o-objects$o))
655
3bbceb12 656others: $(addprefix $(objpfx),$(install-lib))
28f540f4 657
072ebcef
RM
658ifndef objects
659
660# Create the stamp$o files to keep the parent makefile happy.
9afc8a59
UD
661subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
662$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
6e953631 663 $(make-target-directory)
072ebcef
RM
664 rm -f $@; > $@
665else
51f75302 666
97a47867 667# Define explicit rules to update each $(objpfx)stamp.SUFFIX
564210fe 668# timestamp file; these rules (one explicit rule is generated for each
97a47867
UD
669# object suffix) write a list of objects to update in the stamp file.
670# The parent will then actually add them all to the archive in the
671# archive rule, below.
564210fe 672define o-iterator-doit
97a47867
UD
673$(objpfx)stamp$o: $(o-objects); $$(do-stamp)
674endef
675define do-stamp
a709dd43 676echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
b22fc5f5 677mv -f $@T $@
564210fe 678endef
9afc8a59 679object-suffixes-left := $(object-suffixes-for-libc)
564210fe 680include $(o-iterator)
28f540f4 681
51f75302 682endif
28f540f4 683
97a47867 684# Now define explicit rules to build the library archives; these depend
a709dd43 685# on the stamp files built above.
dbdb6189 686define o-iterator-doit
97a47867
UD
687$(common-objpfx)$(patsubst %,$(libtype$o),c): \
688 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
689endef
690define do-makelib
b22fc5f5 691cd $(common-objdir) && \
a709dd43
UD
692$(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
693$(RANLIB) $@
dbdb6189 694endef
97a47867
UD
695subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
696subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
b22fc5f5 697ifndef subdir
ae9b308c 698$(subdirs-stamps): subdir_lib;
97a47867 699endif
9afc8a59 700object-suffixes-left = $(object-suffixes-for-libc)
dbdb6189
RM
701include $(o-iterator)
702
28f540f4
RM
703
704# This makes all the object files.
97a47867
UD
705.PHONY: objects objs libobjs extra-objs
706objects objs: libobjs extra-objs
707libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
708extra-objs: $(addprefix $(objpfx),$(extra-objs))
f0bf9cb9
RM
709
710# Canned sequence for building an extra library archive.
711define build-extra-lib
af3878df 712$(patsubst %/,cd % &&,$(objpfx)) \
f38931a9 713$(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
f0bf9cb9
RM
714 $(patsubst $(objpfx)%,%,$^)
715$(RANLIB) $@
716endef
28f540f4
RM
717\f
718# Installation.
719
73237de3
UD
720.PHONY: force-install
721force-install:
722
28f540f4
RM
723# $(install-lib) are installed from the object directory into $(libdir);
724# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
725# unless they also appear in $(non-lib.a). $(install-data) are installed
726# as they are into $(datadir). $(headers) are installed as they are in
6c3ebebd
UD
727# $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
728# are installed from the object directory into $(bindir), $(bindir) and
729# $(sbindir), respectively. $(install-others) are absolute path names of
730# files to install; rules to install them are defined elsewhere.
28f540f4
RM
731
732# The simple library name to install libc.a under.
733# This could be defined by a sysdep Makefile.
734ifndef libc-name
735libc-name := c
736endif
737
738define do-install
739$(make-target-directory)
740$(INSTALL_DATA) $< $@
741endef
742
a182affd
RM
743# Make the target directory if it doesn't exist, using the `mkinstalldirs'
744# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
28f540f4 745define make-target-directory
5bc2f642 746$(addprefix $(..)./scripts/mkinstalldirs ,\
a182affd 747 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
28f540f4
RM
748endef
749
a709dd43
UD
750# Any directory (parent or subdir) should install libc.a; this way
751# "make install" in a subdir is guaranteed to install everything it changes.
cab24c37 752installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
8d57beea
UD
753 $(inst_libdir)/$(patsubst %,$(libtype$o),\
754 $(libprefix)$(libc-name)))
51f75302 755install: $(installed-libcs)
73237de3 756$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
28f540f4 757 $(make-target-directory)
c316b486 758 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
9f2233e8
RM
759# Running ranlib after installing makes the __.SYMDEF time stamp up to
760# date, which avoids messages from some linkers.
28f540f4 761 $(RANLIB) $@
28f540f4 762
273d56ce
RM
763define do-install-program
764$(make-target-directory)
765$(INSTALL_PROGRAM) $< $@.new
766mv -f $@.new $@
767endef
768
6c3ebebd
UD
769define do-install-script
770$(make-target-directory)
771$(INSTALL_SCRIPT) $< $@.new
772mv -f $@.new $@
773endef
774
5bf62f2d 775install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
0700dfa1 776install-lib := $(filter-out %.so %_pic.a,$(install-lib))
0e3426bb 777
a9ddb793 778ifeq (yes,$(build-shared))
0e3426bb 779# Find which .so's have versions.
05d4c982
RM
780versioned := $(strip $(foreach so,$(install-lib.so),\
781 $(patsubst %,$(so),$($(so)-version))))
0e3426bb 782
a9ddb793
UD
783install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
784install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
785
786install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
787 $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
788
0e3426bb 789# Install all the unversioned shared libraries.
a9ddb793
UD
790$(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
791 $(objpfx)%.so $(+force)
792 $(do-install-program)
0e3426bb 793
8a523922 794ifneq ($(findstring -s,$(LN_S)),)
f36f8dcf 795define make-link
f8b87ef0 796rm -f $@.new
5bc2f642 797$(SHELL) $(..)scripts/rellns-sh $< $@.new
8a523922
UD
798mv -f $@.new $@
799endef
800else
801# If we have no symbolic links don't bother with rellns-sh.
802define make-link
f8b87ef0
UD
803rm -f $@.new
804$(LN_S) $< $@.new
8a523922 805mv -f $@.new $@
f36f8dcf 806endef
8a523922 807endif
0e3426bb 808
9d141cae 809ifeq (yes,$(build-shared))
6a08db09 810ifeq (no,$(cross-compiling))
9d141cae
UD
811symbolic-link-prog := $(common-objpfx)elf/sln
812symbolic-link-list := $(common-objpfx)elf/symlink.list
1ef32c3d 813define make-shlib-link
9d141cae 814echo $(<F) $@ >> $(symbolic-link-list)
1ef32c3d 815endef
6a08db09
RM
816else # cross-compiling
817# We need a definition that can be used by elf/Makefile's install rules.
818symbolic-link-prog = $(LN_S)
1ef32c3d
UD
819endif
820endif
821ifndef make-shlib-link
822define make-shlib-link
9d141cae
UD
823rm -f $@
824$(LN_S) $(<F) $@
1ef32c3d
UD
825endef
826endif
827
0e3426bb
RM
828ifdef libc.so-version
829# For a library specified to be version N, install three files:
830# libc.so -> libc.so.N (e.g. libc.so.6)
831# libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
832
73237de3
UD
833$(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
834 $(+force)
1ef32c3d 835 $(make-shlib-link)
73237de3 836$(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
8d57beea
UD
837 $(do-install-program)
838install: $(inst_slibdir)/libc.so$(libc.so-version)
7c713e28 839
aa1075ea 840ifndef subdir
57ba7bb4
UD
841# What we install as libc.so for programs to link against is in fact a
842# link script. It contains references for the various libraries we need.
843# The libc.so object is not complete since some functions are only defined
71bedb76 844# in libc_nonshared.a.
e980ca92
UD
845# We need to use absolute paths since otherwise local copies (if they exist)
846# of the files are taken by the linker.
8d57beea
UD
847install: $(inst_libdir)/libc.so
848$(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
a44d2393 849 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
73237de3
UD
850 $(libprefix)$(libc-name)) \
851 $(+force)
47707456
UD
852 (echo '/* GNU ld script';\
853 echo ' Use the shared library, but some functions are only in';\
a44d2393 854 echo ' the static library, so try that secondarily. */';\
af6f3906 855 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
a44d2393
UD
856 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
857 ')' \
858 ) > $@.new
0f90ef96
RM
859 mv -f $@.new $@
860
aa1075ea 861endif
7c713e28 862
0e3426bb 863else
8d57beea 864install: $(inst_slibdir)/libc.so
73237de3 865$(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
8d57beea 866 $(do-install-program)
0e3426bb
RM
867endif
868
0e3426bb
RM
869ifneq (,$(versioned))
870# Produce three sets of rules as above for all the smaller versioned libraries.
871
872define o-iterator-doit
73237de3 873$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
0e3426bb
RM
874endef
875object-suffixes-left := $(versioned)
dc997231 876include $(o-iterator)
0e3426bb 877
20c81189
RM
878# Make symlinks in the build directory, because the versioned names might
879# be referenced by a DT_NEEDED in another library.
880define o-iterator-doit
881$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
882endef
883object-suffixes-left := $(versioned)
dc997231 884include $(o-iterator)
20c81189 885
da2d1bc5 886generated += $(foreach o,$(versioned),$o$($o-version))
20c81189 887
499e7464 888ifeq (,$($(subdir)-version))
0e3426bb 889define o-iterator-doit
73237de3
UD
890$(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
891 $(+force);
1ef32c3d 892 $$(make-shlib-link)
0e3426bb
RM
893endef
894object-suffixes-left := $(versioned)
dc997231 895include $(o-iterator)
0e3426bb
RM
896
897define o-iterator-doit
73237de3
UD
898$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
899 $$(do-install-program)
0e3426bb
RM
900endef
901object-suffixes-left := $(versioned)
dc997231 902include $(o-iterator)
499e7464
UD
903else
904define o-iterator-doit
8d57beea 905$(inst_slibdir)/$o$($o-version): \
73237de3 906 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1ef32c3d 907 $$(make-shlib-link)
499e7464
UD
908endef
909object-suffixes-left := $(versioned)
910include $(o-iterator)
911
912define o-iterator-doit
73237de3 913$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
499e7464
UD
914 $$(do-install-program)
915endef
916object-suffixes-left := $(versioned)
917include $(o-iterator)
918endif
0e3426bb 919endif
102800e0
RM
920
921define do-install-so
922$(do-install-program)
923$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
924 $(filter-out %.so,$@))
925endef
094bacdb 926
102800e0
RM
927so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
928$(foreach v,$(so-versions),\
73237de3
UD
929 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
930 $(+force)
102800e0
RM
931 $(do-install-so)
932$(foreach v,$(so-versions),\
73237de3 933 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
102800e0 934 $(do-install-so)
51f75302
RM
935endif
936
28f540f4 937ifdef install-bin
73237de3
UD
938$(addprefix $(inst_bindir)/,$(install-bin)): \
939 $(inst_bindir)/%: $(objpfx)% $(+force)
273d56ce 940 $(do-install-program)
28f540f4 941endif
6c3ebebd
UD
942ifdef install-bin-script
943$(addprefix $(inst_bindir)/,$(install-bin-script)): \
944 $(inst_bindir)/%: $(objpfx)% $(+force)
945 $(do-install-script)
946endif
1ef32c3d 947ifdef install-rootsbin
73237de3
UD
948$(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
949 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1ef32c3d
UD
950 $(do-install-program)
951endif
28f540f4 952ifdef install-sbin
73237de3
UD
953$(addprefix $(inst_sbindir)/,$(install-sbin)): \
954 $(inst_sbindir)/%: $(objpfx)% $(+force)
273d56ce 955 $(do-install-program)
28f540f4
RM
956endif
957ifdef install-lib
958install-lib.a := $(filter lib%.a,$(install-lib))
959install-lib-non.a := $(filter-out lib%.a,$(install-lib))
960ifdef install-lib-non.a
9d187dd4 961$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
73237de3 962 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
28f540f4
RM
963 $(do-install)
964endif
965ifdef install-lib.a
8d57beea 966$(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
73237de3 967 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
28f540f4
RM
968 $(do-install)
969 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
970endif
971endif
972ifdef install-data
73237de3 973$(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
8d57beea 974 $(do-install)
28f540f4
RM
975endif
976headers := $(strip $(headers))
977ifdef headers
73237de3 978$(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
8d57beea 979 $(do-install)
28f540f4
RM
980endif # headers
981
6c3ebebd
UD
982.PHONY: install-bin-nosubdir install-bin-script-nosubdir \
983 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
984 install-data-nosubdir install-headers-nosubdir
8d57beea 985install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
6c3ebebd 986install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
8d57beea
UD
987install-rootsbin-nosubdir: \
988 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
989install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
990install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
28f540f4
RM
991 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
992 $(addprefix $(libprefix),$(install-lib-non.a)))
8d57beea
UD
993install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
994install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
28f540f4
RM
995install-others-nosubdir: $(install-others)
996
997# We need all the `-nosubdir' targets so that `install' in the parent
998# doesn't depend on several things which each iterate over the subdirs.
999# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1000# subroutine. Then in the parent `install-FOO' also causes subdir makes.
1001install-%:: install-%-nosubdir ;
1002
1003.PHONY: install install-no-libc.a-nosubdir
da2d1bc5 1004ifeq ($(build-programs),yes)
28f540f4 1005install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
6c3ebebd
UD
1006 install-bin-nosubdir install-bin-script-nosubdir \
1007 install-lib-nosubdir install-others-nosubdir \
1008 install-rootsbin-nosubdir install-sbin-nosubdir
da2d1bc5
UD
1009else
1010install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1011 install-lib-nosubdir install-others-nosubdir
1012endif
28f540f4
RM
1013install: install-no-libc.a-nosubdir
1014\f
1015# Command to compile $< in $(objdir) using the native libraries.
1016define native-compile
377a515b 1017$(make-target-directory)
af3878df 1018$(patsubst %/,cd % &&,$(objpfx)) \
377a515b
UD
1019$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1020 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
28f540f4
RM
1021endef
1022
1023# Command to compile $< in $(common-objdir) using the native libraries.
0d204b0a 1024# We must cd to $(objdir) anyway so that $(..)config.h is valid.
28f540f4 1025define common-objdir-compile
af3878df 1026$(patsubst %/,cd % &&,$(objpfx)) \
377a515b
UD
1027$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1028 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
28f540f4
RM
1029endef
1030
1031# We always want to use configuration definitions.
377a515b
UD
1032# Note that this is only used for commands running in $(objpfx).
1033ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
28f540f4
RM
1034
1035# Support the GNU standard name for this target.
1036.PHONY: check
1037check: tests
c238ecf7
UD
1038# Special target to run tests which cannot be run unconditionally.
1039# Maintainers should use this target.
1040.PHONY: xcheck
1041xcheck: xtests
776cc5d3
UD
1042
1043ifneq (,$(tests))
1044cpp-srcs-left = $(tests)
6b87a564 1045lib := tests
776cc5d3
UD
1046include $(patsubst %,$(..)cppflags-iterator.mk,$(tests))
1047endif
c238ecf7
UD
1048ifneq (,$(xtests))
1049cpp-srcs-left = $(xtests)
1050lib := tests
1051include $(patsubst %,$(..)cppflags-iterator.mk,$(xtests))
1052endif
28f540f4
RM
1053\f
1054.PHONY: TAGS
5649a1d6 1055TAGS: $(objpfx)distinfo $(..)MakeTAGS
dbdb6189 1056 $(MAKE) $(addprefix -f ,$^) $@
28f540f4 1057
5649a1d6 1058$(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
ce563359
RM
1059 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1060FORCE:
a182affd
RM
1061
1062
28f540f4
RM
1063.PHONY: echo-headers
1064echo-headers:
1065 @echo $(headers)
1066
1067\f
1068# Common cleaning targets.
1069
3c5edd4d 1070.PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
28f540f4
RM
1071clean: common-clean
1072mostlyclean: common-mostlyclean
1073
3c5edd4d 1074do-tests-clean:
c238ecf7
UD
1075 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1076 $(test-srcs)) \
1077 $(addsuffix -bp.out,$(tests) $(xtests) \
1078 $(test-srcs)))
3c5edd4d 1079
28f540f4
RM
1080# Remove the object files.
1081common-mostlyclean:
c238ecf7
UD
1082 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1083 $(others) $(sysdep-others) stubs \
1084 $(addsuffix .o,$(tests) $(xtests) \
1085 $(test-srcs) $(others) \
414fd335 1086 $(sysdep-others)) \
c238ecf7
UD
1087 $(addsuffix -bp,$(tests) $(xtests) \
1088 $(test-srcs)) \
1089 $(addsuffix .out,$(tests) $(xtests) \
1090 $(test-srcs)) \
1091 $(addsuffix -bp.out,$(tests) $(xtests) \
1092 $(test-srcs)))
da2d1bc5
UD
1093 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1094 $(install-lib.so) \
1095 $(install-lib.so:%.so=%_pic.a))
97a47867 1096 -rm -f core
51f75302
RM
1097 $(rmobjs)
1098define rmobjs
9afc8a59 1099$(foreach o,$(object-suffixes-for-libc),
51702635 1100-rm -f $(objpfx)stamp$o $(o-objects))
51f75302 1101endef
28f540f4
RM
1102
1103# Also remove the dependencies and generated source files.
1104common-clean: common-mostlyclean
deab9dea 1105 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
5290baf0 1106 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
924840c5 1107 -rm -f $(addprefix $(common-objpfx),$(common-generated))
5649a1d6 1108 -rm -f $(objpfx)distinfo
28f540f4 1109\f
97a47867 1110# Produce a file `stubs' which contains `#define __stub_FUNCTION'
28f540f4 1111# for each function which is a stub. We grovel over all the .d files
f2ea0f5b
UD
1112# looking for references to <stub-tag.h>. Then we grovel over each
1113# referenced source file to see what stub function it defines.
28f540f4 1114
b22fc5f5 1115ifdef objpfx
28f540f4 1116.PHONY: stubs # The parent Makefile calls this target.
97a47867 1117stubs: $(objpfx)stubs
b22fc5f5 1118endif
f2ea0f5b 1119s = $(sysdep_dir)/generic
97a47867 1120$(objpfx)stubs: $(+depfiles)
28f540f4 1121# Use /dev/null since `...` might expand to empty.
c218729d 1122 (s=`cd $s && $(PWD_P)`; \
af3878df 1123 $(patsubst %/,cd % &&,$(objpfx)) \
c4cc693d 1124 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
f43ce637 1125 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
f2ea0f5b 1126 -e '/stub-tag\.h/{; g; p; }' \
c4cc693d
RM
1127 $(patsubst $(objpfx)%,%,$^) /dev/null` \
1128 /dev/null) > $@T
28f540f4
RM
1129 mv -f $@T $@
1130\f
1131# Make the distribution tar file.
1132
1133.PHONY: dist
5649a1d6 1134dist: $(objpfx)distinfo $(..)Make-dist
28f540f4
RM
1135 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1136
10ceac89
RM
1137# Avoid depending on source files found in sysdeps dirs,
1138# because the references affect implicit rule selection.
1139dist: $(filter-out %.c %.S %.s,$(distribute))
28f540f4
RM
1140
1141# We used to simply export all these variables, but that frequently made the
1142# environment get too large. Instead, we write all the information into
1143# a generated makefile fragment `distinfo', and then include it with -f in
1144# the sub-make that makes the distribution (above).
5649a1d6
UD
1145$(objpfx)distinfo: Makefile $(..)Makerules \
1146 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
714a562f 1147 $(make-target-directory)
28f540f4
RM
1148 $(distinfo-vars)
1149 mv -f $@.new $@
5649a1d6
UD
1150.PHONY: subdir_distinfo
1151subdir_distinfo: $(objpfx)distinfo
28f540f4
RM
1152
1153define distinfo-vars
1154rm -f $@.new
a4242e25
RM
1155echo > $@.new 'subdir := $(subdir)'
1156$(foreach var,subdir-dirs sources elided-routines sysdep_routines \
dfe1754a 1157 headers sysdep_headers distribute dont_distribute generated \
c238ecf7
UD
1158 others tests xtests test-srcs extra-libs versioned \
1159 $(extra-libs:%=%-routines) \
6c3ebebd 1160 $(addprefix install-,lib lib.so data bin bin-script sbin others),
4d6acc61
RM
1161echo >> $@.new '$(subdir)-$(var) := $($(var))'
1162echo >> $@.new '$(var) = $$($(subdir)-$(var))')
28f540f4
RM
1163endef
1164\f
1165ifneq (,$(strip $(gpl2lgpl)))
1166ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1167# Snarf from the master source and frob the copying notice.
1168$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1169 sed -f $^ > $@-tmp
1170# So I don't edit them by mistake.
1171 chmod a-w $@-tmp
1172 mv -f $@-tmp $@
4d06461a 1173ifeq ($(with-cvs),yes)
379bb425 1174 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
28f540f4
RM
1175endif
1176endif
4d06461a 1177endif
c238ecf7
UD
1178
1179# Local Variables:
1180# mode: makefile
1181# End: