1 # Copyright (C) 1991-1999, 2000,2001 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
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 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB. If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
20 # Common rules for making the GNU C library. This file is included
21 # by the top-level Makefile and by all subdirectory makefiles
25 This makefile requires GNU Make.
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32 $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version. See above for the version needed.
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq "$(findstring env,$(origin sources))" ""
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full_config_sysdirs))
62 +sysdir_pfx = $(common-objpfx)
64 export sysdirs := $(sysdirs)
66 +sysdep_dirs := $(full_config_sysdirs)
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
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.
79 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
81 # Include any system-specific makefiles.
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.
86 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87 $(+sysdep_dirs) $(..)))
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91 $(+sysdep_dirs) $(..)))
93 # Some sysdep makefiles use this to distinguish being included here from
94 # being included individually by a subdir makefile (hurd/Makefile needs this).
97 sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98 ifneq (,$(sysdep-makefiles))
99 include $(sysdep-makefiles)
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).
107 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
109 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
112 # Even before that, we need abi-versions.h which is generated right here.
113 ifeq ($(versioning),yes)
114 ifndef avoid-generated
115 before-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
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
125 endif # avoid-generated
126 endif # $(versioning) = yes
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
134 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
136 # Don't let any before-compile file be an intermediate and get removed.
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.
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.
150 define make-dummy-dep
151 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
153 $(common-objpfx)dummy.d:
154 echo '# .s files cannot contain includes, so they need no deps.' > $@
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.
161 define o-iterator-doit
162 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
164 object-suffixes-left := $(all-object-suffixes)
165 include $(o-iterator)
166 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
168 define o-iterator-doit
169 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
171 object-suffixes-left := $(all-object-suffixes)
172 include $(o-iterator)
173 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
175 define o-iterator-doit
176 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
178 object-suffixes-left := $(all-object-suffixes)
179 include $(o-iterator)
180 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
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.
185 # Define first rules to find the source files in $(objpfx).
186 # Generated source files will end up there.
187 define o-iterator-doit
188 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
190 object-suffixes-left := $(all-object-suffixes)
191 include $(o-iterator)
192 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
194 define o-iterator-doit
195 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
197 object-suffixes-left := $(all-object-suffixes)
198 include $(o-iterator)
199 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
201 define o-iterator-doit
202 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
204 object-suffixes-left := $(all-object-suffixes)
205 include $(o-iterator)
206 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
209 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
210 # patterns matching sysdep directories whose assembly source files should
212 ifdef inhibit-sysdep-asm
213 define open-check-inhibit-asm
214 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
216 close-check-inhibit-asm = ;; esac ;
219 -include $(+sysdir_pfx)sysd-rules
220 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
221 # The value of $(+sysdep_dirs) the sysd-rules was computed for
222 # differs from the one we are using now. So force a rebuild of sysd-rules.
223 sysd-rules-force = FORCE
226 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
227 $(wildcard $(foreach dir,$(sysdirs),\
231 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
232 for dir in $(config-sysdirs:%='$$(..)%'); do \
233 for o in $(all-object-suffixes); do \
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)"; \
243 $(open-check-inhibit-asm) \
244 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
245 \$$(make-dummy-dep)"; \
246 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
248 $(close-check-inhibit-asm) \
249 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
252 echo 'sysd-rules-done = t') > $@T
255 ifndef sysd-rules-done
256 # Don't do deps until this exists, because it provides rules to make the deps.
260 # Generate version maps, but wait until sysdep-subdirs is known
261 ifeq ($(sysd-sorted-done),t)
262 ifeq ($(versioning),yes)
263 -include $(common-objpfx)sysd-versions
264 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
265 common-generated += $(version-maps)
266 postclean-generated += sysd-versions Versions.all abi-versions.h
268 ifndef avoid-generated
269 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
270 sysd-versions-force = FORCE
273 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
274 $(common-objpfx)soversions.i \
276 $(wildcard $(add-ons:%=$(..)%/Versions.def))
277 { while read lib version setname; do \
278 test -z "$$setname" || echo "$$lib : $$setname"; \
279 done < $(word 2,$^); \
280 cat $(filter-out $< $(word 2,$^),$^) \
281 | $(preprocess-versions); \
282 } | LC_ALL=C $(AWK) -f $< > $@T
284 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
285 $(..)scripts/versions.awk \
286 $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
287 $(wildcard $(sysdirs:%=%/Versions)) \
288 $(sysd-versions-force)
289 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
290 cat $(filter-out $< $(word 2,$^) $(sysd-versions-force),$^) \
291 | $(preprocess-versions) \
292 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
293 -v move_if_change='$(move-if-change)' \
297 endif # avoid-generated
298 endif # $(versioning) = yes
299 endif # sysd-sorted-done
302 ifndef compile-command.S
303 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
305 ifndef compile-command.s
306 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
308 ifndef compile-command.c
309 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
312 # GCC can grok options after the file name, and it looks nicer that way.
313 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
315 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
317 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
318 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
320 # If we want to generate MD% checksums for the sources do this now.
322 generate-md5 = ; rm -f $(@:.d=.md5); \
323 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
324 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
329 # We need this for the output to go in the right place. It will default to
330 # empty if make was configured to work with a cc that can't grok -c and -o
331 # together. You can't compile the C library with such a compiler.
332 OUTPUT_OPTION = -o $@
334 S-CPPFLAGS = $(asm-CPPFLAGS)
336 $(make-target-directory)
338 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
340 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
341 $(sed-remove-objpfx) > $(@:.d=.T)
342 mv -f $(@:.d=.T) $@ $(generate-md5)
345 # Continuation lines here are dangerous because they introduce spaces!
346 define sed-remove-objpfx
347 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
348 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
352 # Modify the list of routines we build for different targets
354 ifeq (yes,$(build-shared))
355 ifndef libc.so-version
356 # Undefine this because it can't work when we libc.so is unversioned.
357 static-only-routines =
361 # Bounded pointer thunks are only built for *.ob
362 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
364 elide-routines.oS += $(filter-out $(static-only-routines),\
365 $(routines) $(aux) $(sysdep_routines)) \
367 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
369 # If we have versioned code we don't need the old versions in any of the
371 elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
372 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
373 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
374 elide-routines.ob += $(shared-only-routines)
376 # Shared library building.
378 ifeq (yes,$(build-shared))
380 # Reference map file only when versioning is selected and a map file name
382 ifeq ($(versioning),yes)
383 map-file = $(firstword $($(@F:.so=-map)) \
384 $(addprefix $(common-objpfx), \
385 $(filter $(@F:.so=.map),$(version-maps))))
386 load-map-file = $(map-file:%=-Wl,--version-script=%)
389 # Pattern rule to build a shared object from an archive of PIC objects.
390 # This must come after the installation rules so Make doesn't try to
391 # build shared libraries in place from the installed *_pic.a files.
392 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
393 # on other shared objects.
394 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
397 define build-shlib-helper
398 $(LINK.o) -shared -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
399 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
400 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
401 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
402 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
403 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
407 # binutils only position loadable notes into the first page for binaries,
408 # not for shared objects
410 $(build-shlib-helper) \
411 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
412 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
413 sed -e '/^=========/,/^=========/!d;/^=========/d' \
414 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
417 $(build-shlib-helper) -o $@ -T $@.lds \
418 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
423 $(build-shlib-helper) \
424 $(build-shlib-objlist)
428 define build-module-helper
429 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) \
430 -B$(csu-objpfx) $(load-map-file) \
431 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
432 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
435 # This macro is similar to build-shlib but it does not define a soname
436 # and it does not depend on the destination name to start with `lib'.
438 # binutils only position loadable notes into the first page for binaries,
439 # not for shared objects
441 $(build-module-helper) \
442 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
443 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
444 sed -e '/^=========/,/^=========/!d;/^=========/d' \
445 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
448 $(build-module-helper) -o $@ -T $@.lds \
449 $(csu-objpfx)abi-note.o $(build-module-objlist)
454 $(build-module-helper) \
456 $(build-module-objlist)
460 build-module-helper-objlist = \
461 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
462 $(filter-out $(map-file) $(+preinit) $(+postinit),$^))
463 whole-archive := -Wl,--whole-archive
465 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
466 build-shlib-objlist = $(build-module-helper-objlist) \
467 $(LDLIBS-$(@F:lib%.so=%).so)
469 # Don't try to use -lc when making libc.so itself.
470 # Also omits crti.o and crtn.o, which we do not want
471 # since we define our own `.init' section specially.
472 LDFLAGS-c.so = -nostdlib -nostartfiles
473 # But we still want to link libc.so against $(gnulib).
474 LDLIBS-c.so += $(gnulib)
475 # Give libc.so an entry point and make it directly runnable itself.
476 LDFLAGS-c.so += -e __libc_main
477 # Force the backward compatibility EH functions to be linked.
478 LDFLAGS-c.so += -u __register_frame
479 # Pre-link the objects of libc_pic.a so that we can locally resolve
480 # COMMON symbols before we link against ld.so. This is because ld.so
481 # contains some of libc_pic.a already, which will prevent the COMMONs
482 # from being allocated in libc.so, which introduces evil dependencies
483 # between libc.so and ld.so, which can make it impossible to upgrade.
484 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
485 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
486 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
487 # Use our own special initializer and finalizer files for libc.so.
488 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
489 $(common-objpfx)libc_pic.os \
490 $(elfobjdir)/sofini.os \
491 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
493 ifeq ($(versioning),yes)
494 $(common-objpfx)libc.so: $(common-objpfx)libc.map
496 common-generated += libc.so libc_pic.os
497 ifdef libc.so-version
498 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
500 common-generated += libc.so$(libc.so-version)
504 # Figure out the source filenames in this directory.
506 override sources := $(addsuffix .c,\
507 $(filter-out $(elided-routines),\
510 sysdep_routines := $(sysdep_routines)
512 headers := $(headers) $(sysdep_headers)
514 # This is the list of all object files, gotten by
515 # replacing every ".c" in `sources' with a ".o".
516 # We also add bounded-pointer thunks, which are later
517 # elided for all suffixes except for `.ob'.
518 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
519 $(patsubst %,$(bppfx)%.o,\
520 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
523 # The makefile may define $(extra-libs) with `libfoo libbar'
524 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
526 # extra-lib.mk is included once for each extra lib to define rules
527 # to build it, and to add its objects to the various variables.
528 # During its evaluation, $(lib) is set to the name of the library.
529 extra-libs-left := $(extra-libs)
530 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
533 +depfiles := $(sources:.c=.d) \
534 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
535 $(addsuffix .d,$(tests) $(test-srcs))
536 ifeq ($(build-programs),yes)
537 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
539 +depfiles := $(addprefix $(objpfx),\
540 $(filter-out $(addsuffix .d,$(omit-deps)),\
545 -include $(+depfiles)
549 # Maximize efficiency by minimizing the number of rules.
550 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
551 # Don't define any builtin rules.
552 MAKEFLAGS := $(MAKEFLAGS)r
554 # Generic rule for making directories.
556 # mkdir isn't smart enough to strip a trailing /.
559 # Make sure that object files are not removed
560 # when they are intermediates between sources and library members.
561 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
563 # Make sure that the parent library archive is never removed.
564 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
566 # Use the verbose option of ar and tar when not running silently.
567 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
573 ARFLAGS := r$(verbose)
574 CREATE_ARFLAGS := cru$(verbose)
576 # This makes all the object files in the parent library archive.
578 .PHONY: lib lib-noranlib
579 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
580 lib-noranlib: libobjs
582 # For object-suffix $o, the list of objects with that suffix.
583 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
584 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
585 $(elide-routines$o)),\
587 $(addprefix $(objpfx),$(o-objects$o))
589 others: $(addprefix $(objpfx),$(install-lib))
593 # Create the stamp$o files to keep the parent makefile happy.
594 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
595 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
596 $(make-target-directory)
600 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
601 # timestamp file; these rules (one explicit rule is generated for each
602 # object suffix) write a list of objects to update in the stamp file.
603 # The parent will then actually add them all to the archive in the
604 # archive rule, below.
605 define o-iterator-doit
606 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
609 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
612 object-suffixes-left := $(object-suffixes-for-libc)
613 include $(o-iterator)
617 # Now define explicit rules to build the library archives; these depend
618 # on the stamp files built above.
619 define o-iterator-doit
620 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
621 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
624 cd $(common-objdir) && \
625 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
628 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
629 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
631 $(subdirs-stamps): subdir_lib;
633 object-suffixes-left = $(object-suffixes-for-libc)
634 include $(o-iterator)
637 # This makes all the object files.
638 .PHONY: objects objs libobjs extra-objs
639 objects objs: libobjs extra-objs
640 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
641 extra-objs: $(addprefix $(objpfx),$(extra-objs))
643 # Canned sequence for building an extra library archive.
644 define build-extra-lib
645 $(patsubst %/,cd % &&,$(objpfx)) \
646 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
647 $(patsubst $(objpfx)%,%,$^)
653 .PHONY: force-install
656 # $(install-lib) are installed from the object directory into $(libdir);
657 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
658 # unless they also appear in $(non-lib.a). $(install-data) are installed
659 # as they are into $(datadir). $(headers) are installed as they are in
660 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
661 # object directory into $(bindir) and $(sbindir), respectively.
662 # $(install-others) are absolute path names of files to install; rules to
663 # install them are defined elsewhere.
665 # The simple library name to install libc.a under.
666 # This could be defined by a sysdep Makefile.
672 $(make-target-directory)
673 $(INSTALL_DATA) $< $@
676 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
677 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
678 define make-target-directory
679 $(addprefix $(..)./scripts/mkinstalldirs ,\
680 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
683 # Any directory (parent or subdir) should install libc.a; this way
684 # "make install" in a subdir is guaranteed to install everything it changes.
685 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
686 $(inst_libdir)/$(patsubst %,$(libtype$o),\
687 $(libprefix)$(libc-name)))
688 install: $(installed-libcs)
689 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
690 $(make-target-directory)
691 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
692 # Running ranlib after installing makes the __.SYMDEF time stamp up to
693 # date, which avoids messages from some linkers.
696 define do-install-program
697 $(make-target-directory)
698 $(INSTALL_PROGRAM) $< $@.new
702 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
703 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
705 ifeq (yes,$(build-shared))
706 # Find which .so's have versions.
707 versioned := $(strip $(foreach so,$(install-lib.so),\
708 $(patsubst %,$(so),$($(so)-version))))
710 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
711 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
713 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
714 $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
716 # Install all the unversioned shared libraries.
717 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
718 $(objpfx)%.so $(+force)
719 $(do-install-program)
721 ifneq ($(findstring -s,$(LN_S)),)
724 $(SHELL) $(..)scripts/rellns-sh $< $@.new
728 # If we have no symbolic links don't bother with rellns-sh.
736 ifeq (yes,$(build-shared))
737 ifeq (no,$(cross-compiling))
738 symbolic-link-prog := $(common-objpfx)elf/sln
739 symbolic-link-list := $(common-objpfx)elf/symlink.list
740 define make-shlib-link
741 echo $(<F) $@ >> $(symbolic-link-list)
743 else # cross-compiling
744 # We need a definition that can be used by elf/Makefile's install rules.
745 symbolic-link-prog = $(LN_S)
748 ifndef make-shlib-link
749 define make-shlib-link
755 ifdef libc.so-version
756 # For a library specified to be version N, install three files:
757 # libc.so -> libc.so.N (e.g. libc.so.6)
758 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
760 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
763 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
764 $(do-install-program)
765 install: $(inst_slibdir)/libc.so$(libc.so-version)
768 # What we install as libc.so for programs to link against is in fact a
769 # link script. It contains references for the various libraries we need.
770 # The libc.so object is not complete since some functions are only defined
771 # in libc_nonshared.a.
772 # We need to use absolute paths since otherwise local copies (if they exist)
773 # of the files are taken by the linker.
774 install: $(inst_libdir)/libc.so
775 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
776 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
777 $(libprefix)$(libc-name)) \
779 (echo '/* GNU ld script';\
780 echo ' Use the shared library, but some functions are only in';\
781 echo ' the static library, so try that secondarily. */';\
782 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
783 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
791 install: $(inst_slibdir)/libc.so
792 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
793 $(do-install-program)
796 ifneq (,$(versioned))
797 # Produce three sets of rules as above for all the smaller versioned libraries.
799 define o-iterator-doit
800 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
802 object-suffixes-left := $(versioned)
803 include $(o-iterator)
805 # Make symlinks in the build directory, because the versioned names might
806 # be referenced by a DT_NEEDED in another library.
807 define o-iterator-doit
808 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
810 object-suffixes-left := $(versioned)
811 include $(o-iterator)
813 generated += $(foreach o,$(versioned),$o$($o-version))
815 ifeq (,$($(subdir)-version))
816 define o-iterator-doit
817 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
821 object-suffixes-left := $(versioned)
822 include $(o-iterator)
824 define o-iterator-doit
825 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
826 $$(do-install-program)
828 object-suffixes-left := $(versioned)
829 include $(o-iterator)
831 define o-iterator-doit
832 $(inst_slibdir)/$o$($o-version): \
833 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
836 object-suffixes-left := $(versioned)
837 include $(o-iterator)
839 define o-iterator-doit
840 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
841 $$(do-install-program)
843 object-suffixes-left := $(versioned)
844 include $(o-iterator)
849 $(do-install-program)
850 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
851 $(filter-out %.so,$@))
854 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
855 $(foreach v,$(so-versions),\
856 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
859 $(foreach v,$(so-versions),\
860 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
865 $(addprefix $(inst_bindir)/,$(install-bin)): \
866 $(inst_bindir)/%: $(objpfx)% $(+force)
867 $(do-install-program)
869 ifdef install-rootsbin
870 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
871 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
872 $(do-install-program)
875 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
876 $(inst_sbindir)/%: $(objpfx)% $(+force)
877 $(do-install-program)
880 install-lib.a := $(filter lib%.a,$(install-lib))
881 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
882 ifdef install-lib-non.a
883 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
884 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
888 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
889 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
891 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
895 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
898 headers := $(strip $(headers))
900 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
904 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
905 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
906 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
907 install-rootsbin-nosubdir: \
908 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
909 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
910 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
911 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
912 $(addprefix $(libprefix),$(install-lib-non.a)))
913 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
914 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
915 install-others-nosubdir: $(install-others)
917 # We need all the `-nosubdir' targets so that `install' in the parent
918 # doesn't depend on several things which each iterate over the subdirs.
919 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
920 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
921 install-%:: install-%-nosubdir ;
923 .PHONY: install install-no-libc.a-nosubdir
924 ifeq ($(build-programs),yes)
925 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
926 install-bin-nosubdir install-lib-nosubdir \
927 install-others-nosubdir install-rootsbin-nosubdir \
928 install-sbin-nosubdir
930 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
931 install-lib-nosubdir install-others-nosubdir
933 install: install-no-libc.a-nosubdir
935 # Command to compile $< in $(objdir) using the native libraries.
936 define native-compile
937 $(make-target-directory)
938 $(patsubst %/,cd % &&,$(objpfx)) \
939 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
940 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
943 # Command to compile $< in $(common-objdir) using the native libraries.
944 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
945 define common-objdir-compile
946 $(patsubst %/,cd % &&,$(objpfx)) \
947 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
948 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
951 # We always want to use configuration definitions.
952 # Note that this is only used for commands running in $(objpfx).
953 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
955 # Support the GNU standard name for this target.
960 TAGS: $(objpfx)distinfo $(..)MakeTAGS
961 $(MAKE) $(addprefix -f ,$^) $@
963 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
964 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
973 # Common cleaning targets.
975 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
977 mostlyclean: common-mostlyclean
980 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(test-srcs)) \
981 $(addsuffix -bp.out,$(tests) $(test-srcs)))
983 # Remove the object files.
985 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
986 $(sysdep-others) stubs \
987 $(addsuffix .o,$(tests) $(test-srcs) \
990 $(addsuffix -bp,$(tests) $(test-srcs)) \
991 $(addsuffix .out,$(tests) $(test-srcs)) \
992 $(addsuffix -bp.out,$(tests) $(test-srcs)))
993 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
995 $(install-lib.so:%.so=%_pic.a))
999 $(foreach o,$(object-suffixes-for-libc),
1000 -rm -f $(objpfx)stamp$o $(o-objects))
1003 # Also remove the dependencies and generated source files.
1004 common-clean: common-mostlyclean
1005 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
1006 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1007 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1008 -rm -f $(objpfx)distinfo
1010 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1011 # for each function which is a stub. We grovel over all the .d files
1012 # looking for references to <stub-tag.h>. Then we grovel over each
1013 # referenced source file to see what stub function it defines.
1016 .PHONY: stubs # The parent Makefile calls this target.
1017 stubs: $(objpfx)stubs
1019 s = $(sysdep_dir)/generic
1020 $(objpfx)stubs: $(+depfiles)
1021 # Use /dev/null since `...` might expand to empty.
1022 (s=`cd $s && $(PWD_P)`; \
1023 $(patsubst %/,cd % &&,$(objpfx)) \
1024 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1025 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
1026 -e '/stub-tag\.h/{; g; p; }' \
1027 $(patsubst $(objpfx)%,%,$^) /dev/null` \
1031 # Make the distribution tar file.
1034 dist: $(objpfx)distinfo $(..)Make-dist
1035 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1037 # Avoid depending on source files found in sysdeps dirs,
1038 # because the references affect implicit rule selection.
1039 dist: $(filter-out %.c %.S %.s,$(distribute))
1041 # We used to simply export all these variables, but that frequently made the
1042 # environment get too large. Instead, we write all the information into
1043 # a generated makefile fragment `distinfo', and then include it with -f in
1044 # the sub-make that makes the distribution (above).
1045 $(objpfx)distinfo: Makefile $(..)Makerules \
1046 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1047 $(make-target-directory)
1050 .PHONY: subdir_distinfo
1051 subdir_distinfo: $(objpfx)distinfo
1053 define distinfo-vars
1055 echo > $@.new 'subdir := $(subdir)'
1056 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1057 headers sysdep_headers distribute dont_distribute generated \
1058 others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
1060 $(addprefix install-,lib lib.so data bin sbin others),
1061 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1062 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1065 ifneq (,$(strip $(gpl2lgpl)))
1066 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1067 # Snarf from the master source and frob the copying notice.
1068 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1070 # So I don't edit them by mistake.
1073 ifeq ($(with-cvs),yes)
1074 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@