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
113 # If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
114 # /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
115 # (instead of stdlib/stdlib.h or math/math.h in the glibc source
116 # directory), and this turns up as a make dependency. An implicit
117 # rule will kick in and make will try to install stdlib/stdlib.h or
118 # math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
119 # the target is out of date. We make a copy of <cstdlib> and <cmath>
120 # in the glibc build directory so that stdlib/stdlib.h and math/math.h
121 # will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
122 before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
124 cstdlib=$(shell echo "\#include <cstdlib>" | $(CXX) -M -MP -x c++ - \
125 | sed -n "/cstdlib:/{s/:$$//;p}")
126 $(common-objpfx)cstdlib: $(cstdlib)
127 $(INSTALL_DATA) $< $@T
128 $(move-if-change) $@T $@
129 cmath=$(shell echo "\#include <cmath>" | $(CXX) -M -MP -x c++ - \
130 | sed -n "/cmath:/{s/:$$//;p}")
131 $(common-objpfx)cmath: $(cmath)
132 $(INSTALL_DATA) $< $@T
133 $(move-if-change) $@T $@
136 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
137 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
138 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
139 $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
143 $(base-machine)-$(config-vendor)-$(config-os) \
144 < $(word 2,$^) > $(@:.stamp=.h)T
145 $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
147 common-generated += $(common-objpfx)libc-abis.h
148 endif # avoid-generated
150 ifeq (yes,$(build-shared))
151 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
152 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
153 $(make-target-directory)
154 echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
156 $(move-if-change) ${@:stamp=T} ${@:stamp=h}
160 # Make sure the subdirectory for object files gets created.
162 ifeq (,$(wildcard $(objpfx).))
163 before-compile += $(objpfx).
165 $(make-target-directory)
169 # Remove existing files from `before-compile'. Things are added there when
170 # they must exist for dependency generation to work right, but once they
171 # exist there is no further need for every single file to depend on them,
172 # and those gratuitous dependencies result in many gratuitous
174 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
176 # Don't let any before-compile file be an intermediate and get removed.
181 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
184 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
186 common-before-compile = $(before-compile)
190 # If a makefile needs to do something conditional on something that
191 # can only be figured out from headers, write a FOO.make.c input
192 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
193 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
195 # We only generate these in the top-level makefile, to avoid any weirdness
196 # from subdir-specific makefile tweaks creeping in on an update.
197 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
199 (echo '# Generated from $*.make.c by Makerules.'; \
200 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
201 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
202 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
203 echo 'common-generated += $(@F)'; \
204 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
210 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
211 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
213 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
214 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
218 ifdef gen-as-const-headers
219 # Generating headers for assembly constants.
220 # We need this defined early to get into before-compile before
221 # it's used in sysd-rules, below.
222 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
223 %.sym $(common-before-compile)
224 $(AWK) -f $< $(filter %.sym,$^) \
225 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
226 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
227 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
228 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
230 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
231 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
233 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
234 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
235 vpath %.sym $(sysdirs)
236 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
238 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
239 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
240 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
241 %.sym $(common-objpfx)%.h
242 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
243 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
244 echo '#include "$(..)test-skeleton.c"') > $@T
248 ifeq (yes,$(build-shared))
249 # Generate the header containing the names of all shared libraries.
250 # We use a stamp file to avoid unnecessary recompilations.
251 before-compile += $(common-objpfx)gnu/lib-names.h
252 ifeq ($(soversions.mk-done),t)
254 lib-names-h-abi = gnu/lib-names.h
255 lib-names-stmp-abi = gnu/lib-names.stmp
257 lib-names-h-abi = gnu/lib-names-$(default-abi).h
258 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
259 before-compile += $(common-objpfx)$(lib-names-h-abi)
260 common-generated += gnu/lib-names.h
261 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
262 $(common-objpfx)gnu/lib-names.h:
263 $(make-target-directory)
265 echo '/* This file is automatically generated.';\
266 echo ' It defines macros to allow user program to find the shared'; \
267 echo ' library files which come as part of GNU libc. */'; \
268 echo '#ifndef __GNU_LIB_NAMES_H'; \
269 echo '#define __GNU_LIB_NAMES_H 1'; \
271 $(if $(abi-includes), \
272 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
274 $(foreach v,$(abi-variants),\
275 $(if $(abi-$(v)-condition),\
276 echo '#if $(abi-$(v)-condition)'; \
277 echo '# include <gnu/lib-names-$(v).h>'); \
278 $(if $(abi-$(v)-condition),echo '#endif';)) \
280 echo '#endif /* gnu/lib-names.h */'; \
283 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
284 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
285 $(common-objpfx)soversions.i
286 $(make-target-directory)
288 $(if $(abi-variants), \
289 echo '/* This file is automatically generated. */';\
290 echo '#ifndef __GNU_LIB_NAMES_H'; \
291 echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
293 echo '/* This file is automatically generated.';\
294 echo ' It defines macros to allow user program to find the shared'; \
295 echo ' library files which come as part of GNU libc. */'; \
296 echo '#ifndef __GNU_LIB_NAMES_H'; \
297 echo '#define __GNU_LIB_NAMES_H 1';) \
299 ($(foreach s,$(all-sonames), echo $(s);)) \
300 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
301 $(if $(abi-variants),, \
303 echo '#endif /* gnu/lib-names.h */';) \
305 $(move-if-change) ${@:stmp=T} ${@:stmp=h}
308 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
311 ###############################################################################
312 # NOTE! Everything adding to before-compile needs to come before this point! #
313 ###############################################################################
315 # Generate an ordered list of implicit rules which find the source files in
316 # each sysdep directory. The old method was to use vpath to search all the
317 # sysdep directories. However, that had the problem that a .S file in a
318 # later directory would be chosen over a .c file in an earlier directory,
319 # which does not preserve the desired sysdeps ordering behavior.
321 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
322 # matching sysdep directories whose assembly source files should be
325 -include $(common-objpfx)sysd-rules
326 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
327 # The value of $(+sysdep_dirs) the sysd-rules was computed for
328 # differs from the one we are using now. So force a rebuild of sysd-rules.
329 sysd-rules-force = FORCE
332 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
333 $(common-objpfx)config.make $(..)Makerules \
334 $(sysdep-makefiles) $(sysdep-makeconfigs) \
337 LC_ALL=C $(AWK) -f $< > $@T \
338 -v all_object_suffixes='$(all-object-suffixes)' \
339 -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
340 -v sysd_rules_patterns='$(sysd-rules-patterns)' \
341 -v config_sysdirs='$(config-sysdirs)'
344 ifndef sysd-rules-done
345 # Don't do deps until this exists, because it provides rules to make the deps.
349 define o-iterator-doit
350 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
352 object-suffixes-left := $(all-object-suffixes)
353 include $(o-iterator)
355 define o-iterator-doit
356 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
358 object-suffixes-left := $(all-object-suffixes)
359 include $(o-iterator)
361 define o-iterator-doit
362 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
364 object-suffixes-left := $(all-object-suffixes)
365 include $(o-iterator)
367 # Omit the objpfx rules when building in the source tree, because
368 # objpfx is empty and so these rules just override the ones above.
370 # Define first rules to find the source files in $(objpfx).
371 # Generated source files will end up there.
372 define o-iterator-doit
373 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
375 object-suffixes-left := $(all-object-suffixes)
376 include $(o-iterator)
378 define o-iterator-doit
379 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
381 object-suffixes-left := $(all-object-suffixes)
382 include $(o-iterator)
385 # Generate version maps, but wait until sysdep-subdirs is known
386 ifeq ($(sysd-sorted-done),t)
387 ifeq ($(build-shared),yes)
388 -include $(common-objpfx)sysd-versions
389 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
390 common-generated += $(version-maps)
391 postclean-generated += sysd-versions Versions.all abi-versions.h \
392 Versions.def Versions.v.i Versions.v
394 ifndef avoid-generated
395 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
396 sysd-versions-force = FORCE
400 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
401 $(common-objpfx)Versions.v
402 LC_ALL=C $(AWK) -f $^ > $@T
405 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
406 $(common-objpfx)soversions.i \
407 $(common-objpfx)Versions.def
408 { while read which lib version setname; do \
409 test x"$$which" = xDEFAULT || continue; \
410 test -z "$$setname" || echo "$$lib : $$setname"; \
411 done < $(word 2,$^); \
413 } | LC_ALL=C $(AWK) -f $< > $@T
415 # See %.v/%.v.i implicit rules in Makeconfig.
416 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
417 $(wildcard $(sysdirs:%=%/Versions)) \
418 $(sysd-versions-force)
419 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
420 $(common-objpfx)Versions.v \
421 $(..)scripts/versions.awk
422 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
424 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
425 -v move_if_change='$(move-if-change)' \
429 endif # avoid-generated
430 endif # $(build-shared) = yes
431 endif # sysd-sorted-done
433 # Generate .dT files as we compile.
434 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
435 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
436 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
437 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
439 # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
440 # track system includes here, they may spuriously trigger an install rule,
441 # and would cause the check-local-headers test to fail.
442 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
444 # GCC can grok options after the file name, and it looks nicer that way.
445 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
446 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
447 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
448 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
449 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
450 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
451 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
453 # We need this for the output to go in the right place. It will default to
454 # empty if make was configured to work with a cc that can't grok -c and -o
455 # together. You can't compile the C library with such a compiler.
456 OUTPUT_OPTION = -o $@
458 # This is the end of the pipeline for compiling generated C code.
459 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
461 # We need the $(CFLAGS) to be in there to have the right predefines during
462 # the dependency run for C sources. But having it for assembly sources can
463 # get the wrong predefines.
464 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
467 $(make-target-directory)
468 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
469 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
470 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
471 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
472 mv -f $(@:.d=.T) $@ $(generate-md5)
476 # Continuation lines here are dangerous because they introduce spaces!
477 define sed-remove-objpfx
478 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
479 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
483 # Modify the list of routines we build for different targets
485 ifeq (yes,$(build-shared))
486 ifndef libc.so-version
487 # Undefine this because it can't work when we libc.so is unversioned.
488 static-only-routines =
492 elide-routines.oS += $(filter-out $(static-only-routines),\
493 $(routines) $(aux) $(sysdep_routines))
494 elide-routines.os += $(static-only-routines)
496 # If we have versioned code we don't need the old versions in any of the
498 elide-routines.o += $(shared-only-routines)
499 elide-routines.op += $(shared-only-routines)
501 # Shared library building.
503 ifeq (yes,$(build-shared))
505 # Reference map file only when shared libraries are built and a map file name
507 ifeq ($(build-shared),yes)
508 map-file = $(firstword $($(@F:.so=-map)) \
509 $(addprefix $(common-objpfx), \
510 $(filter $(@F:.so=.map),$(version-maps))))
511 load-map-file = $(map-file:%=-Wl,--version-script=%)
514 # Compiler arguments to use to link a shared object with libc and
515 # ld.so. This is intended to be as similar as possible to a default
516 # link with an installed libc.
517 link-libc-args = -Wl,--start-group \
519 $(common-objpfx)libc_nonshared.a \
520 $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
523 # The corresponding shared libc to use. This may be modified for a
525 libc-for-link = $(common-objpfx)libc.so
527 # The corresponding dependencies. As these are used in dependencies,
528 # not just commands, they cannot use target-specific variables so need
529 # to name both possible libc.so objects.
530 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
531 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
533 # Pattern rule to build a shared object from an archive of PIC objects.
534 # This must come after the installation rules so Make doesn't try to
535 # build shared libraries in place from the installed *_pic.a files.
536 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
537 # on other shared objects. The linking with libc and ld.so is intended
538 # to be as similar as possible to a default link with an installed libc.
539 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
540 $(build-shlib) $(link-libc-args)
541 $(call after-link,$@)
543 define build-shlib-helper
544 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
545 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
546 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
547 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
548 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
549 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
550 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
553 ifeq (yes,$(use-default-link))
554 # If the linker is good enough, we can let it use its default linker script.
558 # binutils only position loadable notes into the first page for binaries,
559 # not for shared objects
560 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
561 $(LINK.o) -shared -Wl,-O1 \
562 -nostdlib -nostartfiles \
563 $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
564 -Wl,--verbose 2>&1 | \
566 -e '/^=========/,/^=========/!d;/^=========/d' \
567 $(if $(filter yes,$(have-hash-style)), \
568 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
569 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
570 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
572 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
574 -e 's/^.*\*(\.dynbss).*$$/& \
575 PROVIDE(__start___libc_freeres_ptrs = .); \
576 *(__libc_freeres_ptrs) \
577 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
578 -e 's@^.*\*(\.jcr).*$$@& \
579 PROVIDE(__start___libc_subfreeres = .);\
580 __libc_subfreeres : { *(__libc_subfreeres) }\
581 PROVIDE(__stop___libc_subfreeres = .);\
582 PROVIDE(__start___libc_atexit = .);\
583 __libc_atexit : { *(__libc_atexit) }\
584 PROVIDE(__stop___libc_atexit = .);\
585 PROVIDE(__start___libc_thread_subfreeres = .);\
586 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
587 PROVIDE(__stop___libc_thread_subfreeres = .);\
588 PROVIDE(__start___libc_IO_vtables = .);\
589 __libc_IO_vtables : { *(__libc_IO_vtables) }\
590 PROVIDE(__stop___libc_IO_vtables = .);\
591 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
594 common-generated += shlib.lds
596 shlib-lds = $(common-objpfx)shlib.lds
597 shlib-lds-flags = -T $(shlib-lds)
601 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
602 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
605 define build-module-helper
606 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
607 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
608 -B$(csu-objpfx) $(load-map-file) \
609 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
610 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
613 # This macro is similar to build-shlib but it does not define a soname
614 # and it does not depend on the destination name to start with `lib'.
615 # binutils only position loadable notes into the first page for binaries,
616 # not for shared objects
618 $(build-module-helper) -o $@ $(shlib-lds-flags) \
619 $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
620 $(call after-link,$@)
622 define build-module-asneeded
623 $(build-module-helper) -o $@ $(shlib-lds-flags) \
624 $(csu-objpfx)abi-note.o \
625 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
627 $(call after-link,$@)
630 build-module-helper-objlist = \
631 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
632 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
633 $(link-libc-deps),$^))
635 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
636 build-shlib-objlist = $(build-module-helper-objlist) \
637 $(LDLIBS-$(@F:lib%.so=%).so)
639 # Don't try to use -lc when making libc.so itself.
640 # Also omits crti.o and crtn.o, which we do not want
641 # since we define our own `.init' section specially.
642 LDFLAGS-c.so = -nostdlib -nostartfiles
643 # But we still want to link libc.so against $(libc.so-gnulib).
644 LDLIBS-c.so += $(libc.so-gnulib)
645 # Give libc.so an entry point and make it directly runnable itself.
646 LDFLAGS-c.so += -e __libc_main
647 # If lazy relocation is disabled add the -z now flag.
648 ifeq ($(bind-now),yes)
649 LDFLAGS-c.so += -Wl,-z,now
651 # Pre-link the objects of libc_pic.a so that we can locally resolve
652 # COMMON symbols before we link against ld.so. This is because ld.so
653 # contains some of libc_pic.a already, which will prevent the COMMONs
654 # from being allocated in libc.so, which introduces evil dependencies
655 # between libc.so and ld.so, which can make it impossible to upgrade.
656 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
657 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
658 $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
660 ifeq (,$(strip $(shlib-lds-flags)))
661 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
662 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
664 $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
667 # Apply those -R options.
668 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
669 $(common-objpfx)libc_pic.os
671 generated += libc_pic.opts libc_pic.os.clean
673 libc_pic_clean := .clean
676 # Build a possibly-modified version of libc_pic.a for use in building
678 ifeq (,$(filter sunrpc,$(subdirs)))
679 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
680 $(make-target-directory)
683 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
684 $(common-objpfx)sunrpc/librpc_compat_pic.a
685 $(make-target-directory)
686 (cd $(common-objpfx)linkobj; \
687 $(AR) x ../libc_pic.a; \
688 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
689 $(AR) x ../sunrpc/librpc_compat_pic.a; \
690 $(AR) cr libc_pic.a *.os; \
692 endif # $(subdirs) contains sunrpc
694 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
695 # filter ld.so out of the list of linked objects.
696 $(common-objpfx)libc.so: link-libc-deps = # empty
697 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
699 # Use our own special initializer and finalizer files for the libc.so
701 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
702 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
703 $(elf-objpfx)sofini.os \
704 $(elf-objpfx)interp.os \
708 $(call after-link,$@)
710 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
711 $(common-objpfx)linkobj/libc_pic.a \
712 $(elf-objpfx)sofini.os \
713 $(elf-objpfx)interp.os \
717 $(call after-link,$@)
719 ifeq ($(build-shared),yes)
720 $(common-objpfx)libc.so: $(common-objpfx)libc.map
722 common-generated += libc.so libc_pic.os
723 ifdef libc.so-version
724 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
726 common-generated += libc.so$(libc.so-version)
730 # Figure out the source filenames in this directory.
732 override sources := $(addsuffix .c,\
733 $(filter-out $(elided-routines),\
736 sysdep_routines := $(sysdep_routines)
738 headers := $(headers) $(sysdep_headers)
740 # This is the list of all object files, gotten by
741 # replacing every ".c" in `sources' with a ".o".
742 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
745 # The makefile may define $(extra-libs) with `libfoo libbar'
746 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
748 # extra-lib.mk is included once for each extra lib to define rules
749 # to build it, and to add its objects to the various variables.
750 # During its evaluation, $(lib) is set to the name of the library.
751 extra-libs-left := $(extra-libs)
752 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
756 # The makefile may define $(modules-names) to build additional modules.
757 # These are built with $(build-module), except any in $(modules-names-nobuild).
759 # extra-lib.mk is included once for each extra lib to define rules
760 # to build it, and to add its objects to the various variables.
761 # During its evaluation, $(lib) is set to the name of the library.
762 extra-modules-left := $(modules-names)
763 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
765 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
766 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
767 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
771 +depfiles := $(sources:.c=.d) \
772 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
773 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
774 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
775 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
776 ifeq ($(build-programs),yes)
777 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
779 +depfiles := $(addprefix $(objpfx),\
780 $(filter-out $(addsuffix .d,$(omit-deps)),\
782 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
783 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
784 $(wildcard $(all-dt-files:.dt=.d))
786 # This is a funny rule in that it removes its input file.
788 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
789 mv -f $(@:.d=.T) $@ && \
792 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
793 # They will be generated when they're needed, and trying too early won't work.
794 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
795 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
800 -include $(+depfiles)
804 # Maximize efficiency by minimizing the number of rules.
805 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
806 # Don't define any builtin rules.
807 MAKEFLAGS := $(MAKEFLAGS)r
809 # Generic rule for making directories.
811 # mkdir isn't smart enough to strip a trailing /.
812 # We always require a mkdir which supports the -p option to avoid error
813 # messages in case of races.
816 # Make sure that object files are not removed
817 # when they are intermediates between sources and library members.
818 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
820 # Make sure that the parent library archive is never removed.
821 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
823 # Use the verbose option of ar and tar when not running silently.
824 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
830 ARFLAGS := r$(verbose)
831 CREATE_ARFLAGS := cru$(verbose)
833 # This makes all the object files in the parent library archive.
835 .PHONY: lib lib-noranlib
836 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
837 lib-noranlib: libobjs
839 # For object-suffix $o, the list of objects with that suffix.
840 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
841 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
842 $(elide-routines$o)),\
844 $(addprefix $(objpfx),$(o-objects$o))
846 others: $(addprefix $(objpfx),$(install-lib))
850 # Create the stamp$o files to keep the parent makefile happy.
851 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
852 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
853 $(make-target-directory)
857 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
858 # timestamp file; these rules (one explicit rule is generated for each
859 # object suffix) write a list of objects to update in the stamp file.
860 # The parent will then actually add them all to the archive in the
861 # archive rule, below.
862 define o-iterator-doit
863 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
866 $(make-target-directory)
867 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
870 object-suffixes-left := $(object-suffixes-for-libc)
871 include $(o-iterator)
875 # Now define explicit rules to build the library archives; these depend
876 # on the stamp files built above.
877 define o-iterator-doit
878 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
879 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
882 cd $(common-objdir) && \
883 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
885 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
886 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
888 $(subdirs-stamps): subdir_lib;
890 object-suffixes-left = $(object-suffixes-for-libc)
891 include $(o-iterator)
894 # This makes all the object files.
895 .PHONY: objects objs libobjs extra-objs
896 objects objs: libobjs extra-objs
897 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
898 extra-objs: $(addprefix $(objpfx),$(extra-objs))
900 # Canned sequence for building an extra library archive.
901 define build-extra-lib
902 $(patsubst %/,cd % &&,$(objpfx)) \
903 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
904 $(patsubst $(objpfx)%,%,$^)
909 .PHONY: force-install
912 # $(install-lib) are installed from the object directory into $(libdir);
913 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
914 # unless they also appear in $(non-lib.a). $(install-data) are installed as
915 # they are into $(datadir). $(headers) are installed as they are in
916 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
917 # are installed from the object directory into $(bindir), $(bindir) and
918 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
919 # are absolute path names of files to install; rules to install them are
922 # The simple library name to install libc.a under.
923 # This could be defined by a sysdep Makefile.
929 $(make-target-directory)
930 $(INSTALL_DATA) $< $@
933 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
934 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
935 define make-target-directory
936 $(addprefix $(..)./scripts/mkinstalldirs ,\
937 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
940 # Any directory (parent or subdir) should install libc.a; this way
941 # "make install" in a subdir is guaranteed to install everything it changes.
942 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
943 $(inst_libdir)/$(patsubst %,$(libtype$o),\
944 $(libprefix)$(libc-name)))
946 .PHONY: check-install-supported
947 check-install-supported:
949 # Check to see if the prefix or exec_prefix GNU standard variable
950 # has been overridden on the command line and, if so, fail with
951 # an error message since doing so is not supported (set DESTDIR
953 ifeq ($(origin prefix),command line)
954 check-install-supported:
955 $(error Overriding prefix is not supported. Set DESTDIR instead.)
958 ifeq ($(origin exec_prefix),command line)
959 check-install-supported:
960 $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
963 install: check-install-supported
965 install: $(installed-libcs)
966 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
967 $(make-target-directory)
968 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
970 define do-install-program
971 $(make-target-directory)
972 $(INSTALL_PROGRAM) $< $@.new
976 define do-install-script
977 $(make-target-directory)
978 $(INSTALL_SCRIPT) $< $@.new
982 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
983 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
985 ifeq (yes,$(build-shared))
986 # Find which .so's have versions.
987 versioned := $(strip $(foreach so,$(install-lib.so),\
988 $(patsubst %,$(so),$($(so)-version))))
990 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
991 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
993 # For versioned libraries, we install three files:
994 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
995 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
996 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
997 lib-version := $(firstword $($(subdir)-version) $(version))
998 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
999 $(foreach L,$(install-lib.so-versioned),\
1001 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
1002 $(inst_slibdir)/$L$($L-version))
1004 # Install all the unversioned shared libraries.
1005 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
1006 $(objpfx)%.so $(+force)
1007 $(do-install-program)
1009 ifneq ($(findstring -s,$(LN_S)),)
1012 $(SHELL) $(..)scripts/rellns-sh $< $@.new
1016 # If we have no symbolic links don't bother with rellns-sh.
1024 ifeq (yes,$(build-shared))
1025 ifeq (no,$(cross-compiling))
1026 symbolic-link-prog := $(elf-objpfx)sln
1027 symbolic-link-list := $(elf-objpfx)symlink.list
1028 define make-shlib-link
1029 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
1031 else # cross-compiling
1032 # We need a definition that can be used by elf/Makefile's install rules.
1033 symbolic-link-prog = $(LN_S)
1036 ifndef make-shlib-link
1037 define make-shlib-link
1039 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
1043 ifdef libc.so-version
1044 # For a library specified to be version N, install three files:
1045 # libc.so -> libc.so.N (e.g. libc.so.6)
1046 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
1048 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1051 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1052 $(do-install-program)
1053 install: $(inst_slibdir)/libc.so$(libc.so-version)
1055 # This fragment of linker script gives the OUTPUT_FORMAT statement
1056 # for the configuration we are building. We put this statement into
1057 # the linker scripts we install for -lc et al so that they will not be
1058 # used by a link for a different format on a multi-architecture system.
1059 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
1060 $(common-objpfx)config.make \
1061 $(common-objpfx)config.h $(..)Makerules
1062 ifneq (unknown,$(output-format))
1063 echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1065 $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
1066 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1067 | sed -n -f $< > $@.new
1072 common-generated += format.lds
1075 # What we install as libc.so for programs to link against is in fact a
1076 # link script. It contains references for the various libraries we need.
1077 # The libc.so object is not complete since some functions are only defined
1078 # in libc_nonshared.a.
1079 # We need to use absolute paths since otherwise local copies (if they exist)
1080 # of the files are taken by the linker.
1081 install: $(inst_libdir)/libc.so
1082 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1083 $(common-objpfx)libc.so$(libc.so-version) \
1084 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1085 $(libprefix)$(libc-name)) \
1087 (echo '/* GNU ld script';\
1088 echo ' Use the shared library, but some functions are only in';\
1089 echo ' the static library, so try that secondarily. */';\
1091 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1092 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1093 ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1100 install: $(inst_slibdir)/libc.so
1101 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1102 $(do-install-program)
1105 ifneq (,$(versioned))
1106 # Produce three sets of rules as above for all the smaller versioned libraries.
1108 define o-iterator-doit
1109 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1111 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1112 ifneq (,$(object-suffixes-left))
1113 include $(o-iterator)
1116 # Make symlinks in the build directory, because the versioned names might
1117 # be referenced by a DT_NEEDED in another library.
1118 define o-iterator-doit
1119 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1121 object-suffixes-left := $(versioned)
1122 include $(o-iterator)
1124 generated += $(foreach o,$(versioned),$o$($o-version))
1126 ifeq (,$($(subdir)-version))
1127 define o-iterator-doit
1128 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1132 object-suffixes-left := $(versioned)
1133 include $(o-iterator)
1135 define o-iterator-doit
1136 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1137 $$(do-install-program)
1139 object-suffixes-left := $(versioned)
1140 include $(o-iterator)
1142 define o-iterator-doit
1143 $(inst_slibdir)/$o$($o-version): \
1144 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1147 object-suffixes-left := $(versioned)
1148 include $(o-iterator)
1150 define o-iterator-doit
1151 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1152 $$(do-install-program)
1154 object-suffixes-left := $(versioned)
1155 include $(o-iterator)
1159 define do-install-so
1160 $(do-install-program)
1161 $(patsubst %,$(LN_S) -f $(@F) \
1162 $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1163 $(filter-out %.so,$@))
1166 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1167 $(foreach v,$(so-versions),\
1168 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1171 $(foreach v,$(so-versions),\
1172 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1177 $(addprefix $(inst_bindir)/,$(install-bin)): \
1178 $(inst_bindir)/%: $(objpfx)% $(+force)
1179 $(do-install-program)
1181 ifdef install-bin-script
1182 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1183 $(inst_bindir)/%: $(objpfx)% $(+force)
1184 $(do-install-script)
1186 ifdef install-rootsbin
1187 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1188 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1189 $(do-install-program)
1192 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1193 $(inst_sbindir)/%: $(objpfx)% $(+force)
1194 $(do-install-program)
1197 install-lib.a := $(filter lib%.a,$(install-lib))
1198 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1199 ifdef install-lib-non.a
1200 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1201 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1205 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1206 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1211 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1214 headers := $(strip $(headers))
1216 # This implicit rule installs headers from the source directory.
1217 # It may be ignored in preference to rules from sysd-rules to find
1218 # headers in the sysdeps tree.
1219 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1221 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1223 $(inst_includedir)/%.h: %.h $(+force)
1225 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1227 headers-nonh := $(filter-out %.h,$(headers))
1229 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1232 endif # headers-nonh
1235 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1236 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1237 install-data-nosubdir install-headers-nosubdir
1238 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1239 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1240 install-rootsbin-nosubdir: \
1241 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1242 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1243 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1244 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1245 $(addprefix $(libprefix),$(install-lib-non.a)))
1246 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1247 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1248 install-others-nosubdir: $(install-others)
1249 install-others-programs-nosubdir: $(install-others-programs)
1251 # We need all the `-nosubdir' targets so that `install' in the parent
1252 # doesn't depend on several things which each iterate over the subdirs.
1253 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1254 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1255 install-%:: install-%-nosubdir ;
1257 .PHONY: install install-no-libc.a-nosubdir
1258 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1259 install-lib-nosubdir install-others-nosubdir
1260 ifeq ($(build-programs),yes)
1261 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1262 install-rootsbin-nosubdir install-sbin-nosubdir \
1263 install-others-programs-nosubdir
1265 install: install-no-libc.a-nosubdir
1267 # Command to compile $< using the native libraries.
1268 define native-compile
1269 $(make-target-directory)
1270 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1271 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1274 # We always want to use configuration definitions.
1275 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1276 -DIS_IN_build -include $(common-objpfx)config.h
1278 # Support the GNU standard name for this target.
1281 # Special target to run tests which cannot be run unconditionally.
1282 # Maintainers should use this target.
1286 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1287 ifneq (,$(all-nonlib))
1288 cpp-srcs-left = $(all-nonlib)
1290 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1294 ifeq ($(build-shared),yes)
1295 # Generate normalized lists of symbols, versions, and data sizes.
1296 # This is handy for checking against existing library binaries.
1298 %.symlist: $(..)scripts/abilist.awk %.dynsym
1299 LC_ALL=C $(AWK) -f $^ > $@T
1303 LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1306 # A sysdeps/.../Makefile can set abilist-pattern to something like
1307 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1308 # This makes sense if multiple ABIs can be most cleanly supported by a
1309 # configuration without using separate sysdeps directories for each.
1310 ifdef abilist-pattern
1311 vpath $(abilist-pattern) $(+sysdep_dirs)
1314 vpath %.abilist $(+sysdep_dirs)
1316 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1317 # target pattern is %.symlist from being considered "intermediate files"
1318 # and automatically removed. We only want these files to be removed by
1319 # 'make clean', which is handled by the 'generated' variable.
1320 .PRECIOUS: %.symlist
1321 generated += $(extra-libs:=.symlist)
1323 ifdef abilist-pattern
1324 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1326 $(check-abi-pattern); \
1328 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1329 $(common-objpfx)%.symlist
1330 $(check-abi-pattern); \
1333 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1337 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1338 $(common-objpfx)%.symlist
1341 define check-abi-pattern
1342 diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1346 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1349 ifdef abilist-pattern
1350 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1351 $(update-abi-pattern)
1352 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1353 $(update-abi-pattern)
1355 update-abi-%: $(objpfx)%.symlist %.abilist
1357 update-abi-%: $(common-objpfx)%.symlist %.abilist
1359 define update-abi-pattern
1360 @if cmp -s $^ 2> /dev/null; \
1362 echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1364 echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1368 @if cmp -s $^ 2> /dev/null; \
1370 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1372 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1376 # Patch all .abilist files for one DSO. The find command locates
1377 # abilist files for all architectures. The regular expression in the
1378 # find invocation is needed to separate libc.abilist and
1379 # libcrypt.abilist, for example. It assumes that abilist-pattern, if
1380 # set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
1381 # a non-alphanumeric seperator between the pattern and the suffix
1382 # added. The abilist files in /generic/ are filtered out because
1383 # these are expected to remain empty.
1384 define update-all-abi
1385 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1386 $$(find $(..)sysdeps \
1387 -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
1388 \! -regex '.*/generic/.*')
1390 ifdef abilist-pattern
1391 update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
1393 update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
1396 update-all-abi-%: %.abilist $(objpfx)%.symlist
1398 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1401 .PHONY: update-abi update-all-abi check-abi
1402 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1403 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1404 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1405 $(install-lib.so-versioned))
1406 check-abi: $(check-abi-list)
1408 subdir_check-abi: check-abi
1409 subdir_update-abi: update-abi
1410 subdir_update-all-abi: update-all-abi
1412 check-abi: subdir_check-abi
1413 if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1414 cat $(objpfx)*/check-abi*.out && exit 1; fi
1415 update-abi: subdir_update-abi
1416 update-all-abi: subdir_update-all-abi
1419 ifeq ($(subdir),elf)
1420 check-abi: $(objpfx)check-abi-libc.out
1421 tests-special += $(objpfx)check-abi-libc.out
1422 update-abi: update-abi-libc
1423 update-all-abi: update-all-abi-libc
1424 common-generated += libc.symlist
1427 ifeq ($(build-shared),yes)
1429 tests-special += $(check-abi-list)
1435 # These will have been set by sysdeps/posix/Makefile.
1441 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1443 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1444 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1445 $(common-objpfx)config.make
1446 $(make-target-directory)
1447 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1448 echo '#define _LIBC 1'; \
1449 echo '#include "$(..)misc/sys/uio.h"'; } | \
1450 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1451 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1452 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1453 $(@:st=dT) > $(@:st=dt)
1454 mv -f $(@:st=dt) $(@:st=d)
1455 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1456 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1457 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1458 fopen_max=$${fopen_max:-16}; \
1459 filename_max=$${filename_max:-1024}; \
1460 if [ -z "$$iov_max" ]; then \
1461 define_iov_max="# undef IOV_MAX"; \
1463 define_iov_max="# define IOV_MAX $$iov_max"; \
1465 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1466 -e "s/@FILENAME_MAX@/$$filename_max/" \
1467 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1468 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1469 -e "s/@L_ctermid@/$(L_ctermid)/" \
1470 -e "s/@L_cuserid@/$(L_cuserid)/" \
1471 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1473 $(move-if-change) $(@:st=h.new) $(@:st=h)
1474 # Remove these last so that they can be examined if something went wrong.
1475 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1479 -include $(stdio_lim:h=d)
1481 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1485 .PHONY: echo-headers
1489 %.bz2: %; bzip2 -9vk $<
1490 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1491 %.xz: %; xz -9evk $<
1493 # Common cleaning targets.
1495 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1497 mostlyclean: common-mostlyclean
1500 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1502 $(addsuffix .test-result,$(tests) \
1506 # Remove the object files.
1508 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1509 $(others) $(sysdep-others) stubs \
1510 $(addsuffix .o,$(tests) $(xtests) \
1511 $(test-srcs) $(others) \
1513 $(addsuffix .out,$(tests) $(xtests) \
1515 $(addsuffix .test-result,$(tests) \
1518 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1519 $(install-lib) $(install-lib.so) \
1520 $(install-lib.so:%.so=%_pic.a))
1522 -rm -f $(objpfx)rtld-*.os
1525 $(foreach o,$(object-suffixes-for-libc),
1526 -rm -f $(objpfx)stamp$o $(o-objects))
1529 # Also remove the dependencies and generated source files.
1530 common-clean: common-mostlyclean
1531 -rm -f $(addprefix $(objpfx),$(generated))
1532 -rm -f $(objpfx)*.d $(objpfx)*.dt
1533 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1534 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1535 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1537 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1538 # for each function which is a stub.
1541 .PHONY: stubs # The parent Makefile calls this target.
1542 stubs: $(objpfx)stubs
1544 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1545 $(addprefix $(objpfx),$(extra-objs))
1546 $(objpfx)stubs: $(objs-for-stubs)
1547 ifneq (,$(strip $(objs-for-stubs)))
1548 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1549 $(AWK) '/\.gnu\.glibc-stub\./ { \
1550 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1552 END { for (s in stubs) print "#define __stub_" s }' > $@T
1558 ifneq (,$(strip $(gpl2lgpl)))
1559 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1560 # Snarf from the master source and frob the copying notice.
1561 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1563 # So I don't edit them by mistake.