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
120 endif # avoid-generated
121 endif # $(versioning) = yes
124 # Remove existing files from `before-compile'. Things are added there when
125 # they must exist for dependency generation to work right, but once they
126 # exist there is no further need for every single file to depend on them,
127 # and those gratuitous dependencies result in many gratuitous
129 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
131 # Don't let any before-compile file be an intermediate and get removed.
136 # Generate an ordered list of implicit rules which find the source files in
137 # each sysdep directory. The old method was to use vpath to search all the
138 # sysdep directories. However, that had the problem that a .S file in a
139 # later directory would be chosen over a .c file in an earlier directory,
140 # which does not preserve the desired sysdeps ordering behavior.
142 # When making the list of .d files to include, we can't know which ones
143 # have source in .s files, and thus do not in fact need a .d file.
144 # So we must define rules to make .d files for .s files.
145 define make-dummy-dep
146 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
148 $(common-objpfx)dummy.d:
149 echo '# .s files cannot contain includes, so they need no deps.' > $@
151 # It matters that this set of rules, for compiling from sources in
152 # the current directory (the $srcdir/$subdir) come before the
153 # generated sysdep rules in included from sysd-rules below. When
154 # compiling in the source tree, generated sources go into the current
155 # directory, and those should be chosen before any sources in sysdeps.
156 define o-iterator-doit
157 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
159 object-suffixes-left := $(all-object-suffixes)
160 include $(o-iterator)
161 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
163 define o-iterator-doit
164 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
166 object-suffixes-left := $(all-object-suffixes)
167 include $(o-iterator)
168 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
170 define o-iterator-doit
171 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
173 object-suffixes-left := $(all-object-suffixes)
174 include $(o-iterator)
175 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
177 # Omit the objpfx rules when building in the source tree, because
178 # objpfx is empty and so these rules just override the ones above.
180 # Define first rules to find the source files in $(objpfx).
181 # Generated source files will end up there.
182 define o-iterator-doit
183 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
185 object-suffixes-left := $(all-object-suffixes)
186 include $(o-iterator)
187 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
189 define o-iterator-doit
190 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
192 object-suffixes-left := $(all-object-suffixes)
193 include $(o-iterator)
194 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
196 define o-iterator-doit
197 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
199 object-suffixes-left := $(all-object-suffixes)
200 include $(o-iterator)
201 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
204 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
205 # patterns matching sysdep directories whose assembly source files should
207 ifdef inhibit-sysdep-asm
208 define open-check-inhibit-asm
209 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
211 close-check-inhibit-asm = ;; esac ;
214 -include $(+sysdir_pfx)sysd-rules
215 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
216 # The value of $(+sysdep_dirs) the sysd-rules was computed for
217 # differs from the one we are using now. So force a rebuild of sysd-rules.
218 sysd-rules-force = FORCE
221 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
222 $(wildcard $(foreach dir,$(sysdirs),\
226 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
227 for dir in $(config-sysdirs:%='$$(..)%'); do \
228 for o in $(all-object-suffixes); do \
229 $(open-check-inhibit-asm) \
230 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
231 \$$(compile-command.S)"; \
232 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
233 \$$(compile-command.s)"; \
234 $(close-check-inhibit-asm) \
235 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
236 \$$(compile-command.c)"; \
238 $(open-check-inhibit-asm) \
239 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
240 \$$(make-dummy-dep)"; \
241 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
243 $(close-check-inhibit-asm) \
244 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
247 echo 'sysd-rules-done = t') > $@T
250 ifndef sysd-rules-done
251 # Don't do deps until this exists, because it provides rules to make the deps.
255 # Generate version maps, but wait until sysdep-subdirs is known
256 ifeq ($(sysd-sorted-done),t)
257 ifeq ($(versioning),yes)
258 -include $(common-objpfx)sysd-versions
259 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
260 common-generated += $(version-maps)
261 postclean-generated += sysd-versions Versions.all abi-versions.h
263 ifndef avoid-generated
264 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
265 sysd-versions-force = FORCE
268 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
269 $(common-objpfx)soversions.i \
271 $(wildcard $(add-ons:%=$(..)%/Versions.def))
272 { while read lib version setname; do \
273 test -z "$$setname" || echo "$$lib : $$setname"; \
274 done < $(word 2,$^); \
275 cat $(filter-out $< $(word 2,$^),$^) \
276 | $(preprocess-versions); \
277 } | LC_ALL=C $(AWK) -f $< > $@T
279 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
280 $(..)scripts/versions.awk \
281 $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
282 $(wildcard $(sysdirs:%=%/Versions)) \
283 $(sysd-versions-force)
284 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
285 cat $(filter-out $< $(word 2,$^) $(sysd-versions-force),$^) \
286 | $(preprocess-versions) \
287 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
288 -v move_if_change='$(move-if-change)' \
292 endif # avoid-generated
293 endif # $(versioning) = yes
294 endif # sysd-sorted-done
297 ifndef compile-command.S
298 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
300 ifndef compile-command.s
301 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
303 ifndef compile-command.c
304 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
307 # GCC can grok options after the file name, and it looks nicer that way.
308 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
310 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
312 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
313 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
315 # If we want to generate MD% checksums for the sources do this now.
317 generate-md5 = ; rm -f $(@:.d=.md5); \
318 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
319 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
324 # We need this for the output to go in the right place. It will default to
325 # empty if make was configured to work with a cc that can't grok -c and -o
326 # together. You can't compile the C library with such a compiler.
327 OUTPUT_OPTION = -o $@
329 S-CPPFLAGS = $(asm-CPPFLAGS)
331 $(make-target-directory)
333 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
335 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
336 $(sed-remove-objpfx) > $(@:.d=.T)
337 mv -f $(@:.d=.T) $@ $(generate-md5)
340 # Continuation lines here are dangerous because they introduce spaces!
341 define sed-remove-objpfx
342 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
343 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
347 # Modify the list of routines we build for different targets
349 ifeq (yes,$(build-shared))
350 ifndef libc.so-version
351 # Undefine this because it can't work when we libc.so is unversioned.
352 static-only-routines =
356 # Bounded pointer thunks are only built for *.ob
357 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
359 elide-routines.oS += $(filter-out $(static-only-routines),\
360 $(routines) $(aux) $(sysdep_routines)) \
362 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
364 # If we have versioned code we don't need the old versions in any of the
366 elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
367 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
368 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
369 elide-routines.ob += $(shared-only-routines)
371 # Shared library building.
373 ifeq (yes,$(build-shared))
375 # Reference map file only when versioning is selected and a map file name
377 ifeq ($(versioning),yes)
378 map-file = $(firstword $($(@F:.so=-map)) \
379 $(addprefix $(common-objpfx), \
380 $(filter $(@F:.so=.map),$(version-maps))))
381 load-map-file = $(map-file:%=-Wl,--version-script=%)
384 # Pattern rule to build a shared object from an archive of PIC objects.
385 # This must come after the installation rules so Make doesn't try to
386 # build shared libraries in place from the installed *_pic.a files.
387 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
388 # on other shared objects.
389 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
392 define build-shlib-helper
393 $(LINK.o) -shared -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
394 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
395 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
396 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
397 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
398 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
402 # binutils only position loadable notes into the first page for binaries,
403 # not for shared objects
405 $(build-shlib-helper) \
406 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
407 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
408 sed -e '/^=========/,/^=========/!d;/^=========/d' \
409 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
412 $(build-shlib-helper) -o $@ -T $@.lds \
413 -Wl,--whole-archive $(csu-objpfx)abi-note.o \
414 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
415 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
420 $(build-shlib-helper) \
421 -o $@ -Wl,--whole-archive \
422 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
423 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
427 define build-module-helper
428 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) \
429 -B$(csu-objpfx) $(load-map-file) \
430 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
431 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
434 # This macro is similar to build-shlib but it does not define a soname
435 # and it does not depend on the destination name to start with `lib'.
437 # binutils only position loadable notes into the first page for binaries,
438 # not for shared objects
440 $(build-module-helper) \
441 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
442 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
443 sed -e '/^=========/,/^=========/!d;/^=========/d' \
444 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
447 $(build-module-helper) -o $@ -T $@.lds \
448 -Wl,--whole-archive $(csu-objpfx)abi-note.o \
449 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
450 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
455 $(build-module-helper) \
456 -o $@ -Wl,--whole-archive \
457 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
458 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
462 # Don't try to use -lc when making libc.so itself.
463 # Also omits crti.o and crtn.o, which we do not want
464 # since we define our own `.init' section specially.
465 LDFLAGS-c.so = -nostdlib -nostartfiles
466 # But we still want to link libc.so against $(gnulib).
467 LDLIBS-c.so += $(gnulib)
468 # Give libc.so an entry point and make it directly runnable itself.
469 LDFLAGS-c.so += -e __libc_main
470 # Force the backward compatibility EH functions to be linked.
471 LDFLAGS-c.so += -u __register_frame
472 # Pre-link the objects of libc_pic.a so that we can locally resolve
473 # COMMON symbols before we link against ld.so. This is because ld.so
474 # contains some of libc_pic.a already, which will prevent the COMMONs
475 # from being allocated in libc.so, which introduces evil dependencies
476 # between libc.so and ld.so, which can make it impossible to upgrade.
477 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
478 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
479 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
480 # Use our own special initializer and finalizer files for libc.so.
481 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
482 $(common-objpfx)libc_pic.os \
483 $(elfobjdir)/sofini.os \
484 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
486 ifeq ($(versioning),yes)
487 $(common-objpfx)libc.so: $(common-objpfx)libc.map
489 common-generated += libc.so libc_pic.os
490 ifdef libc.so-version
491 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
493 common-generated += libc.so$(libc.so-version)
497 # Figure out the source filenames in this directory.
499 override sources := $(addsuffix .c,\
500 $(filter-out $(elided-routines),\
503 sysdep_routines := $(sysdep_routines)
505 headers := $(headers) $(sysdep_headers)
507 # This is the list of all object files, gotten by
508 # replacing every ".c" in `sources' with a ".o".
509 # We also add bounded-pointer thunks, which are later
510 # elided for all suffixes except for `.ob'.
511 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
512 $(patsubst %,$(bppfx)%.o,\
513 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
516 # The makefile may define $(extra-libs) with `libfoo libbar'
517 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
519 # extra-lib.mk is included once for each extra lib to define rules
520 # to build it, and to add its objects to the various variables.
521 # During its evaluation, $(lib) is set to the name of the library.
522 extra-libs-left := $(extra-libs)
523 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
526 +depfiles := $(sources:.c=.d) \
527 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
528 $(addsuffix .d,$(tests) $(test-srcs))
529 ifeq ($(build-programs),yes)
530 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
532 +depfiles := $(addprefix $(objpfx),\
533 $(filter-out $(addsuffix .d,$(omit-deps)),\
538 -include $(+depfiles)
542 # Maximize efficiency by minimizing the number of rules.
543 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
544 # Don't define any builtin rules.
545 MAKEFLAGS := $(MAKEFLAGS)r
547 # Generic rule for making directories.
549 # mkdir isn't smart enough to strip a trailing /.
552 # Make sure that object files are not removed
553 # when they are intermediates between sources and library members.
554 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
556 # Make sure that the parent library archive is never removed.
557 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
559 # Use the verbose option of ar and tar when not running silently.
560 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
566 ARFLAGS := r$(verbose)
567 CREATE_ARFLAGS := cru$(verbose)
569 # This makes all the object files in the parent library archive.
571 .PHONY: lib lib-noranlib
572 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
573 lib-noranlib: libobjs
575 # For object-suffix $o, the list of objects with that suffix.
576 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
577 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
578 $(elide-routines$o)),\
580 $(addprefix $(objpfx),$(o-objects$o))
582 others: $(addprefix $(objpfx),$(install-lib))
586 # Create the stamp$o files to keep the parent makefile happy.
587 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
588 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
589 $(make-target-directory)
593 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
594 # timestamp file; these rules (one explicit rule is generated for each
595 # object suffix) write a list of objects to update in the stamp file.
596 # The parent will then actually add them all to the archive in the
597 # archive rule, below.
598 define o-iterator-doit
599 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
602 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
605 object-suffixes-left := $(object-suffixes-for-libc)
606 include $(o-iterator)
610 # Now define explicit rules to build the library archives; these depend
611 # on the stamp files built above.
612 define o-iterator-doit
613 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
614 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
617 cd $(common-objdir) && \
618 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
621 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
622 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
624 $(subdirs-stamps): subdir_lib;
626 object-suffixes-left = $(object-suffixes-for-libc)
627 include $(o-iterator)
630 # This makes all the object files.
631 .PHONY: objects objs libobjs extra-objs
632 objects objs: libobjs extra-objs
633 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
634 extra-objs: $(addprefix $(objpfx),$(extra-objs))
636 # Canned sequence for building an extra library archive.
637 define build-extra-lib
638 $(patsubst %/,cd % &&,$(objpfx)) \
639 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
640 $(patsubst $(objpfx)%,%,$^)
646 .PHONY: force-install
649 # $(install-lib) are installed from the object directory into $(libdir);
650 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
651 # unless they also appear in $(non-lib.a). $(install-data) are installed
652 # as they are into $(datadir). $(headers) are installed as they are in
653 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
654 # object directory into $(bindir) and $(sbindir), respectively.
655 # $(install-others) are absolute path names of files to install; rules to
656 # install them are defined elsewhere.
658 # The simple library name to install libc.a under.
659 # This could be defined by a sysdep Makefile.
665 $(make-target-directory)
666 $(INSTALL_DATA) $< $@
669 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
670 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
671 define make-target-directory
672 $(addprefix $(..)./scripts/mkinstalldirs ,\
673 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
676 # Any directory (parent or subdir) should install libc.a; this way
677 # "make install" in a subdir is guaranteed to install everything it changes.
678 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
679 $(inst_libdir)/$(patsubst %,$(libtype$o),\
680 $(libprefix)$(libc-name)))
681 install: $(installed-libcs)
682 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
683 $(make-target-directory)
684 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
685 # Running ranlib after installing makes the __.SYMDEF time stamp up to
686 # date, which avoids messages from some linkers.
689 define do-install-program
690 $(make-target-directory)
691 $(INSTALL_PROGRAM) $< $@.new
695 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
696 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
698 ifeq (yes,$(build-shared))
699 # Find which .so's have versions.
700 versioned := $(strip $(foreach so,$(install-lib.so),\
701 $(patsubst %,$(so),$($(so)-version))))
703 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
704 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
706 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
707 $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
709 # Install all the unversioned shared libraries.
710 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
711 $(objpfx)%.so $(+force)
712 $(do-install-program)
714 ifneq ($(findstring -s,$(LN_S)),)
717 $(SHELL) $(..)scripts/rellns-sh $< $@.new
721 # If we have no symbolic links don't bother with rellns-sh.
729 ifeq (yes,$(build-shared))
730 ifeq (no,$(cross-compiling))
731 symbolic-link-prog := $(common-objpfx)elf/sln
732 symbolic-link-list := $(common-objpfx)elf/symlink.list
733 define make-shlib-link
734 echo $(<F) $@ >> $(symbolic-link-list)
736 else # cross-compiling
737 # We need a definition that can be used by elf/Makefile's install rules.
738 symbolic-link-prog = $(LN_S)
741 ifndef make-shlib-link
742 define make-shlib-link
748 ifdef libc.so-version
749 # For a library specified to be version N, install three files:
750 # libc.so -> libc.so.N (e.g. libc.so.6)
751 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
753 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
756 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
757 $(do-install-program)
758 install: $(inst_slibdir)/libc.so$(libc.so-version)
761 # What we install as libc.so for programs to link against is in fact a
762 # link script. It contains references for the various libraries we need.
763 # The libc.so object is not complete since some functions are only defined
764 # in libc_nonshared.a.
765 # We need to use absolute paths since otherwise local copies (if they exist)
766 # of the files are taken by the linker.
767 install: $(inst_libdir)/libc.so
768 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
769 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
770 $(libprefix)$(libc-name)) \
772 (echo '/* GNU ld script';\
773 echo ' Use the shared library, but some functions are only in';\
774 echo ' the static library, so try that secondarily. */';\
775 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
776 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
784 install: $(inst_slibdir)/libc.so
785 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
786 $(do-install-program)
789 ifneq (,$(versioned))
790 # Produce three sets of rules as above for all the smaller versioned libraries.
792 define o-iterator-doit
793 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
795 object-suffixes-left := $(versioned)
796 include $(o-iterator)
798 # Make symlinks in the build directory, because the versioned names might
799 # be referenced by a DT_NEEDED in another library.
800 define o-iterator-doit
801 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
803 object-suffixes-left := $(versioned)
804 include $(o-iterator)
806 generated += $(foreach o,$(versioned),$o$($o-version))
808 ifeq (,$($(subdir)-version))
809 define o-iterator-doit
810 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
814 object-suffixes-left := $(versioned)
815 include $(o-iterator)
817 define o-iterator-doit
818 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
819 $$(do-install-program)
821 object-suffixes-left := $(versioned)
822 include $(o-iterator)
824 define o-iterator-doit
825 $(inst_slibdir)/$o$($o-version): \
826 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
829 object-suffixes-left := $(versioned)
830 include $(o-iterator)
832 define o-iterator-doit
833 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
834 $$(do-install-program)
836 object-suffixes-left := $(versioned)
837 include $(o-iterator)
842 $(do-install-program)
843 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
844 $(filter-out %.so,$@))
847 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
848 $(foreach v,$(so-versions),\
849 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
852 $(foreach v,$(so-versions),\
853 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
858 $(addprefix $(inst_bindir)/,$(install-bin)): \
859 $(inst_bindir)/%: $(objpfx)% $(+force)
860 $(do-install-program)
862 ifdef install-rootsbin
863 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
864 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
865 $(do-install-program)
868 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
869 $(inst_sbindir)/%: $(objpfx)% $(+force)
870 $(do-install-program)
873 install-lib.a := $(filter lib%.a,$(install-lib))
874 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
875 ifdef install-lib-non.a
876 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
877 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
881 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
882 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
884 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
888 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
891 headers := $(strip $(headers))
893 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
897 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
898 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
899 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
900 install-rootsbin-nosubdir: \
901 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
902 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
903 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
904 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
905 $(addprefix $(libprefix),$(install-lib-non.a)))
906 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
907 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
908 install-others-nosubdir: $(install-others)
910 # We need all the `-nosubdir' targets so that `install' in the parent
911 # doesn't depend on several things which each iterate over the subdirs.
912 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
913 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
914 install-%:: install-%-nosubdir ;
916 .PHONY: install install-no-libc.a-nosubdir
917 ifeq ($(build-programs),yes)
918 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
919 install-bin-nosubdir install-lib-nosubdir \
920 install-others-nosubdir install-rootsbin-nosubdir \
921 install-sbin-nosubdir
923 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
924 install-lib-nosubdir install-others-nosubdir
926 install: install-no-libc.a-nosubdir
928 # Command to compile $< in $(objdir) using the native libraries.
929 define native-compile
930 $(make-target-directory)
931 $(patsubst %/,cd % &&,$(objpfx)) \
932 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
933 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
936 # Command to compile $< in $(common-objdir) using the native libraries.
937 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
938 define common-objdir-compile
939 $(patsubst %/,cd % &&,$(objpfx)) \
940 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
941 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
944 # We always want to use configuration definitions.
945 # Note that this is only used for commands running in $(objpfx).
946 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
948 # Support the GNU standard name for this target.
953 TAGS: $(objpfx)distinfo $(..)MakeTAGS
954 $(MAKE) $(addprefix -f ,$^) $@
956 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
957 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
966 # Common cleaning targets.
968 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
970 mostlyclean: common-mostlyclean
973 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(test-srcs)) \
974 $(addsuffix -bp.out,$(tests) $(test-srcs)))
976 # Remove the object files.
978 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
979 $(sysdep-others) stubs \
980 $(addsuffix .o,$(tests) $(test-srcs) \
983 $(addsuffix -bp,$(tests) $(test-srcs)) \
984 $(addsuffix .out,$(tests) $(test-srcs)) \
985 $(addsuffix -bp.out,$(tests) $(test-srcs)))
986 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
988 $(install-lib.so:%.so=%_pic.a))
992 $(foreach o,$(object-suffixes-for-libc),
993 -rm -f $(objpfx)stamp$o $(o-objects))
996 # Also remove the dependencies and generated source files.
997 common-clean: common-mostlyclean
998 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
999 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1000 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1001 -rm -f $(objpfx)distinfo
1003 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1004 # for each function which is a stub. We grovel over all the .d files
1005 # looking for references to <stub-tag.h>. Then we grovel over each
1006 # referenced source file to see what stub function it defines.
1009 .PHONY: stubs # The parent Makefile calls this target.
1010 stubs: $(objpfx)stubs
1012 s = $(sysdep_dir)/generic
1013 $(objpfx)stubs: $(+depfiles)
1014 # Use /dev/null since `...` might expand to empty.
1015 (s=`cd $s && $(PWD_P)`; \
1016 $(patsubst %/,cd % &&,$(objpfx)) \
1017 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1018 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
1019 -e '/stub-tag\.h/{; g; p; }' \
1020 $(patsubst $(objpfx)%,%,$^) /dev/null` \
1024 # Make the distribution tar file.
1027 dist: $(objpfx)distinfo $(..)Make-dist
1028 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1030 # Avoid depending on source files found in sysdeps dirs,
1031 # because the references affect implicit rule selection.
1032 dist: $(filter-out %.c %.S %.s,$(distribute))
1034 # We used to simply export all these variables, but that frequently made the
1035 # environment get too large. Instead, we write all the information into
1036 # a generated makefile fragment `distinfo', and then include it with -f in
1037 # the sub-make that makes the distribution (above).
1038 $(objpfx)distinfo: Makefile $(..)Makerules \
1039 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1040 $(make-target-directory)
1043 .PHONY: subdir_distinfo
1044 subdir_distinfo: $(objpfx)distinfo
1046 define distinfo-vars
1048 echo > $@.new 'subdir := $(subdir)'
1049 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1050 headers sysdep_headers distribute dont_distribute generated \
1051 others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
1053 $(addprefix install-,lib lib.so data bin sbin others),
1054 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1055 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1058 ifneq (,$(strip $(gpl2lgpl)))
1059 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1060 # Snarf from the master source and frob the copying notice.
1061 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1063 # So I don't edit them by mistake.
1066 ifeq ($(with-cvs),yes)
1067 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@