1 # Copyright (C) 1991-2017 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 $(common-objpfx)cstdlib: $(c++-cstdlib-header)
125 $(INSTALL_DATA) $< $@T
126 $(move-if-change) $@T $@
127 $(common-objpfx)cmath: $(c++-cmath-header)
128 $(INSTALL_DATA) $< $@T
129 $(move-if-change) $@T $@
132 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
133 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
134 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
135 $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
139 $(base-machine)-$(config-vendor)-$(config-os) \
140 < $(word 2,$^) > $(@:.stamp=.h)T
141 $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
143 common-generated += $(common-objpfx)libc-abis.h
144 endif # avoid-generated
146 ifeq (yes,$(build-shared))
147 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
148 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
149 $(make-target-directory)
150 echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
152 $(move-if-change) ${@:stamp=T} ${@:stamp=h}
156 # Make sure the subdirectory for object files gets created.
158 ifeq (,$(wildcard $(objpfx).))
159 before-compile += $(objpfx).
161 $(make-target-directory)
165 # Remove existing files from `before-compile'. Things are added there when
166 # they must exist for dependency generation to work right, but once they
167 # exist there is no further need for every single file to depend on them,
168 # and those gratuitous dependencies result in many gratuitous
170 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
172 # Don't let any before-compile file be an intermediate and get removed.
177 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
180 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
182 common-before-compile = $(before-compile)
186 # If a makefile needs to do something conditional on something that
187 # can only be figured out from headers, write a FOO.make.c input
188 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
189 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
191 # We only generate these in the top-level makefile, to avoid any weirdness
192 # from subdir-specific makefile tweaks creeping in on an update.
193 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
195 (echo '# Generated from $*.make.c by Makerules.'; \
196 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
197 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
198 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
199 echo 'common-generated += $(@F)'; \
200 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
206 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
207 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
209 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
210 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
213 ifdef gen-py-const-headers
214 # We'll use a static pattern rule to match .pysym files with their
215 # corresponding generated .py files.
216 # The generated .py files go in the submodule's dir in the glibc build dir.
217 py-const-files := $(patsubst %.pysym,%.py,$(gen-py-const-headers))
218 py-const-dir := $(objpfx)
219 py-const := $(addprefix $(py-const-dir),$(py-const-files))
220 py-const-script := $(..)scripts/gen-py-const.awk
222 # This is a hack we use to generate .py files with constants for Python
223 # pretty printers. It works the same way as gen-as-const.
224 # See scripts/gen-py-const.awk for details on how the awk | gcc mechanism
227 # $@.tmp and $@.tmp2 are temporary files we use to store the partial contents
228 # of the target file. We do this instead of just writing on $@ because, if the
229 # build process terminates prematurely, re-running Make wouldn't run this rule
230 # since Make would see that the target file already exists (despite it being
233 # The sed line replaces "@name@SOME_NAME@value@SOME_VALUE@" strings from the
234 # output of 'gcc -S' with "SOME_NAME = SOME_VALUE" strings.
235 # The '-n' option, combined with the '/p' command, makes sed output only the
236 # modified lines instead of the whole input file. The output is redirected
237 # to a .py file; we'll import it in the pretty printers file to read
238 # the constants generated by gen-py-const.awk.
239 # The regex has two capturing groups, for SOME_NAME and SOME_VALUE
240 # respectively. Notice SOME_VALUE may be prepended by a special character,
241 # depending on the assembly syntax (e.g. immediates are prefixed by a '$'
242 # in AT&T x86, and by a '#' in ARM). We discard it using a complemented set
243 # before the second capturing group.
244 $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
245 $(common-before-compile)
246 $(make-target-directory)
247 $(AWK) -f $(py-const-script) $< \
248 | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
249 echo '# GENERATED FILE\n' > $@.tmp2
250 echo '# Constant definitions for pretty printers.' >> $@.tmp2
251 echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
252 sed -n -r 's/^.*@name@([^@]+)@value@[^[:xdigit:]Xx-]*([[:xdigit:]Xx-]+)@.*/\1 = \2/p' \
257 generated += $(py-const)
258 endif # gen-py-const-headers
260 ifdef gen-as-const-headers
261 # Generating headers for assembly constants.
262 # We need this defined early to get into before-compile before
263 # it's used in sysd-rules, below.
264 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
265 %.sym $(common-before-compile)
266 $(AWK) -f $< $(filter %.sym,$^) \
267 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
268 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
269 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
270 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
272 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
273 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
275 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
276 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
277 vpath %.sym $(sysdirs)
278 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
280 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
281 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
282 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
283 %.sym $(common-objpfx)%.h
284 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
285 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
286 echo '#include "$(..)test-skeleton.c"') > $@T
290 ifeq (yes,$(build-shared))
291 # Generate the header containing the names of all shared libraries.
292 # We use a stamp file to avoid unnecessary recompilations.
293 before-compile += $(common-objpfx)gnu/lib-names.h
294 ifeq ($(soversions.mk-done),t)
296 lib-names-h-abi = gnu/lib-names.h
297 lib-names-stmp-abi = gnu/lib-names.stmp
299 lib-names-h-abi = gnu/lib-names-$(default-abi).h
300 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
301 before-compile += $(common-objpfx)$(lib-names-h-abi)
302 common-generated += gnu/lib-names.h
303 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
304 $(common-objpfx)gnu/lib-names.h:
305 $(make-target-directory)
307 echo '/* This file is automatically generated.';\
308 echo ' It defines macros to allow user program to find the shared'; \
309 echo ' library files which come as part of GNU libc. */'; \
310 echo '#ifndef __GNU_LIB_NAMES_H'; \
311 echo '#define __GNU_LIB_NAMES_H 1'; \
313 $(if $(abi-includes), \
314 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
316 $(foreach v,$(abi-variants),\
317 $(if $(abi-$(v)-condition),\
318 echo '#if $(abi-$(v)-condition)'; \
319 echo '# include <gnu/lib-names-$(v).h>'); \
320 $(if $(abi-$(v)-condition),echo '#endif';)) \
322 echo '#endif /* gnu/lib-names.h */'; \
325 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
326 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
327 $(common-objpfx)soversions.i
328 $(make-target-directory)
330 $(if $(abi-variants), \
331 echo '/* This file is automatically generated. */';\
332 echo '#ifndef __GNU_LIB_NAMES_H'; \
333 echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
335 echo '/* This file is automatically generated.';\
336 echo ' It defines macros to allow user program to find the shared'; \
337 echo ' library files which come as part of GNU libc. */'; \
338 echo '#ifndef __GNU_LIB_NAMES_H'; \
339 echo '#define __GNU_LIB_NAMES_H 1';) \
341 ($(foreach s,$(all-sonames), echo $(s);)) \
342 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
343 $(if $(abi-variants),, \
345 echo '#endif /* gnu/lib-names.h */';) \
347 $(move-if-change) ${@:stmp=T} ${@:stmp=h}
350 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
353 ###############################################################################
354 # NOTE! Everything adding to before-compile needs to come before this point! #
355 ###############################################################################
357 # Generate an ordered list of implicit rules which find the source files in
358 # each sysdep directory. The old method was to use vpath to search all the
359 # sysdep directories. However, that had the problem that a .S file in a
360 # later directory would be chosen over a .c file in an earlier directory,
361 # which does not preserve the desired sysdeps ordering behavior.
363 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
364 # matching sysdep directories whose assembly source files should be
367 -include $(common-objpfx)sysd-rules
368 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
369 # The value of $(+sysdep_dirs) the sysd-rules was computed for
370 # differs from the one we are using now. So force a rebuild of sysd-rules.
371 sysd-rules-force = FORCE
374 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
375 $(common-objpfx)config.make $(..)Makerules \
376 $(sysdep-makefiles) $(sysdep-makeconfigs) \
379 LC_ALL=C $(AWK) -f $< > $@T \
380 -v all_object_suffixes='$(all-object-suffixes)' \
381 -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
382 -v sysd_rules_patterns='$(sysd-rules-patterns)' \
383 -v config_sysdirs='$(config-sysdirs)'
386 ifndef sysd-rules-done
387 # Don't do deps until this exists, because it provides rules to make the deps.
391 define o-iterator-doit
392 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
394 object-suffixes-left := $(all-object-suffixes)
395 include $(o-iterator)
397 define o-iterator-doit
398 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
400 object-suffixes-left := $(all-object-suffixes)
401 include $(o-iterator)
403 define o-iterator-doit
404 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
406 object-suffixes-left := $(all-object-suffixes)
407 include $(o-iterator)
409 # Omit the objpfx rules when building in the source tree, because
410 # objpfx is empty and so these rules just override the ones above.
412 # Define first rules to find the source files in $(objpfx).
413 # Generated source files will end up there.
414 define o-iterator-doit
415 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
417 object-suffixes-left := $(all-object-suffixes)
418 include $(o-iterator)
420 define o-iterator-doit
421 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
423 object-suffixes-left := $(all-object-suffixes)
424 include $(o-iterator)
427 # Generate version maps, but wait until sysdep-subdirs is known
428 ifeq ($(sysd-sorted-done),t)
429 ifeq ($(build-shared),yes)
430 -include $(common-objpfx)sysd-versions
431 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
432 common-generated += $(version-maps)
433 postclean-generated += sysd-versions Versions.all abi-versions.h \
434 Versions.def Versions.v.i Versions.v
436 ifndef avoid-generated
437 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
438 sysd-versions-force = FORCE
442 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
443 $(common-objpfx)Versions.v
444 LC_ALL=C $(AWK) -f $^ > $@T
447 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
448 $(common-objpfx)soversions.i \
449 $(common-objpfx)Versions.def
450 { while read which lib version setname; do \
451 test x"$$which" = xDEFAULT || continue; \
452 test -z "$$setname" || echo "$$lib : $$setname"; \
453 done < $(word 2,$^); \
455 } | LC_ALL=C $(AWK) -f $< > $@T
457 # See %.v/%.v.i implicit rules in Makeconfig.
458 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
459 $(wildcard $(sysdirs:%=%/Versions)) \
460 $(sysd-versions-force)
461 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
462 $(common-objpfx)Versions.v \
463 $(..)scripts/versions.awk
464 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
466 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
467 -v move_if_change='$(move-if-change)' \
471 endif # avoid-generated
472 endif # $(build-shared) = yes
473 endif # sysd-sorted-done
475 # Generate .dT files as we compile.
476 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
477 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
478 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
479 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
481 # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
482 # track system includes here, they may spuriously trigger an install rule,
483 # and would cause the check-local-headers test to fail.
484 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
486 # GCC can grok options after the file name, and it looks nicer that way.
487 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
488 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
489 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
490 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
491 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
492 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
493 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
495 # We need this for the output to go in the right place. It will default to
496 # empty if make was configured to work with a cc that can't grok -c and -o
497 # together. You can't compile the C library with such a compiler.
498 OUTPUT_OPTION = -o $@
500 # This is the end of the pipeline for compiling generated C code.
501 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
503 # We need the $(CFLAGS) to be in there to have the right predefines during
504 # the dependency run for C sources. But having it for assembly sources can
505 # get the wrong predefines.
506 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
509 $(make-target-directory)
510 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
511 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
512 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
513 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
514 mv -f $(@:.d=.T) $@ $(generate-md5)
518 # Continuation lines here are dangerous because they introduce spaces!
519 define sed-remove-objpfx
520 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
521 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
525 # Modify the list of routines we build for different targets
527 ifeq (yes,$(build-shared))
528 ifndef libc.so-version
529 # Undefine this because it can't work when we libc.so is unversioned.
530 static-only-routines =
534 elide-routines.oS += $(filter-out $(static-only-routines),\
535 $(routines) $(aux) $(sysdep_routines))
536 elide-routines.os += $(static-only-routines)
538 # If we have versioned code we don't need the old versions in any of the
540 elide-routines.o += $(shared-only-routines)
541 elide-routines.op += $(shared-only-routines)
543 # Shared library building.
545 ifeq (yes,$(build-shared))
547 # Reference map file only when shared libraries are built and a map file name
549 ifeq ($(build-shared),yes)
550 map-file = $(firstword $($(@F:.so=-map)) \
551 $(addprefix $(common-objpfx), \
552 $(filter $(@F:.so=.map),$(version-maps))))
553 load-map-file = $(map-file:%=-Wl,--version-script=%)
556 # Compiler arguments to use to link a shared object with libc and
557 # ld.so. This is intended to be as similar as possible to a default
558 # link with an installed libc.
559 link-libc-args = -Wl,--start-group \
561 $(common-objpfx)libc_nonshared.a \
562 $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
565 # The corresponding shared libc to use. This may be modified for a
567 libc-for-link = $(common-objpfx)libc.so
569 # The corresponding dependencies. As these are used in dependencies,
570 # not just commands, they cannot use target-specific variables so need
571 # to name both possible libc.so objects.
572 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
573 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
575 # Pattern rule to build a shared object from an archive of PIC objects.
576 # This must come after the installation rules so Make doesn't try to
577 # build shared libraries in place from the installed *_pic.a files.
578 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
579 # on other shared objects. The linking with libc and ld.so is intended
580 # to be as similar as possible to a default link with an installed libc.
581 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
582 $(build-shlib) $(link-libc-args)
583 $(call after-link,$@)
585 define build-shlib-helper
586 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
587 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
588 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
589 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
590 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
591 $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
592 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
595 ifeq (yes,$(use-default-link))
596 # If the linker is good enough, we can let it use its default linker script.
600 # binutils only position loadable notes into the first page for binaries,
601 # not for shared objects
602 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
603 $(LINK.o) -shared -Wl,-O1 \
604 -nostdlib -nostartfiles \
605 $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
606 -Wl,--verbose 2>&1 | \
608 -e '/^=========/,/^=========/!d;/^=========/d' \
609 $(if $(filter yes,$(have-hash-style)), \
610 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
611 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
612 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
614 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
616 -e 's/^.*\*(\.dynbss).*$$/& \
617 PROVIDE(__start___libc_freeres_ptrs = .); \
618 *(__libc_freeres_ptrs) \
619 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
620 -e 's@^.*\*(\.jcr).*$$@& \
621 PROVIDE(__start___libc_subfreeres = .);\
622 __libc_subfreeres : { *(__libc_subfreeres) }\
623 PROVIDE(__stop___libc_subfreeres = .);\
624 PROVIDE(__start___libc_atexit = .);\
625 __libc_atexit : { *(__libc_atexit) }\
626 PROVIDE(__stop___libc_atexit = .);\
627 PROVIDE(__start___libc_thread_subfreeres = .);\
628 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
629 PROVIDE(__stop___libc_thread_subfreeres = .);\
630 PROVIDE(__start___libc_IO_vtables = .);\
631 __libc_IO_vtables : { *(__libc_IO_vtables) }\
632 PROVIDE(__stop___libc_IO_vtables = .);\
633 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
636 common-generated += shlib.lds
638 shlib-lds = $(common-objpfx)shlib.lds
639 shlib-lds-flags = -T $(shlib-lds)
643 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
644 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
647 define build-module-helper
648 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
649 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
650 -B$(csu-objpfx) $(load-map-file) \
651 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
652 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
655 # This macro is similar to build-shlib but it does not define a soname
656 # and it does not depend on the destination name to start with `lib'.
657 # binutils only position loadable notes into the first page for binaries,
658 # not for shared objects
660 $(build-module-helper) -o $@ $(shlib-lds-flags) \
661 $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
662 $(call after-link,$@)
664 define build-module-asneeded
665 $(build-module-helper) -o $@ $(shlib-lds-flags) \
666 $(csu-objpfx)abi-note.o \
667 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
669 $(call after-link,$@)
672 build-module-helper-objlist = \
673 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
674 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
675 $(link-libc-deps),$^))
677 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
678 build-shlib-objlist = $(build-module-helper-objlist) \
679 $(LDLIBS-$(@F:lib%.so=%).so)
681 # Don't try to use -lc when making libc.so itself.
682 # Also omits crti.o and crtn.o, which we do not want
683 # since we define our own `.init' section specially.
684 LDFLAGS-c.so = -nostdlib -nostartfiles
685 # But we still want to link libc.so against $(libc.so-gnulib).
686 LDLIBS-c.so += $(libc.so-gnulib)
687 # Give libc.so an entry point and make it directly runnable itself.
688 LDFLAGS-c.so += -e __libc_main
689 # Pre-link the objects of libc_pic.a so that we can locally resolve
690 # COMMON symbols before we link against ld.so. This is because ld.so
691 # contains some of libc_pic.a already, which will prevent the COMMONs
692 # from being allocated in libc.so, which introduces evil dependencies
693 # between libc.so and ld.so, which can make it impossible to upgrade.
694 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
695 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
696 $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
698 ifeq (,$(strip $(shlib-lds-flags)))
699 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
700 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
702 $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
705 # Apply those -R options.
706 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
707 $(common-objpfx)libc_pic.os
709 generated += libc_pic.opts libc_pic.os.clean
711 libc_pic_clean := .clean
714 # Build a possibly-modified version of libc_pic.a for use in building
716 ifeq (,$(filter sunrpc,$(subdirs)))
717 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
718 $(make-target-directory)
721 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
722 $(common-objpfx)sunrpc/librpc_compat_pic.a
723 $(make-target-directory)
724 (cd $(common-objpfx)linkobj; \
725 $(AR) x ../libc_pic.a; \
726 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
727 $(AR) x ../sunrpc/librpc_compat_pic.a; \
728 $(AR) cr libc_pic.a *.os; \
730 endif # $(subdirs) contains sunrpc
732 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
733 # filter ld.so out of the list of linked objects.
734 $(common-objpfx)libc.so: link-libc-deps = # empty
735 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
737 # Use our own special initializer and finalizer files for the libc.so
739 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
740 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
741 $(elf-objpfx)sofini.os \
742 $(elf-objpfx)interp.os \
746 $(call after-link,$@)
748 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
749 $(common-objpfx)linkobj/libc_pic.a \
750 $(elf-objpfx)sofini.os \
751 $(elf-objpfx)interp.os \
755 $(call after-link,$@)
757 ifeq ($(build-shared),yes)
758 $(common-objpfx)libc.so: $(common-objpfx)libc.map
760 common-generated += libc.so libc_pic.os
761 ifdef libc.so-version
762 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
764 common-generated += libc.so$(libc.so-version)
768 # Figure out the source filenames in this directory.
770 override sources := $(addsuffix .c,\
771 $(filter-out $(elided-routines),\
774 sysdep_routines := $(sysdep_routines)
776 headers := $(headers) $(sysdep_headers)
778 # This is the list of all object files, gotten by
779 # replacing every ".c" in `sources' with a ".o".
780 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
783 # The makefile may define $(extra-libs) with `libfoo libbar'
784 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
786 # extra-lib.mk is included once for each extra lib to define rules
787 # to build it, and to add its objects to the various variables.
788 # During its evaluation, $(lib) is set to the name of the library.
789 extra-libs-left := $(extra-libs)
790 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
794 # The makefile may define $(modules-names) to build additional modules.
795 # These are built with $(build-module), except any in $(modules-names-nobuild).
797 # extra-lib.mk is included once for each extra lib to define rules
798 # to build it, and to add its objects to the various variables.
799 # During its evaluation, $(lib) is set to the name of the library.
800 extra-modules-left := $(modules-names)
801 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
803 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
804 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
805 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
809 +depfiles := $(sources:.c=.d) \
810 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
811 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
812 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
813 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
814 ifeq ($(build-programs),yes)
815 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
817 +depfiles := $(addprefix $(objpfx),\
818 $(filter-out $(addsuffix .d,$(omit-deps)),\
820 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
821 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
822 $(wildcard $(all-dt-files:.dt=.d))
824 # This is a funny rule in that it removes its input file.
826 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
827 mv -f $(@:.d=.T) $@ && \
830 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
831 # They will be generated when they're needed, and trying too early won't work.
832 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
833 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
838 -include $(+depfiles)
842 # Maximize efficiency by minimizing the number of rules.
843 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
844 # Don't define any builtin rules.
845 MAKEFLAGS := $(MAKEFLAGS)r
847 # Generic rule for making directories.
849 # mkdir isn't smart enough to strip a trailing /.
850 # We always require a mkdir which supports the -p option to avoid error
851 # messages in case of races.
854 # Make sure that object files are not removed
855 # when they are intermediates between sources and library members.
856 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
858 # Make sure that the parent library archive is never removed.
859 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
861 # Use the verbose option of ar and tar when not running silently.
862 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
868 ARFLAGS := r$(verbose)
869 CREATE_ARFLAGS := cru$(verbose)
871 # This makes all the object files in the parent library archive.
873 .PHONY: lib lib-noranlib
874 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
875 lib-noranlib: libobjs
877 # For object-suffix $o, the list of objects with that suffix.
878 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
879 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
880 $(elide-routines$o)),\
882 $(addprefix $(objpfx),$(o-objects$o))
884 others: $(addprefix $(objpfx),$(install-lib))
888 # Create the stamp$o files to keep the parent makefile happy.
889 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
890 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
891 $(make-target-directory)
895 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
896 # timestamp file; these rules (one explicit rule is generated for each
897 # object suffix) write a list of objects to update in the stamp file.
898 # The parent will then actually add them all to the archive in the
899 # archive rule, below.
900 define o-iterator-doit
901 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
904 $(make-target-directory)
905 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
908 object-suffixes-left := $(object-suffixes-for-libc)
909 include $(o-iterator)
913 # Now define explicit rules to build the library archives; these depend
914 # on the stamp files built above.
915 define o-iterator-doit
916 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
917 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
920 cd $(common-objdir) && \
921 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
923 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
924 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
926 $(subdirs-stamps): subdir_lib;
928 object-suffixes-left = $(object-suffixes-for-libc)
929 include $(o-iterator)
932 # This makes all the object files.
933 .PHONY: objects objs libobjs extra-objs
934 objects objs: libobjs extra-objs
935 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
936 extra-objs: $(addprefix $(objpfx),$(extra-objs))
938 # Canned sequence for building an extra library archive.
939 define build-extra-lib
940 $(patsubst %/,cd % &&,$(objpfx)) \
941 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
942 $(patsubst $(objpfx)%,%,$^)
947 .PHONY: force-install
950 # $(install-lib) are installed from the object directory into $(libdir);
951 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
952 # unless they also appear in $(non-lib.a). $(install-data) are installed as
953 # they are into $(datadir). $(headers) are installed as they are in
954 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
955 # are installed from the object directory into $(bindir), $(bindir) and
956 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
957 # are absolute path names of files to install; rules to install them are
960 # The simple library name to install libc.a under.
961 # This could be defined by a sysdep Makefile.
967 $(make-target-directory)
968 $(INSTALL_DATA) $< $@
971 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
972 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
973 define make-target-directory
974 $(addprefix $(..)./scripts/mkinstalldirs ,\
975 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
978 # Any directory (parent or subdir) should install libc.a; this way
979 # "make install" in a subdir is guaranteed to install everything it changes.
980 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
981 $(inst_libdir)/$(patsubst %,$(libtype$o),\
982 $(libprefix)$(libc-name)))
984 .PHONY: check-install-supported
985 check-install-supported:
987 # Check to see if the prefix or exec_prefix GNU standard variable
988 # has been overridden on the command line and, if so, fail with
989 # an error message since doing so is not supported (set DESTDIR
991 ifeq ($(origin prefix),command line)
992 check-install-supported:
993 $(error Overriding prefix is not supported. Set DESTDIR instead.)
996 ifeq ($(origin exec_prefix),command line)
997 check-install-supported:
998 $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
1001 install: check-install-supported
1003 install: $(installed-libcs)
1004 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
1005 $(make-target-directory)
1006 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
1008 define do-install-program
1009 $(make-target-directory)
1010 $(INSTALL_PROGRAM) $< $@.new
1014 define do-install-script
1015 $(make-target-directory)
1016 $(INSTALL_SCRIPT) $< $@.new
1020 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
1021 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
1023 ifeq (yes,$(build-shared))
1024 # Find which .so's have versions.
1025 versioned := $(strip $(foreach so,$(install-lib.so),\
1026 $(patsubst %,$(so),$($(so)-version))))
1028 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
1029 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
1031 # For versioned libraries, we install three files:
1032 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
1033 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
1034 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
1035 lib-version := $(firstword $($(subdir)-version) $(version))
1036 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
1037 $(foreach L,$(install-lib.so-versioned),\
1039 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
1040 $(inst_slibdir)/$L$($L-version))
1042 # Install all the unversioned shared libraries.
1043 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
1044 $(objpfx)%.so $(+force)
1045 $(do-install-program)
1047 ifneq ($(findstring -s,$(LN_S)),)
1050 $(SHELL) $(..)scripts/rellns-sh $< $@.new
1054 # If we have no symbolic links don't bother with rellns-sh.
1062 ifeq (yes,$(build-shared))
1063 ifeq (no,$(cross-compiling))
1064 symbolic-link-prog := $(elf-objpfx)sln
1065 symbolic-link-list := $(elf-objpfx)symlink.list
1066 define make-shlib-link
1067 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
1069 else # cross-compiling
1070 # We need a definition that can be used by elf/Makefile's install rules.
1071 symbolic-link-prog = $(LN_S)
1074 ifndef make-shlib-link
1075 define make-shlib-link
1077 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
1081 ifdef libc.so-version
1082 # For a library specified to be version N, install three files:
1083 # libc.so -> libc.so.N (e.g. libc.so.6)
1084 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
1086 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1089 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1090 $(do-install-program)
1091 install: $(inst_slibdir)/libc.so$(libc.so-version)
1093 # This fragment of linker script gives the OUTPUT_FORMAT statement
1094 # for the configuration we are building. We put this statement into
1095 # the linker scripts we install for -lc et al so that they will not be
1096 # used by a link for a different format on a multi-architecture system.
1097 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
1098 $(common-objpfx)config.make \
1099 $(common-objpfx)config.h $(..)Makerules
1100 ifneq (unknown,$(output-format))
1101 echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1103 $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
1104 $(LDFLAGS.so) $(LDFLAGS-lib.so) \
1105 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1106 | sed -n -f $< > $@.new
1111 common-generated += format.lds
1114 # What we install as libc.so for programs to link against is in fact a
1115 # link script. It contains references for the various libraries we need.
1116 # The libc.so object is not complete since some functions are only defined
1117 # in libc_nonshared.a.
1118 # We need to use absolute paths since otherwise local copies (if they exist)
1119 # of the files are taken by the linker.
1120 install: $(inst_libdir)/libc.so
1121 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1122 $(common-objpfx)libc.so$(libc.so-version) \
1123 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1124 $(libprefix)$(libc-name)) \
1126 (echo '/* GNU ld script';\
1127 echo ' Use the shared library, but some functions are only in';\
1128 echo ' the static library, so try that secondarily. */';\
1130 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1131 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1132 ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1139 install: $(inst_slibdir)/libc.so
1140 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1141 $(do-install-program)
1144 ifneq (,$(versioned))
1145 # Produce three sets of rules as above for all the smaller versioned libraries.
1147 define o-iterator-doit
1148 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1150 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1151 ifneq (,$(object-suffixes-left))
1152 include $(o-iterator)
1155 # Make symlinks in the build directory, because the versioned names might
1156 # be referenced by a DT_NEEDED in another library.
1157 define o-iterator-doit
1158 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1160 object-suffixes-left := $(versioned)
1161 include $(o-iterator)
1163 generated += $(foreach o,$(versioned),$o$($o-version))
1165 ifeq (,$($(subdir)-version))
1166 define o-iterator-doit
1167 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1171 object-suffixes-left := $(versioned)
1172 include $(o-iterator)
1174 define o-iterator-doit
1175 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1176 $$(do-install-program)
1178 object-suffixes-left := $(versioned)
1179 include $(o-iterator)
1181 define o-iterator-doit
1182 $(inst_slibdir)/$o$($o-version): \
1183 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1186 object-suffixes-left := $(versioned)
1187 include $(o-iterator)
1189 define o-iterator-doit
1190 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1191 $$(do-install-program)
1193 object-suffixes-left := $(versioned)
1194 include $(o-iterator)
1198 define do-install-so
1199 $(do-install-program)
1200 $(patsubst %,$(LN_S) -f $(@F) \
1201 $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1202 $(filter-out %.so,$@))
1205 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1206 $(foreach v,$(so-versions),\
1207 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1210 $(foreach v,$(so-versions),\
1211 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1216 $(addprefix $(inst_bindir)/,$(install-bin)): \
1217 $(inst_bindir)/%: $(objpfx)% $(+force)
1218 $(do-install-program)
1220 ifdef install-bin-script
1221 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1222 $(inst_bindir)/%: $(objpfx)% $(+force)
1223 $(do-install-script)
1225 ifdef install-rootsbin
1226 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1227 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1228 $(do-install-program)
1231 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1232 $(inst_sbindir)/%: $(objpfx)% $(+force)
1233 $(do-install-program)
1236 install-lib.a := $(filter lib%.a,$(install-lib))
1237 install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
1238 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1239 ifdef install-lib-non.a
1240 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1241 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1245 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1246 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1251 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1254 headers := $(strip $(headers))
1256 # This implicit rule installs headers from the source directory.
1257 # It may be ignored in preference to rules from sysd-rules to find
1258 # headers in the sysdeps tree.
1259 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1261 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1263 $(inst_includedir)/%.h: %.h $(+force)
1265 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1267 headers-nonh := $(filter-out %.h,$(headers))
1269 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1272 endif # headers-nonh
1275 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1276 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1277 install-data-nosubdir install-headers-nosubdir
1278 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1279 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1280 install-rootsbin-nosubdir: \
1281 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1282 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1283 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1284 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1285 $(addprefix $(libprefix),$(install-lib-non.a)))
1286 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1287 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1288 install-others-nosubdir: $(install-others)
1289 install-others-programs-nosubdir: $(install-others-programs)
1291 # We need all the `-nosubdir' targets so that `install' in the parent
1292 # doesn't depend on several things which each iterate over the subdirs.
1293 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1294 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1295 install-%:: install-%-nosubdir ;
1297 .PHONY: install install-no-libc.a-nosubdir
1298 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1299 install-lib-nosubdir install-others-nosubdir
1300 ifeq ($(build-programs),yes)
1301 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1302 install-rootsbin-nosubdir install-sbin-nosubdir \
1303 install-others-programs-nosubdir
1305 install: install-no-libc.a-nosubdir
1307 # Command to compile $< using the native libraries.
1308 define native-compile
1309 $(make-target-directory)
1310 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1311 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1314 # We always want to use configuration definitions.
1315 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1316 -DIS_IN_build -include $(common-objpfx)config.h
1318 # Support the GNU standard name for this target.
1321 # Special target to run tests which cannot be run unconditionally.
1322 # Maintainers should use this target.
1326 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1327 ifneq (,$(all-nonlib))
1328 cpp-srcs-left = $(all-nonlib)
1330 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1334 ifeq ($(build-shared),yes)
1335 # Generate normalized lists of symbols, versions, and data sizes.
1336 # This is handy for checking against existing library binaries.
1338 %.symlist: $(..)scripts/abilist.awk %.dynsym
1339 LC_ALL=C $(AWK) -f $^ > $@T
1343 LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1346 # A sysdeps/.../Makefile can set abilist-pattern to something like
1347 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1348 # This makes sense if multiple ABIs can be most cleanly supported by a
1349 # configuration without using separate sysdeps directories for each.
1350 ifdef abilist-pattern
1351 vpath $(abilist-pattern) $(+sysdep_dirs)
1354 vpath %.abilist $(+sysdep_dirs)
1356 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1357 # target pattern is %.symlist from being considered "intermediate files"
1358 # and automatically removed. We only want these files to be removed by
1359 # 'make clean', which is handled by the 'generated' variable.
1360 .PRECIOUS: %.symlist
1361 generated += $(extra-libs:=.symlist)
1363 ifdef abilist-pattern
1364 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1366 $(check-abi-pattern); \
1368 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1369 $(common-objpfx)%.symlist
1370 $(check-abi-pattern); \
1373 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1377 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1378 $(common-objpfx)%.symlist
1381 define check-abi-pattern
1382 diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1386 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1389 ifdef abilist-pattern
1390 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1391 $(update-abi-pattern)
1392 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1393 $(update-abi-pattern)
1395 update-abi-%: $(objpfx)%.symlist %.abilist
1397 update-abi-%: $(common-objpfx)%.symlist %.abilist
1399 define update-abi-pattern
1400 @if cmp -s $^ 2> /dev/null; \
1402 echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1404 echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1408 @if cmp -s $^ 2> /dev/null; \
1410 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1412 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1416 # Patch all .abilist files for one DSO. The find command locates
1417 # abilist files for all architectures. The regular expression in the
1418 # find invocation is needed to separate libc.abilist and
1419 # libcrypt.abilist, for example. It assumes that abilist-pattern, if
1420 # set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
1421 # a non-alphanumeric seperator between the pattern and the suffix
1422 # added. The abilist files in /generic/ are filtered out because
1423 # these are expected to remain empty.
1424 define update-all-abi
1425 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1426 $$(find $(..)sysdeps \
1427 -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
1428 \! -regex '.*/generic/.*')
1430 ifdef abilist-pattern
1431 update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
1433 update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
1436 update-all-abi-%: %.abilist $(objpfx)%.symlist
1438 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1441 .PHONY: update-abi update-all-abi check-abi
1442 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1443 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1444 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1445 $(install-lib.so-versioned))
1446 check-abi: $(check-abi-list)
1448 subdir_check-abi: check-abi
1449 subdir_update-abi: update-abi
1450 subdir_update-all-abi: update-all-abi
1452 check-abi: subdir_check-abi
1453 if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1454 cat $(objpfx)*/check-abi*.out && exit 1; fi
1455 update-abi: subdir_update-abi
1456 update-all-abi: subdir_update-all-abi
1459 ifeq ($(subdir),elf)
1460 check-abi: $(objpfx)check-abi-libc.out
1461 tests-special += $(objpfx)check-abi-libc.out
1462 update-abi: update-abi-libc
1463 update-all-abi: update-all-abi-libc
1464 common-generated += libc.symlist
1467 ifeq ($(build-shared),yes)
1469 tests-special += $(check-abi-list)
1475 # These will have been set by sysdeps/posix/Makefile.
1481 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1483 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1484 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1485 $(common-objpfx)config.make
1486 $(make-target-directory)
1487 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1488 echo '#define _LIBC 1'; \
1489 echo '#include "$(..)misc/sys/uio.h"'; } | \
1490 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1491 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1492 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1493 $(@:st=dT) > $(@:st=dt)
1494 mv -f $(@:st=dt) $(@:st=d)
1495 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1496 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1497 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1498 fopen_max=$${fopen_max:-16}; \
1499 filename_max=$${filename_max:-1024}; \
1500 if [ -z "$$iov_max" ]; then \
1501 define_iov_max="# undef IOV_MAX"; \
1503 define_iov_max="# define IOV_MAX $$iov_max"; \
1505 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1506 -e "s/@FILENAME_MAX@/$$filename_max/" \
1507 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1508 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1509 -e "s/@L_ctermid@/$(L_ctermid)/" \
1510 -e "s/@L_cuserid@/$(L_cuserid)/" \
1511 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1513 $(move-if-change) $(@:st=h.new) $(@:st=h)
1514 # Remove these last so that they can be examined if something went wrong.
1515 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1519 -include $(stdio_lim:h=d)
1521 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1525 .PHONY: echo-headers
1529 %.bz2: %; bzip2 -9vk $<
1530 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1531 %.xz: %; xz -9evk $<
1533 # Common cleaning targets.
1535 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1537 mostlyclean: common-mostlyclean
1540 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1542 $(addsuffix .test-result,$(tests) \
1546 # Remove the object files.
1548 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1549 $(others) $(sysdep-others) stubs \
1550 $(addsuffix .o,$(tests) $(xtests) \
1551 $(test-srcs) $(others) \
1553 $(addsuffix .out,$(tests) $(xtests) \
1555 $(addsuffix .test-result,$(tests) \
1558 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1559 $(install-lib) $(install-lib.so) \
1560 $(install-lib.so:%.so=%_pic.a))
1562 -rm -f $(objpfx)rtld-*.os
1565 $(foreach o,$(object-suffixes-for-libc),
1566 -rm -f $(objpfx)stamp$o $(o-objects))
1569 # Also remove the dependencies and generated source files.
1570 common-clean: common-mostlyclean
1571 -rm -f $(addprefix $(objpfx),$(generated))
1572 -rm -f $(objpfx)*.d $(objpfx)*.dt
1573 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1574 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1575 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1577 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1578 # for each function which is a stub.
1581 .PHONY: stubs # The parent Makefile calls this target.
1582 stubs: $(objpfx)stubs
1584 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1585 $(addprefix $(objpfx),$(extra-objs))
1586 $(objpfx)stubs: $(objs-for-stubs)
1587 ifneq (,$(strip $(objs-for-stubs)))
1588 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1589 $(AWK) '/\.gnu\.glibc-stub\./ { \
1590 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1592 END { for (s in stubs) print "#define __stub_" s }' > $@T
1598 ifneq (,$(strip $(gpl2lgpl)))
1599 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1600 # Snarf from the master source and frob the copying notice.
1601 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1603 # So I don't edit them by mistake.