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
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
115 endif # avoid-generated
116 endif # $(build-shared) = yes
118 ifndef avoid-generated
120 # If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
121 # /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
122 # (instead of stdlib/stdlib.h or math/math.h in the glibc source
123 # directory), and this turns up as a make dependency. An implicit
124 # rule will kick in and make will try to install stdlib/stdlib.h or
125 # math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
126 # the target is out of date. We make a copy of <cstdlib> and <cmath>
127 # in the glibc build directory so that stdlib/stdlib.h and math/math.h
128 # will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
129 before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
131 $(common-objpfx)cstdlib: $(c++-cstdlib-header)
132 $(INSTALL_DATA) $< $@T
133 $(move-if-change) $@T $@
134 $(common-objpfx)cmath: $(c++-cmath-header)
135 $(INSTALL_DATA) $< $@T
136 $(move-if-change) $@T $@
139 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
140 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
141 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
142 $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
146 $(base-machine)-$(config-vendor)-$(config-os) \
147 < $(word 2,$^) > $(@:.stamp=.h)T
148 $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
150 common-generated += $(common-objpfx)libc-abis.h
151 endif # avoid-generated
153 ifeq (yes,$(build-shared))
154 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
155 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
156 $(make-target-directory)
157 echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
159 $(move-if-change) ${@:stamp=T} ${@:stamp=h}
163 # Make sure the subdirectory for object files gets created.
165 ifeq (,$(wildcard $(objpfx).))
166 before-compile += $(objpfx).
168 $(make-target-directory)
172 # Remove existing files from `before-compile'. Things are added there when
173 # they must exist for dependency generation to work right, but once they
174 # exist there is no further need for every single file to depend on them,
175 # and those gratuitous dependencies result in many gratuitous
177 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
179 # Don't let any before-compile file be an intermediate and get removed.
184 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
187 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
189 common-before-compile = $(before-compile)
193 # If a makefile needs to do something conditional on something that
194 # can only be figured out from headers, write a FOO.make.c input
195 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
196 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
198 # We only generate these in the top-level makefile, to avoid any weirdness
199 # from subdir-specific makefile tweaks creeping in on an update.
200 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
202 (echo '# Generated from $*.make.c by Makerules.'; \
203 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
204 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
205 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
206 echo 'common-generated += $(@F)'; \
207 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
213 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
214 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
216 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
217 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
220 ifdef gen-py-const-headers
221 # We'll use a static pattern rule to match .pysym files with their
222 # corresponding generated .py files.
223 # The generated .py files go in the submodule's dir in the glibc build dir.
224 py-const-files := $(patsubst %.pysym,%.py,$(gen-py-const-headers))
225 py-const-dir := $(objpfx)
226 py-const := $(addprefix $(py-const-dir),$(py-const-files))
227 py-const-script := $(..)scripts/gen-py-const.awk
229 # This is a hack we use to generate .py files with constants for Python
230 # pretty printers. It works the same way as gen-as-const.
231 # See scripts/gen-py-const.awk for details on how the awk | gcc mechanism
234 # $@.tmp and $@.tmp2 are temporary files we use to store the partial contents
235 # of the target file. We do this instead of just writing on $@ because, if the
236 # build process terminates prematurely, re-running Make wouldn't run this rule
237 # since Make would see that the target file already exists (despite it being
240 # The sed line replaces "@name@SOME_NAME@value@SOME_VALUE@" strings from the
241 # output of 'gcc -S' with "SOME_NAME = SOME_VALUE" strings.
242 # The '-n' option, combined with the '/p' command, makes sed output only the
243 # modified lines instead of the whole input file. The output is redirected
244 # to a .py file; we'll import it in the pretty printers file to read
245 # the constants generated by gen-py-const.awk.
246 # The regex has two capturing groups, for SOME_NAME and SOME_VALUE
247 # respectively. Notice SOME_VALUE may be prepended by a special character,
248 # depending on the assembly syntax (e.g. immediates are prefixed by a '$'
249 # in AT&T x86, and by a '#' in ARM). We discard it using a complemented set
250 # before the second capturing group.
251 $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
252 $(common-before-compile)
253 $(make-target-directory)
254 $(AWK) -f $(py-const-script) $< \
255 | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
256 echo '# GENERATED FILE\n' > $@.tmp2
257 echo '# Constant definitions for pretty printers.' >> $@.tmp2
258 echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
259 sed -n -r 's/^.*@name@([^@]+)@value@[^[:xdigit:]Xx-]*([[:xdigit:]Xx-]+)@.*/\1 = \2/p' \
264 generated += $(py-const)
265 endif # gen-py-const-headers
267 ifdef gen-as-const-headers
268 # Generating headers for assembly constants.
269 # We need this defined early to get into before-compile before
270 # it's used in sysd-rules, below.
271 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
272 %.sym $(common-before-compile)
273 $(AWK) -f $< $(filter %.sym,$^) \
274 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
275 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
276 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
277 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
279 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
280 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
282 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
283 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
284 vpath %.sym $(sysdirs)
285 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
287 tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
288 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
289 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
290 %.sym $(common-objpfx)%.h
291 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
292 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
293 echo '#include "$(..)test-skeleton.c"') > $@T
297 ifeq (yes,$(build-shared))
298 # Generate the header containing the names of all shared libraries.
299 # We use a stamp file to avoid unnecessary recompilations.
300 before-compile += $(common-objpfx)gnu/lib-names.h
301 ifeq ($(soversions.mk-done),t)
303 lib-names-h-abi = gnu/lib-names.h
304 lib-names-stmp-abi = gnu/lib-names.stmp
306 lib-names-h-abi = gnu/lib-names-$(default-abi).h
307 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
308 before-compile += $(common-objpfx)$(lib-names-h-abi)
309 common-generated += gnu/lib-names.h
310 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
311 $(common-objpfx)gnu/lib-names.h:
312 $(make-target-directory)
314 echo '/* This file is automatically generated.';\
315 echo ' It defines macros to allow user program to find the shared'; \
316 echo ' library files which come as part of GNU libc. */'; \
317 echo '#ifndef __GNU_LIB_NAMES_H'; \
318 echo '#define __GNU_LIB_NAMES_H 1'; \
320 $(if $(abi-includes), \
321 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
323 $(foreach v,$(abi-variants),\
324 $(if $(abi-$(v)-condition),\
325 echo '#if $(abi-$(v)-condition)'; \
326 echo '# include <gnu/lib-names-$(v).h>'); \
327 $(if $(abi-$(v)-condition),echo '#endif';)) \
329 echo '#endif /* gnu/lib-names.h */'; \
332 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
333 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
334 $(common-objpfx)soversions.i
335 $(make-target-directory)
337 $(if $(abi-variants), \
338 echo '/* This file is automatically generated. */';\
339 echo '#ifndef __GNU_LIB_NAMES_H'; \
340 echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
342 echo '/* This file is automatically generated.';\
343 echo ' It defines macros to allow user program to find the shared'; \
344 echo ' library files which come as part of GNU libc. */'; \
345 echo '#ifndef __GNU_LIB_NAMES_H'; \
346 echo '#define __GNU_LIB_NAMES_H 1';) \
348 ($(foreach s,$(all-sonames), echo $(s);)) \
349 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
350 $(if $(abi-variants),, \
352 echo '#endif /* gnu/lib-names.h */';) \
354 $(move-if-change) ${@:stmp=T} ${@:stmp=h}
357 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
360 ###############################################################################
361 # NOTE! Everything adding to before-compile needs to come before this point! #
362 ###############################################################################
364 # Generate an ordered list of implicit rules which find the source files in
365 # each sysdep directory. The old method was to use vpath to search all the
366 # sysdep directories. However, that had the problem that a .S file in a
367 # later directory would be chosen over a .c file in an earlier directory,
368 # which does not preserve the desired sysdeps ordering behavior.
370 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
371 # matching sysdep directories whose assembly source files should be
374 -include $(common-objpfx)sysd-rules
375 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
376 # The value of $(+sysdep_dirs) the sysd-rules was computed for
377 # differs from the one we are using now. So force a rebuild of sysd-rules.
378 sysd-rules-force = FORCE
381 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
382 $(common-objpfx)config.make $(..)Makerules \
383 $(sysdep-makefiles) $(sysdep-makeconfigs) \
386 LC_ALL=C $(AWK) -f $< > $@T \
387 -v all_object_suffixes='$(all-object-suffixes)' \
388 -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
389 -v sysd_rules_patterns='$(sysd-rules-patterns)' \
390 -v config_sysdirs='$(config-sysdirs)'
393 ifndef sysd-rules-done
394 # Don't do deps until this exists, because it provides rules to make the deps.
398 define o-iterator-doit
399 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
401 object-suffixes-left := $(all-object-suffixes)
402 include $(o-iterator)
404 define o-iterator-doit
405 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
407 object-suffixes-left := $(all-object-suffixes)
408 include $(o-iterator)
410 define o-iterator-doit
411 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
413 object-suffixes-left := $(all-object-suffixes)
414 include $(o-iterator)
416 # Omit the objpfx rules when building in the source tree, because
417 # objpfx is empty and so these rules just override the ones above.
419 # Define first rules to find the source files in $(objpfx).
420 # Generated source files will end up there.
421 define o-iterator-doit
422 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
424 object-suffixes-left := $(all-object-suffixes)
425 include $(o-iterator)
427 define o-iterator-doit
428 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
430 object-suffixes-left := $(all-object-suffixes)
431 include $(o-iterator)
434 # Generate version maps, but wait until sysdep-subdirs is known
435 ifeq ($(sysd-sorted-done),t)
436 ifeq ($(build-shared),yes)
437 -include $(common-objpfx)sysd-versions
438 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
439 common-generated += $(version-maps)
440 postclean-generated += sysd-versions Versions.all abi-versions.h \
441 Versions.def Versions.v.i Versions.v
443 ifndef avoid-generated
444 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
445 sysd-versions-force = FORCE
449 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
450 $(common-objpfx)Versions.v
451 LC_ALL=C $(AWK) -f $^ > $@T
454 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
455 $(common-objpfx)soversions.i \
456 $(common-objpfx)Versions.def
457 { while read which lib version setname; do \
458 test x"$$which" = xDEFAULT || continue; \
459 test -z "$$setname" || echo "$$lib : $$setname"; \
460 done < $(word 2,$^); \
462 } | LC_ALL=C $(AWK) -f $< > $@T
464 # See %.v/%.v.i implicit rules in Makeconfig.
465 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
466 $(wildcard $(sysdirs:%=%/Versions)) \
467 $(sysd-versions-force)
468 $(common-objpfx)sysd-versions: $(common-objpfx)versions.stmp
469 $(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
470 $(common-objpfx)Versions.v \
471 $(..)scripts/versions.awk
472 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
474 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
475 -v move_if_change='$(move-if-change)' \
477 ) > $(common-objpfx)sysd-versionsT
478 mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
480 endif # avoid-generated
481 endif # $(build-shared) = yes
482 endif # sysd-sorted-done
484 # Generate .dT files as we compile.
485 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
486 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
487 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
488 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
490 # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
491 # track system includes here, they may spuriously trigger an install rule,
492 # and would cause the check-local-headers test to fail.
493 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
495 # GCC can grok options after the file name, and it looks nicer that way.
496 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
497 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
498 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
499 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
500 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
501 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
502 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
504 # We need this for the output to go in the right place. It will default to
505 # empty if make was configured to work with a cc that can't grok -c and -o
506 # together. You can't compile the C library with such a compiler.
507 OUTPUT_OPTION = -o $@
509 # This is the end of the pipeline for compiling generated C code.
510 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
512 # We need the $(CFLAGS) to be in there to have the right predefines during
513 # the dependency run for C sources. But having it for assembly sources can
514 # get the wrong predefines.
515 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
518 $(make-target-directory)
519 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
520 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
521 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
522 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
523 mv -f $(@:.d=.T) $@ $(generate-md5)
527 # Continuation lines here are dangerous because they introduce spaces!
528 define sed-remove-objpfx
529 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
530 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
534 # Modify the list of routines we build for different targets
536 ifeq (yes,$(build-shared))
537 ifndef libc.so-version
538 # Undefine this because it can't work when we libc.so is unversioned.
539 static-only-routines =
543 elide-routines.oS += $(filter-out $(static-only-routines),\
544 $(routines) $(aux) $(sysdep_routines))
545 elide-routines.os += $(static-only-routines)
547 # If we have versioned code we don't need the old versions in any of the
549 elide-routines.o += $(shared-only-routines)
550 elide-routines.op += $(shared-only-routines)
552 # Shared library building.
554 ifeq (yes,$(build-shared))
556 # Reference map file only when shared libraries are built and a map file name
558 ifeq ($(build-shared),yes)
559 map-file = $(firstword $($(@F:.so=-map)) \
560 $(addprefix $(common-objpfx), \
561 $(filter $(@F:.so=.map),$(version-maps))))
562 load-map-file = $(map-file:%=-Wl,--version-script=%)
565 # Compiler arguments to use to link a shared object with libc and
566 # ld.so. This is intended to be as similar as possible to a default
567 # link with an installed libc.
568 link-libc-args = -Wl,--start-group \
570 $(common-objpfx)libc_nonshared.a \
571 $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
574 # The corresponding shared libc to use. This may be modified for a
576 libc-for-link = $(common-objpfx)libc.so
578 # The corresponding dependencies. As these are used in dependencies,
579 # not just commands, they cannot use target-specific variables so need
580 # to name both possible libc.so objects.
581 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
582 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
584 # Pattern rule to build a shared object from an archive of PIC objects.
585 # This must come after the installation rules so Make doesn't try to
586 # build shared libraries in place from the installed *_pic.a files.
587 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
588 # on other shared objects. The linking with libc and ld.so is intended
589 # to be as similar as possible to a default link with an installed libc.
590 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
591 $(build-shlib) $(link-libc-args)
592 $(call after-link,$@)
594 define build-shlib-helper
595 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
596 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
597 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
598 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
599 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
600 $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
601 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
604 ifeq (yes,$(use-default-link))
605 # If the linker is good enough, we can let it use its default linker script.
609 # binutils only position loadable notes into the first page for binaries,
610 # not for shared objects
611 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
612 $(LINK.o) -shared -Wl,-O1 \
613 -nostdlib -nostartfiles \
614 $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
615 -Wl,--verbose 2>&1 | \
617 -e '/^=========/,/^=========/!d;/^=========/d' \
618 $(if $(filter yes,$(have-hash-style)), \
619 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
620 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
621 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
623 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
625 -e 's/^.*\*(\.dynbss).*$$/& \
626 PROVIDE(__start___libc_freeres_ptrs = .); \
627 *(__libc_freeres_ptrs) \
628 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
629 -e 's@^.*\*(\.jcr).*$$@& \
630 PROVIDE(__start___libc_subfreeres = .);\
631 __libc_subfreeres : { *(__libc_subfreeres) }\
632 PROVIDE(__stop___libc_subfreeres = .);\
633 PROVIDE(__start___libc_atexit = .);\
634 __libc_atexit : { *(__libc_atexit) }\
635 PROVIDE(__stop___libc_atexit = .);\
636 PROVIDE(__start___libc_thread_subfreeres = .);\
637 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
638 PROVIDE(__stop___libc_thread_subfreeres = .);\
639 PROVIDE(__start___libc_IO_vtables = .);\
640 __libc_IO_vtables : { *(__libc_IO_vtables) }\
641 PROVIDE(__stop___libc_IO_vtables = .);\
642 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
645 common-generated += shlib.lds
647 shlib-lds = $(common-objpfx)shlib.lds
648 shlib-lds-flags = -T $(shlib-lds)
652 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
653 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
656 define build-module-helper
657 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
658 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
659 -B$(csu-objpfx) $(load-map-file) \
660 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
661 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
664 # This macro is similar to build-shlib but it does not define a soname
665 # and it does not depend on the destination name to start with `lib'.
666 # binutils only position loadable notes into the first page for binaries,
667 # not for shared objects
669 $(build-module-helper) -o $@ $(shlib-lds-flags) \
670 $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
671 $(call after-link,$@)
673 define build-module-asneeded
674 $(build-module-helper) -o $@ $(shlib-lds-flags) \
675 $(csu-objpfx)abi-note.o \
676 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
678 $(call after-link,$@)
681 build-module-helper-objlist = \
682 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
683 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
684 $(link-libc-deps),$^))
686 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
687 build-shlib-objlist = $(build-module-helper-objlist) \
688 $(LDLIBS-$(@F:lib%.so=%).so)
690 # Don't try to use -lc when making libc.so itself.
691 # Also omits crti.o and crtn.o, which we do not want
692 # since we define our own `.init' section specially.
693 LDFLAGS-c.so = -nostdlib -nostartfiles
694 # But we still want to link libc.so against $(libc.so-gnulib).
695 LDLIBS-c.so += $(libc.so-gnulib)
696 # Give libc.so an entry point and make it directly runnable itself.
697 LDFLAGS-c.so += -e __libc_main
698 # Pre-link the objects of libc_pic.a so that we can locally resolve
699 # COMMON symbols before we link against ld.so. This is because ld.so
700 # contains some of libc_pic.a already, which will prevent the COMMONs
701 # from being allocated in libc.so, which introduces evil dependencies
702 # between libc.so and ld.so, which can make it impossible to upgrade.
703 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
704 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
705 $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
707 ifeq (,$(strip $(shlib-lds-flags)))
708 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
709 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
711 $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
714 # Apply those -R options.
715 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
716 $(common-objpfx)libc_pic.os
718 generated += libc_pic.opts libc_pic.os.clean
720 libc_pic_clean := .clean
723 # Build a possibly-modified version of libc_pic.a for use in building
725 ifeq (,$(filter sunrpc,$(subdirs)))
726 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
727 $(make-target-directory)
730 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
731 $(common-objpfx)sunrpc/librpc_compat_pic.a
732 $(make-target-directory)
733 (cd $(common-objpfx)linkobj; \
734 $(AR) x ../libc_pic.a; \
735 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
736 $(AR) x ../sunrpc/librpc_compat_pic.a; \
737 $(AR) cr libc_pic.a *.os; \
739 endif # $(subdirs) contains sunrpc
741 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
742 # filter ld.so out of the list of linked objects.
743 $(common-objpfx)libc.so: link-libc-deps = # empty
744 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
746 # Use our own special initializer and finalizer files for the libc.so
748 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
749 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
750 $(elf-objpfx)sofini.os \
751 $(elf-objpfx)interp.os \
755 $(call after-link,$@)
757 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
758 $(common-objpfx)linkobj/libc_pic.a \
759 $(elf-objpfx)sofini.os \
760 $(elf-objpfx)interp.os \
764 $(call after-link,$@)
766 ifeq ($(build-shared),yes)
767 $(common-objpfx)libc.so: $(common-objpfx)libc.map
769 common-generated += libc.so libc_pic.os
770 ifdef libc.so-version
771 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
773 common-generated += libc.so$(libc.so-version)
777 # Figure out the source filenames in this directory.
779 override sources := $(addsuffix .c,\
780 $(filter-out $(elided-routines),\
783 sysdep_routines := $(sysdep_routines)
785 headers := $(headers) $(sysdep_headers)
787 # This is the list of all object files, gotten by
788 # replacing every ".c" in `sources' with a ".o".
789 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
792 # The makefile may define $(extra-libs) with `libfoo libbar'
793 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
795 # extra-lib.mk is included once for each extra lib to define rules
796 # to build it, and to add its objects to the various variables.
797 # During its evaluation, $(lib) is set to the name of the library.
798 extra-libs-left := $(extra-libs)
799 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
803 # The makefile may define $(modules-names) to build additional modules.
804 # These are built with $(build-module), except any in $(modules-names-nobuild).
805 # MODULE_NAME=extramodules, except any in $(modules-names-tests).
807 cpp-srcs-left := $(filter-out $(modules-names-tests),$(modules-names))
808 ifneq (,$(cpp-srcs-left))
810 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
813 ifdef modules-names-tests
814 cpp-srcs-left := $(filter $(modules-names-tests),$(modules-names))
815 ifneq (,$(cpp-srcs-left))
817 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
821 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
822 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
823 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
827 +depfiles := $(sources:.c=.d) \
828 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
829 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
830 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
831 $(addsuffix .d,$(tests) $(tests-internal) $(xtests) $(test-srcs))
832 ifeq ($(build-programs),yes)
833 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
835 +depfiles := $(addprefix $(objpfx),\
836 $(filter-out $(addsuffix .d,$(omit-deps)),\
838 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
839 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
840 $(wildcard $(all-dt-files:.dt=.d))
842 # This is a funny rule in that it removes its input file.
844 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
845 mv -f $(@:.d=.T) $@ && \
848 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
849 # They will be generated when they're needed, and trying too early won't work.
850 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
851 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
856 -include $(+depfiles)
860 # Maximize efficiency by minimizing the number of rules.
861 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
862 # Don't define any builtin rules.
863 MAKEFLAGS := $(MAKEFLAGS)r
865 # Generic rule for making directories.
867 # mkdir isn't smart enough to strip a trailing /.
868 # We always require a mkdir which supports the -p option to avoid error
869 # messages in case of races.
872 # Make sure that object files are not removed
873 # when they are intermediates between sources and library members.
874 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
876 # Make sure that the parent library archive is never removed.
877 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
879 # Use the verbose option of ar and tar when not running silently.
880 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
886 ARFLAGS := r$(verbose)
887 CREATE_ARFLAGS := cru$(verbose)
889 # This makes all the object files in the parent library archive.
891 .PHONY: lib lib-noranlib
892 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
893 lib-noranlib: libobjs
895 # For object-suffix $o, the list of objects with that suffix.
896 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
897 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
898 $(elide-routines$o)),\
900 $(addprefix $(objpfx),$(o-objects$o))
902 others: $(addprefix $(objpfx),$(install-lib))
906 # Create the stamp$o files to keep the parent makefile happy.
907 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
908 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
909 $(make-target-directory)
913 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
914 # timestamp file; these rules (one explicit rule is generated for each
915 # object suffix) write a list of objects to update in the stamp file.
916 # The parent will then actually add them all to the archive in the
917 # archive rule, below.
918 define o-iterator-doit
919 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
922 $(make-target-directory)
923 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
926 object-suffixes-left := $(object-suffixes-for-libc)
927 include $(o-iterator)
931 # Now define explicit rules to build the library archives; these depend
932 # on the stamp files built above.
933 define o-iterator-doit
934 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
935 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
938 cd $(common-objdir) && \
939 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
941 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
942 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
944 $(subdirs-stamps): subdir_lib;
946 object-suffixes-left = $(object-suffixes-for-libc)
947 include $(o-iterator)
950 # This makes all the object files.
951 .PHONY: objects objs libobjs extra-objs
952 objects objs: libobjs extra-objs
953 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
954 extra-objs: $(addprefix $(objpfx),$(extra-objs))
956 # Canned sequence for building an extra library archive.
957 define build-extra-lib
958 $(patsubst %/,cd % &&,$(objpfx)) \
959 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
960 $(patsubst $(objpfx)%,%,$^)
965 .PHONY: force-install
968 # $(install-lib) are installed from the object directory into $(libdir);
969 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
970 # unless they also appear in $(non-lib.a). $(install-data) are installed as
971 # they are into $(datadir). $(headers) are installed as they are in
972 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
973 # are installed from the object directory into $(bindir), $(bindir) and
974 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
975 # are absolute path names of files to install; rules to install them are
978 # The simple library name to install libc.a under.
979 # This could be defined by a sysdep Makefile.
985 $(make-target-directory)
986 $(INSTALL_DATA) $< $@
989 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
990 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
991 define make-target-directory
992 $(addprefix $(..)./scripts/mkinstalldirs ,\
993 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
996 # Any directory (parent or subdir) should install libc.a; this way
997 # "make install" in a subdir is guaranteed to install everything it changes.
998 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
999 $(inst_libdir)/$(patsubst %,$(libtype$o),\
1000 $(libprefix)$(libc-name)))
1002 .PHONY: check-install-supported
1003 check-install-supported:
1005 # Check to see if the prefix or exec_prefix GNU standard variable
1006 # has been overridden on the command line and, if so, fail with
1007 # an error message since doing so is not supported (set DESTDIR
1009 ifeq ($(origin prefix),command line)
1010 check-install-supported:
1011 $(error Overriding prefix is not supported. Set DESTDIR instead.)
1014 ifeq ($(origin exec_prefix),command line)
1015 check-install-supported:
1016 $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
1019 install: check-install-supported
1021 install: $(installed-libcs)
1022 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
1023 $(make-target-directory)
1024 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
1026 define do-install-program
1027 $(make-target-directory)
1028 $(INSTALL_PROGRAM) $< $@.new
1032 define do-install-script
1033 $(make-target-directory)
1034 $(INSTALL_SCRIPT) $< $@.new
1038 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
1039 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
1041 ifeq (yes,$(build-shared))
1042 # Find which .so's have versions.
1043 versioned := $(strip $(foreach so,$(install-lib.so),\
1044 $(patsubst %,$(so),$($(so)-version))))
1046 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
1047 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
1049 # For versioned libraries, we install three files:
1050 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
1051 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
1052 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
1053 lib-version := $(firstword $($(subdir)-version) $(version))
1054 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
1055 $(foreach L,$(install-lib.so-versioned),\
1057 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
1058 $(inst_slibdir)/$L$($L-version))
1060 # Install all the unversioned shared libraries.
1061 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
1062 $(objpfx)%.so $(+force)
1063 $(do-install-program)
1065 ifneq ($(findstring -s,$(LN_S)),)
1068 $(SHELL) $(..)scripts/rellns-sh $< $@.new
1072 # If we have no symbolic links don't bother with rellns-sh.
1080 ifeq (yes,$(build-shared))
1081 ifeq (no,$(cross-compiling))
1082 symbolic-link-prog := $(elf-objpfx)sln
1083 symbolic-link-list := $(elf-objpfx)symlink.list
1084 define make-shlib-link
1085 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
1087 else # cross-compiling
1088 # We need a definition that can be used by elf/Makefile's install rules.
1089 symbolic-link-prog = $(LN_S)
1092 ifndef make-shlib-link
1093 define make-shlib-link
1095 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
1099 ifdef libc.so-version
1100 # For a library specified to be version N, install three files:
1101 # libc.so -> libc.so.N (e.g. libc.so.6)
1102 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
1104 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1107 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1108 $(do-install-program)
1109 install: $(inst_slibdir)/libc.so$(libc.so-version)
1111 # This fragment of linker script gives the OUTPUT_FORMAT statement
1112 # for the configuration we are building. We put this statement into
1113 # the linker scripts we install for -lc et al so that they will not be
1114 # used by a link for a different format on a multi-architecture system.
1115 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
1116 $(common-objpfx)config.make \
1117 $(common-objpfx)config.h $(..)Makerules
1118 ifneq (unknown,$(output-format))
1119 echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1121 $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
1122 $(LDFLAGS.so) $(LDFLAGS-lib.so) \
1123 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1124 | sed -n -f $< > $@.new
1129 common-generated += format.lds
1132 # What we install as libc.so for programs to link against is in fact a
1133 # link script. It contains references for the various libraries we need.
1134 # The libc.so object is not complete since some functions are only defined
1135 # in libc_nonshared.a.
1136 # We need to use absolute paths since otherwise local copies (if they exist)
1137 # of the files are taken by the linker.
1138 install: $(inst_libdir)/libc.so
1139 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1140 $(common-objpfx)libc.so$(libc.so-version) \
1141 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1142 $(libprefix)$(libc-name)) \
1144 (echo '/* GNU ld script';\
1145 echo ' Use the shared library, but some functions are only in';\
1146 echo ' the static library, so try that secondarily. */';\
1148 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1149 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1150 ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1157 install: $(inst_slibdir)/libc.so
1158 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1159 $(do-install-program)
1162 ifneq (,$(versioned))
1163 # Produce three sets of rules as above for all the smaller versioned libraries.
1165 define o-iterator-doit
1166 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1168 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1169 ifneq (,$(object-suffixes-left))
1170 include $(o-iterator)
1173 # Make symlinks in the build directory, because the versioned names might
1174 # be referenced by a DT_NEEDED in another library.
1175 define o-iterator-doit
1176 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1178 object-suffixes-left := $(versioned)
1179 include $(o-iterator)
1181 generated += $(foreach o,$(versioned),$o$($o-version))
1183 ifeq (,$($(subdir)-version))
1184 define o-iterator-doit
1185 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1189 object-suffixes-left := $(versioned)
1190 include $(o-iterator)
1192 define o-iterator-doit
1193 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1194 $$(do-install-program)
1196 object-suffixes-left := $(versioned)
1197 include $(o-iterator)
1199 define o-iterator-doit
1200 $(inst_slibdir)/$o$($o-version): \
1201 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1204 object-suffixes-left := $(versioned)
1205 include $(o-iterator)
1207 define o-iterator-doit
1208 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1209 $$(do-install-program)
1211 object-suffixes-left := $(versioned)
1212 include $(o-iterator)
1216 define do-install-so
1217 $(do-install-program)
1218 $(patsubst %,$(LN_S) -f $(@F) \
1219 $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1220 $(filter-out %.so,$@))
1223 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1224 $(foreach v,$(so-versions),\
1225 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1228 $(foreach v,$(so-versions),\
1229 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1234 $(addprefix $(inst_bindir)/,$(install-bin)): \
1235 $(inst_bindir)/%: $(objpfx)% $(+force)
1236 $(do-install-program)
1238 ifdef install-bin-script
1239 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1240 $(inst_bindir)/%: $(objpfx)% $(+force)
1241 $(do-install-script)
1243 ifdef install-rootsbin
1244 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1245 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1246 $(do-install-program)
1249 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1250 $(inst_sbindir)/%: $(objpfx)% $(+force)
1251 $(do-install-program)
1254 install-lib.a := $(filter lib%.a,$(install-lib))
1255 install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
1256 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1257 ifdef install-lib-non.a
1258 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1259 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1263 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1264 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1269 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1272 headers := $(strip $(headers))
1274 # This implicit rule installs headers from the source directory.
1275 # It may be ignored in preference to rules from sysd-rules to find
1276 # headers in the sysdeps tree.
1277 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1279 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1281 $(inst_includedir)/%.h: %.h $(+force)
1283 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1285 headers-nonh := $(filter-out %.h,$(headers))
1287 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1290 endif # headers-nonh
1293 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1294 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1295 install-data-nosubdir install-headers-nosubdir
1296 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1297 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1298 install-rootsbin-nosubdir: \
1299 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1300 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1301 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1302 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1303 $(addprefix $(libprefix),$(install-lib-non.a)))
1304 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1305 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1306 install-others-nosubdir: $(install-others)
1307 install-others-programs-nosubdir: $(install-others-programs)
1309 # We need all the `-nosubdir' targets so that `install' in the parent
1310 # doesn't depend on several things which each iterate over the subdirs.
1311 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1312 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1313 install-%:: install-%-nosubdir ;
1315 .PHONY: install install-no-libc.a-nosubdir
1316 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1317 install-lib-nosubdir install-others-nosubdir
1318 ifeq ($(build-programs),yes)
1319 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1320 install-rootsbin-nosubdir install-sbin-nosubdir \
1321 install-others-programs-nosubdir
1323 install: install-no-libc.a-nosubdir
1325 # Command to compile $< using the native libraries.
1326 define native-compile
1327 $(make-target-directory)
1328 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1329 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1332 # We always want to use configuration definitions.
1333 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1334 -DIS_IN_build -include $(common-objpfx)config.h
1336 # Support the GNU standard name for this target.
1339 # Special target to run tests which cannot be run unconditionally.
1340 # Maintainers should use this target.
1344 # The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
1345 # that almost all internal declarations from config.h, libc-symbols.h, and
1346 # include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
1347 all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras))
1348 ifneq (,$(all-testsuite))
1349 cpp-srcs-left = $(all-testsuite)
1351 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1354 all-nonlib := $(strip $(tests-internal) $(test-internal-extras) $(others))
1355 ifneq (,$(all-nonlib))
1356 cpp-srcs-left = $(all-nonlib)
1358 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1362 ifeq ($(build-shared),yes)
1363 # Generate normalized lists of symbols, versions, and data sizes.
1364 # This is handy for checking against existing library binaries.
1366 %.symlist: $(..)scripts/abilist.awk %.dynsym
1367 LC_ALL=C $(AWK) -f $^ > $@T
1371 LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1374 # A sysdeps/.../Makefile can set abilist-pattern to something like
1375 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1376 # This makes sense if multiple ABIs can be most cleanly supported by a
1377 # configuration without using separate sysdeps directories for each.
1378 ifdef abilist-pattern
1379 vpath $(abilist-pattern) $(+sysdep_dirs)
1382 vpath %.abilist $(+sysdep_dirs)
1384 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1385 # target pattern is %.symlist from being considered "intermediate files"
1386 # and automatically removed. We only want these files to be removed by
1387 # 'make clean', which is handled by the 'generated' variable.
1388 .PRECIOUS: %.symlist
1389 generated += $(extra-libs:=.symlist)
1391 ifdef abilist-pattern
1392 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1394 $(check-abi-pattern); \
1396 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1397 $(common-objpfx)%.symlist
1398 $(check-abi-pattern); \
1401 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1405 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1406 $(common-objpfx)%.symlist
1409 define check-abi-pattern
1410 diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1414 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1417 ifdef abilist-pattern
1418 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1419 $(update-abi-pattern)
1420 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1421 $(update-abi-pattern)
1423 update-abi-%: $(objpfx)%.symlist %.abilist
1425 update-abi-%: $(common-objpfx)%.symlist %.abilist
1427 define update-abi-pattern
1428 @if cmp -s $^ 2> /dev/null; \
1430 echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1432 echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1436 @if cmp -s $^ 2> /dev/null; \
1438 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1440 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1444 # Patch all .abilist files for one DSO. The find command locates
1445 # abilist files for all architectures. The regular expression in the
1446 # find invocation is needed to separate libc.abilist and
1447 # libcrypt.abilist, for example. It assumes that abilist-pattern, if
1448 # set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
1449 # a non-alphanumeric seperator between the pattern and the suffix
1450 # added. The abilist files in /generic/ are filtered out because
1451 # these are expected to remain empty.
1452 define update-all-abi
1453 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1454 $$(find $(..)sysdeps \
1455 -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
1456 \! -regex '.*/generic/.*')
1458 ifdef abilist-pattern
1459 update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
1461 update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
1464 update-all-abi-%: %.abilist $(objpfx)%.symlist
1466 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1469 .PHONY: update-abi update-all-abi check-abi
1470 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1471 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1472 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1473 $(install-lib.so-versioned))
1474 check-abi: $(check-abi-list)
1476 subdir_check-abi: check-abi
1477 subdir_update-abi: update-abi
1478 subdir_update-all-abi: update-all-abi
1480 check-abi: subdir_check-abi
1481 if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1482 cat $(objpfx)*/check-abi*.out && exit 1; fi
1483 update-abi: subdir_update-abi
1484 update-all-abi: subdir_update-all-abi
1487 ifeq ($(subdir),elf)
1488 check-abi: $(objpfx)check-abi-libc.out
1489 tests-special += $(objpfx)check-abi-libc.out
1490 update-abi: update-abi-libc
1491 update-all-abi: update-all-abi-libc
1492 common-generated += libc.symlist
1495 ifeq ($(build-shared),yes)
1497 tests-special += $(check-abi-list)
1503 # These will have been set by sysdeps/posix/Makefile.
1509 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1511 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1512 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1513 $(common-objpfx)config.make
1514 $(make-target-directory)
1515 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1516 echo '#define _LIBC 1'; \
1517 echo '#include "$(..)misc/sys/uio.h"'; } | \
1518 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1519 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1520 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1521 $(@:st=dT) > $(@:st=dt)
1522 mv -f $(@:st=dt) $(@:st=d)
1523 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1524 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1525 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1526 fopen_max=$${fopen_max:-16}; \
1527 filename_max=$${filename_max:-1024}; \
1528 if [ -z "$$iov_max" ]; then \
1529 define_iov_max="# undef IOV_MAX"; \
1531 define_iov_max="# define IOV_MAX $$iov_max"; \
1533 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1534 -e "s/@FILENAME_MAX@/$$filename_max/" \
1535 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1536 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1537 -e "s/@L_ctermid@/$(L_ctermid)/" \
1538 -e "s/@L_cuserid@/$(L_cuserid)/" \
1539 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1541 $(move-if-change) $(@:st=h.new) $(@:st=h)
1542 # Remove these last so that they can be examined if something went wrong.
1543 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1547 -include $(stdio_lim:h=d)
1549 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1553 .PHONY: echo-headers
1557 %.bz2: %; bzip2 -9vk $<
1558 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1559 %.xz: %; xz -9evk $<
1561 # Common cleaning targets.
1563 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1565 mostlyclean: common-mostlyclean
1568 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) \
1572 $(addsuffix .test-result,$(tests) \
1577 # Remove the object files.
1579 -rm -f $(addprefix $(objpfx),$(tests) $(tests-internal) $(xtests) \
1581 $(others) $(sysdep-others) stubs \
1582 $(addsuffix .o,$(tests) \
1588 $(addsuffix .out,$(tests) \
1592 $(addsuffix .test-result,$(tests) \
1596 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1597 $(install-lib) $(install-lib.so) \
1598 $(install-lib.so:%.so=%_pic.a))
1600 -rm -f $(objpfx)rtld-*.os
1603 $(foreach o,$(object-suffixes-for-libc),
1604 -rm -f $(objpfx)stamp$o $(o-objects))
1607 # Also remove the dependencies and generated source files.
1608 common-clean: common-mostlyclean
1609 -rm -f $(addprefix $(objpfx),$(generated))
1610 -rm -f $(objpfx)*.d $(objpfx)*.dt
1611 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1612 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1613 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1615 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1616 # for each function which is a stub.
1619 .PHONY: stubs # The parent Makefile calls this target.
1620 stubs: $(objpfx)stubs
1622 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1623 $(addprefix $(objpfx),$(extra-objs))
1624 $(objpfx)stubs: $(objs-for-stubs)
1625 ifneq (,$(strip $(objs-for-stubs)))
1626 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1627 $(AWK) '/\.gnu\.glibc-stub\./ { \
1628 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1630 END { for (s in stubs) print "#define __stub_" s }' > $@T
1636 ifneq (,$(strip $(gpl2lgpl)))
1637 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1638 # Snarf from the master source and frob the copying notice.
1639 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1641 # So I don't edit them by mistake.