1 # Copyright (C) 1991-2018 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 $@
137 ifneq (,$(c++-bits-std_abs-h))
138 # Also make a copy of <bits/std_abs.h> from GCC 7 to prevent it from
139 # including /usr/include/stdlib.h.
140 before-compile := $(common-objpfx)bits/std_abs.h $(before-compile)
141 $(common-objpfx)bits/std_abs.h: $(c++-bits-std_abs-h)
142 $(INSTALL_DATA) $< $@T
143 $(move-if-change) $@T $@
147 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
148 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
149 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
150 $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
154 $(base-machine)-$(config-vendor)-$(config-os) \
155 < $(word 2,$^) > $(@:.stamp=.h)T
156 $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
158 common-generated += $(common-objpfx)libc-abis.h
159 endif # avoid-generated
161 ifeq (yes,$(build-shared))
162 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
163 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
164 $(make-target-directory)
165 echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
167 $(move-if-change) ${@:stamp=T} ${@:stamp=h}
171 # Make sure the subdirectory for object files gets created.
173 ifeq (,$(wildcard $(objpfx).))
174 before-compile += $(objpfx).
176 $(make-target-directory)
180 # Remove existing files from `before-compile'. Things are added there when
181 # they must exist for dependency generation to work right, but once they
182 # exist there is no further need for every single file to depend on them,
183 # and those gratuitous dependencies result in many gratuitous
185 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
187 # Don't let any before-compile file be an intermediate and get removed.
192 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
195 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
197 common-before-compile = $(before-compile)
201 # If a makefile needs to do something conditional on something that
202 # can only be figured out from headers, write a FOO.make.c input
203 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
204 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
206 # We only generate these in the top-level makefile, to avoid any weirdness
207 # from subdir-specific makefile tweaks creeping in on an update.
208 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
210 (echo '# Generated from $*.make.c by Makerules.'; \
211 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
212 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
213 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
214 echo 'common-generated += $(@F)'; \
215 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
221 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
222 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
224 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
225 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
228 ifdef gen-py-const-headers
229 # We'll use a static pattern rule to match .pysym files with their
230 # corresponding generated .py files.
231 # The generated .py files go in the submodule's dir in the glibc build dir.
232 py-const-files := $(patsubst %.pysym,%.py,$(gen-py-const-headers))
233 py-const-dir := $(objpfx)
234 py-const := $(addprefix $(py-const-dir),$(py-const-files))
235 py-const-script := $(..)scripts/gen-py-const.awk
237 # This is a hack we use to generate .py files with constants for Python
238 # pretty printers. It works the same way as gen-as-const.
239 # See scripts/gen-py-const.awk for details on how the awk | gcc mechanism
242 # $@.tmp and $@.tmp2 are temporary files we use to store the partial contents
243 # of the target file. We do this instead of just writing on $@ because, if the
244 # build process terminates prematurely, re-running Make wouldn't run this rule
245 # since Make would see that the target file already exists (despite it being
248 # The sed line replaces "@name@SOME_NAME@value@SOME_VALUE@" strings from the
249 # output of 'gcc -S' with "SOME_NAME = SOME_VALUE" strings.
250 # The '-n' option, combined with the '/p' command, makes sed output only the
251 # modified lines instead of the whole input file. The output is redirected
252 # to a .py file; we'll import it in the pretty printers file to read
253 # the constants generated by gen-py-const.awk.
254 # The regex has two capturing groups, for SOME_NAME and SOME_VALUE
255 # respectively. Notice SOME_VALUE may be prepended by a special character,
256 # depending on the assembly syntax (e.g. immediates are prefixed by a '$'
257 # in AT&T x86, and by a '#' in ARM). We discard it using a complemented set
258 # before the second capturing group.
259 $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
260 $(common-before-compile)
261 $(make-target-directory)
262 $(AWK) -f $(py-const-script) $< \
263 | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
264 echo '# GENERATED FILE\n' > $@.tmp2
265 echo '# Constant definitions for pretty printers.' >> $@.tmp2
266 echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
267 sed -n -r 's/^.*@name@([^@]+)@value@[^[:xdigit:]Xx-]*([[:xdigit:]Xx-]+)@.*/\1 = \2/p' \
272 generated += $(py-const)
273 endif # gen-py-const-headers
275 ifdef gen-as-const-headers
276 # Generating headers for assembly constants.
277 # We need this defined early to get into before-compile before
278 # it's used in sysd-rules, below.
279 # Define GEN_AS_CONST_HEADERS to avoid circular dependency [BZ #22792].
280 # NB: <tcb-offsets.h> is generated from tcb-offsets.sym to define
281 # offsets and sizes of types in <tls.h> and maybe <pthread.h> which
282 # may include <tcb-offsets.h>. Target header files can check if
283 # GEN_AS_CONST_HEADERS is defined to avoid circular dependency which
284 # may lead to build hang on a many-core machine.
285 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
286 %.sym $(common-before-compile)
287 $(AWK) -f $< $(filter %.sym,$^) \
288 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) \
289 -DGEN_AS_CONST_HEADERS -x c - \
290 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
291 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
292 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
294 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
295 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
297 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
298 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
299 vpath %.sym $(sysdirs)
300 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
302 tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
303 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
304 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
305 %.sym $(common-objpfx)%.h
306 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
307 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
308 echo '#include "$(..)test-skeleton.c"') > $@T
312 ifeq (yes,$(build-shared))
313 # Generate the header containing the names of all shared libraries.
314 # We use a stamp file to avoid unnecessary recompilations.
315 before-compile += $(common-objpfx)gnu/lib-names.h
316 ifeq ($(soversions.mk-done),t)
318 lib-names-h-abi = gnu/lib-names.h
319 lib-names-stmp-abi = gnu/lib-names.stmp
321 lib-names-h-abi = gnu/lib-names-$(default-abi).h
322 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
323 before-compile += $(common-objpfx)$(lib-names-h-abi)
324 common-generated += gnu/lib-names.h
325 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
326 $(common-objpfx)gnu/lib-names.h:
327 $(make-target-directory)
329 echo '/* This file is automatically generated.';\
330 echo ' It defines macros to allow user program to find the shared'; \
331 echo ' library files which come as part of GNU libc. */'; \
332 echo '#ifndef __GNU_LIB_NAMES_H'; \
333 echo '#define __GNU_LIB_NAMES_H 1'; \
335 $(if $(abi-includes), \
336 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
338 $(foreach v,$(abi-variants),\
339 $(if $(abi-$(v)-condition),\
340 echo '#if $(abi-$(v)-condition)'; \
341 echo '# include <gnu/lib-names-$(v).h>'); \
342 $(if $(abi-$(v)-condition),echo '#endif';)) \
344 echo '#endif /* gnu/lib-names.h */'; \
347 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
348 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
349 $(common-objpfx)soversions.i
350 $(make-target-directory)
352 $(if $(abi-variants), \
353 echo '/* This file is automatically generated. */';\
354 echo '#ifndef __GNU_LIB_NAMES_H'; \
355 echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
357 echo '/* This file is automatically generated.';\
358 echo ' It defines macros to allow user program to find the shared'; \
359 echo ' library files which come as part of GNU libc. */'; \
360 echo '#ifndef __GNU_LIB_NAMES_H'; \
361 echo '#define __GNU_LIB_NAMES_H 1';) \
363 ($(foreach s,$(all-sonames), echo $(s);)) \
364 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
365 $(if $(abi-variants),, \
367 echo '#endif /* gnu/lib-names.h */';) \
369 $(move-if-change) ${@:stmp=T} ${@:stmp=h}
372 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
375 ###############################################################################
376 # NOTE! Everything adding to before-compile needs to come before this point! #
377 ###############################################################################
379 # Generate an ordered list of implicit rules which find the source files in
380 # each sysdep directory. The old method was to use vpath to search all the
381 # sysdep directories. However, that had the problem that a .S file in a
382 # later directory would be chosen over a .c file in an earlier directory,
383 # which does not preserve the desired sysdeps ordering behavior.
385 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
386 # matching sysdep directories whose assembly source files should be
389 -include $(common-objpfx)sysd-rules
390 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
391 # The value of $(+sysdep_dirs) the sysd-rules was computed for
392 # differs from the one we are using now. So force a rebuild of sysd-rules.
393 sysd-rules-force = FORCE
396 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
397 $(common-objpfx)config.make $(..)Makerules \
398 $(sysdep-makefiles) $(sysdep-makeconfigs) \
401 LC_ALL=C $(AWK) -f $< > $@T \
402 -v all_object_suffixes='$(all-object-suffixes)' \
403 -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
404 -v sysd_rules_patterns='$(sysd-rules-patterns)' \
405 -v config_sysdirs='$(config-sysdirs)'
408 ifndef sysd-rules-done
409 # Don't do deps until this exists, because it provides rules to make the deps.
413 define o-iterator-doit
414 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
416 object-suffixes-left := $(all-object-suffixes)
417 include $(o-iterator)
419 define o-iterator-doit
420 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
422 object-suffixes-left := $(all-object-suffixes)
423 include $(o-iterator)
425 define o-iterator-doit
426 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
428 object-suffixes-left := $(all-object-suffixes)
429 include $(o-iterator)
431 # Omit the objpfx rules when building in the source tree, because
432 # objpfx is empty and so these rules just override the ones above.
434 # Define first rules to find the source files in $(objpfx).
435 # Generated source files will end up there.
436 define o-iterator-doit
437 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
439 object-suffixes-left := $(all-object-suffixes)
440 include $(o-iterator)
442 define o-iterator-doit
443 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
445 object-suffixes-left := $(all-object-suffixes)
446 include $(o-iterator)
449 # Generate version maps, but wait until sysdep-subdirs is known
450 ifeq ($(sysd-sorted-done),t)
451 ifeq ($(build-shared),yes)
452 -include $(common-objpfx)sysd-versions
453 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
454 common-generated += $(version-maps)
455 postclean-generated += sysd-versions Versions.all abi-versions.h \
456 Versions.def Versions.v.i Versions.v
458 ifndef avoid-generated
459 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
460 sysd-versions-force = FORCE
464 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
465 $(common-objpfx)Versions.v
466 LC_ALL=C $(AWK) -f $^ > $@T
469 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
470 $(common-objpfx)soversions.i \
471 $(common-objpfx)Versions.def
472 { while read which lib version setname; do \
473 test x"$$which" = xDEFAULT || continue; \
474 test -z "$$setname" || echo "$$lib : $$setname"; \
475 done < $(word 2,$^); \
477 } | LC_ALL=C $(AWK) -f $< > $@T
479 # See %.v/%.v.i implicit rules in Makeconfig.
480 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
481 $(wildcard $(sysdirs:%=%/Versions)) \
482 $(sysd-versions-force)
483 $(common-objpfx)sysd-versions: $(common-objpfx)versions.stmp
484 $(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
485 $(common-objpfx)Versions.v \
486 $(..)scripts/versions.awk
487 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
489 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
490 -v move_if_change='$(move-if-change)' \
492 ) > $(common-objpfx)sysd-versionsT
493 mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
495 endif # avoid-generated
496 endif # $(build-shared) = yes
497 endif # sysd-sorted-done
499 # Generate .dT files as we compile.
500 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
501 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
502 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
503 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
505 # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
506 # track system includes here, they may spuriously trigger an install rule,
507 # and would cause the check-local-headers test to fail.
508 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
510 # GCC can grok options after the file name, and it looks nicer that way.
511 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
512 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
513 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
514 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
515 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
516 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
517 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
519 # We need this for the output to go in the right place. It will default to
520 # empty if make was configured to work with a cc that can't grok -c and -o
521 # together. You can't compile the C library with such a compiler.
522 OUTPUT_OPTION = -o $@
524 # This is the end of the pipeline for compiling generated C code.
525 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
527 # We need the $(CFLAGS) to be in there to have the right predefines during
528 # the dependency run for C sources. But having it for assembly sources can
529 # get the wrong predefines.
530 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
533 $(make-target-directory)
534 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
535 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
536 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
537 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
538 mv -f $(@:.d=.T) $@ $(generate-md5)
542 # Continuation lines here are dangerous because they introduce spaces!
543 define sed-remove-objpfx
544 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
545 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
549 # Modify the list of routines we build for different targets
551 ifeq (yes,$(build-shared))
552 ifndef libc.so-version
553 # Undefine this because it can't work when we libc.so is unversioned.
554 static-only-routines =
558 elide-routines.oS += $(filter-out $(static-only-routines),\
559 $(routines) $(aux) $(sysdep_routines))
560 elide-routines.os += $(static-only-routines)
562 # If we have versioned code we don't need the old versions in any of the
564 elide-routines.o += $(shared-only-routines)
565 elide-routines.op += $(shared-only-routines)
567 # Shared library building.
569 ifeq (yes,$(build-shared))
571 # Reference map file only when shared libraries are built and a map file name
573 ifeq ($(build-shared),yes)
574 map-file = $(firstword $($(@F:.so=-map)) \
575 $(addprefix $(common-objpfx), \
576 $(filter $(@F:.so=.map),$(version-maps))))
577 load-map-file = $(map-file:%=-Wl,--version-script=%)
580 # Compiler arguments to use to link a shared object with libc and
581 # ld.so. This is intended to be as similar as possible to a default
582 # link with an installed libc.
583 link-libc-args = -Wl,--start-group \
585 $(common-objpfx)libc_nonshared.a \
586 $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
589 # The corresponding shared libc to use. This may be modified for a
591 libc-for-link = $(common-objpfx)libc.so
593 # The corresponding dependencies. As these are used in dependencies,
594 # not just commands, they cannot use target-specific variables so need
595 # to name both possible libc.so objects.
596 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
597 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
599 # Pattern rule to build a shared object from an archive of PIC objects.
600 # This must come after the installation rules so Make doesn't try to
601 # build shared libraries in place from the installed *_pic.a files.
602 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
603 # on other shared objects. The linking with libc and ld.so is intended
604 # to be as similar as possible to a default link with an installed libc.
605 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
606 $(build-shlib) $(link-libc-args)
607 $(call after-link,$@)
609 define build-shlib-helper
610 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
611 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
612 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
613 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
614 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
615 $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
616 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
619 ifeq (yes,$(use-default-link))
620 # If the linker is good enough, we can let it use its default linker script.
624 # binutils only position loadable notes into the first page for binaries,
625 # not for shared objects
626 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
627 $(LINK.o) -shared -Wl,-O1 \
628 -nostdlib -nostartfiles \
629 $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
630 -Wl,--verbose 2>&1 | \
632 -e '/^=========/,/^=========/!d;/^=========/d' \
633 $(if $(filter yes,$(have-hash-style)), \
634 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
635 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
636 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
638 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
640 -e 's/^.*\*(\.dynbss).*$$/& \
641 PROVIDE(__start___libc_freeres_ptrs = .); \
642 *(__libc_freeres_ptrs) \
643 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
644 -e 's@^.*\*(\.jcr).*$$@& \
645 PROVIDE(__start___libc_subfreeres = .);\
646 __libc_subfreeres : { *(__libc_subfreeres) }\
647 PROVIDE(__stop___libc_subfreeres = .);\
648 PROVIDE(__start___libc_atexit = .);\
649 __libc_atexit : { *(__libc_atexit) }\
650 PROVIDE(__stop___libc_atexit = .);\
651 PROVIDE(__start___libc_thread_subfreeres = .);\
652 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
653 PROVIDE(__stop___libc_thread_subfreeres = .);\
654 PROVIDE(__start___libc_IO_vtables = .);\
655 __libc_IO_vtables : { *(__libc_IO_vtables) }\
656 PROVIDE(__stop___libc_IO_vtables = .);\
657 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
660 common-generated += shlib.lds
662 shlib-lds = $(common-objpfx)shlib.lds
663 shlib-lds-flags = -T $(shlib-lds)
667 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
668 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
671 define build-module-helper
672 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
673 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
674 -B$(csu-objpfx) $(load-map-file) \
675 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
676 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
679 # This macro is similar to build-shlib but it does not define a soname
680 # and it does not depend on the destination name to start with `lib'.
681 # binutils only position loadable notes into the first page for binaries,
682 # not for shared objects
684 $(build-module-helper) -o $@ $(shlib-lds-flags) \
685 $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
686 $(call after-link,$@)
688 define build-module-asneeded
689 $(build-module-helper) -o $@ $(shlib-lds-flags) \
690 $(csu-objpfx)abi-note.o \
691 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
693 $(call after-link,$@)
696 # sofini.os must be placed last since it terminates .eh_frame section.
697 build-module-helper-objlist = \
698 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
699 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
700 $(elf-objpfx)sofini.os \
701 $(link-libc-deps),$^))
703 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
704 build-shlib-objlist = $(build-module-helper-objlist) \
705 $(LDLIBS-$(@F:lib%.so=%).so) \
706 $(filter $(elf-objpfx)sofini.os,$^)
708 # Don't try to use -lc when making libc.so itself.
709 # Also omits crti.o and crtn.o, which we do not want
710 # since we define our own `.init' section specially.
711 LDFLAGS-c.so = -nostdlib -nostartfiles
712 # But we still want to link libc.so against $(libc.so-gnulib).
713 LDLIBS-c.so += $(libc.so-gnulib)
714 # Give libc.so an entry point and make it directly runnable itself.
715 LDFLAGS-c.so += -e __libc_main
716 # Pre-link the objects of libc_pic.a so that we can locally resolve
717 # COMMON symbols before we link against ld.so. This is because ld.so
718 # contains some of libc_pic.a already, which will prevent the COMMONs
719 # from being allocated in libc.so, which introduces evil dependencies
720 # between libc.so and ld.so, which can make it impossible to upgrade.
721 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
722 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
723 $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
725 ifeq (,$(strip $(shlib-lds-flags)))
726 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
727 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
729 $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
732 # Apply those -R options.
733 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
734 $(common-objpfx)libc_pic.os
736 generated += libc_pic.opts libc_pic.os.clean
738 libc_pic_clean := .clean
741 # Build a possibly-modified version of libc_pic.a for use in building
743 ifeq (,$(filter sunrpc,$(subdirs)))
744 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
745 $(make-target-directory)
748 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
749 $(common-objpfx)sunrpc/librpc_compat_pic.a
750 $(make-target-directory)
751 (cd $(common-objpfx)linkobj; \
752 $(AR) x ../libc_pic.a; \
753 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
754 $(AR) x ../sunrpc/librpc_compat_pic.a; \
755 $(AR) cr libc_pic.a *.os; \
757 endif # $(subdirs) contains sunrpc
759 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
760 # filter ld.so out of the list of linked objects.
761 $(common-objpfx)libc.so: link-libc-deps = # empty
762 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
764 # Use our own special initializer and finalizer files for the libc.so
766 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
767 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
768 $(elf-objpfx)sofini.os \
769 $(elf-objpfx)interp.os \
773 $(call after-link,$@)
775 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
776 $(common-objpfx)linkobj/libc_pic.a \
777 $(elf-objpfx)sofini.os \
778 $(elf-objpfx)interp.os \
782 $(call after-link,$@)
784 ifeq ($(build-shared),yes)
785 $(common-objpfx)libc.so: $(common-objpfx)libc.map
787 common-generated += libc.so libc_pic.os
788 ifdef libc.so-version
789 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
791 common-generated += libc.so$(libc.so-version)
795 # Figure out the source filenames in this directory.
797 override sources := $(addsuffix .c,\
798 $(filter-out $(elided-routines),\
801 sysdep_routines := $(sysdep_routines)
803 headers := $(headers) $(sysdep_headers)
805 # This is the list of all object files, gotten by
806 # replacing every ".c" in `sources' with a ".o".
807 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
810 # The makefile may define $(extra-libs) with `libfoo libbar'
811 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
813 # extra-lib.mk is included once for each extra lib to define rules
814 # to build it, and to add its objects to the various variables.
815 # During its evaluation, $(lib) is set to the name of the library.
816 extra-libs-left := $(extra-libs)
817 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
821 # The makefile may define $(modules-names) to build additional modules.
822 # These are built with $(build-module), except any in $(modules-names-nobuild).
823 # MODULE_NAME=extramodules, except any in $(modules-names-tests).
825 cpp-srcs-left := $(filter-out $(modules-names-tests),$(modules-names))
826 ifneq (,$(cpp-srcs-left))
828 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
831 ifdef modules-names-tests
832 cpp-srcs-left := $(filter $(modules-names-tests),$(modules-names))
833 ifneq (,$(cpp-srcs-left))
835 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
839 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
840 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
841 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
845 +depfiles := $(sources:.c=.d) \
846 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
847 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
848 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
849 $(addsuffix .d,$(tests) $(tests-internal) $(xtests) $(test-srcs))
850 ifeq ($(build-programs),yes)
851 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
853 +depfiles := $(addprefix $(objpfx),\
854 $(filter-out $(addsuffix .d,$(omit-deps)),\
856 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
857 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
858 $(wildcard $(all-dt-files:.dt=.d))
860 # This is a funny rule in that it removes its input file.
862 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
863 mv -f $(@:.d=.T) $@ && \
866 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
867 # They will be generated when they're needed, and trying too early won't work.
868 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
869 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
874 -include $(+depfiles)
878 # Maximize efficiency by minimizing the number of rules.
879 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
880 # Don't define any builtin rules.
881 MAKEFLAGS := $(MAKEFLAGS)r
883 # Generic rule for making directories.
885 # mkdir isn't smart enough to strip a trailing /.
886 # We always require a mkdir which supports the -p option to avoid error
887 # messages in case of races.
890 # Make sure that object files are not removed
891 # when they are intermediates between sources and library members.
892 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
894 # Make sure that the parent library archive is never removed.
895 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
897 # Use the verbose option of ar and tar when not running silently.
898 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
904 ARFLAGS := r$(verbose)
905 CREATE_ARFLAGS := cru$(verbose)
907 # This makes all the object files in the parent library archive.
909 .PHONY: lib lib-noranlib
910 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
911 lib-noranlib: libobjs
913 # For object-suffix $o, the list of objects with that suffix.
914 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
915 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
916 $(elide-routines$o)),\
918 $(addprefix $(objpfx),$(o-objects$o))
920 others: $(addprefix $(objpfx),$(install-lib))
924 # Create the stamp$o files to keep the parent makefile happy.
925 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
926 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
927 $(make-target-directory)
931 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
932 # timestamp file; these rules (one explicit rule is generated for each
933 # object suffix) write a list of objects to update in the stamp file.
934 # The parent will then actually add them all to the archive in the
935 # archive rule, below.
936 define o-iterator-doit
937 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
940 $(make-target-directory)
941 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
944 object-suffixes-left := $(object-suffixes-for-libc)
945 include $(o-iterator)
949 # Now define explicit rules to build the library archives; these depend
950 # on the stamp files built above.
951 define o-iterator-doit
952 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
953 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
956 cd $(common-objdir) && \
957 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
959 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
960 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
962 $(subdirs-stamps): subdir_lib;
964 object-suffixes-left = $(object-suffixes-for-libc)
965 include $(o-iterator)
968 # This makes all the object files.
969 .PHONY: objects objs libobjs extra-objs
970 objects objs: libobjs extra-objs
971 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
972 extra-objs: $(addprefix $(objpfx),$(extra-objs))
974 # Canned sequence for building an extra library archive.
975 define build-extra-lib
976 $(patsubst %/,cd % &&,$(objpfx)) \
977 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
978 $(patsubst $(objpfx)%,%,$^)
983 .PHONY: force-install
986 # $(install-lib) are installed from the object directory into $(libdir);
987 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
988 # unless they also appear in $(non-lib.a). $(install-data) are installed as
989 # they are into $(datadir). $(headers) are installed as they are in
990 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
991 # are installed from the object directory into $(bindir), $(bindir) and
992 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
993 # are absolute path names of files to install; rules to install them are
996 # The simple library name to install libc.a under.
997 # This could be defined by a sysdep Makefile.
1003 $(make-target-directory)
1004 $(INSTALL_DATA) $< $@
1007 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
1008 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
1009 define make-target-directory
1010 $(addprefix $(..)./scripts/mkinstalldirs ,\
1011 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
1014 # Any directory (parent or subdir) should install libc.a; this way
1015 # "make install" in a subdir is guaranteed to install everything it changes.
1016 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
1017 $(inst_libdir)/$(patsubst %,$(libtype$o),\
1018 $(libprefix)$(libc-name)))
1020 .PHONY: check-install-supported
1021 check-install-supported:
1023 # Check to see if the prefix or exec_prefix GNU standard variable
1024 # has been overridden on the command line and, if so, fail with
1025 # an error message since doing so is not supported (set DESTDIR
1027 ifeq ($(origin prefix),command line)
1028 check-install-supported:
1029 $(error Overriding prefix is not supported. Set DESTDIR instead.)
1032 ifeq ($(origin exec_prefix),command line)
1033 check-install-supported:
1034 $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
1037 install: check-install-supported
1039 install: $(installed-libcs)
1040 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
1041 $(make-target-directory)
1042 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
1044 define do-install-program
1045 $(make-target-directory)
1046 $(INSTALL_PROGRAM) $< $@.new
1050 define do-install-script
1051 $(make-target-directory)
1052 $(INSTALL_SCRIPT) $< $@.new
1056 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
1057 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
1059 ifeq (yes,$(build-shared))
1060 # Find which .so's have versions.
1061 versioned := $(strip $(foreach so,$(install-lib.so),\
1062 $(patsubst %,$(so),$($(so)-version))))
1064 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
1065 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
1067 # For versioned libraries, we install three files:
1068 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
1069 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
1070 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
1071 lib-version := $(firstword $($(subdir)-version) $(version))
1072 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
1073 $(foreach L,$(install-lib.so-versioned),\
1075 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
1076 $(inst_slibdir)/$L$($L-version))
1078 # Install all the unversioned shared libraries.
1079 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
1080 $(objpfx)%.so $(+force)
1081 $(do-install-program)
1083 ifneq ($(findstring -s,$(LN_S)),)
1086 $(SHELL) $(..)scripts/rellns-sh $< $@.new
1089 define make-link-multidir
1090 $(patsubst %/,cd %,$(objpfx)); \
1091 $(addprefix $(abspath $(..)scripts/mkinstalldirs) ,$(dir $(multidir))); \
1092 $(LN_S) . $(multidir) 2> /dev/null; \
1096 # If we have no symbolic links don't bother with rellns-sh.
1102 define make-link-multidir
1103 $(make-target-directory)
1104 ln -f $(objpfx)/$(@F) $@
1108 ifeq (yes,$(build-shared))
1109 ifeq (no,$(cross-compiling))
1110 symbolic-link-prog := $(elf-objpfx)sln
1111 symbolic-link-list := $(elf-objpfx)symlink.list
1112 define make-shlib-link
1113 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
1115 else # cross-compiling
1116 # We need a definition that can be used by elf/Makefile's install rules.
1117 symbolic-link-prog = $(LN_S)
1120 ifndef make-shlib-link
1121 define make-shlib-link
1123 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
1127 ifdef libc.so-version
1128 # For a library specified to be version N, install three files:
1129 # libc.so -> libc.so.N (e.g. libc.so.6)
1130 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
1132 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1135 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1136 $(do-install-program)
1137 install: $(inst_slibdir)/libc.so$(libc.so-version)
1139 # This fragment of linker script gives the OUTPUT_FORMAT statement
1140 # for the configuration we are building. We put this statement into
1141 # the linker scripts we install for -lc et al so that they will not be
1142 # used by a link for a different format on a multi-architecture system.
1143 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
1144 $(common-objpfx)config.make \
1145 $(common-objpfx)config.h $(..)Makerules
1146 ifneq (unknown,$(output-format))
1147 echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1149 $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
1150 $(LDFLAGS.so) $(LDFLAGS-lib.so) \
1151 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1152 | sed -n -f $< > $@.new
1157 common-generated += format.lds
1160 # What we install as libc.so for programs to link against is in fact a
1161 # link script. It contains references for the various libraries we need.
1162 # The libc.so object is not complete since some functions are only defined
1163 # in libc_nonshared.a.
1164 # We need to use absolute paths since otherwise local copies (if they exist)
1165 # of the files are taken by the linker.
1166 install: $(inst_libdir)/libc.so
1167 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1168 $(common-objpfx)libc.so$(libc.so-version) \
1169 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1170 $(libprefix)$(libc-name)) \
1172 (echo '/* GNU ld script';\
1173 echo ' Use the shared library, but some functions are only in';\
1174 echo ' the static library, so try that secondarily. */';\
1176 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1177 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1178 ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1185 install: $(inst_slibdir)/libc.so
1186 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1187 $(do-install-program)
1190 ifneq (,$(versioned))
1191 # Produce three sets of rules as above for all the smaller versioned libraries.
1193 define o-iterator-doit
1194 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1196 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1197 ifneq (,$(object-suffixes-left))
1198 include $(o-iterator)
1201 # Make symlinks in the build directory, because the versioned names might
1202 # be referenced by a DT_NEEDED in another library.
1203 define o-iterator-doit
1204 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1206 object-suffixes-left := $(versioned)
1207 include $(o-iterator)
1209 generated += $(foreach o,$(versioned),$o$($o-version))
1211 ifeq (,$($(subdir)-version))
1212 define o-iterator-doit
1213 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1217 object-suffixes-left := $(versioned)
1218 include $(o-iterator)
1220 define o-iterator-doit
1221 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1222 $$(do-install-program)
1224 object-suffixes-left := $(versioned)
1225 include $(o-iterator)
1227 define o-iterator-doit
1228 $(inst_slibdir)/$o$($o-version): \
1229 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1232 object-suffixes-left := $(versioned)
1233 include $(o-iterator)
1235 define o-iterator-doit
1236 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1237 $$(do-install-program)
1239 object-suffixes-left := $(versioned)
1240 include $(o-iterator)
1244 define do-install-so
1245 $(do-install-program)
1246 $(patsubst %,$(LN_S) -f $(@F) \
1247 $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1248 $(filter-out %.so,$@))
1251 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1252 $(foreach v,$(so-versions),\
1253 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1256 $(foreach v,$(so-versions),\
1257 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1262 $(addprefix $(inst_bindir)/,$(install-bin)): \
1263 $(inst_bindir)/%: $(objpfx)% $(+force)
1264 $(do-install-program)
1266 ifdef install-bin-script
1267 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1268 $(inst_bindir)/%: $(objpfx)% $(+force)
1269 $(do-install-script)
1271 ifdef install-rootsbin
1272 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1273 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1274 $(do-install-program)
1277 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1278 $(inst_sbindir)/%: $(objpfx)% $(+force)
1279 $(do-install-program)
1282 install-lib.a := $(filter lib%.a,$(install-lib))
1283 install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
1284 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1285 ifdef install-lib-non.a
1286 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1287 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1291 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1292 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1297 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1300 headers := $(strip $(headers))
1302 # This implicit rule installs headers from the source directory.
1303 # It may be ignored in preference to rules from sysd-rules to find
1304 # headers in the sysdeps tree.
1305 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1307 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1309 $(inst_includedir)/%.h: %.h $(+force)
1311 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1313 headers-nonh := $(filter-out %.h,$(headers))
1315 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1318 endif # headers-nonh
1321 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1322 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1323 install-data-nosubdir install-headers-nosubdir
1324 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1325 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1326 install-rootsbin-nosubdir: \
1327 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1328 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1329 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1330 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1331 $(addprefix $(libprefix),$(install-lib-non.a)))
1332 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1333 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1334 install-others-nosubdir: $(install-others)
1335 install-others-programs-nosubdir: $(install-others-programs)
1337 # We need all the `-nosubdir' targets so that `install' in the parent
1338 # doesn't depend on several things which each iterate over the subdirs.
1339 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1340 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1341 install-%:: install-%-nosubdir ;
1343 .PHONY: install install-no-libc.a-nosubdir
1344 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1345 install-lib-nosubdir install-others-nosubdir
1346 ifeq ($(build-programs),yes)
1347 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1348 install-rootsbin-nosubdir install-sbin-nosubdir \
1349 install-others-programs-nosubdir
1351 install: install-no-libc.a-nosubdir
1353 # Command to compile $< using the native libraries.
1354 define native-compile
1355 $(make-target-directory)
1356 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1357 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1360 # We always want to use configuration definitions.
1361 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1362 -DIS_IN_build -include $(common-objpfx)config.h
1364 # Support the GNU standard name for this target.
1367 # Special target to run tests which cannot be run unconditionally.
1368 # Maintainers should use this target.
1372 # The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
1373 # that almost all internal declarations from config.h, libc-symbols.h, and
1374 # include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
1375 all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras))
1376 ifneq (,$(all-testsuite))
1377 cpp-srcs-left = $(all-testsuite)
1379 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1382 all-nonlib := $(strip $(tests-internal) $(test-internal-extras) \
1383 $(others) $(others-extras))
1384 ifneq (,$(all-nonlib))
1385 cpp-srcs-left = $(all-nonlib)
1387 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1391 ifeq ($(build-shared),yes)
1392 # Generate normalized lists of symbols, versions, and data sizes.
1393 # This is handy for checking against existing library binaries.
1395 %.symlist: $(..)scripts/abilist.awk %.dynsym
1396 LC_ALL=C $(AWK) -f $^ > $@T
1400 LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1403 # A sysdeps/.../Makefile can set abilist-pattern to something like
1404 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1405 # This makes sense if multiple ABIs can be most cleanly supported by a
1406 # configuration without using separate sysdeps directories for each.
1407 ifdef abilist-pattern
1408 vpath $(abilist-pattern) $(+sysdep_dirs)
1411 vpath %.abilist $(+sysdep_dirs)
1413 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1414 # target pattern is %.symlist from being considered "intermediate files"
1415 # and automatically removed. We only want these files to be removed by
1416 # 'make clean', which is handled by the 'generated' variable.
1417 .PRECIOUS: %.symlist
1418 generated += $(extra-libs:=.symlist)
1420 ifdef abilist-pattern
1421 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1423 $(check-abi-pattern); \
1425 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1426 $(common-objpfx)%.symlist
1427 $(check-abi-pattern); \
1430 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1434 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1435 $(common-objpfx)%.symlist
1438 define check-abi-pattern
1439 diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1443 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1446 ifdef abilist-pattern
1447 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1448 $(update-abi-pattern)
1449 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1450 $(update-abi-pattern)
1452 update-abi-%: $(objpfx)%.symlist %.abilist
1454 update-abi-%: $(common-objpfx)%.symlist %.abilist
1456 define update-abi-pattern
1457 @if cmp -s $^ 2> /dev/null; \
1459 echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1461 echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1465 @if cmp -s $^ 2> /dev/null; \
1467 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1469 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1473 # Patch all .abilist files for one DSO. The find command locates
1474 # abilist files for all architectures. The regular expression in the
1475 # find invocation is needed to separate libc.abilist and
1476 # libcrypt.abilist, for example. It assumes that abilist-pattern, if
1477 # set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
1478 # a non-alphanumeric seperator between the pattern and the suffix
1479 # added. The abilist files in /generic/ are filtered out because
1480 # these are expected to remain empty.
1481 define update-all-abi
1482 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1483 $$(find $(..)sysdeps \
1484 -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
1485 \! -regex '.*/generic/.*')
1487 ifdef abilist-pattern
1488 update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
1490 update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
1493 update-all-abi-%: %.abilist $(objpfx)%.symlist
1495 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1498 .PHONY: update-abi update-all-abi check-abi
1499 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1500 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1501 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1502 $(install-lib.so-versioned))
1503 check-abi: $(check-abi-list)
1505 subdir_check-abi: check-abi
1506 subdir_update-abi: update-abi
1507 subdir_update-all-abi: update-all-abi
1509 check-abi: subdir_check-abi
1510 if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1511 cat $(objpfx)*/check-abi*.out && exit 1; fi
1512 update-abi: subdir_update-abi
1513 update-all-abi: subdir_update-all-abi
1516 ifeq ($(subdir),elf)
1517 check-abi: $(objpfx)check-abi-libc.out
1518 tests-special += $(objpfx)check-abi-libc.out
1519 update-abi: update-abi-libc
1520 update-all-abi: update-all-abi-libc
1521 common-generated += libc.symlist
1524 ifeq ($(build-shared),yes)
1526 tests-special += $(check-abi-list)
1532 # These will have been set by sysdeps/posix/Makefile.
1538 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1540 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1541 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1542 $(common-objpfx)config.make
1543 $(make-target-directory)
1544 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1546 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1547 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1548 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1549 $(@:st=dT) > $(@:st=dt)
1550 mv -f $(@:st=dt) $(@:st=d)
1551 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1552 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1553 fopen_max=$${fopen_max:-16}; \
1554 filename_max=$${filename_max:-1024}; \
1555 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1556 -e "s/@FILENAME_MAX@/$$filename_max/" \
1557 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1558 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1559 -e "s/@L_ctermid@/$(L_ctermid)/" \
1560 -e "s/@L_cuserid@/$(L_cuserid)/" \
1562 $(move-if-change) $(@:st=h.new) $(@:st=h)
1563 # Remove these last so that they can be examined if something went wrong.
1564 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1568 -include $(stdio_lim:h=d)
1570 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1574 .PHONY: echo-headers
1578 %.bz2: %; bzip2 -9vk $<
1579 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1580 %.xz: %; xz -9evk $<
1582 # Common cleaning targets.
1584 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1586 mostlyclean: common-mostlyclean
1589 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) \
1593 $(addsuffix .test-result,$(tests) \
1598 # Remove the object files.
1600 -rm -f $(addprefix $(objpfx),$(tests) $(tests-internal) $(xtests) \
1602 $(others) $(sysdep-others) stubs \
1603 $(addsuffix .o,$(tests) \
1609 $(addsuffix .out,$(tests) \
1613 $(addsuffix .test-result,$(tests) \
1617 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1618 $(install-lib) $(install-lib.so) \
1619 $(install-lib.so:%.so=%_pic.a))
1621 -rm -f $(objpfx)rtld-*.os
1624 $(foreach o,$(object-suffixes-for-libc),
1625 -rm -f $(objpfx)stamp$o $(o-objects))
1628 # Also remove the dependencies and generated source files.
1629 common-clean: common-mostlyclean
1630 -rm -f $(addprefix $(objpfx),$(generated))
1631 -rm -f $(objpfx)*.d $(objpfx)*.dt
1632 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1633 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1634 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1636 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1637 # for each function which is a stub.
1640 .PHONY: stubs # The parent Makefile calls this target.
1641 stubs: $(objpfx)stubs
1643 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1644 $(addprefix $(objpfx),$(extra-objs))
1645 $(objpfx)stubs: $(objs-for-stubs)
1646 ifneq (,$(strip $(objs-for-stubs)))
1647 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1648 $(AWK) '/\.gnu\.glibc-stub\./ { \
1649 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1651 END { for (s in stubs) print "#define __stub_" s }' > $@T
1657 ifneq (,$(strip $(gpl2lgpl)))
1658 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1659 # Snarf from the master source and frob the copying notice.
1660 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1662 # So I don't edit them by mistake.