1 # Copyright (C) 1991-2022 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 # <https://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
109 # first-versions.h and ldbl-compat-choose.h provide macros used in
110 # various symbol versioning macro calls.
111 before-compile := $(common-objpfx)first-versions.h \
112 $(common-objpfx)ldbl-compat-choose.h $(before-compile)
113 $(common-objpfx)first-versions.h: $(common-objpfx)versions.stmp
114 $(common-objpfx)ldbl-compat-choose.h: $(common-objpfx)versions.stmp
116 # libc_early_init_name.h provides the actual name of the
117 # __libc_early_init function. It is used as a protocol version marker
118 # between ld.so and libc.so
119 before-compile := $(common-objpfx)libc_early_init_name.h $(before-compile)
120 libc_early_init_name-deps = \
121 $(..)NEWS $(..)sysdeps/generic/ldsodefs.h $(..)include/link.h
122 $(common-objpfx)libc_early_init_name.h: $(..)scripts/libc_early_init_name.py \
123 $(common-objpfx)config.make $(libc_early_init_name-deps)
124 $(PYTHON) $(..)scripts/libc_early_init_name.py \
126 --extra-version-id="$(extra-version-id)" \
127 $(libc_early_init_name-deps)
128 $(move-if-change) $@T $@
129 endif # avoid-generated
130 endif # $(build-shared) = yes
132 ifndef avoid-generated
134 # If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
135 # /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
136 # (instead of stdlib/stdlib.h or math/math.h in the glibc source
137 # directory), and this turns up as a make dependency. An implicit
138 # rule will kick in and make will try to install stdlib/stdlib.h or
139 # math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
140 # the target is out of date. We make a copy of <cstdlib> and <cmath>
141 # in the glibc build directory so that stdlib/stdlib.h and math/math.h
142 # will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
143 before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
145 $(common-objpfx)cstdlib: $(c++-cstdlib-header)
146 $(INSTALL_DATA) $< $@T
147 $(move-if-change) $@T $@
148 $(common-objpfx)cmath: $(c++-cmath-header)
149 $(INSTALL_DATA) $< $@T
150 $(move-if-change) $@T $@
151 ifneq (,$(c++-bits-std_abs-h))
152 # Also make a copy of <bits/std_abs.h> from GCC 7 to prevent it from
153 # including /usr/include/stdlib.h.
154 before-compile := $(common-objpfx)bits/std_abs.h $(before-compile)
155 $(common-objpfx)bits/std_abs.h: $(c++-bits-std_abs-h)
156 $(INSTALL_DATA) $< $@T
157 $(move-if-change) $@T $@
161 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
162 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
163 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
164 $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
168 $(base-machine)-$(config-vendor)-$(config-os) \
169 < $(word 2,$^) > $(@:.stamp=.h)T
170 $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
172 common-generated += $(common-objpfx)libc-abis.h
173 endif # avoid-generated
175 ifeq (yes,$(build-shared))
176 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
177 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
178 $(make-target-directory)
179 echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
181 $(move-if-change) ${@:stamp=T} ${@:stamp=h}
185 # Make sure the subdirectory for object files gets created.
187 ifeq (,$(wildcard $(objpfx).))
188 before-compile += $(objpfx).
190 $(make-target-directory)
194 # Remove existing files from `before-compile'. Things are added there when
195 # they must exist for dependency generation to work right, but once they
196 # exist there is no further need for every single file to depend on them,
197 # and those gratuitous dependencies result in many gratuitous
199 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
201 # Don't let any before-compile file be an intermediate and get removed.
206 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
209 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
211 common-before-compile = $(before-compile)
215 # If a makefile needs to do something conditional on something that
216 # can only be figured out from headers, write a FOO.make.c input
217 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
218 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
220 # We only generate these in the top-level makefile, to avoid any weirdness
221 # from subdir-specific makefile tweaks creeping in on an update.
222 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
224 (echo '# Generated from $*.make.c by Makerules.'; \
225 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
226 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
227 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
228 echo 'common-generated += $(@F)'; \
229 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
235 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
236 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
238 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
239 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
242 ifdef gen-py-const-headers
243 # We'll use a static pattern rule to match .pysym files with their
244 # corresponding generated .py files.
245 # The generated .py files go in the submodule's dir in the glibc build dir.
246 py-const-files := $(patsubst %.pysym,%.py,$(gen-py-const-headers))
247 py-const-dir := $(objpfx)
248 py-const := $(addprefix $(py-const-dir),$(py-const-files))
249 py-const-script := $(..)scripts/gen-as-const.py
251 # This is a hack we use to generate .py files with constants for
254 # $@.tmp is a temporary file we use to store the partial contents of
255 # the target file. We do this instead of just writing on $@ because,
256 # if the build process terminates prematurely, re-running Make
257 # wouldn't run this rule since Make would see that the target file
258 # already exists (despite it being incomplete).
260 # The output is redirected to a .py file; we'll import it in the main
261 # Python code to read the constants generated by gen-as-const.py.
262 $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
263 $(common-before-compile)
264 $(make-target-directory)
265 $(PYTHON) $(py-const-script) --python \
266 --cc="$(CC) $(CFLAGS) $(CPPFLAGS)" $< \
270 generated += $(py-const)
271 endif # gen-py-const-headers
273 ifdef gen-as-const-headers
274 # Generating headers for assembly constants.
275 # We need this defined early to get into before-compile before
276 # it's used in sysd-rules, below.
277 # Define GEN_AS_CONST_HEADERS to avoid circular dependency [BZ #22792].
278 # NB: <tcb-offsets.h> is generated from tcb-offsets.sym to define
279 # offsets and sizes of types in <tls.h> and maybe <pthread.h> which
280 # may include <tcb-offsets.h>. Target header files can check if
281 # GEN_AS_CONST_HEADERS is defined to avoid circular dependency which
282 # may lead to build hang on a many-core machine.
283 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.py \
284 %.sym $(common-before-compile)
285 $(PYTHON) $< --cc="$(CC) $(CFLAGS) $(CPPFLAGS) -DGEN_AS_CONST_HEADERS \
286 -MD -MP -MF $(@:.h=.h.d)T \
287 -MT '$(@:.h=.h.d) $(@:.h.d=.h)'" \
288 $(filter %.sym,$^) > $(@:.h.d=.h)T
289 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
290 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
292 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
293 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
294 vpath %.sym $(sysdirs)
295 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
297 tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
298 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
299 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.py $(..)Makerules \
300 %.sym $(common-objpfx)%.h
301 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
302 $(PYTHON) $< --test $(filter %.sym,$^)) > $@T
306 ifeq (yes,$(build-shared))
307 # Generate the header containing the names of all shared libraries.
308 # We use a stamp file to avoid unnecessary recompilations.
309 before-compile += $(common-objpfx)gnu/lib-names.h
310 ifeq ($(soversions.mk-done),t)
312 lib-names-h-abi = gnu/lib-names.h
313 lib-names-stmp-abi = gnu/lib-names.stmp
315 lib-names-h-abi = gnu/lib-names-$(default-abi).h
316 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
317 before-compile += $(common-objpfx)$(lib-names-h-abi)
318 common-generated += gnu/lib-names.h
319 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
320 $(common-objpfx)gnu/lib-names.h:
321 $(make-target-directory)
323 echo '/* This file is automatically generated.';\
324 echo ' It defines macros to allow user program to find the shared'; \
325 echo ' library files which come as part of GNU libc. */'; \
326 echo '#ifndef __GNU_LIB_NAMES_H'; \
327 echo '#define __GNU_LIB_NAMES_H 1'; \
329 $(if $(abi-includes), \
330 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
332 $(foreach v,$(abi-variants),\
333 $(if $(abi-$(v)-condition),\
334 echo '#if $(abi-$(v)-condition)'; \
335 echo '# include <gnu/lib-names-$(v).h>'); \
336 $(if $(abi-$(v)-condition),echo '#endif';)) \
338 echo '#endif /* gnu/lib-names.h */'; \
341 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
342 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
343 $(common-objpfx)soversions.i
344 $(make-target-directory)
346 $(if $(abi-variants), \
347 echo '/* This file is automatically generated. */';\
348 echo '#ifndef __GNU_LIB_NAMES_H'; \
349 echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
351 echo '/* This file is automatically generated.';\
352 echo ' It defines macros to allow user program to find the shared'; \
353 echo ' library files which come as part of GNU libc. */'; \
354 echo '#ifndef __GNU_LIB_NAMES_H'; \
355 echo '#define __GNU_LIB_NAMES_H 1';) \
357 ($(foreach s,$(all-sonames), echo $(s);)) \
358 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
359 $(if $(abi-variants),, \
361 echo '#endif /* gnu/lib-names.h */';) \
363 $(move-if-change) ${@:stmp=T} ${@:stmp=h}
366 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
369 ###############################################################################
370 # NOTE! Everything adding to before-compile needs to come before this point! #
371 ###############################################################################
373 # Generate an ordered list of implicit rules which find the source files in
374 # each sysdep directory. The old method was to use vpath to search all the
375 # sysdep directories. However, that had the problem that a .S file in a
376 # later directory would be chosen over a .c file in an earlier directory,
377 # which does not preserve the desired sysdeps ordering behavior.
379 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
380 # matching sysdep directories whose assembly source files should be
383 -include $(common-objpfx)sysd-rules
384 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
385 # The value of $(+sysdep_dirs) the sysd-rules was computed for
386 # differs from the one we are using now. So force a rebuild of sysd-rules.
387 sysd-rules-force = FORCE
390 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
391 $(common-objpfx)config.make $(..)Makerules \
392 $(sysdep-makefiles) $(sysdep-makeconfigs) \
395 LC_ALL=C $(AWK) -f $< > $@T \
396 -v all_object_suffixes='$(all-object-suffixes)' \
397 -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
398 -v sysd_rules_patterns='$(sysd-rules-patterns)' \
399 -v config_sysdirs='$(config-sysdirs)'
402 ifndef sysd-rules-done
403 # Don't do deps until this exists, because it provides rules to make the deps.
407 define o-iterator-doit
408 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
410 object-suffixes-left := $(all-object-suffixes)
411 include $(o-iterator)
413 define o-iterator-doit
414 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
416 object-suffixes-left := $(all-object-suffixes)
417 include $(o-iterator)
419 define o-iterator-doit
420 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
422 object-suffixes-left := $(all-object-suffixes)
423 include $(o-iterator)
425 # Omit the objpfx rules when building in the source tree, because
426 # objpfx is empty and so these rules just override the ones above.
428 # Define first rules to find the source files in $(objpfx).
429 # Generated source files will end up there.
430 define o-iterator-doit
431 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
433 object-suffixes-left := $(all-object-suffixes)
434 include $(o-iterator)
436 define o-iterator-doit
437 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
439 object-suffixes-left := $(all-object-suffixes)
440 include $(o-iterator)
442 define o-iterator-doit
443 $(objpfx)%$o: $(objpfx)%.cc $(before-compile); $$(compile-command.cc)
445 object-suffixes-left := $(all-object-suffixes)
446 include $(o-iterator)
449 # Generate .dT files as we compile.
450 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
451 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
452 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
453 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
455 # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
456 # track system includes here, they may spuriously trigger an install rule,
457 # and would cause the check-local-headers test to fail.
458 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
460 # GCC can grok options after the file name, and it looks nicer that way.
461 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
462 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
463 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
464 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
465 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
466 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
467 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
469 # We need this for the output to go in the right place. It will default to
470 # empty if make was configured to work with a cc that can't grok -c and -o
471 # together. You can't compile the C library with such a compiler.
472 OUTPUT_OPTION = -o $@
474 # This is the end of the pipeline for compiling generated C code.
475 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
477 # We need the $(CFLAGS) to be in there to have the right predefines during
478 # the dependency run for C sources. But having it for assembly sources can
479 # get the wrong predefines.
480 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
483 # Continuation lines here are dangerous because they introduce spaces!
484 define sed-remove-objpfx
485 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
486 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
490 # Modify the list of routines we build for different targets
492 ifeq (yes,$(build-shared))
493 ifndef libc.so-version
494 # Undefine this because it can't work when we libc.so is unversioned.
495 static-only-routines =
499 elide-routines.oS += $(filter-out $(static-only-routines),\
500 $(routines) $(aux) $(sysdep_routines))
501 elide-routines.os += $(static-only-routines)
503 # If we have versioned code we don't need the old versions in any of the
505 elide-routines.o += $(shared-only-routines)
506 elide-routines.op += $(shared-only-routines)
508 # Shared library building.
510 ifeq (yes,$(build-shared))
512 # Reference map file only when shared libraries are built and a map file name
514 ifeq ($(build-shared),yes)
515 map-file = $(firstword $($(@F:.so=-map)) \
516 $(addprefix $(common-objpfx), \
517 $(filter $(@F:.so=.map),$(version-maps))))
518 load-map-file = $(map-file:%=-Wl,--version-script=%)
521 # Compiler arguments to use to link a shared object with libc and
522 # ld.so. This is intended to be as similar as possible to a default
523 # link with an installed libc.
524 link-libc-args = -Wl,--start-group \
526 $(common-objpfx)libc_nonshared.a \
527 -Wl,--as-needed $(elf-objpfx)ld.so -Wl,--no-as-needed \
530 # The corresponding shared libc to use. This may be modified for a
532 libc-for-link = $(common-objpfx)libc.so
534 # The corresponding dependencies. As these are used in dependencies,
535 # not just commands, they cannot use target-specific variables so need
536 # to name both possible libc.so objects.
537 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
538 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
540 # Pattern rule to build a shared object from an archive of PIC objects.
541 # This must come after the installation rules so Make doesn't try to
542 # build shared libraries in place from the installed *_pic.a files.
543 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
544 # on other shared objects. The linking with libc and ld.so is intended
545 # to be as similar as possible to a default link with an installed libc.
546 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
547 $(build-shlib) $(link-libc-args)
548 $(call after-link,$@)
550 define build-shlib-helper
551 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
552 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
553 $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
554 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
555 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
556 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
557 $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
558 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
561 ifeq (yes,$(use-default-link))
562 # If the linker is good enough, we can let it use its default linker script.
566 # binutils only position loadable notes into the first page for binaries,
567 # not for shared objects
568 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
569 $(LINK.o) -shared -Wl,-O1 \
570 -nostdlib -nostartfiles \
571 $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
572 -Wl,--verbose 2>/dev/null | \
574 -e '/^=========/,/^=========/!d;/^=========/d' \
575 -e 's/^.*\*(\.dynbss).*$$/& \
576 PROVIDE(__start___libc_freeres_ptrs = .); \
577 *(__libc_freeres_ptrs) \
578 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
579 -e 's@^.*\*(\.jcr).*$$@& \
580 PROVIDE(__start___libc_subfreeres = .);\
581 __libc_subfreeres : { *(__libc_subfreeres) }\
582 PROVIDE(__stop___libc_subfreeres = .);\
583 PROVIDE(__start___libc_atexit = .);\
584 __libc_atexit : { *(__libc_atexit) }\
585 PROVIDE(__stop___libc_atexit = .);\
586 PROVIDE(__start___libc_IO_vtables = .);\
587 __libc_IO_vtables : { *(__libc_IO_vtables) }\
588 PROVIDE(__stop___libc_IO_vtables = .);\
589 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
592 common-generated += shlib.lds
594 shlib-lds = $(common-objpfx)shlib.lds
595 shlib-lds-flags = -T $(shlib-lds)
599 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
600 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
603 define build-module-helper
604 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
605 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
606 $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
607 -B$(csu-objpfx) $(load-map-file) \
608 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
609 $(link-test-modules-rpath-link) \
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 # sofini.os must be placed last since it terminates .eh_frame section.
631 build-module-helper-objlist = \
632 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
633 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
634 $(elf-objpfx)sofini.os \
635 $(link-libc-deps),$^))
637 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
638 build-shlib-objlist = $(build-module-helper-objlist) \
639 $(LDLIBS-$(@F:lib%.so=%).so) \
640 $(filter $(elf-objpfx)sofini.os,$^)
642 # Don't try to use -lc when making libc.so itself.
643 # Also omits crti.o and crtn.o, which we do not want
644 # since we define our own `.init' section specially.
645 LDFLAGS-c.so = -nostdlib -nostartfiles
646 # But we still want to link libc.so against $(libc.so-gnulib).
647 LDLIBS-c.so += $(libc.so-gnulib)
648 # Give libc.so an entry point and make it directly runnable itself.
649 LDFLAGS-c.so += -e __libc_main
650 # Pre-link the objects of libc_pic.a for .gnu.glibc-stub.* processing.
651 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
652 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
653 $(LDFLAGS-c_pic.os) $(whole-archive) $^ -o $@
655 ifeq (,$(strip $(shlib-lds-flags)))
656 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
657 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
659 $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
662 # Apply those -R options.
663 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
664 $(common-objpfx)libc_pic.os
666 generated += libc_pic.opts libc_pic.os.clean
668 libc_pic_clean := .clean
671 # Build a possibly-modified version of libc_pic.a for use in building
673 ifeq (,$(filter sunrpc,$(subdirs)))
674 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
675 $(make-target-directory)
678 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
679 $(common-objpfx)sunrpc/librpc_compat_pic.a
680 $(make-target-directory)
681 (cd $(common-objpfx)linkobj; \
682 $(AR) x ../libc_pic.a; \
683 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
684 $(AR) x ../sunrpc/librpc_compat_pic.a; \
685 $(AR) cr libc_pic.a *.os; \
687 endif # $(subdirs) contains sunrpc
689 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
690 # filter ld.so out of the list of linked objects.
691 $(common-objpfx)libc.so: link-libc-deps = # empty
692 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
694 # Use our own special initializer and finalizer files for the libc.so
696 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.os$(libc_pic_clean) \
697 $(elf-objpfx)sofini.os \
698 $(elf-objpfx)interp.os \
702 $(call after-link,$@)
704 $(common-objpfx)linkobj/libc.so: $(common-objpfx)linkobj/libc_pic.a \
705 $(elf-objpfx)sofini.os \
706 $(elf-objpfx)interp.os \
710 $(call after-link,$@)
712 ifeq ($(build-shared),yes)
713 $(common-objpfx)libc.so: $(common-objpfx)libc.map
715 common-generated += libc.so libc_pic.os
716 ifdef libc.so-version
717 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
719 common-generated += libc.so$(libc.so-version)
723 # Figure out the source filenames in this directory.
725 override sources := $(addsuffix .c,\
726 $(filter-out $(elided-routines),\
729 sysdep_routines := $(sysdep_routines)
731 headers := $(headers) $(sysdep_headers)
733 # This is the list of all object files, gotten by
734 # replacing every ".c" in `sources' with a ".o".
735 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
738 # The makefile may define $(extra-libs) with `libfoo libbar'
739 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
741 # extra-lib.mk is included once for each extra lib to define rules
742 # to build it, and to add its objects to the various variables.
743 # During its evaluation, $(lib) is set to the name of the library.
744 extra-libs-left := $(extra-libs)
745 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
749 # The makefile may define $(modules-names) to build additional modules.
750 # These are built with $(build-module), except any in $(modules-names-nobuild).
751 # MODULE_NAME=extramodules, except any in $(modules-names-tests).
753 cpp-srcs-left := $(filter-out $(modules-names-tests),$(modules-names))
754 ifneq (,$(cpp-srcs-left))
756 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
759 ifdef modules-names-tests
760 cpp-srcs-left := $(filter $(modules-names-tests),$(modules-names))
761 ifneq (,$(cpp-srcs-left))
763 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
767 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
768 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
769 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
773 +depfiles := $(sources:.c=.d) \
774 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
775 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
776 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
777 $(addsuffix .d,$(tests) $(tests-internal) $(xtests) \
778 $(tests-container) $(tests-printers) \
779 $(test-srcs) $(tests-time64) $(xtests-time64))
780 ifeq ($(build-programs),yes)
781 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
783 +depfiles := $(addprefix $(objpfx),\
784 $(filter-out $(addsuffix .d,$(omit-deps)),\
786 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
787 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
788 $(wildcard $(all-dt-files:.dt=.d))
790 # This is a funny rule in that it removes its input file.
792 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
793 mv -f $(@:.d=.T) $@ && \
796 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
797 # They will be generated when they're needed, and trying too early won't work.
798 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
799 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
804 -include $(+depfiles)
808 # Maximize efficiency by minimizing the number of rules.
809 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
810 # Don't define any builtin rules.
811 MAKEFLAGS := $(MAKEFLAGS)r
813 # Generic rule for making directories.
815 # mkdir isn't smart enough to strip a trailing /.
816 # We always require a mkdir which supports the -p option to avoid error
817 # messages in case of races.
820 # Make sure that object files are not removed
821 # when they are intermediates between sources and library members.
822 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
824 # Make sure that the parent library archive is never removed.
825 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
827 # Use the verbose option of ar and tar when not running silently.
828 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
834 ARFLAGS := r$(verbose)
835 CREATE_ARFLAGS := cru$(verbose)
837 # This makes all the object files in the parent library archive.
839 .PHONY: lib lib-noranlib
840 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
841 lib-noranlib: libobjs
843 # For object-suffix $o, the list of objects with that suffix.
844 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
845 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
846 $(elide-routines$o)),\
848 $(addprefix $(objpfx),$(o-objects$o))
850 others: $(addprefix $(objpfx),$(install-lib))
854 # Create the stamp$o files to keep the parent makefile happy.
855 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
856 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
857 $(make-target-directory)
861 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
862 # timestamp file; these rules (one explicit rule is generated for each
863 # object suffix) write a list of objects to update in the stamp file.
864 # The parent will then actually add them all to the archive in the
865 # archive rule, below.
866 define o-iterator-doit
867 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
870 $(make-target-directory)
871 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
874 object-suffixes-left := $(object-suffixes-for-libc)
875 include $(o-iterator)
879 # Now define explicit rules to build the library archives; these depend
880 # on the stamp files built above.
881 define o-iterator-doit
882 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
883 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
886 cd $(common-objdir) && \
887 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
889 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
890 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
892 $(subdirs-stamps): subdir_lib;
894 object-suffixes-left = $(object-suffixes-for-libc)
895 include $(o-iterator)
898 # This makes all the object files.
899 .PHONY: objects objs libobjs extra-objs
900 objects objs: libobjs extra-objs
901 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
902 extra-objs: $(addprefix $(objpfx),$(extra-objs))
904 # Canned sequence for building an extra library archive.
905 define build-extra-lib
906 $(patsubst %/,cd % &&,$(objpfx)) \
907 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
908 $(patsubst $(objpfx)%,%,$^)
913 .PHONY: force-install
916 # $(install-lib) are installed from the object directory into $(libdir);
917 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
918 # unless they also appear in $(non-lib.a). $(install-data) are installed as
919 # they are into $(datadir). $(headers) are installed as they are in
920 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
921 # are installed from the object directory into $(bindir), $(bindir) and
922 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
923 # are absolute path names of files to install; rules to install them are
926 # The simple library name to install libc.a under.
927 # This could be defined by a sysdep Makefile.
933 $(make-target-directory)
934 $(INSTALL_DATA) $< $@
937 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
938 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
939 define make-target-directory
940 $(addprefix $(..)./scripts/mkinstalldirs ,\
941 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
944 # Any directory (parent or subdir) should install libc.a; this way
945 # "make install" in a subdir is guaranteed to install everything it changes.
946 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
947 $(inst_libdir)/$(patsubst %,$(libtype$o),\
948 $(libprefix)$(libc-name)))
950 .PHONY: check-install-supported
951 check-install-supported:
953 # Check to see if the prefix or exec_prefix GNU standard variable
954 # has been overridden on the command line and, if so, fail with
955 # an error message since doing so is not supported (set DESTDIR
957 ifeq ($(origin prefix),command line)
958 check-install-supported:
959 $(error Overriding prefix is not supported. Set DESTDIR instead.)
962 ifeq ($(origin exec_prefix),command line)
963 check-install-supported:
964 $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
967 install: check-install-supported
969 install: $(installed-libcs)
970 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
971 $(make-target-directory)
972 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
974 define do-install-program
975 $(make-target-directory)
976 $(INSTALL_PROGRAM) $< $@.new
980 define do-install-script
981 $(make-target-directory)
982 $(INSTALL_SCRIPT) $< $@.new
986 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
987 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
989 ifeq (yes,$(build-shared))
990 # Find which .so's have a version number in their soname.
991 versioned := $(strip $(foreach so,$(install-lib.so),\
992 $(patsubst %,$(so),$($(so)-version))))
994 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
995 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
997 # For libraries whose soname have version numbers, we install two files:
998 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
999 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME
1000 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
1001 $(foreach L,$(install-lib.so-versioned),\
1003 $(inst_slibdir)/$L$($L-version))
1005 # Install all the unversioned shared libraries.
1006 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
1007 $(objpfx)%.so $(+force)
1008 $(do-install-program)
1010 ifneq ($(findstring -s,$(LN_S)),)
1013 $(SHELL) $(..)scripts/rellns-sh $< $@.new
1016 define make-link-multidir
1017 $(patsubst %/,cd %,$(objpfx)); \
1018 $(addprefix $(abspath $(..)scripts/mkinstalldirs) ,$(dir $(multidir))); \
1019 $(LN_S) . $(multidir) 2> /dev/null; \
1023 # If we have no symbolic links don't bother with rellns-sh.
1029 define make-link-multidir
1030 $(make-target-directory)
1031 ln -f $(objpfx)/$(@F) $@
1035 ifdef libc.so-version
1036 $(inst_slibdir)/libc.so$(libc.so-version): $(common-objpfx)libc.so $(+force)
1037 $(do-install-program)
1039 install: $(inst_slibdir)/libc.so$(libc.so-version)
1041 # This fragment of linker script gives the OUTPUT_FORMAT statement
1042 # for the configuration we are building. We put this statement into
1043 # the linker scripts we install for -lc et al so that they will not be
1044 # used by a link for a different format on a multi-architecture system.
1045 $(common-objpfx)format.lds: $(common-objpfx)config.make \
1046 $(common-objpfx)config.h $(..)Makerules
1047 $(LINK.o) -shared -nostdlib -nostartfiles \
1048 -x assembler /dev/null -o $@.so
1049 $(OBJDUMP) -f $@.so | sed -n 's/.*file format \(.*\)/OUTPUT_FORMAT(\1)/;T;p' > $@
1051 common-generated += format.lds
1054 # What we install as libc.so for programs to link against is in fact a
1055 # link script. It contains references for the various libraries we need.
1056 # The libc.so object is not complete since some functions are only defined
1057 # in libc_nonshared.a.
1058 # We need to use absolute paths since otherwise local copies (if they exist)
1059 # of the files are taken by the linker.
1060 install: $(inst_libdir)/libc.so
1061 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1062 $(common-objpfx)libc.so$(libc.so-version) \
1063 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1064 $(libprefix)$(libc-name)) \
1066 (echo '/* GNU ld script';\
1067 echo ' Use the shared library, but some functions are only in';\
1068 echo ' the static library, so try that secondarily. */';\
1070 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1071 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1072 ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1079 install: $(inst_slibdir)/libc.so
1080 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1081 $(do-install-program)
1084 ifneq (,$(versioned))
1085 # Produce three sets of rules as above for all the smaller versioned libraries.
1087 define o-iterator-doit
1088 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1090 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1091 ifneq (,$(object-suffixes-left))
1092 include $(o-iterator)
1095 # Make symlinks in the build directory, because the versioned names might
1096 # be referenced by a DT_NEEDED in another library.
1097 define o-iterator-doit
1098 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1100 object-suffixes-left := $(versioned)
1101 include $(o-iterator)
1103 generated += $(foreach o,$(versioned),$o$($o-version))
1105 define o-iterator-doit
1106 $(inst_slibdir)/$o$($o-version): $(objpfx)$o $(+force);
1107 $$(do-install-program)
1109 object-suffixes-left := $(versioned)
1110 include $(o-iterator)
1111 endif # ifneq (,$(versioned))
1113 define do-install-so
1114 $(do-install-program)
1115 $(patsubst %,$(LN_S) -f $(@F) \
1116 $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1117 $(filter-out %.so,$@))
1120 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1121 $(foreach v,$(so-versions),\
1122 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1125 $(foreach v,$(so-versions),\
1126 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1131 $(addprefix $(inst_bindir)/,$(install-bin)): \
1132 $(inst_bindir)/%: $(objpfx)% $(+force)
1133 $(do-install-program)
1135 ifdef install-bin-script
1136 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1137 $(inst_bindir)/%: $(objpfx)% $(+force)
1138 $(do-install-script)
1140 ifdef install-rootsbin
1141 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1142 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1143 $(do-install-program)
1146 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1147 $(inst_sbindir)/%: $(objpfx)% $(+force)
1148 $(do-install-program)
1151 install-lib.a := $(filter lib%.a,$(install-lib))
1152 install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
1153 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1154 ifdef install-lib-non.a
1155 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1156 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1160 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1161 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1166 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1169 headers := $(strip $(headers))
1171 # This implicit rule installs headers from the source directory.
1172 # It may be ignored in preference to rules from sysd-rules to find
1173 # headers in the sysdeps tree.
1174 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1176 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1178 $(inst_includedir)/%.h: %.h $(+force)
1180 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1182 headers-nonh := $(filter-out %.h,$(headers))
1184 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1187 endif # headers-nonh
1190 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1191 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1192 install-data-nosubdir install-headers-nosubdir
1193 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1194 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1195 install-rootsbin-nosubdir: \
1196 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1197 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1198 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1199 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1200 $(addprefix $(libprefix),$(install-lib-non.a)))
1201 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1202 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1203 install-others-nosubdir: $(install-others)
1204 install-others-programs-nosubdir: $(install-others-programs)
1206 # We need all the `-nosubdir' targets so that `install' in the parent
1207 # doesn't depend on several things which each iterate over the subdirs.
1208 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1209 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1210 install-%:: install-%-nosubdir ;
1212 .PHONY: install install-no-libc.a-nosubdir
1213 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1214 install-lib-nosubdir install-others-nosubdir
1215 ifeq ($(build-programs),yes)
1216 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1217 install-rootsbin-nosubdir install-sbin-nosubdir \
1218 install-others-programs-nosubdir
1220 install: install-no-libc.a-nosubdir
1222 # Command to compile $< using the native libraries.
1223 define native-compile
1224 $(make-target-directory)
1225 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1226 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1229 # We always want to use configuration definitions.
1230 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1231 -DIS_IN_build -include $(common-objpfx)config.h
1233 # Support the GNU standard name for this target.
1236 # Special target to run tests which cannot be run unconditionally.
1237 # Maintainers should use this target.
1241 # Handle tests-time64 and xtests-time64 that should built with LFS
1242 # and 64-bit time support.
1243 include $(o-iterator)
1244 define o-iterator-doit
1245 $(foreach f,$(tests-time64) $(xtests-time64),\
1246 $(objpfx)$(f)$(o)): CFLAGS += -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64
1248 object-suffixes-left := $(all-object-suffixes)
1249 include $(o-iterator)
1251 ifeq ($(have-time64-compat),yes)
1252 tests += $(foreach t,$(tests-time64),$(t))
1253 xtests += $(foreach t,$(xtests-time64),$(t))
1256 # The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
1257 # that almost all internal declarations from config.h, libc-symbols.h, and
1258 # include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
1259 all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) \
1261 ifneq (,$(all-testsuite))
1262 cpp-srcs-left = $(all-testsuite)
1264 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1267 all-nonlib := $(strip $(others) $(others-extras))
1268 ifneq (,$(all-nonlib))
1269 cpp-srcs-left = $(all-nonlib)
1271 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1274 # All internal tests use testsuite-internal module since for 64 bit time
1275 # support is set as default for MODULE_NAME=nonlib (which include some
1276 # installed programs).
1277 all-testsuite-internal := $(strip $(tests-internal) $(test-internal-extras))
1278 ifneq (,$(all-testsuite-internal))
1279 cpp-srcs-left = $(all-testsuite-internal)
1280 lib := testsuite-internal
1281 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1284 ifeq ($(build-shared),yes)
1285 # Generate normalized lists of symbols, versions, and data sizes.
1286 # This is handy for checking against existing library binaries.
1288 %.symlist: $(..)scripts/abilist.awk %.dynsym
1289 LC_ALL=C $(AWK) -f $^ > $@T
1293 LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1296 vpath %.abilist $(+sysdep_dirs)
1298 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1299 # target pattern is %.symlist from being considered "intermediate files"
1300 # and automatically removed. We only want these files to be removed by
1301 # 'make clean', which is handled by the 'generated' variable.
1302 .PRECIOUS: %.symlist
1303 generated += $(extra-libs:=.symlist)
1305 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1309 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1310 $(common-objpfx)%.symlist
1314 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1317 update-abi-%: $(objpfx)%.symlist %.abilist
1319 update-abi-%: $(common-objpfx)%.symlist %.abilist
1322 @if cmp -s $^ 2> /dev/null; \
1324 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1326 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1330 # Patch all .abilist files for one DSO. The find command locates abilist
1331 # files for all architectures. The abilist files in /generic/ are
1332 # filtered out because these are expected to remain empty.
1333 define update-all-abi
1334 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1335 $$(find $(..)sysdeps -name '$*.abilist' \! -path '*/generic/*')
1337 update-all-abi-%: %.abilist $(objpfx)%.symlist
1339 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1342 .PHONY: update-abi update-all-abi check-abi
1343 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1344 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1345 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1346 $(install-lib.so-versioned))
1347 check-abi: $(check-abi-list)
1349 subdir_check-abi: check-abi
1350 subdir_update-abi: update-abi
1351 subdir_update-all-abi: update-all-abi
1353 check-abi: subdir_check-abi
1354 if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1355 cat $(objpfx)*/check-abi*.out && exit 1; fi
1356 update-abi: subdir_update-abi
1357 update-all-abi: subdir_update-all-abi
1360 ifeq ($(subdir),elf)
1361 check-abi: $(objpfx)check-abi-libc.out
1362 tests-special += $(objpfx)check-abi-libc.out
1363 update-abi: update-abi-libc
1364 update-all-abi: update-all-abi-libc
1365 common-generated += libc.symlist
1368 ifeq ($(build-shared),yes)
1370 tests-special += $(check-abi-list)
1376 # These will have been set by sysdeps/posix/Makefile.
1382 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1384 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1385 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1386 $(common-objpfx)config.make
1387 $(make-target-directory)
1388 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1390 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1391 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1392 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1393 $(@:st=dT) > $(@:st=dt)
1394 mv -f $(@:st=dt) $(@:st=d)
1395 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1396 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1397 fopen_max=$${fopen_max:-16}; \
1398 filename_max=$${filename_max:-1024}; \
1399 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1400 -e "s/@FILENAME_MAX@/$$filename_max/" \
1401 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1402 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1403 -e "s/@L_ctermid@/$(L_ctermid)/" \
1404 -e "s/@L_cuserid@/$(L_cuserid)/" \
1406 $(move-if-change) $(@:st=h.new) $(@:st=h)
1407 # Remove these last so that they can be examined if something went wrong.
1408 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1412 -include $(stdio_lim:h=d)
1414 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1418 .PHONY: echo-headers
1422 %.bz2: %; bzip2 -9vk $<
1423 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1424 %.xz: %; xz -9evk $<
1426 # Common cleaning targets.
1428 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1430 mostlyclean: common-mostlyclean
1433 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) \
1437 $(addsuffix .test-result,$(tests) \
1442 # Remove the object files.
1444 -rm -f $(addprefix $(objpfx),$(tests) $(tests-internal) $(xtests) \
1446 $(others) $(sysdep-others) stubs \
1447 $(addsuffix .o,$(tests) \
1453 $(addsuffix .out,$(tests) \
1457 $(addsuffix .test-result,$(tests) \
1461 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1462 $(install-lib) $(install-lib.so) \
1463 $(install-lib.so:%.so=%_pic.a))
1465 -rm -f $(objpfx)rtld-*.os
1468 $(foreach o,$(object-suffixes-for-libc),
1469 -rm -f $(objpfx)stamp$o $(o-objects))
1472 # Also remove the dependencies and generated source files.
1473 common-clean: common-mostlyclean
1474 -rm -f $(addprefix $(objpfx),$(generated))
1475 -rm -f $(objpfx)*.d $(objpfx)*.dt
1476 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1477 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1478 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1480 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1481 # for each function which is a stub.
1484 .PHONY: stubs # The parent Makefile calls this target.
1485 stubs: $(objpfx)stubs
1487 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1488 $(addprefix $(objpfx),$(extra-objs))
1489 $(objpfx)stubs: $(objs-for-stubs)
1490 ifneq (,$(strip $(objs-for-stubs)))
1491 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1492 $(AWK) '/\.gnu\.glibc-stub\./ { \
1493 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1495 END { for (s in stubs) print "#define __stub_" s }' > $@T
1501 ifneq (,$(strip $(gpl2lgpl)))
1502 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1503 # Snarf from the master source and frob the copying notice.
1504 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1506 # So I don't edit them by mistake.