arm: Implement armv6 optimized string routines
[glibc.git] / Makerules
blobb115f1a92c77c1f76e28672edaa7d57213b7b8d8
1 # Copyright (C) 1991-2013 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
21 #       (through Rules).
23 ifneq (,)
24 This makefile requires GNU Make.
25 endif
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.
33 endif
36 ifdef   subdir
37 ..      := ../
38 endif   # subdir
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))" ""
43 sources :=
44 endif
46 oPATH := $(PATH)
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.
50 else
51 PATH := $(oPATH)
52 endif
54 ifndef +included-Makeconfig
55 include $(..)Makeconfig
56 endif
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).
78 in-Makerules := yes
80 sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
81 ifneq (,$(sysdep-makefiles))
82 include $(sysdep-makefiles)
83 endif
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%,\
91                            $(before-compile)) \
92                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
93                                $(before-compile))
95 # Even before that, we need abi-versions.h which is generated right here.
96 ifeq ($(versioning),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) -v oldest_abi=$(oldest-abi) -f $^ > $@T
102         mv -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
107         mv -f $@T $@
108 endif # avoid-generated
109 endif # $(versioning) = yes
111 ifndef avoid-generated
112 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
113 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
114 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
115                              $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
116                                          $(..)libc-abis) \
117                              $(..)Makerules
118         $(SHELL) $< \
119                  $(base-machine)-$(config-vendor)-$(config-os) \
120                  < $(word 2,$^) > $(@:.stamp=.h)T
121         $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
122         touch $@
123 common-generated += $(common-objpfx)libc-abis.h
124 endif # avoid-generated
126 # Make sure the subdirectory for object files gets created.
127 ifdef objpfx
128 ifeq (,$(wildcard $(objpfx).))
129 before-compile += $(objpfx).
130 $(objpfx).:
131         $(make-target-directory)
132 endif
133 endif
135 # Remove existing files from `before-compile'.  Things are added there when
136 # they must exist for dependency generation to work right, but once they
137 # exist there is no further need for every single file to depend on them,
138 # and those gratuitous dependencies result in many gratuitous
139 # recompilations.
140 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
142 # Don't let any before-compile file be an intermediate and get removed.
143 ifdef before-compile
144 $(before-compile):
145 endif
147 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
148 # in subdirs.
149 ifdef subdir
150 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
151 else
152 common-before-compile = $(before-compile)
153 endif
155 ifndef subdir
156 # If a makefile needs to do something conditional on something that
157 # can only be figured out from headers, write a FOO.make.c input
158 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
159 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
161 # We only generate these in the top-level makefile, to avoid any weirdness
162 # from subdir-specific makefile tweaks creeping in on an update.
163 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
164         rm -f $@T $@.dT
165         (echo '# Generated from $*.make.c by Makerules.'; \
166          $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
167                -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
168          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
169          echo 'common-generated += $(@F)'; \
170          sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
171          rm -f $@.dT) > $@T
172         mv -f $@T $@
173 endif
175 ifdef subdir
176 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g' \
177                      -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
178 else
179 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g' \
180                      -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
181 endif
184 ifdef gen-as-const-headers
185 # Generating headers for assembly constants.
186 # We need this defined early to get into before-compile before
187 # it's used in sysd-rules, below.
188 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
189                                            %.sym $(common-before-compile)
190         $(AWK) -f $< $(filter %.sym,$^) \
191         | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
192                 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
193         sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
194                 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
195         rm -f $(@:.h.d=.h)T3
196         sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
197             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
198         rm -f $(@:.h=.h.d)T
199         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
200         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
201 vpath %.sym $(sysdirs)
202 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
204 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
205 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
206 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
207                             %.sym $(common-objpfx)%.h
208         ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
209          $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
210          echo '#include "$(..)test-skeleton.c"') > $@T
211         mv -f $@T $@
212 endif
214 # Generate an ordered list of implicit rules which find the source files in
215 # each sysdep directory.  The old method was to use vpath to search all the
216 # sysdep directories.  However, that had the problem that a .S file in a
217 # later directory would be chosen over a .c file in an earlier directory,
218 # which does not preserve the desired sysdeps ordering behavior.
220 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
221 # patterns matching sysdep directories whose assembly source files should
222 # be suppressed.
223 ifdef inhibit-sysdep-asm
224 define check-inhibit-asm
225 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) asm= ;; esac;
226 endef
227 endif
229 -include $(common-objpfx)sysd-rules
230 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
231 # The value of $(+sysdep_dirs) the sysd-rules was computed for
232 # differs from the one we are using now.  So force a rebuild of sysd-rules.
233 sysd-rules-force = FORCE
234 FORCE:
235 endif
236 $(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
237                             $(sysdep-makefiles) $(sysdep-makeconfigs) \
238                             $(sysd-rules-force)
239         -@rm -f $@T
240         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
241          for dir in $(config-sysdirs); do                                     \
242            case "$$dir" in                                                    \
243            /*) ;;                                                             \
244            *) dir="\$$(..)$$dir" ;;                                           \
245            esac;                                                              \
246            asm='.S';                                                          \
247            $(check-inhibit-asm)                                               \
248            for o in $(all-object-suffixes); do                                \
249              set $(subst :, ,$(sysd-rules-patterns));                         \
250              while [ $$# -ge 2 ]; do                                          \
251                t=$$1; shift;                                                  \
252                d=$$1; shift;                                                  \
253                v=$${t%%%}; [ x"$$v" = x ] || v="\$$($${v}CPPFLAGS)";          \
254                for s in $$asm .c; do                                          \
255                  echo "\$$(objpfx)$$t$$o: $$dir/$$d$$s \$$(before-compile)";  \
256                  echo " \$$(compile-command$$s) $$v";                         \
257                done;                                                          \
258              done;                                                            \
259            done;                                                              \
260            echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force)";            \
261            echo "       \$$(do-install)";                                     \
262          done;                                                                \
263          echo 'sysd-rules-done = t') > $@T
264         mv -f $@T $@
266 ifndef sysd-rules-done
267 # Don't do deps until this exists, because it provides rules to make the deps.
268 no_deps=t
269 endif
271 define o-iterator-doit
272 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
273 endef
274 object-suffixes-left := $(all-object-suffixes)
275 include $(o-iterator)
277 define o-iterator-doit
278 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
279 endef
280 object-suffixes-left := $(all-object-suffixes)
281 include $(o-iterator)
283 define o-iterator-doit
284 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
285 endef
286 object-suffixes-left := $(all-object-suffixes)
287 include $(o-iterator)
289 # Omit the objpfx rules when building in the source tree, because
290 # objpfx is empty and so these rules just override the ones above.
291 ifdef objpfx
292 # Define first rules to find the source files in $(objpfx).
293 # Generated source files will end up there.
294 define o-iterator-doit
295 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
296 endef
297 object-suffixes-left := $(all-object-suffixes)
298 include $(o-iterator)
300 define o-iterator-doit
301 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
302 endef
303 object-suffixes-left := $(all-object-suffixes)
304 include $(o-iterator)
305 endif
307 # Generate version maps, but wait until sysdep-subdirs is known
308 ifeq ($(sysd-sorted-done),t)
309 ifeq ($(versioning),yes)
310 -include $(common-objpfx)sysd-versions
311 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
312 common-generated += $(version-maps)
313 postclean-generated += sysd-versions Versions.all abi-versions.h \
314                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
316 ifndef avoid-generated
317 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
318 sysd-versions-force = FORCE
319 FORCE:
320 endif
321 # See %.v/%.v.i implicit rules in Makeconfig.
322 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
323                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
324 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
325                               $(common-objpfx)soversions.i \
326                               $(common-objpfx)Versions.def.v
327         { while read which lib version setname; do \
328             test x"$$which" = xDEFAULT || continue; \
329             test -z "$$setname" || echo "$$lib : $$setname"; \
330           done < $(word 2,$^); \
331           cat $(word 3,$^); \
332         } | LC_ALL=C $(AWK) -f $< > $@T
333         mv -f $@T $@
334 # See %.v/%.v.i implicit rules in Makeconfig.
335 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
336                               $(wildcard $(sysdirs:%=%/Versions)) \
337                               $(common-objpfx)abi-versions.h \
338                               $(sysd-versions-force)
339 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
340                                $(common-objpfx)Versions.v \
341                                $(..)scripts/versions.awk
342         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
343           cat $(word 2,$^) \
344           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
345                             -v move_if_change='$(move-if-change)' \
346                             -f $(word 3,$^); \
347         ) > $@T
348         mv -f $@T $@
349 endif # avoid-generated
350 endif # $(versioning) = yes
351 endif # sysd-sorted-done
353 # Generate .dT files as we compile.
354 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
355 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
356 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
357 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
359 # Like compile-mkdep-flags, but for use with $(BUILD_CC).  We don't want to
360 # track system includes here, they may spuriously trigger an install rule,
361 # and would cause the check-local-headers test to fail.
362 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
364 # GCC can grok options after the file name, and it looks nicer that way.
365 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
366 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
367 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
368                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
369 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
370 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
371                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
373 # We need this for the output to go in the right place.  It will default to
374 # empty if make was configured to work with a cc that can't grok -c and -o
375 # together.  You can't compile the C library with such a compiler.
376 OUTPUT_OPTION = -o $@
378 # This is the end of the pipeline for compiling generated C code.
379 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
381 # We need the $(CFLAGS) to be in there to have the right predefines during
382 # the dependency run for C sources.  But having it for assembly sources can
383 # get the wrong predefines.
384 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
386 define +make-deps
387 $(make-target-directory)
388 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
389              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
390 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
391 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
392 mv -f $(@:.d=.T) $@ $(generate-md5)
393 endef
395 ifneq (,$(objpfx))
396 # Continuation lines here are dangerous because they introduce spaces!
397 define sed-remove-objpfx
398 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
399 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
400 endef
401 endif
403 # Modify the list of routines we build for different targets
405 ifeq (yes,$(build-shared))
406 ifndef libc.so-version
407 # Undefine this because it can't work when we libc.so is unversioned.
408 static-only-routines =
409 endif
410 endif
412 elide-routines.oS += $(filter-out $(static-only-routines),\
413                                   $(routines) $(aux) $(sysdep_routines))
414 elide-routines.os += $(static-only-routines)
416 # If we have versioned code we don't need the old versions in any of the
417 # static libraries.
418 elide-routines.o  += $(shared-only-routines)
419 elide-routines.op += $(shared-only-routines)
420 elide-routines.og += $(shared-only-routines)
422 # Shared library building.
424 ifeq (yes,$(build-shared))
426 # Reference map file only when versioning is selected and a map file name
427 # is given.
428 ifeq ($(versioning),yes)
429 map-file = $(firstword $($(@F:.so=-map)) \
430                        $(addprefix $(common-objpfx), \
431                                    $(filter $(@F:.so=.map),$(version-maps))))
432 load-map-file = $(map-file:%=-Wl,--version-script=%)
433 endif
435 # Pattern rule to build a shared object from an archive of PIC objects.
436 # This must come after the installation rules so Make doesn't try to
437 # build shared libraries in place from the installed *_pic.a files.
438 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
439 # on other shared objects.
440 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
441         $(build-shlib)
443 define build-shlib-helper
444 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
445           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
446           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
447           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
448           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
449           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
450           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
451 endef
453 ifeq (yes,$(use-default-link))
454 # If the linker is good enough, we can let it use its default linker script.
455 shlib-lds =
456 shlib-lds-flags =
457 else
458 # binutils only position loadable notes into the first page for binaries,
459 # not for shared objects
460 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
461         $(LINK.o) -shared -Wl,-O1 \
462                   -nostdlib -nostartfiles \
463                   $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
464                   -Wl,--verbose 2>&1 | \
465           sed > $@T \
466               -e '/^=========/,/^=========/!d;/^=========/d' \
467               $(if $(filter yes,$(have-hash-style)), \
468                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
469                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
470                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
471                 , \
472                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
473                ) \
474               -e 's/^.*\*(\.dynbss).*$$/& \
475                  PROVIDE(__start___libc_freeres_ptrs = .); \
476                  *(__libc_freeres_ptrs) \
477                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
478               -e 's@^.*\*(\.jcr).*$$@& \
479                  PROVIDE(__start___libc_subfreeres = .);\
480                  __libc_subfreeres : { *(__libc_subfreeres) }\
481                  PROVIDE(__stop___libc_subfreeres = .);\
482                  PROVIDE(__start___libc_atexit = .);\
483                  __libc_atexit : { *(__libc_atexit) }\
484                  PROVIDE(__stop___libc_atexit = .);\
485                  PROVIDE(__start___libc_thread_subfreeres = .);\
486                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
487                  PROVIDE(__stop___libc_thread_subfreeres = .);\
488                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
489         test -s $@T
490         mv -f $@T $@
491 common-generated += shlib.lds
493 shlib-lds = $(common-objpfx)shlib.lds
494 shlib-lds-flags = -T $(shlib-lds)
495 endif
497 define build-shlib
498 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
499           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
500 endef
502 define build-module-helper
503 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
504           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
505           -B$(csu-objpfx) $(load-map-file) \
506           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
507           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
508 endef
510 # This macro is similar to build-shlib but it does not define a soname
511 # and it does not depend on the destination name to start with `lib'.
512 # binutils only position loadable notes into the first page for binaries,
513 # not for shared objects
514 define build-module
515 $(build-module-helper) -o $@ $(shlib-lds-flags) \
516           $(csu-objpfx)abi-note.o $(build-module-objlist)
517 endef
518 define build-module-asneeded
519 $(build-module-helper) -o $@ $(shlib-lds-flags) \
520           $(csu-objpfx)abi-note.o \
521           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
522 endef
524 build-module-helper-objlist = \
525         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
526                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
528 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
529 build-shlib-objlist = $(build-module-helper-objlist) \
530                       $(LDLIBS-$(@F:lib%.so=%).so)
532 # Don't try to use -lc when making libc.so itself.
533 # Also omits crti.o and crtn.o, which we do not want
534 # since we define our own `.init' section specially.
535 LDFLAGS-c.so = -nostdlib -nostartfiles
536 # But we still want to link libc.so against $(libc.so-gnulib).
537 LDLIBS-c.so += $(libc.so-gnulib)
538 # Give libc.so an entry point and make it directly runnable itself.
539 LDFLAGS-c.so += -e __libc_main
540 # If lazy relocation is disabled add the -z now flag.
541 ifeq ($(bind-now),yes)
542 LDFLAGS-c.so += -Wl,-z,now
543 endif
544 # Pre-link the objects of libc_pic.a so that we can locally resolve
545 # COMMON symbols before we link against ld.so.  This is because ld.so
546 # contains some of libc_pic.a already, which will prevent the COMMONs
547 # from being allocated in libc.so, which introduces evil dependencies
548 # between libc.so and ld.so, which can make it impossible to upgrade.
549 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
550         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
551         $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
553 ifeq (,$(strip $(shlib-lds-flags)))
554 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
555 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
556         $(OBJDUMP) -h $< | \
557         $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
558                 > $@T
559         mv -f $@T $@
560 # Apply those -R options.
561 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
562                                    $(common-objpfx)libc_pic.os
563         $(OBJCOPY) @$^ $@
564 generated += libc_pic.opts libc_pic.os.clean
566 libc_pic_clean := .clean
567 endif
569 # Use our own special initializer and finalizer files for libc.so.
570 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
571                          $(common-objpfx)libc_pic.os$(libc_pic_clean) \
572                          $(elfobjdir)/sofini.os \
573                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
574                          $(shlib-lds)
575         $(build-shlib)
576 ifeq ($(versioning),yes)
577 $(common-objpfx)libc.so: $(common-objpfx)libc.map
578 endif
579 common-generated += libc.so libc_pic.os
580 ifdef libc.so-version
581 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
582         $(make-link)
583 common-generated += libc.so$(libc.so-version)
584 endif
585 endif
587 # Figure out the source filenames in this directory.
589 override sources := $(addsuffix .c,\
590                         $(filter-out $(elided-routines),\
591                             $(routines) $(aux) \
592                             $(sysdep_routines)))
593 sysdep_routines := $(sysdep_routines)
595 headers := $(headers) $(sysdep_headers)
597 # This is the list of all object files, gotten by
598 # replacing every ".c" in `sources' with a ".o".
599 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
602 # The makefile may define $(extra-libs) with `libfoo libbar'
603 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
604 ifdef extra-libs
605 # extra-lib.mk is included once for each extra lib to define rules
606 # to build it, and to add its objects to the various variables.
607 # During its evaluation, $(lib) is set to the name of the library.
608 extra-libs-left := $(extra-libs)
609 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
610 endif
613 # The makefile may define $(modules-names) to build additional modules.
614 # These are built with $(build-module), except any in $(modules-names-nobuild).
615 ifdef modules-names
616 # extra-lib.mk is included once for each extra lib to define rules
617 # to build it, and to add its objects to the various variables.
618 # During its evaluation, $(lib) is set to the name of the library.
619 extra-modules-left := $(modules-names)
620 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
622 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
623 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
624                 $(objpfx)%.os $(shlib-lds) \
625                 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
626         $(build-module)
627 endif
629 +depfiles := $(sources:.c=.d) \
630              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
631              $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
632              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
633              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
634 ifeq ($(build-programs),yes)
635 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
636 endif
637 +depfiles := $(addprefix $(objpfx),\
638                          $(filter-out $(addsuffix .d,$(omit-deps)),\
639                                       $(+depfiles)))
640 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
641 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
642              $(wildcard $(all-dt-files:.dt=.d))
644 # This is a funny rule in that it removes its input file.
645 %.d: %.dt
646         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
647          mv -f $(@:.d=.T) $@ && \
648          rm -f $<
650 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
651 # They will be generated when they're needed, and trying too early won't work.
652 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
653 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
654                                                 $(+gen-as-const)))
656 ifdef +depfiles
657 ifneq ($(no_deps),t)
658 -include $(+depfiles)
659 endif
660 endif
661 \f\f
662 # Maximize efficiency by minimizing the number of rules.
663 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
664 # Don't define any builtin rules.
665 MAKEFLAGS := $(MAKEFLAGS)r
667 # Generic rule for making directories.
669 # mkdir isn't smart enough to strip a trailing /.
670 # We always require a mkdir which supports the -p option to avoid error
671 # messages in case of races.
672         mkdir -p $(@:%/=%)
674 # Make sure that object files are not removed
675 # when they are intermediates between sources and library members.
676 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
678 # Make sure that the parent library archive is never removed.
679 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
681 # Use the verbose option of ar and tar when not running silently.
682 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
683 verbose := v
684 else                                            # -s
685 verbose :=
686 endif                                           # not -s
688 ARFLAGS := r$(verbose)
689 CREATE_ARFLAGS := cru$(verbose)
691 # This makes all the object files in the parent library archive.
693 .PHONY: lib lib-noranlib
694 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
695 lib-noranlib: libobjs
697 # For object-suffix $o, the list of objects with that suffix.
698 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
699 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
700                                                        $(elide-routines$o)),\
701                                             $(objects))) \
702             $(addprefix $(objpfx),$(o-objects$o))
704 others: $(addprefix $(objpfx),$(install-lib))
706 ifndef objects
708 # Create the stamp$o files to keep the parent makefile happy.
709 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
710 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
711         $(make-target-directory)
712         rm -f $@; > $@
713 else
715 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
716 # timestamp file; these rules (one explicit rule is generated for each
717 # object suffix) write a list of objects to update in the stamp file.
718 # The parent will then actually add them all to the archive in the
719 # archive rule, below.
720 define o-iterator-doit
721 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
722 endef
723 define do-stamp
724 $(make-target-directory)
725 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
726 mv -f $@T $@
727 endef
728 object-suffixes-left := $(object-suffixes-for-libc)
729 include $(o-iterator)
731 endif
733 # Now define explicit rules to build the library archives; these depend
734 # on the stamp files built above.
735 define o-iterator-doit
736 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
737                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
738 endef
739 define do-makelib
740 cd $(common-objdir) && \
741 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
742 endef
743 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
744 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
745 ifndef subdir
746 $(subdirs-stamps): subdir_lib;
747 endif
748 object-suffixes-left = $(object-suffixes-for-libc)
749 include $(o-iterator)
752 # This makes all the object files.
753 .PHONY: objects objs libobjs extra-objs
754 objects objs: libobjs extra-objs
755 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
756 extra-objs: $(addprefix $(objpfx),$(extra-objs))
758 # Canned sequence for building an extra library archive.
759 define build-extra-lib
760 $(patsubst %/,cd % &&,$(objpfx)) \
761 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
762       $(patsubst $(objpfx)%,%,$^)
763 endef
765 # Installation.
767 .PHONY: force-install
768 force-install:
770 # $(install-lib) are installed from the object directory into $(libdir);
771 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
772 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
773 # they are into $(datadir).  $(headers) are installed as they are in
774 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
775 # are installed from the object directory into $(bindir), $(bindir) and
776 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
777 # are absolute path names of files to install; rules to install them are
778 # defined elsewhere.
780 # The simple library name to install libc.a under.
781 # This could be defined by a sysdep Makefile.
782 ifndef libc-name
783 libc-name := c
784 endif
786 define do-install
787 $(make-target-directory)
788 $(INSTALL_DATA) $< $@
789 endef
791 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
792 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
793 define make-target-directory
794 $(addprefix $(..)./scripts/mkinstalldirs ,\
795             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
796 endef
798 # Any directory (parent or subdir) should install libc.a; this way
799 # "make install" in a subdir is guaranteed to install everything it changes.
800 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
801                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
802                                                      $(libprefix)$(libc-name)))
803 install: $(installed-libcs)
804 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
805         $(make-target-directory)
806         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
808 define do-install-program
809 $(make-target-directory)
810 $(INSTALL_PROGRAM) $< $@.new
811 mv -f $@.new $@
812 endef
814 define do-install-script
815 $(make-target-directory)
816 $(INSTALL_SCRIPT) $< $@.new
817 mv -f $@.new $@
818 endef
820 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
821 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
823 ifeq (yes,$(build-shared))
824 # Find which .so's have versions.
825 versioned := $(strip $(foreach so,$(install-lib.so),\
826                                $(patsubst %,$(so),$($(so)-version))))
828 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
829 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
831 # For versioned libraries, we install three files:
832 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
833 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
834 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
835 lib-version := $(firstword $($(subdir)-version) $(version))
836 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
837                       $(foreach L,$(install-lib.so-versioned),\
838                                 $(inst_libdir)/$L \
839                                 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
840                                 $(inst_slibdir)/$L$($L-version))
842 # Install all the unversioned shared libraries.
843 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
844     $(objpfx)%.so $(+force)
845         $(do-install-program)
847 ifneq ($(findstring -s,$(LN_S)),)
848 define make-link
849 rm -f $@.new
850 $(SHELL) $(..)scripts/rellns-sh $< $@.new
851 mv -f $@.new $@
852 endef
853 else
854 # If we have no symbolic links don't bother with rellns-sh.
855 define make-link
856 rm -f $@.new
857 $(LN_S) $< $@.new
858 mv -f $@.new $@
859 endef
860 endif
862 ifeq (yes,$(build-shared))
863 ifeq (no,$(cross-compiling))
864 symbolic-link-prog := $(common-objpfx)elf/sln
865 symbolic-link-list := $(common-objpfx)elf/symlink.list
866 define make-shlib-link
867 echo $(<F) $@ >> $(symbolic-link-list)
868 endef
869 else # cross-compiling
870 # We need a definition that can be used by elf/Makefile's install rules.
871 symbolic-link-prog = $(LN_S)
872 endif
873 endif
874 ifndef make-shlib-link
875 define make-shlib-link
876 rm -f $@
877 $(LN_S) $(<F) $@
878 endef
879 endif
881 ifdef libc.so-version
882 # For a library specified to be version N, install three files:
883 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
884 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
886 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
887                                            $(+force)
888         $(make-shlib-link)
889 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
890         $(do-install-program)
891 install: $(inst_slibdir)/libc.so$(libc.so-version)
893 # This fragment of linker script gives the OUTPUT_FORMAT statement
894 # for the configuration we are building.  We put this statement into
895 # the linker scripts we install for -lc et al so that they will not be
896 # used by a link for a different format on a multi-architecture system.
897 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
898                             $(common-objpfx)config.make \
899                             $(common-objpfx)config.h $(..)Makerules
900 ifneq (unknown,$(output-format))
901         echo > $@.new 'OUTPUT_FORMAT($(output-format))'
902 else
903         $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
904                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
905         | sed -n -f $< > $@.new
906         test -s $@.new
907         rm -f $@.so
908 endif
909         mv -f $@.new $@
910 common-generated += format.lds
912 ifndef subdir
913 # What we install as libc.so for programs to link against is in fact a
914 # link script.  It contains references for the various libraries we need.
915 # The libc.so object is not complete since some functions are only defined
916 # in libc_nonshared.a.
917 # We need to use absolute paths since otherwise local copies (if they exist)
918 # of the files are taken by the linker.
919 install: $(inst_libdir)/libc.so
920 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
921                         $(common-objpfx)libc.so$(libc.so-version) \
922                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
923                                                   $(libprefix)$(libc-name)) \
924                         $(+force)
925         (echo '/* GNU ld script';\
926          echo '   Use the shared library, but some functions are only in';\
927          echo '   the static library, so try that secondarily.  */';\
928          cat $<; \
929          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
930               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
931               ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
932         ) > $@.new
933         mv -f $@.new $@
935 endif
937 else
938 install: $(inst_slibdir)/libc.so
939 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
940         $(do-install-program)
941 endif
943 ifneq (,$(versioned))
944 # Produce three sets of rules as above for all the smaller versioned libraries.
946 define o-iterator-doit
947 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
948 endef
949 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
950 ifneq (,$(object-suffixes-left))
951 include $(o-iterator)
952 endif
954 # Make symlinks in the build directory, because the versioned names might
955 # be referenced by a DT_NEEDED in another library.
956 define o-iterator-doit
957 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
958 endef
959 object-suffixes-left := $(versioned)
960 include $(o-iterator)
962 generated += $(foreach o,$(versioned),$o$($o-version))
964 ifeq (,$($(subdir)-version))
965 define o-iterator-doit
966 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
967                                  $(+force);
968         $$(make-shlib-link)
969 endef
970 object-suffixes-left := $(versioned)
971 include $(o-iterator)
973 define o-iterator-doit
974 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
975         $$(do-install-program)
976 endef
977 object-suffixes-left := $(versioned)
978 include $(o-iterator)
979 else
980 define o-iterator-doit
981 $(inst_slibdir)/$o$($o-version): \
982   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
983         $$(make-shlib-link)
984 endef
985 object-suffixes-left := $(versioned)
986 include $(o-iterator)
988 define o-iterator-doit
989 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
990         $$(do-install-program)
991 endef
992 object-suffixes-left := $(versioned)
993 include $(o-iterator)
994 endif
995 endif
997 define do-install-so
998 $(do-install-program)
999 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1000            $(filter-out %.so,$@))
1001 endef
1003 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1004 $(foreach v,$(so-versions),\
1005           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1006                                                $(+force)
1007         $(do-install-so)
1008 $(foreach v,$(so-versions),\
1009           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1010         $(do-install-so)
1011 endif
1013 ifdef install-bin
1014 $(addprefix $(inst_bindir)/,$(install-bin)): \
1015     $(inst_bindir)/%: $(objpfx)% $(+force)
1016         $(do-install-program)
1017 endif
1018 ifdef install-bin-script
1019 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1020     $(inst_bindir)/%: $(objpfx)% $(+force)
1021         $(do-install-script)
1022 endif
1023 ifdef install-rootsbin
1024 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1025    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1026         $(do-install-program)
1027 endif
1028 ifdef install-sbin
1029 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1030     $(inst_sbindir)/%: $(objpfx)% $(+force)
1031         $(do-install-program)
1032 endif
1033 ifdef install-lib
1034 install-lib.a := $(filter lib%.a,$(install-lib))
1035 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1036 ifdef install-lib-non.a
1037 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1038   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1039         $(do-install)
1040 endif
1041 ifdef install-lib.a
1042 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1043   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1044         $(do-install)
1045 endif
1046 endif
1047 ifdef install-data
1048 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1049         $(do-install)
1050 endif
1051 headers := $(strip $(headers))
1052 ifdef headers
1053 # This implicit rule installs headers from the source directory.
1054 # It may be ignored in preference to rules from sysd-rules to find
1055 # headers in the sysdeps tree.
1056 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1057         $(do-install)
1058 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1059         $(do-install)
1060 $(inst_includedir)/%.h: %.h $(+force)
1061         $(do-install)
1062 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1063         $(do-install)
1064 headers-nonh := $(filter-out %.h,$(headers))
1065 ifdef headers-nonh
1066 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1067                                                  % $(+force)
1068         $(do-install)
1069 endif   # headers-nonh
1070 endif   # headers
1072 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1073         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1074         install-data-nosubdir install-headers-nosubdir
1075 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1076 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1077 install-rootsbin-nosubdir: \
1078         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1079 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1080 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1081                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1082                        $(addprefix $(libprefix),$(install-lib-non.a)))
1083 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1084 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1085 install-others-nosubdir: $(install-others)
1086 install-others-programs-nosubdir: $(install-others-programs)
1088 # We need all the `-nosubdir' targets so that `install' in the parent
1089 # doesn't depend on several things which each iterate over the subdirs.
1090 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1091 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1092 install-%:: install-%-nosubdir ;
1094 .PHONY: install install-no-libc.a-nosubdir
1095 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1096                             install-lib-nosubdir install-others-nosubdir
1097 ifeq ($(build-programs),yes)
1098 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1099                             install-rootsbin-nosubdir install-sbin-nosubdir \
1100                             install-others-programs-nosubdir
1101 endif
1102 install: install-no-libc.a-nosubdir
1104 # Command to compile $< using the native libraries.
1105 define native-compile
1106 $(make-target-directory)
1107 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1108             $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1109 endef
1111 # We always want to use configuration definitions.
1112 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1113                    -DIS_IN_build -include $(common-objpfx)config.h
1115 # Support the GNU standard name for this target.
1116 .PHONY: check
1117 check: tests
1118 # Special target to run tests which cannot be run unconditionally.
1119 # Maintainers should use this target.
1120 .PHONY: xcheck
1121 xcheck: xtests
1123 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1124 ifneq (,$(all-nonlib))
1125 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1126 lib := nonlib
1127 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1128 endif
1130 # The include magic above causes those files to use this variable for flags.
1131 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1134 ifeq ($(versioning),yes)
1135 # Generate normalized lists of symbols, versions, and data sizes.
1136 # This is handy for checking against existing library binaries.
1138 %.symlist: $(..)scripts/abilist.awk %.dynsym
1139         LC_ALL=C $(AWK) -f $^ > $@T
1140         mv -f $@T $@
1142 %.dynsym: %.so
1143         LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1144         mv -f $@T $@
1146 vpath %.abilist $(+sysdep_dirs)
1148 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1149 # target pattern is %.symlist from being considered "intermediate files"
1150 # and automatically removed.  We only want these files to be removed by
1151 # 'make clean', which is handled by the 'generated' variable.
1152 .PRECIOUS: %.symlist
1153 generated += $(extra-libs:=.symlist)
1155 check-abi-%: $(common-objpfx)config.make %.abilist $(objpfx)%.symlist
1156         $(check-abi)
1157 check-abi-%: $(common-objpfx)config.make %.abilist $(common-objpfx)%.symlist
1158         $(check-abi)
1159 define check-abi
1160         diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^)
1161 endef
1163 update-abi-%: $(objpfx)%.symlist %.abilist
1164         $(update-abi)
1165 update-abi-%: $(common-objpfx)%.symlist %.abilist
1166         $(update-abi)
1167 define update-abi
1168 @if cmp -s $^ 2> /dev/null; \
1169  then \
1170       echo '+++ $(filter %.abilist,$^) is unchanged'; \
1171  else cp -f $^; \
1172       echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1173  fi
1174 endef
1176 .PHONY: update-abi check-abi
1177 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1178 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1179 ifdef subdir
1180 subdir_check-abi: check-abi
1181 subdir_update-abi: update-abi
1182 else
1183 check-abi: subdir_check-abi
1184 update-abi: subdir_update-abi
1185 endif
1187 ifeq ($(subdir),elf)
1188 check-abi: check-abi-libc
1189 update-abi: update-abi-libc
1190 common-generated += libc.symlist
1191 endif
1193 ifeq ($(build-shared),yes)
1194 ifdef subdir
1195 tests: check-abi
1196 endif
1197 endif
1199 endif
1201 # These will have been set by sysdeps/posix/Makefile.
1202 L_tmpnam  ?= 1
1203 TMP_MAX   ?= 0
1204 L_ctermid ?= 1
1205 L_cuserid ?= 1
1207 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1209 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1210 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1211                    $(common-objpfx)config.make
1212         $(make-target-directory)
1213         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1214           echo '#define _LIBC 1';                                       \
1215           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1216         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1217               $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1218         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1219             $(@:st=dT) > $(@:st=dt)
1220         mv -f $(@:st=dt) $(@:st=d)
1221         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1222         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1223         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1224         fopen_max=$${fopen_max:-16};                                    \
1225         filename_max=$${filename_max:-1024};                            \
1226         if [ -z "$$iov_max" ]; then                                     \
1227           define_iov_max="# undef IOV_MAX";                             \
1228         else                                                            \
1229           define_iov_max="# define IOV_MAX $$iov_max";                  \
1230         fi;                                                             \
1231         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1232             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1233             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1234             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1235             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1236             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1237             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1238             $< > $(@:st=h.new)
1239         $(move-if-change) $(@:st=h.new) $(@:st=h)
1240 # Remove these last so that they can be examined if something went wrong.
1241         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1242         touch $@
1243 # Get dependencies.
1244 ifndef no_deps
1245 -include $(stdio_lim:h=d)
1246 endif
1247 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1249 FORCE:
1251 .PHONY: echo-headers
1252 echo-headers:
1253         @echo $(headers)
1255 %.bz2: %; bzip2 -9vk $<
1256 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1257 %.xz: %; xz -9evk $<
1259 # Common cleaning targets.
1261 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1262 clean: common-clean
1263 mostlyclean: common-mostlyclean
1265 do-tests-clean:
1266         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1267                                                       $(test-srcs)))
1269 # Remove the object files.
1270 common-mostlyclean:
1271         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1272                                      $(others) $(sysdep-others) stubs \
1273                                      $(addsuffix .o,$(tests) $(xtests) \
1274                                                     $(test-srcs) $(others) \
1275                                                     $(sysdep-others)) \
1276                                      $(addsuffix .out,$(tests) $(xtests) \
1277                                                       $(test-srcs)))
1278         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1279                                      $(install-lib) $(install-lib.so) \
1280                                      $(install-lib.so:%.so=%_pic.a))
1281         -rm -f core
1282         -rm -f $(objpfx)rtld-*.os
1283         $(rmobjs)
1284 define rmobjs
1285 $(foreach o,$(object-suffixes-for-libc),
1286 -rm -f $(objpfx)stamp$o $(o-objects))
1287 endef
1289 # Also remove the dependencies and generated source files.
1290 common-clean: common-mostlyclean
1291         -rm -f $(addprefix $(objpfx),$(generated))
1292         -rm -f $(objpfx)*.d $(objpfx)*.dt
1293         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1294         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1295         -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1297 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1298 # for each function which is a stub.
1300 ifdef objpfx
1301 .PHONY: stubs # The parent Makefile calls this target.
1302 stubs: $(objpfx)stubs
1303 endif
1304 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1305                   $(addprefix $(objpfx),$(extra-objs))
1306 $(objpfx)stubs: $(objs-for-stubs)
1307 ifneq (,$(strip $(objs-for-stubs)))
1308         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1309         $(AWK) '/\.gnu\.glibc-stub\./ { \
1310                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1311                   stubs[$$2] = 1; } \
1312                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1313         mv -f $@T $@
1314 else
1315         > $@
1316 endif
1318 ifneq (,$(strip $(gpl2lgpl)))
1319 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1320 # Snarf from the master source and frob the copying notice.
1321 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1322         sed -f $^ > $@-tmp
1323 # So I don't edit them by mistake.
1324         chmod a-w $@-tmp
1325         mv -f $@-tmp $@
1326 endif
1327 endif
1329 # Local Variables:
1330 # mode: makefile
1331 # End: