1 # Copyright (C) 1991-2016 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 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.
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.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <http://www.gnu.org/licenses/>.
19 # Common rules for making the GNU C library. This file is included
20 # by the top-level Makefile and by all subdirectory makefiles
24 This makefile requires GNU Make.
27 REQUIRED_MAKE_VERSION = 3.74
28 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
30 ifneq ($(REQUIRED_MAKE_VERSION), \
31 $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
32 Wrong GNU Make version. See above for the version needed.
40 # If `sources' was defined by the parent makefile, undefine it so
41 # we will later get it from wildcard search in this directory.
42 ifneq "$(findstring env,$(origin sources))" ""
47 PATH := this definition should take precedence over $(oPATH)
48 ifeq ($(PATH),$(oPATH))
49 You must not use the -e flag when building the GNU C library.
54 ifndef +included-Makeconfig
55 include $(..)Makeconfig
58 # This variable is used in ``include $(o-iterator)'' after defining
59 # $(o-iterator-doit) to produce some desired rule using $o for the object
60 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
61 # is produced for each object suffix in use.
62 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
64 # Include any system-specific makefiles.
66 # This is here so things in sysdep Makefiles can easily depend on foo.h as
67 # appropriate and not worry about where foo.h comes from, which may be
68 # system dependent and not known by that Makefile.
69 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
70 $(+sysdep_dirs) $(..)))
72 # The same is true for RPC source files.
73 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
74 $(+sysdep_dirs) $(..)))
76 # Some sysdep makefiles use this to distinguish being included here from
77 # being included individually by a subdir makefile (hurd/Makefile needs this).
80 sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
81 ifneq (,$(sysdep-makefiles))
82 include $(sysdep-makefiles)
86 # Reorder before-compile so that mach things come first, and hurd things
87 # second, before all else. The mach and hurd subdirectories have many
88 # generated header files which the much of rest of the library depends on,
89 # so it is best to build them first (and mach before hurd, at that).
90 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
92 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
95 # Even before that, we need abi-versions.h which is generated right here.
96 ifeq ($(build-shared),yes)
97 ifndef avoid-generated
98 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
99 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
100 $(common-objpfx)Versions.all
101 LC_ALL=C $(AWK) -f $^ > $@T
104 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
105 sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
106 $(common-objpfx)abi-versions.h > $@T
108 endif # avoid-generated
109 endif # $(build-shared) = yes
111 ifndef avoid-generated
112 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
113 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
114 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
115 $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
119 $(base-machine)-$(config-vendor)-$(config-os) \
120 < $(word 2,$^) > $(@:.stamp=.h)T
121 $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
123 common-generated += $(common-objpfx)libc-abis.h
124 endif # avoid-generated
126 ifeq (yes,$(build-shared))
127 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
128 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
129 $(make-target-directory)
130 echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
132 $(move-if-change) ${@:stamp=T} ${@:stamp=h}
136 # Make sure the subdirectory for object files gets created.
138 ifeq (,$(wildcard $(objpfx).))
139 before-compile += $(objpfx).
141 $(make-target-directory)
145 # Remove existing files from `before-compile'. Things are added there when
146 # they must exist for dependency generation to work right, but once they
147 # exist there is no further need for every single file to depend on them,
148 # and those gratuitous dependencies result in many gratuitous
150 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
152 # Don't let any before-compile file be an intermediate and get removed.
157 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
160 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
162 common-before-compile = $(before-compile)
166 # If a makefile needs to do something conditional on something that
167 # can only be figured out from headers, write a FOO.make.c input
168 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
169 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
171 # We only generate these in the top-level makefile, to avoid any weirdness
172 # from subdir-specific makefile tweaks creeping in on an update.
173 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
175 (echo '# Generated from $*.make.c by Makerules.'; \
176 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
177 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
178 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
179 echo 'common-generated += $(@F)'; \
180 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
186 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
187 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
189 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
190 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
194 ifdef gen-as-const-headers
195 # Generating headers for assembly constants.
196 # We need this defined early to get into before-compile before
197 # it's used in sysd-rules, below.
198 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
199 %.sym $(common-before-compile)
200 $(AWK) -f $< $(filter %.sym,$^) \
201 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
202 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
203 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
204 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
206 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
207 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
209 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
210 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
211 vpath %.sym $(sysdirs)
212 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
214 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
215 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
216 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
217 %.sym $(common-objpfx)%.h
218 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
219 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
220 echo '#include "$(..)test-skeleton.c"') > $@T
224 ifeq (yes,$(build-shared))
225 # Generate the header containing the names of all shared libraries.
226 # We use a stamp file to avoid unnecessary recompilations.
227 before-compile += $(common-objpfx)gnu/lib-names.h
228 ifeq ($(soversions.mk-done),t)
230 lib-names-h-abi = gnu/lib-names.h
231 lib-names-stmp-abi = gnu/lib-names.stmp
233 lib-names-h-abi = gnu/lib-names-$(default-abi).h
234 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
235 before-compile += $(common-objpfx)$(lib-names-h-abi)
236 common-generated += gnu/lib-names.h
237 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
238 $(common-objpfx)gnu/lib-names.h:
239 $(make-target-directory)
241 echo '/* This file is automatically generated.';\
242 echo ' It defines macros to allow user program to find the shared'; \
243 echo ' library files which come as part of GNU libc. */'; \
244 echo '#ifndef __GNU_LIB_NAMES_H'; \
245 echo '#define __GNU_LIB_NAMES_H 1'; \
247 $(if $(abi-includes), \
248 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
250 $(foreach v,$(abi-variants),\
251 $(if $(abi-$(v)-condition),\
252 echo '#if $(abi-$(v)-condition)'; \
253 echo '# include <gnu/lib-names-$(v).h>'); \
254 $(if $(abi-$(v)-condition),echo '#endif';)) \
256 echo '#endif /* gnu/lib-names.h */'; \
259 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
260 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
261 $(common-objpfx)soversions.i
262 $(make-target-directory)
264 $(if $(abi-variants), \
265 echo '/* This file is automatically generated. */';\
266 echo '#ifndef __GNU_LIB_NAMES_H'; \
267 echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
269 echo '/* This file is automatically generated.';\
270 echo ' It defines macros to allow user program to find the shared'; \
271 echo ' library files which come as part of GNU libc. */'; \
272 echo '#ifndef __GNU_LIB_NAMES_H'; \
273 echo '#define __GNU_LIB_NAMES_H 1';) \
275 ($(foreach s,$(all-sonames), echo $(s);)) \
276 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
277 $(if $(abi-variants),, \
279 echo '#endif /* gnu/lib-names.h */';) \
281 $(move-if-change) ${@:stmp=T} ${@:stmp=h}
284 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
287 ###############################################################################
288 # NOTE! Everything adding to before-compile needs to come before this point! #
289 ###############################################################################
291 # Generate an ordered list of implicit rules which find the source files in
292 # each sysdep directory. The old method was to use vpath to search all the
293 # sysdep directories. However, that had the problem that a .S file in a
294 # later directory would be chosen over a .c file in an earlier directory,
295 # which does not preserve the desired sysdeps ordering behavior.
297 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
298 # matching sysdep directories whose assembly source files should be
301 -include $(common-objpfx)sysd-rules
302 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
303 # The value of $(+sysdep_dirs) the sysd-rules was computed for
304 # differs from the one we are using now. So force a rebuild of sysd-rules.
305 sysd-rules-force = FORCE
308 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
309 $(common-objpfx)config.make $(..)Makerules \
310 $(sysdep-makefiles) $(sysdep-makeconfigs) \
313 LC_ALL=C $(AWK) -f $< > $@T \
314 -v all_object_suffixes='$(all-object-suffixes)' \
315 -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
316 -v sysd_rules_patterns='$(sysd-rules-patterns)' \
317 -v config_sysdirs='$(config-sysdirs)'
320 ifndef sysd-rules-done
321 # Don't do deps until this exists, because it provides rules to make the deps.
325 define o-iterator-doit
326 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
328 object-suffixes-left := $(all-object-suffixes)
329 include $(o-iterator)
331 define o-iterator-doit
332 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
334 object-suffixes-left := $(all-object-suffixes)
335 include $(o-iterator)
337 define o-iterator-doit
338 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
340 object-suffixes-left := $(all-object-suffixes)
341 include $(o-iterator)
343 # Omit the objpfx rules when building in the source tree, because
344 # objpfx is empty and so these rules just override the ones above.
346 # Define first rules to find the source files in $(objpfx).
347 # Generated source files will end up there.
348 define o-iterator-doit
349 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
351 object-suffixes-left := $(all-object-suffixes)
352 include $(o-iterator)
354 define o-iterator-doit
355 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
357 object-suffixes-left := $(all-object-suffixes)
358 include $(o-iterator)
361 # Generate version maps, but wait until sysdep-subdirs is known
362 ifeq ($(sysd-sorted-done),t)
363 ifeq ($(build-shared),yes)
364 -include $(common-objpfx)sysd-versions
365 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
366 common-generated += $(version-maps)
367 postclean-generated += sysd-versions Versions.all abi-versions.h \
368 Versions.def Versions.v.i Versions.v
370 ifndef avoid-generated
371 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
372 sysd-versions-force = FORCE
376 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
377 $(common-objpfx)Versions.v
378 LC_ALL=C $(AWK) -f $^ > $@T
381 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
382 $(common-objpfx)soversions.i \
383 $(common-objpfx)Versions.def
384 { while read which lib version setname; do \
385 test x"$$which" = xDEFAULT || continue; \
386 test -z "$$setname" || echo "$$lib : $$setname"; \
387 done < $(word 2,$^); \
389 } | LC_ALL=C $(AWK) -f $< > $@T
391 # See %.v/%.v.i implicit rules in Makeconfig.
392 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
393 $(wildcard $(sysdirs:%=%/Versions)) \
394 $(sysd-versions-force)
395 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
396 $(common-objpfx)Versions.v \
397 $(..)scripts/versions.awk
398 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
400 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
401 -v move_if_change='$(move-if-change)' \
405 endif # avoid-generated
406 endif # $(build-shared) = yes
407 endif # sysd-sorted-done
409 # Generate .dT files as we compile.
410 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
411 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
412 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
413 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
415 # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
416 # track system includes here, they may spuriously trigger an install rule,
417 # and would cause the check-local-headers test to fail.
418 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
420 # GCC can grok options after the file name, and it looks nicer that way.
421 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
422 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
423 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
424 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
425 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
426 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
427 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
429 # We need this for the output to go in the right place. It will default to
430 # empty if make was configured to work with a cc that can't grok -c and -o
431 # together. You can't compile the C library with such a compiler.
432 OUTPUT_OPTION = -o $@
434 # This is the end of the pipeline for compiling generated C code.
435 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
437 # We need the $(CFLAGS) to be in there to have the right predefines during
438 # the dependency run for C sources. But having it for assembly sources can
439 # get the wrong predefines.
440 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
443 $(make-target-directory)
444 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
445 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
446 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
447 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
448 mv -f $(@:.d=.T) $@ $(generate-md5)
452 # Continuation lines here are dangerous because they introduce spaces!
453 define sed-remove-objpfx
454 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
455 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
459 # Modify the list of routines we build for different targets
461 ifeq (yes,$(build-shared))
462 ifndef libc.so-version
463 # Undefine this because it can't work when we libc.so is unversioned.
464 static-only-routines =
468 elide-routines.oS += $(filter-out $(static-only-routines),\
469 $(routines) $(aux) $(sysdep_routines))
470 elide-routines.os += $(static-only-routines)
472 # If we have versioned code we don't need the old versions in any of the
474 elide-routines.o += $(shared-only-routines)
475 elide-routines.op += $(shared-only-routines)
476 elide-routines.og += $(shared-only-routines)
478 # Shared library building.
480 ifeq (yes,$(build-shared))
482 # Reference map file only when shared libraries are built and a map file name
484 ifeq ($(build-shared),yes)
485 map-file = $(firstword $($(@F:.so=-map)) \
486 $(addprefix $(common-objpfx), \
487 $(filter $(@F:.so=.map),$(version-maps))))
488 load-map-file = $(map-file:%=-Wl,--version-script=%)
491 # Compiler arguments to use to link a shared object with libc and
492 # ld.so. This is intended to be as similar as possible to a default
493 # link with an installed libc.
494 link-libc-args = -Wl,--start-group \
496 $(common-objpfx)libc_nonshared.a \
497 $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
500 # The corresponding shared libc to use. This may be modified for a
502 libc-for-link = $(common-objpfx)libc.so
504 # The corresponding dependencies. As these are used in dependencies,
505 # not just commands, they cannot use target-specific variables so need
506 # to name both possible libc.so objects.
507 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
508 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
510 # Pattern rule to build a shared object from an archive of PIC objects.
511 # This must come after the installation rules so Make doesn't try to
512 # build shared libraries in place from the installed *_pic.a files.
513 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
514 # on other shared objects. The linking with libc and ld.so is intended
515 # to be as similar as possible to a default link with an installed libc.
516 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
517 $(build-shlib) $(link-libc-args)
518 $(call after-link,$@)
520 define build-shlib-helper
521 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
522 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
523 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
524 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
525 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
526 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
527 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
530 ifeq (yes,$(use-default-link))
531 # If the linker is good enough, we can let it use its default linker script.
535 # binutils only position loadable notes into the first page for binaries,
536 # not for shared objects
537 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
538 $(LINK.o) -shared -Wl,-O1 \
539 -nostdlib -nostartfiles \
540 $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
541 -Wl,--verbose 2>&1 | \
543 -e '/^=========/,/^=========/!d;/^=========/d' \
544 $(if $(filter yes,$(have-hash-style)), \
545 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
546 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
547 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
549 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
551 -e 's/^.*\*(\.dynbss).*$$/& \
552 PROVIDE(__start___libc_freeres_ptrs = .); \
553 *(__libc_freeres_ptrs) \
554 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
555 -e 's@^.*\*(\.jcr).*$$@& \
556 PROVIDE(__start___libc_subfreeres = .);\
557 __libc_subfreeres : { *(__libc_subfreeres) }\
558 PROVIDE(__stop___libc_subfreeres = .);\
559 PROVIDE(__start___libc_atexit = .);\
560 __libc_atexit : { *(__libc_atexit) }\
561 PROVIDE(__stop___libc_atexit = .);\
562 PROVIDE(__start___libc_thread_subfreeres = .);\
563 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
564 PROVIDE(__stop___libc_thread_subfreeres = .);\
565 PROVIDE(__start___libc_IO_vtables = .);\
566 __libc_IO_vtables : { *(__libc_IO_vtables) }\
567 PROVIDE(__stop___libc_IO_vtables = .);\
568 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
571 common-generated += shlib.lds
573 shlib-lds = $(common-objpfx)shlib.lds
574 shlib-lds-flags = -T $(shlib-lds)
578 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
579 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
582 define build-module-helper
583 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
584 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
585 -B$(csu-objpfx) $(load-map-file) \
586 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
587 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
590 # This macro is similar to build-shlib but it does not define a soname
591 # and it does not depend on the destination name to start with `lib'.
592 # binutils only position loadable notes into the first page for binaries,
593 # not for shared objects
595 $(build-module-helper) -o $@ $(shlib-lds-flags) \
596 $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
597 $(call after-link,$@)
599 define build-module-asneeded
600 $(build-module-helper) -o $@ $(shlib-lds-flags) \
601 $(csu-objpfx)abi-note.o \
602 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
604 $(call after-link,$@)
607 build-module-helper-objlist = \
608 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
609 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
610 $(link-libc-deps),$^))
612 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
613 build-shlib-objlist = $(build-module-helper-objlist) \
614 $(LDLIBS-$(@F:lib%.so=%).so)
616 # Don't try to use -lc when making libc.so itself.
617 # Also omits crti.o and crtn.o, which we do not want
618 # since we define our own `.init' section specially.
619 LDFLAGS-c.so = -nostdlib -nostartfiles
620 # But we still want to link libc.so against $(libc.so-gnulib).
621 LDLIBS-c.so += $(libc.so-gnulib)
622 # Give libc.so an entry point and make it directly runnable itself.
623 LDFLAGS-c.so += -e __libc_main
624 # If lazy relocation is disabled add the -z now flag.
625 ifeq ($(bind-now),yes)
626 LDFLAGS-c.so += -Wl,-z,now
628 # Pre-link the objects of libc_pic.a so that we can locally resolve
629 # COMMON symbols before we link against ld.so. This is because ld.so
630 # contains some of libc_pic.a already, which will prevent the COMMONs
631 # from being allocated in libc.so, which introduces evil dependencies
632 # between libc.so and ld.so, which can make it impossible to upgrade.
633 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
634 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
635 $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
637 ifeq (,$(strip $(shlib-lds-flags)))
638 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
639 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
641 $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
644 # Apply those -R options.
645 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
646 $(common-objpfx)libc_pic.os
648 generated += libc_pic.opts libc_pic.os.clean
650 libc_pic_clean := .clean
653 # Build a possibly-modified version of libc_pic.a for use in building
655 ifeq (,$(filter sunrpc,$(subdirs)))
656 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
657 $(make-target-directory)
660 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
661 $(common-objpfx)sunrpc/librpc_compat_pic.a
662 $(make-target-directory)
663 (cd $(common-objpfx)linkobj; \
664 $(AR) x ../libc_pic.a; \
665 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
666 $(AR) x ../sunrpc/librpc_compat_pic.a; \
667 $(AR) cr libc_pic.a *.os; \
669 endif # $(subdirs) contains sunrpc
671 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
672 # filter ld.so out of the list of linked objects.
673 $(common-objpfx)libc.so: link-libc-deps = # empty
674 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
676 # Use our own special initializer and finalizer files for the libc.so
678 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
679 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
680 $(elf-objpfx)sofini.os \
681 $(elf-objpfx)interp.os \
685 $(call after-link,$@)
687 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
688 $(common-objpfx)linkobj/libc_pic.a \
689 $(elf-objpfx)sofini.os \
690 $(elf-objpfx)interp.os \
694 $(call after-link,$@)
696 ifeq ($(build-shared),yes)
697 $(common-objpfx)libc.so: $(common-objpfx)libc.map
699 common-generated += libc.so libc_pic.os
700 ifdef libc.so-version
701 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
703 common-generated += libc.so$(libc.so-version)
707 # Figure out the source filenames in this directory.
709 override sources := $(addsuffix .c,\
710 $(filter-out $(elided-routines),\
713 sysdep_routines := $(sysdep_routines)
715 headers := $(headers) $(sysdep_headers)
717 # This is the list of all object files, gotten by
718 # replacing every ".c" in `sources' with a ".o".
719 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
722 # The makefile may define $(extra-libs) with `libfoo libbar'
723 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
725 # extra-lib.mk is included once for each extra lib to define rules
726 # to build it, and to add its objects to the various variables.
727 # During its evaluation, $(lib) is set to the name of the library.
728 extra-libs-left := $(extra-libs)
729 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
733 # The makefile may define $(modules-names) to build additional modules.
734 # These are built with $(build-module), except any in $(modules-names-nobuild).
736 # extra-lib.mk is included once for each extra lib to define rules
737 # to build it, and to add its objects to the various variables.
738 # During its evaluation, $(lib) is set to the name of the library.
739 extra-modules-left := $(modules-names)
740 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
742 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
743 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
744 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
748 +depfiles := $(sources:.c=.d) \
749 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
750 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
751 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
752 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
753 ifeq ($(build-programs),yes)
754 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
756 +depfiles := $(addprefix $(objpfx),\
757 $(filter-out $(addsuffix .d,$(omit-deps)),\
759 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
760 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
761 $(wildcard $(all-dt-files:.dt=.d))
763 # This is a funny rule in that it removes its input file.
765 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
766 mv -f $(@:.d=.T) $@ && \
769 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
770 # They will be generated when they're needed, and trying too early won't work.
771 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
772 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
777 -include $(+depfiles)
781 # Maximize efficiency by minimizing the number of rules.
782 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
783 # Don't define any builtin rules.
784 MAKEFLAGS := $(MAKEFLAGS)r
786 # Generic rule for making directories.
788 # mkdir isn't smart enough to strip a trailing /.
789 # We always require a mkdir which supports the -p option to avoid error
790 # messages in case of races.
793 # Make sure that object files are not removed
794 # when they are intermediates between sources and library members.
795 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
797 # Make sure that the parent library archive is never removed.
798 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
800 # Use the verbose option of ar and tar when not running silently.
801 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
807 ARFLAGS := r$(verbose)
808 CREATE_ARFLAGS := cru$(verbose)
810 # This makes all the object files in the parent library archive.
812 .PHONY: lib lib-noranlib
813 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
814 lib-noranlib: libobjs
816 # For object-suffix $o, the list of objects with that suffix.
817 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
818 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
819 $(elide-routines$o)),\
821 $(addprefix $(objpfx),$(o-objects$o))
823 others: $(addprefix $(objpfx),$(install-lib))
827 # Create the stamp$o files to keep the parent makefile happy.
828 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
829 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
830 $(make-target-directory)
834 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
835 # timestamp file; these rules (one explicit rule is generated for each
836 # object suffix) write a list of objects to update in the stamp file.
837 # The parent will then actually add them all to the archive in the
838 # archive rule, below.
839 define o-iterator-doit
840 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
843 $(make-target-directory)
844 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
847 object-suffixes-left := $(object-suffixes-for-libc)
848 include $(o-iterator)
852 # Now define explicit rules to build the library archives; these depend
853 # on the stamp files built above.
854 define o-iterator-doit
855 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
856 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
859 cd $(common-objdir) && \
860 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
862 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
863 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
865 $(subdirs-stamps): subdir_lib;
867 object-suffixes-left = $(object-suffixes-for-libc)
868 include $(o-iterator)
871 # This makes all the object files.
872 .PHONY: objects objs libobjs extra-objs
873 objects objs: libobjs extra-objs
874 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
875 extra-objs: $(addprefix $(objpfx),$(extra-objs))
877 # Canned sequence for building an extra library archive.
878 define build-extra-lib
879 $(patsubst %/,cd % &&,$(objpfx)) \
880 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
881 $(patsubst $(objpfx)%,%,$^)
886 .PHONY: force-install
889 # $(install-lib) are installed from the object directory into $(libdir);
890 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
891 # unless they also appear in $(non-lib.a). $(install-data) are installed as
892 # they are into $(datadir). $(headers) are installed as they are in
893 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
894 # are installed from the object directory into $(bindir), $(bindir) and
895 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
896 # are absolute path names of files to install; rules to install them are
899 # The simple library name to install libc.a under.
900 # This could be defined by a sysdep Makefile.
906 $(make-target-directory)
907 $(INSTALL_DATA) $< $@
910 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
911 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
912 define make-target-directory
913 $(addprefix $(..)./scripts/mkinstalldirs ,\
914 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
917 # Any directory (parent or subdir) should install libc.a; this way
918 # "make install" in a subdir is guaranteed to install everything it changes.
919 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
920 $(inst_libdir)/$(patsubst %,$(libtype$o),\
921 $(libprefix)$(libc-name)))
923 .PHONY: check-install-supported
924 check-install-supported:
926 # Check to see if the prefix or exec_prefix GNU standard variable
927 # has been overridden on the command line and, if so, fail with
928 # an error message since doing so is not supported (set DESTDIR
930 ifeq ($(origin prefix),command line)
931 check-install-supported:
932 $(error Overriding prefix is not supported. Set DESTDIR instead.)
935 ifeq ($(origin exec_prefix),command line)
936 check-install-supported:
937 $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
940 install: check-install-supported
942 install: $(installed-libcs)
943 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
944 $(make-target-directory)
945 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
947 define do-install-program
948 $(make-target-directory)
949 $(INSTALL_PROGRAM) $< $@.new
953 define do-install-script
954 $(make-target-directory)
955 $(INSTALL_SCRIPT) $< $@.new
959 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
960 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
962 ifeq (yes,$(build-shared))
963 # Find which .so's have versions.
964 versioned := $(strip $(foreach so,$(install-lib.so),\
965 $(patsubst %,$(so),$($(so)-version))))
967 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
968 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
970 # For versioned libraries, we install three files:
971 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
972 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
973 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
974 lib-version := $(firstword $($(subdir)-version) $(version))
975 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
976 $(foreach L,$(install-lib.so-versioned),\
978 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
979 $(inst_slibdir)/$L$($L-version))
981 # Install all the unversioned shared libraries.
982 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
983 $(objpfx)%.so $(+force)
984 $(do-install-program)
986 ifneq ($(findstring -s,$(LN_S)),)
989 $(SHELL) $(..)scripts/rellns-sh $< $@.new
993 # If we have no symbolic links don't bother with rellns-sh.
1001 ifeq (yes,$(build-shared))
1002 ifeq (no,$(cross-compiling))
1003 symbolic-link-prog := $(elf-objpfx)sln
1004 symbolic-link-list := $(elf-objpfx)symlink.list
1005 define make-shlib-link
1006 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
1008 else # cross-compiling
1009 # We need a definition that can be used by elf/Makefile's install rules.
1010 symbolic-link-prog = $(LN_S)
1013 ifndef make-shlib-link
1014 define make-shlib-link
1016 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
1020 ifdef libc.so-version
1021 # For a library specified to be version N, install three files:
1022 # libc.so -> libc.so.N (e.g. libc.so.6)
1023 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
1025 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1028 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1029 $(do-install-program)
1030 install: $(inst_slibdir)/libc.so$(libc.so-version)
1032 # This fragment of linker script gives the OUTPUT_FORMAT statement
1033 # for the configuration we are building. We put this statement into
1034 # the linker scripts we install for -lc et al so that they will not be
1035 # used by a link for a different format on a multi-architecture system.
1036 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
1037 $(common-objpfx)config.make \
1038 $(common-objpfx)config.h $(..)Makerules
1039 ifneq (unknown,$(output-format))
1040 echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1042 $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
1043 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1044 | sed -n -f $< > $@.new
1049 common-generated += format.lds
1052 # What we install as libc.so for programs to link against is in fact a
1053 # link script. It contains references for the various libraries we need.
1054 # The libc.so object is not complete since some functions are only defined
1055 # in libc_nonshared.a.
1056 # We need to use absolute paths since otherwise local copies (if they exist)
1057 # of the files are taken by the linker.
1058 install: $(inst_libdir)/libc.so
1059 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1060 $(common-objpfx)libc.so$(libc.so-version) \
1061 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1062 $(libprefix)$(libc-name)) \
1064 (echo '/* GNU ld script';\
1065 echo ' Use the shared library, but some functions are only in';\
1066 echo ' the static library, so try that secondarily. */';\
1068 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1069 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1070 ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1077 install: $(inst_slibdir)/libc.so
1078 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1079 $(do-install-program)
1082 ifneq (,$(versioned))
1083 # Produce three sets of rules as above for all the smaller versioned libraries.
1085 define o-iterator-doit
1086 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1088 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1089 ifneq (,$(object-suffixes-left))
1090 include $(o-iterator)
1093 # Make symlinks in the build directory, because the versioned names might
1094 # be referenced by a DT_NEEDED in another library.
1095 define o-iterator-doit
1096 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1098 object-suffixes-left := $(versioned)
1099 include $(o-iterator)
1101 generated += $(foreach o,$(versioned),$o$($o-version))
1103 ifeq (,$($(subdir)-version))
1104 define o-iterator-doit
1105 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1109 object-suffixes-left := $(versioned)
1110 include $(o-iterator)
1112 define o-iterator-doit
1113 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1114 $$(do-install-program)
1116 object-suffixes-left := $(versioned)
1117 include $(o-iterator)
1119 define o-iterator-doit
1120 $(inst_slibdir)/$o$($o-version): \
1121 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1124 object-suffixes-left := $(versioned)
1125 include $(o-iterator)
1127 define o-iterator-doit
1128 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1129 $$(do-install-program)
1131 object-suffixes-left := $(versioned)
1132 include $(o-iterator)
1136 define do-install-so
1137 $(do-install-program)
1138 $(patsubst %,$(LN_S) -f $(@F) \
1139 $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1140 $(filter-out %.so,$@))
1143 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1144 $(foreach v,$(so-versions),\
1145 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1148 $(foreach v,$(so-versions),\
1149 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1154 $(addprefix $(inst_bindir)/,$(install-bin)): \
1155 $(inst_bindir)/%: $(objpfx)% $(+force)
1156 $(do-install-program)
1158 ifdef install-bin-script
1159 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1160 $(inst_bindir)/%: $(objpfx)% $(+force)
1161 $(do-install-script)
1163 ifdef install-rootsbin
1164 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1165 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1166 $(do-install-program)
1169 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1170 $(inst_sbindir)/%: $(objpfx)% $(+force)
1171 $(do-install-program)
1174 install-lib.a := $(filter lib%.a,$(install-lib))
1175 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1176 ifdef install-lib-non.a
1177 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1178 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1182 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1183 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1188 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1191 headers := $(strip $(headers))
1193 # This implicit rule installs headers from the source directory.
1194 # It may be ignored in preference to rules from sysd-rules to find
1195 # headers in the sysdeps tree.
1196 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1198 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1200 $(inst_includedir)/%.h: %.h $(+force)
1202 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1204 headers-nonh := $(filter-out %.h,$(headers))
1206 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1209 endif # headers-nonh
1212 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1213 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1214 install-data-nosubdir install-headers-nosubdir
1215 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1216 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1217 install-rootsbin-nosubdir: \
1218 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1219 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1220 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1221 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1222 $(addprefix $(libprefix),$(install-lib-non.a)))
1223 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1224 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1225 install-others-nosubdir: $(install-others)
1226 install-others-programs-nosubdir: $(install-others-programs)
1228 # We need all the `-nosubdir' targets so that `install' in the parent
1229 # doesn't depend on several things which each iterate over the subdirs.
1230 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1231 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1232 install-%:: install-%-nosubdir ;
1234 .PHONY: install install-no-libc.a-nosubdir
1235 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1236 install-lib-nosubdir install-others-nosubdir
1237 ifeq ($(build-programs),yes)
1238 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1239 install-rootsbin-nosubdir install-sbin-nosubdir \
1240 install-others-programs-nosubdir
1242 install: install-no-libc.a-nosubdir
1244 # Command to compile $< using the native libraries.
1245 define native-compile
1246 $(make-target-directory)
1247 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1248 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1251 # We always want to use configuration definitions.
1252 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1253 -DIS_IN_build -include $(common-objpfx)config.h
1255 # Support the GNU standard name for this target.
1258 # Special target to run tests which cannot be run unconditionally.
1259 # Maintainers should use this target.
1263 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1264 ifneq (,$(all-nonlib))
1265 cpp-srcs-left = $(all-nonlib)
1267 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1271 ifeq ($(build-shared),yes)
1272 # Generate normalized lists of symbols, versions, and data sizes.
1273 # This is handy for checking against existing library binaries.
1275 %.symlist: $(..)scripts/abilist.awk %.dynsym
1276 LC_ALL=C $(AWK) -f $^ > $@T
1280 LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1283 # A sysdeps/.../Makefile can set abilist-pattern to something like
1284 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1285 # This makes sense if multiple ABIs can be most cleanly supported by a
1286 # configuration without using separate sysdeps directories for each.
1287 ifdef abilist-pattern
1288 vpath $(abilist-pattern) $(+sysdep_dirs)
1291 vpath %.abilist $(+sysdep_dirs)
1293 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1294 # target pattern is %.symlist from being considered "intermediate files"
1295 # and automatically removed. We only want these files to be removed by
1296 # 'make clean', which is handled by the 'generated' variable.
1297 .PRECIOUS: %.symlist
1298 generated += $(extra-libs:=.symlist)
1300 ifdef abilist-pattern
1301 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1303 $(check-abi-pattern); \
1305 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1306 $(common-objpfx)%.symlist
1307 $(check-abi-pattern); \
1310 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1314 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1315 $(common-objpfx)%.symlist
1318 define check-abi-pattern
1319 diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1323 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1326 ifdef abilist-pattern
1327 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1328 $(update-abi-pattern)
1329 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1330 $(update-abi-pattern)
1332 update-abi-%: $(objpfx)%.symlist %.abilist
1334 update-abi-%: $(common-objpfx)%.symlist %.abilist
1336 define update-abi-pattern
1337 @if cmp -s $^ 2> /dev/null; \
1339 echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1341 echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1345 @if cmp -s $^ 2> /dev/null; \
1347 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1349 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1353 # Patch all .abilist files for one DSO. The find command locates
1354 # abilist files for all architectures. The regular expression in the
1355 # find invocation is needed to separate libc.abilist and
1356 # libcrypt.abilist, for example. It assumes that abilist-pattern, if
1357 # set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
1358 # a non-alphanumeric seperator between the pattern and the suffix
1359 # added. The abilist files in /generic/ are filtered out because
1360 # these are expected to remain empty.
1361 define update-all-abi
1362 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1363 $$(find $(..)sysdeps \
1364 -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
1365 \! -regex '.*/generic/.*')
1367 ifdef abilist-pattern
1368 update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
1370 update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
1373 update-all-abi-%: %.abilist $(objpfx)%.symlist
1375 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1378 .PHONY: update-abi update-all-abi check-abi
1379 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1380 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1381 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1382 $(install-lib.so-versioned))
1383 check-abi: $(check-abi-list)
1385 subdir_check-abi: check-abi
1386 subdir_update-abi: update-abi
1387 subdir_update-all-abi: update-all-abi
1389 check-abi: subdir_check-abi
1390 if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1391 cat $(objpfx)*/check-abi*.out && exit 1; fi
1392 update-abi: subdir_update-abi
1393 update-all-abi: subdir_update-all-abi
1396 ifeq ($(subdir),elf)
1397 check-abi: $(objpfx)check-abi-libc.out
1398 tests-special += $(objpfx)check-abi-libc.out
1399 update-abi: update-abi-libc
1400 update-all-abi: update-all-abi-libc
1401 common-generated += libc.symlist
1404 ifeq ($(build-shared),yes)
1406 tests-special += $(check-abi-list)
1412 # These will have been set by sysdeps/posix/Makefile.
1418 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1420 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1421 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1422 $(common-objpfx)config.make
1423 $(make-target-directory)
1424 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1425 echo '#define _LIBC 1'; \
1426 echo '#include "$(..)misc/sys/uio.h"'; } | \
1427 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1428 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1429 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1430 $(@:st=dT) > $(@:st=dt)
1431 mv -f $(@:st=dt) $(@:st=d)
1432 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1433 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1434 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1435 fopen_max=$${fopen_max:-16}; \
1436 filename_max=$${filename_max:-1024}; \
1437 if [ -z "$$iov_max" ]; then \
1438 define_iov_max="# undef IOV_MAX"; \
1440 define_iov_max="# define IOV_MAX $$iov_max"; \
1442 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1443 -e "s/@FILENAME_MAX@/$$filename_max/" \
1444 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1445 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1446 -e "s/@L_ctermid@/$(L_ctermid)/" \
1447 -e "s/@L_cuserid@/$(L_cuserid)/" \
1448 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1450 $(move-if-change) $(@:st=h.new) $(@:st=h)
1451 # Remove these last so that they can be examined if something went wrong.
1452 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1456 -include $(stdio_lim:h=d)
1458 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1462 .PHONY: echo-headers
1466 %.bz2: %; bzip2 -9vk $<
1467 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1468 %.xz: %; xz -9evk $<
1470 # Common cleaning targets.
1472 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1474 mostlyclean: common-mostlyclean
1477 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1479 $(addsuffix .test-result,$(tests) \
1483 # Remove the object files.
1485 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1486 $(others) $(sysdep-others) stubs \
1487 $(addsuffix .o,$(tests) $(xtests) \
1488 $(test-srcs) $(others) \
1490 $(addsuffix .out,$(tests) $(xtests) \
1492 $(addsuffix .test-result,$(tests) \
1495 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1496 $(install-lib) $(install-lib.so) \
1497 $(install-lib.so:%.so=%_pic.a))
1499 -rm -f $(objpfx)rtld-*.os
1502 $(foreach o,$(object-suffixes-for-libc),
1503 -rm -f $(objpfx)stamp$o $(o-objects))
1506 # Also remove the dependencies and generated source files.
1507 common-clean: common-mostlyclean
1508 -rm -f $(addprefix $(objpfx),$(generated))
1509 -rm -f $(objpfx)*.d $(objpfx)*.dt
1510 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1511 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1512 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1514 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1515 # for each function which is a stub.
1518 .PHONY: stubs # The parent Makefile calls this target.
1519 stubs: $(objpfx)stubs
1521 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1522 $(addprefix $(objpfx),$(extra-objs))
1523 $(objpfx)stubs: $(objs-for-stubs)
1524 ifneq (,$(strip $(objs-for-stubs)))
1525 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1526 $(AWK) '/\.gnu\.glibc-stub\./ { \
1527 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1529 END { for (s in stubs) print "#define __stub_" s }' > $@T
1535 ifneq (,$(strip $(gpl2lgpl)))
1536 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1537 # Snarf from the master source and frob the copying notice.
1538 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1540 # So I don't edit them by mistake.