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