1 # Copyright (C) 1991-2010, 2011 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, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 # Common rules for making the GNU C library. This file is included
21 # by the top-level Makefile and by all subdirectory makefiles
25 This makefile requires GNU Make.
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32 $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version. See above for the version needed.
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq "$(findstring env,$(origin sources))" ""
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
59 # This variable is used in ``include $(o-iterator)'' after defining
60 # $(o-iterator-doit) to produce some desired rule using $o for the object
61 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
62 # is produced for each object suffix in use.
63 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
65 # Include any system-specific makefiles.
67 # This is here so things in sysdep Makefiles can easily depend on foo.h as
68 # appropriate and not worry about where foo.h comes from, which may be
69 # system dependent and not known by that Makefile.
70 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
71 $(+sysdep_dirs) $(..)))
73 # The same is true for RPC source files.
74 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
75 $(+sysdep_dirs) $(..)))
77 # Some sysdep makefiles use this to distinguish being included here from
78 # being included individually by a subdir makefile (hurd/Makefile needs this).
81 sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
82 ifneq (,$(sysdep-makefiles))
83 include $(sysdep-makefiles)
87 # Reorder before-compile so that mach things come first, and hurd things
88 # second, before all else. The mach and hurd subdirectories have many
89 # generated header files which the much of rest of the library depends on,
90 # so it is best to build them first (and mach before hurd, at that).
91 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
93 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
96 # Even before that, we need abi-versions.h which is generated right here.
97 ifeq ($(versioning),yes)
98 ifndef avoid-generated
99 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
100 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
101 $(common-objpfx)Versions.all
102 LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
105 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
106 sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
107 $(common-objpfx)abi-versions.h > $@T
109 endif # avoid-generated
110 endif # $(versioning) = yes
112 ifndef avoid-generated
113 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
114 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
115 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
116 $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
120 $(base-machine)-$(config-vendor)-$(config-os) \
121 < $(word 2,$^) > $(@:.stamp=.h)T
122 $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
124 common-generated += $(common-objpfx)libc-abis.h
125 endif # avoid-generated
127 # Make sure the subdirectory for object files gets created.
129 ifeq (,$(wildcard $(objpfx).))
130 before-compile += $(objpfx).
132 $(make-target-directory)
136 # Remove existing files from `before-compile'. Things are added there when
137 # they must exist for dependency generation to work right, but once they
138 # exist there is no further need for every single file to depend on them,
139 # and those gratuitous dependencies result in many gratuitous
141 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
143 # Don't let any before-compile file be an intermediate and get removed.
148 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
151 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
153 common-before-compile = $(before-compile)
157 # If a makefile needs to do something conditional on something that
158 # can only be figured out from headers, write a FOO.make.c input
159 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
160 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
162 # We only generate these in the top-level makefile, to avoid any weirdness
163 # from subdir-specific makefile tweaks creeping in on an update.
164 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
166 (echo '# Generated from $*.make.c by Makerules.'; \
167 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
168 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
169 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
170 echo 'common-generated += $(@F)'; \
171 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
177 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
178 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
180 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
181 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
185 ifdef gen-as-const-headers
186 # Generating headers for assembly constants.
187 # We need this defined early to get into before-compile before
188 # it's used in sysd-rules, below.
189 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
190 %.sym $(common-before-compile)
191 $(AWK) -f $< $(filter %.sym,$^) \
192 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
193 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
194 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
195 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
197 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
198 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
200 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
201 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
202 vpath %.sym $(sysdirs)
203 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
205 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
206 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
207 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
208 %.sym $(common-objpfx)%.h
209 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
210 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
211 echo '#include "$(..)test-skeleton.c"') > $@T
215 # Generate an ordered list of implicit rules which find the source files in
216 # each sysdep directory. The old method was to use vpath to search all the
217 # sysdep directories. However, that had the problem that a .S file in a
218 # later directory would be chosen over a .c file in an earlier directory,
219 # which does not preserve the desired sysdeps ordering behavior.
221 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
222 # patterns matching sysdep directories whose assembly source files should
224 ifdef inhibit-sysdep-asm
225 define check-inhibit-asm
226 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) asm= ;; esac;
230 -include $(common-objpfx)sysd-rules
231 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
232 # The value of $(+sysdep_dirs) the sysd-rules was computed for
233 # differs from the one we are using now. So force a rebuild of sysd-rules.
234 sysd-rules-force = FORCE
237 $(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
238 $(sysdep-makefiles) $(sysdep-makeconfigs) \
241 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
242 for dir in $(config-sysdirs); do \
245 *) dir="\$$(..)$$dir" ;; \
248 $(check-inhibit-asm) \
249 for o in $(all-object-suffixes); do \
250 set $(subst :, ,$(sysd-rules-patterns)); \
251 while [ $$# -ge 2 ]; do \
254 v=$${t%%%}; [ x"$$v" = x ] || v="\$$($${v}CPPFLAGS)"; \
255 for s in $$asm .c; do \
256 echo "\$$(objpfx)$$t$$o: $$dir/$$d$$s \$$(before-compile)"; \
257 echo " \$$(compile-command$$s) $$v"; \
261 echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force)"; \
262 echo " \$$(do-install)"; \
264 echo 'sysd-rules-done = t') > $@T
267 ifndef sysd-rules-done
268 # Don't do deps until this exists, because it provides rules to make the deps.
272 define o-iterator-doit
273 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
275 object-suffixes-left := $(all-object-suffixes)
276 include $(o-iterator)
278 define o-iterator-doit
279 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
281 object-suffixes-left := $(all-object-suffixes)
282 include $(o-iterator)
284 define o-iterator-doit
285 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
287 object-suffixes-left := $(all-object-suffixes)
288 include $(o-iterator)
290 define o-iterator-doit
291 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
293 object-suffixes-left := $(all-object-suffixes)
294 include $(o-iterator)
296 # Omit the objpfx rules when building in the source tree, because
297 # objpfx is empty and so these rules just override the ones above.
299 # Define first rules to find the source files in $(objpfx).
300 # Generated source files will end up there.
301 define o-iterator-doit
302 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
304 object-suffixes-left := $(all-object-suffixes)
305 include $(o-iterator)
307 define o-iterator-doit
308 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
310 object-suffixes-left := $(all-object-suffixes)
311 include $(o-iterator)
313 define o-iterator-doit
314 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
316 object-suffixes-left := $(all-object-suffixes)
317 include $(o-iterator)
320 # Generate version maps, but wait until sysdep-subdirs is known
321 ifeq ($(sysd-sorted-done),t)
322 ifeq ($(versioning),yes)
323 -include $(common-objpfx)sysd-versions
324 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
325 common-generated += $(version-maps)
326 postclean-generated += sysd-versions Versions.all abi-versions.h \
327 Versions.def.v.i Versions.def.v Versions.v.i Versions.v
329 ifndef avoid-generated
330 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
331 sysd-versions-force = FORCE
334 # See %.v/%.v.i implicit rules in Makeconfig.
335 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
336 $(wildcard $(add-ons:%=$(..)%/Versions.def))
337 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
338 $(common-objpfx)soversions.i \
339 $(common-objpfx)Versions.def.v
340 { while read which lib version setname; do \
341 test x"$$which" = xDEFAULT || continue; \
342 test -z "$$setname" || echo "$$lib : $$setname"; \
343 done < $(word 2,$^); \
345 } | LC_ALL=C $(AWK) -f $< > $@T
347 # See %.v/%.v.i implicit rules in Makeconfig.
348 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
349 $(wildcard $(sysdirs:%=%/Versions)) \
350 $(common-objpfx)abi-versions.h \
351 $(sysd-versions-force)
352 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
353 $(common-objpfx)Versions.v \
354 $(..)scripts/versions.awk
355 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
357 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
358 -v move_if_change='$(move-if-change)' \
362 endif # avoid-generated
363 endif # $(versioning) = yes
364 endif # sysd-sorted-done
366 # Generate .dT files as we compile.
367 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
368 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
369 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
370 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
371 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
373 # GCC can grok options after the file name, and it looks nicer that way.
374 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
375 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
376 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
377 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
378 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
379 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
380 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
382 # We need this for the output to go in the right place. It will default to
383 # empty if make was configured to work with a cc that can't grok -c and -o
384 # together. You can't compile the C library with such a compiler.
385 OUTPUT_OPTION = -o $@
387 # We need the $(CFLAGS) to be in there to have the right predefines during
388 # the dependency run for C sources. But having it for assembly sources can
389 # get the wrong predefines.
390 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
393 $(make-target-directory)
394 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
395 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
396 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
397 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
398 mv -f $(@:.d=.T) $@ $(generate-md5)
402 # Continuation lines here are dangerous because they introduce spaces!
403 define sed-remove-objpfx
404 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
405 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
409 # Modify the list of routines we build for different targets
411 ifeq (yesyes,$(build-shared)$(elf))
412 ifndef libc.so-version
413 # Undefine this because it can't work when we libc.so is unversioned.
414 static-only-routines =
418 # Bounded pointer thunks are only built for *.ob
419 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
421 elide-routines.oS += $(filter-out $(static-only-routines),\
422 $(routines) $(aux) $(sysdep_routines)) \
424 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
426 # If we have versioned code we don't need the old versions in any of the
428 elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
429 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
430 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
431 elide-routines.ob += $(shared-only-routines)
433 # Shared library building.
435 ifeq (yes,$(build-shared))
437 # Reference map file only when versioning is selected and a map file name
439 ifeq ($(versioning),yes)
440 map-file = $(firstword $($(@F:.so=-map)) \
441 $(addprefix $(common-objpfx), \
442 $(filter $(@F:.so=.map),$(version-maps))))
443 load-map-file = $(map-file:%=-Wl,--version-script=%)
446 # Pattern rule to build a shared object from an archive of PIC objects.
447 # This must come after the installation rules so Make doesn't try to
448 # build shared libraries in place from the installed *_pic.a files.
449 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
450 # on other shared objects.
451 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
452 ifneq (,$(findstring aix,$(config-os)))
454 dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
459 define build-shlib-helper
460 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
461 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
462 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
463 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
464 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
465 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
466 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
469 ifneq (,$(findstring aix,$(config-os)))
470 define build-shlib-helper
471 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
472 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
473 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
474 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
475 -L$(subst :, -L,$(rpath-link))
482 # binutils only position loadable notes into the first page for binaries,
483 # not for shared objects
484 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
485 $(LINK.o) -shared -Wl,-O1 \
486 -nostdlib -nostartfiles \
487 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
488 -Wl,--verbose 2>&1 | \
490 -e '/^=========/,/^=========/!d;/^=========/d' \
491 $(if $(filter yes,$(have-hash-style)), \
492 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
493 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
494 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
496 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
498 -e 's/^.*\*(\.dynbss).*$$/& \
499 PROVIDE(__start___libc_freeres_ptrs = .); \
500 *(__libc_freeres_ptrs) \
501 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
502 -e 's@^.*\*(\.jcr).*$$@& \
503 PROVIDE(__start___libc_subfreeres = .);\
504 __libc_subfreeres : { *(__libc_subfreeres) }\
505 PROVIDE(__stop___libc_subfreeres = .);\
506 PROVIDE(__start___libc_atexit = .);\
507 __libc_atexit : { *(__libc_atexit) }\
508 PROVIDE(__stop___libc_atexit = .);\
509 PROVIDE(__start___libc_thread_subfreeres = .);\
510 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
511 PROVIDE(__stop___libc_thread_subfreeres = .);\
512 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
515 common-generated += shlib.lds
518 $(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
519 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
522 ifneq (,$(findstring aix,$(config-os)))
524 $(build-shlib-helper) \
526 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
527 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
530 $(build-shlib-helper) \
531 $(build-shlib-objlist)
536 ifneq (,$(findstring aix,$(config-os)))
537 define build-module-helper
538 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
539 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
541 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
542 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
545 define build-module-helper
546 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
547 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
548 -B$(csu-objpfx) $(load-map-file) \
549 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
550 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
554 # This macro is similar to build-shlib but it does not define a soname
555 # and it does not depend on the destination name to start with `lib'.
557 # binutils only position loadable notes into the first page for binaries,
558 # not for shared objects
560 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
561 $(csu-objpfx)abi-note.o $(build-module-objlist)
563 define build-module-asneeded
564 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
565 $(csu-objpfx)abi-note.o \
566 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
569 ifneq (,$(findstring aix,$(config-os)))
571 $(build-module-helper) \
573 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
574 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
579 $(build-module-helper) \
581 $(build-module-objlist)
586 build-module-helper-objlist = \
587 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
588 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
589 whole-archive := -Wl,--whole-archive
591 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
592 build-shlib-objlist = $(build-module-helper-objlist) \
593 $(LDLIBS-$(@F:lib%.so=%).so)
595 # Don't try to use -lc when making libc.so itself.
596 # Also omits crti.o and crtn.o, which we do not want
597 # since we define our own `.init' section specially.
598 LDFLAGS-c.so = -nostdlib -nostartfiles
599 # But we still want to link libc.so against $(libc.so-gnulib).
600 LDLIBS-c.so += $(libc.so-gnulib)
601 # Give libc.so an entry point and make it directly runnable itself.
602 LDFLAGS-c.so += -e __libc_main
603 # If lazy relocation is disabled add the -z now flag.
604 ifeq ($(bind-now),yes)
605 LDFLAGS-c.so += -Wl,-z,now
607 # Pre-link the objects of libc_pic.a so that we can locally resolve
608 # COMMON symbols before we link against ld.so. This is because ld.so
609 # contains some of libc_pic.a already, which will prevent the COMMONs
610 # from being allocated in libc.so, which introduces evil dependencies
611 # between libc.so and ld.so, which can make it impossible to upgrade.
613 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
614 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
615 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
616 # Use our own special initializer and finalizer files for libc.so.
617 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
618 $(common-objpfx)libc_pic.os \
619 $(elfobjdir)/sofini.os \
620 $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
621 $(common-objpfx)shlib.lds
623 ifeq ($(versioning),yes)
624 $(common-objpfx)libc.so: $(common-objpfx)libc.map
626 common-generated += libc.so libc_pic.os
627 ifdef libc.so-version
628 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
630 common-generated += libc.so$(libc.so-version)
634 ifneq (,$(findstring aix,$(config-os)))
635 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
638 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
639 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
640 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
641 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
642 -bE:$(common-objpfx)syscalls.exp \
643 -bI:$(common-objpfx)syscalls.exp \
644 -L$(common-objpfx) -o $@ $^
645 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
646 cp $@ $(common-objpfx)shr.o
647 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
651 # Figure out the source filenames in this directory.
653 override sources := $(addsuffix .c,\
654 $(filter-out $(elided-routines),\
657 sysdep_routines := $(sysdep_routines)
659 headers := $(headers) $(sysdep_headers)
661 # This is the list of all object files, gotten by
662 # replacing every ".c" in `sources' with a ".o".
663 # We also add bounded-pointer thunks, which are later
664 # elided for all suffixes except for `.ob'.
665 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
666 $(patsubst %,$(bppfx)%.o,\
667 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
670 # The makefile may define $(extra-libs) with `libfoo libbar'
671 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
673 # extra-lib.mk is included once for each extra lib to define rules
674 # to build it, and to add its objects to the various variables.
675 # During its evaluation, $(lib) is set to the name of the library.
676 extra-libs-left := $(extra-libs)
677 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
681 # The makefile may define $(modules-names) to build additional modules.
682 # These are built with $(build-module), except any in $(modules-names-nobuild).
684 # extra-lib.mk is included once for each extra lib to define rules
685 # to build it, and to add its objects to the various variables.
686 # During its evaluation, $(lib) is set to the name of the library.
687 extra-modules-left := $(modules-names)
688 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
690 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
691 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
692 $(objpfx)%.os $(common-objpfx)shlib.lds \
693 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
697 +depfiles := $(sources:.c=.d) \
698 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
699 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
700 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
701 ifeq ($(build-programs),yes)
702 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
704 +depfiles := $(addprefix $(objpfx),\
705 $(filter-out $(addsuffix .d,$(omit-deps)),\
707 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
708 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
709 $(wildcard $(all-dt-files:.dt=.d))
711 # This is a funny rule in that it removes its input file.
713 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
714 mv -f $(@:.d=.T) $@ && \
717 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
718 # They will be generated when they're needed, and trying too early won't work.
719 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
720 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
725 -include $(+depfiles)
729 # Maximize efficiency by minimizing the number of rules.
730 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
731 # Don't define any builtin rules.
732 MAKEFLAGS := $(MAKEFLAGS)r
734 # Generic rule for making directories.
736 # mkdir isn't smart enough to strip a trailing /.
737 # We always require a mkdir which supports the -p option to avoid error
738 # messages in case of races.
741 # Make sure that object files are not removed
742 # when they are intermediates between sources and library members.
743 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
745 # Make sure that the parent library archive is never removed.
746 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
748 # Use the verbose option of ar and tar when not running silently.
749 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
755 ARFLAGS := r$(verbose)
756 CREATE_ARFLAGS := cru$(verbose)
758 # This makes all the object files in the parent library archive.
760 .PHONY: lib lib-noranlib
761 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
762 lib-noranlib: libobjs
764 # For object-suffix $o, the list of objects with that suffix.
765 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
766 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
767 $(elide-routines$o)),\
769 $(addprefix $(objpfx),$(o-objects$o))
771 others: $(addprefix $(objpfx),$(install-lib))
775 # Create the stamp$o files to keep the parent makefile happy.
776 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
777 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
778 $(make-target-directory)
782 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
783 # timestamp file; these rules (one explicit rule is generated for each
784 # object suffix) write a list of objects to update in the stamp file.
785 # The parent will then actually add them all to the archive in the
786 # archive rule, below.
787 define o-iterator-doit
788 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
791 $(make-target-directory)
792 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
795 object-suffixes-left := $(object-suffixes-for-libc)
796 include $(o-iterator)
800 # Now define explicit rules to build the library archives; these depend
801 # on the stamp files built above.
802 define o-iterator-doit
803 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
804 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
807 cd $(common-objdir) && \
808 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
810 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
811 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
813 $(subdirs-stamps): subdir_lib;
815 object-suffixes-left = $(object-suffixes-for-libc)
816 include $(o-iterator)
819 # This makes all the object files.
820 .PHONY: objects objs libobjs extra-objs
821 objects objs: libobjs extra-objs
822 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
823 extra-objs: $(addprefix $(objpfx),$(extra-objs))
825 # Canned sequence for building an extra library archive.
826 define build-extra-lib
827 $(patsubst %/,cd % &&,$(objpfx)) \
828 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
829 $(patsubst $(objpfx)%,%,$^)
834 .PHONY: force-install
837 # $(install-lib) are installed from the object directory into $(libdir);
838 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
839 # unless they also appear in $(non-lib.a). $(install-data) are installed as
840 # they are into $(datadir). $(headers) are installed as they are in
841 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
842 # are installed from the object directory into $(bindir), $(bindir) and
843 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
844 # are absolute path names of files to install; rules to install them are
847 # The simple library name to install libc.a under.
848 # This could be defined by a sysdep Makefile.
854 $(make-target-directory)
855 $(INSTALL_DATA) $< $@
858 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
859 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
860 define make-target-directory
861 $(addprefix $(..)./scripts/mkinstalldirs ,\
862 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
865 # Any directory (parent or subdir) should install libc.a; this way
866 # "make install" in a subdir is guaranteed to install everything it changes.
867 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
868 $(inst_libdir)/$(patsubst %,$(libtype$o),\
869 $(libprefix)$(libc-name)))
870 install: $(installed-libcs)
871 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
872 $(make-target-directory)
873 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
875 define do-install-program
876 $(make-target-directory)
877 $(INSTALL_PROGRAM) $< $@.new
881 define do-install-script
882 $(make-target-directory)
883 $(INSTALL_SCRIPT) $< $@.new
887 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
888 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
890 ifeq (yes,$(build-shared))
891 # Find which .so's have versions.
892 versioned := $(strip $(foreach so,$(install-lib.so),\
893 $(patsubst %,$(so),$($(so)-version))))
895 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
896 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
898 # For versioned libraries, we install three files:
899 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
900 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
901 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
902 V := $(firstword $($(subdir)-version) $(version))
903 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
904 $(foreach L,$(install-lib.so-versioned),\
906 $(inst_slibdir)/$(L:.so=)-$V.so \
907 $(inst_slibdir)/$L$($L-version))
909 # Install all the unversioned shared libraries.
910 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
911 $(objpfx)%.so $(+force)
912 $(do-install-program)
914 ifneq ($(findstring -s,$(LN_S)),)
917 $(SHELL) $(..)scripts/rellns-sh $< $@.new
921 # If we have no symbolic links don't bother with rellns-sh.
929 ifeq (yes,$(build-shared))
930 ifeq (no,$(cross-compiling))
931 symbolic-link-prog := $(common-objpfx)elf/sln
932 symbolic-link-list := $(common-objpfx)elf/symlink.list
933 define make-shlib-link
934 echo $(<F) $@ >> $(symbolic-link-list)
936 else # cross-compiling
937 # We need a definition that can be used by elf/Makefile's install rules.
938 symbolic-link-prog = $(LN_S)
941 ifndef make-shlib-link
942 define make-shlib-link
948 ifdef libc.so-version
949 # For a library specified to be version N, install three files:
950 # libc.so -> libc.so.N (e.g. libc.so.6)
951 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
953 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
956 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
957 $(do-install-program)
958 install: $(inst_slibdir)/libc.so$(libc.so-version)
960 # This fragment of linker script gives the OUTPUT_FORMAT statement
961 # for the configuration we are building. We put this statement into
962 # the linker scripts we install for -lc et al so that they will not be
963 # used by a link for a different format on a multi-architecture system.
964 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
965 $(common-objpfx)config.make \
966 $(common-objpfx)config.h $(..)Makerules
967 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
968 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
969 | sed -n -f $< > $@.new
972 common-generated += format.lds
975 # What we install as libc.so for programs to link against is in fact a
976 # link script. It contains references for the various libraries we need.
977 # The libc.so object is not complete since some functions are only defined
978 # in libc_nonshared.a.
979 # We need to use absolute paths since otherwise local copies (if they exist)
980 # of the files are taken by the linker.
981 install: $(inst_libdir)/libc.so
982 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
983 $(common-objpfx)libc.so$(libc.so-version) \
984 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
985 $(libprefix)$(libc-name)) \
987 (echo '/* GNU ld script';\
988 echo ' Use the shared library, but some functions are only in';\
989 echo ' the static library, so try that secondarily. */';\
991 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
992 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
993 ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1000 install: $(inst_slibdir)/libc.so
1001 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1002 $(do-install-program)
1005 ifneq (,$(versioned))
1006 # Produce three sets of rules as above for all the smaller versioned libraries.
1008 define o-iterator-doit
1009 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1011 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1012 ifneq (,$(object-suffixes-left))
1013 include $(o-iterator)
1016 # Make symlinks in the build directory, because the versioned names might
1017 # be referenced by a DT_NEEDED in another library.
1018 define o-iterator-doit
1019 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1021 object-suffixes-left := $(versioned)
1022 include $(o-iterator)
1024 generated += $(foreach o,$(versioned),$o$($o-version))
1026 ifeq (,$($(subdir)-version))
1027 define o-iterator-doit
1028 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1032 object-suffixes-left := $(versioned)
1033 include $(o-iterator)
1035 define o-iterator-doit
1036 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1037 $$(do-install-program)
1039 object-suffixes-left := $(versioned)
1040 include $(o-iterator)
1042 define o-iterator-doit
1043 $(inst_slibdir)/$o$($o-version): \
1044 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1047 object-suffixes-left := $(versioned)
1048 include $(o-iterator)
1050 define o-iterator-doit
1051 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1052 $$(do-install-program)
1054 object-suffixes-left := $(versioned)
1055 include $(o-iterator)
1059 define do-install-so
1060 $(do-install-program)
1061 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1062 $(filter-out %.so,$@))
1065 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1066 $(foreach v,$(so-versions),\
1067 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1070 $(foreach v,$(so-versions),\
1071 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1076 $(addprefix $(inst_bindir)/,$(install-bin)): \
1077 $(inst_bindir)/%: $(objpfx)% $(+force)
1078 $(do-install-program)
1080 ifdef install-bin-script
1081 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1082 $(inst_bindir)/%: $(objpfx)% $(+force)
1083 $(do-install-script)
1085 ifdef install-rootsbin
1086 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1087 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1088 $(do-install-program)
1091 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1092 $(inst_sbindir)/%: $(objpfx)% $(+force)
1093 $(do-install-program)
1096 install-lib.a := $(filter lib%.a,$(install-lib))
1097 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1098 ifdef install-lib-non.a
1099 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1100 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1104 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1105 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1110 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1113 headers := $(strip $(headers))
1115 # This implicit rule installs headers from the source directory.
1116 # It may be ignored in preference to rules from sysd-rules to find
1117 # headers in the sysdeps tree.
1118 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1120 $(inst_includedir)/%.h: %.h $(+force)
1122 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1124 headers-nonh := $(filter-out %.h,$(headers))
1126 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1129 endif # headers-nonh
1132 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1133 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1134 install-data-nosubdir install-headers-nosubdir
1135 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1136 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1137 install-rootsbin-nosubdir: \
1138 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1139 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1140 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1141 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1142 $(addprefix $(libprefix),$(install-lib-non.a)))
1143 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1144 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1145 install-others-nosubdir: $(install-others)
1146 install-others-programs-nosubdir: $(install-others-programs)
1148 # We need all the `-nosubdir' targets so that `install' in the parent
1149 # doesn't depend on several things which each iterate over the subdirs.
1150 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1151 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1152 install-%:: install-%-nosubdir ;
1154 .PHONY: install install-no-libc.a-nosubdir
1155 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1156 install-lib-nosubdir install-others-nosubdir
1157 ifeq ($(build-programs),yes)
1158 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1159 install-rootsbin-nosubdir install-sbin-nosubdir \
1160 install-others-programs-nosubdir
1162 install: install-no-libc.a-nosubdir
1164 # Command to compile $< in $(objdir) using the native libraries.
1165 define native-compile
1166 $(make-target-directory)
1167 $(patsubst %/,cd % &&,$(objpfx)) \
1168 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1169 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1172 # Command to compile $< in $(common-objdir) using the native libraries.
1173 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1174 define common-objdir-compile
1175 $(patsubst %/,cd % &&,$(objpfx)) \
1176 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1177 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1180 # We always want to use configuration definitions.
1181 # Note that this is only used for commands running in $(objpfx).
1182 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1184 # Support the GNU standard name for this target.
1187 # Special target to run tests which cannot be run unconditionally.
1188 # Maintainers should use this target.
1192 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1193 ifneq (,$(all-nonlib))
1194 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1196 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1199 # The include magic above causes those files to use this variable for flags.
1200 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1203 ifeq ($(versioning),yes)
1204 # Generate normalized lists of symbols, versions, and data sizes.
1205 # This is handy for checking against existing library binaries.
1207 %.symlist: $(..)scripts/abilist.awk %.dynsym
1208 LC_ALL=C $(AWK) -f $^ > $@T
1212 $(OBJDUMP) --dynamic-syms $< > $@T
1215 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1216 $(..)abilist/%.abilist $(objpfx)%.symlist
1218 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1219 $(..)abilist/%.abilist $(common-objpfx)%.symlist
1223 $(AWK) -f $< -v 'config=$(check-abi-config)' \
1224 $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1225 $(filter %.abilist,$^) \
1226 | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1228 ifeq ($(enable-check-abi),warn)
1229 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1232 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1233 -include $(common-objpfx)tls.make
1235 ifeq ($(use-thread),yes)
1236 config-tls := thread
1238 check-abi-config := \
1239 $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1242 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1245 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1246 $(common-objpfx)%.symlist
1248 ifndef update-abi-config
1250 @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1254 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1255 > $(..)abilist/$*.abilist.new
1256 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1257 then rm -f $(..)abilist/$*.abilist.new; \
1258 echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1259 else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1260 echo '*** Now check $*.abilist changes for correctness ***'; \
1265 .PHONY: update-abi check-abi
1266 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1267 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1269 subdir_check-abi: check-abi
1270 subdir_update-abi: update-abi
1272 check-abi: subdir_check-abi
1273 update-abi: subdir_update-abi
1276 ifeq ($(subdir),elf)
1277 check-abi: check-abi-libc
1278 update-abi: update-abi-libc
1279 common-generated += libc.symlist
1282 ifeq ($(build-shared),yes)
1283 ifneq ($(enable-check-abi),no)
1292 # These will have been set by sysdeps/posix/Makefile.
1298 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1300 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1301 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1302 $(common-objpfx)config.make
1303 $(make-target-directory)
1304 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1305 echo '#define _LIBC 1'; \
1306 echo '#include "$(..)misc/sys/uio.h"'; } | \
1307 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1308 $(+includes) -xc - -o $(@:st=hT)
1309 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1310 $(@:st=dT) > $(@:st=dt)
1311 mv -f $(@:st=dt) $(@:st=d)
1312 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1313 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1314 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1315 fopen_max=$${fopen_max:-16}; \
1316 filename_max=$${filename_max:-1024}; \
1317 if [ -z "$$iov_max" ]; then \
1318 define_iov_max="# undef IOV_MAX"; \
1320 define_iov_max="# define IOV_MAX $$iov_max"; \
1322 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1323 -e "s/@FILENAME_MAX@/$$filename_max/" \
1324 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1325 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1326 -e "s/@L_ctermid@/$(L_ctermid)/" \
1327 -e "s/@L_cuserid@/$(L_cuserid)/" \
1328 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1330 $(move-if-change) $(@:st=h.new) $(@:st=h)
1331 # Remove these last so that they can be examined if something went wrong.
1332 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1336 -include $(stdio_lim:h=d)
1338 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1342 .PHONY: echo-headers
1346 %.bz2: %; bzip2 -9vk $<
1347 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1348 %.xz: %; xz -9evk $<
1350 # Common cleaning targets.
1352 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1354 mostlyclean: common-mostlyclean
1357 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1359 $(addsuffix -bp.out,$(tests) $(xtests) \
1362 # Remove the object files.
1364 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1365 $(others) $(sysdep-others) stubs \
1366 $(addsuffix .o,$(tests) $(xtests) \
1367 $(test-srcs) $(others) \
1369 $(addsuffix -bp,$(tests) $(xtests) \
1371 $(addsuffix .out,$(tests) $(xtests) \
1373 $(addsuffix -bp.out,$(tests) $(xtests) \
1375 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1376 $(install-lib) $(install-lib.so) \
1377 $(install-lib.so:%.so=%_pic.a))
1379 -rm -f $(objpfx)rtld-*.os
1382 $(foreach o,$(object-suffixes-for-libc),
1383 -rm -f $(objpfx)stamp$o $(o-objects))
1386 # Also remove the dependencies and generated source files.
1387 common-clean: common-mostlyclean
1388 -rm -f $(addprefix $(objpfx),$(generated))
1389 -rm -f $(objpfx)*.d $(objpfx)*.dt
1390 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1391 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1393 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1394 # for each function which is a stub. We grovel over all the .d files
1395 # looking for references to <stub-tag.h>. Then we grovel over each
1396 # referenced source file to see what stub function it defines.
1399 .PHONY: stubs # The parent Makefile calls this target.
1400 stubs: $(objpfx)stubs
1402 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1403 $(addprefix $(objpfx),$(extra-objs))
1404 $(objpfx)stubs: $(objs-for-stubs)
1405 ifneq (,$(strip $(objs-for-stubs)))
1406 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1407 $(AWK) '/\.gnu\.glibc-stub\./ { \
1408 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1410 END { for (s in stubs) print "#define __stub_" s }' > $@T
1416 ifneq (,$(strip $(gpl2lgpl)))
1417 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1418 # Snarf from the master source and frob the copying notice.
1419 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1421 # So I don't edit them by mistake.
1424 ifeq ($(with-cvs),yes)
1425 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@