Add a test for BZ #15674
[glibc.git] / Makerules
blob03eafb036f375cad50d764e6e81d961a61390b37
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' regexps
221 # matching sysdep directories whose assembly source files should be
222 # suppressed.
224 -include $(common-objpfx)sysd-rules
225 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
226 # The value of $(+sysdep_dirs) the sysd-rules was computed for
227 # differs from the one we are using now.  So force a rebuild of sysd-rules.
228 sysd-rules-force = FORCE
229 FORCE:
230 endif
231 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
232                             $(common-objpfx)config.make $(..)Makerules \
233                             $(sysdep-makefiles) $(sysdep-makeconfigs) \
234                             $(sysd-rules-force)
235         -@rm -f $@T
236         LC_ALL=C $(AWK) -f $< > $@T \
237                         -v all_object_suffixes='$(all-object-suffixes)' \
238                         -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
239                         -v sysd_rules_patterns='$(sysd-rules-patterns)' \
240                         -v config_sysdirs='$(config-sysdirs)'
241         mv -f $@T $@
243 ifndef sysd-rules-done
244 # Don't do deps until this exists, because it provides rules to make the deps.
245 no_deps=t
246 endif
248 define o-iterator-doit
249 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
250 endef
251 object-suffixes-left := $(all-object-suffixes)
252 include $(o-iterator)
254 define o-iterator-doit
255 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
256 endef
257 object-suffixes-left := $(all-object-suffixes)
258 include $(o-iterator)
260 define o-iterator-doit
261 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
262 endef
263 object-suffixes-left := $(all-object-suffixes)
264 include $(o-iterator)
266 # Omit the objpfx rules when building in the source tree, because
267 # objpfx is empty and so these rules just override the ones above.
268 ifdef objpfx
269 # Define first rules to find the source files in $(objpfx).
270 # Generated source files will end up there.
271 define o-iterator-doit
272 $(objpfx)%$o: $(objpfx)%.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: $(objpfx)%.c $(before-compile); $$(compile-command.c)
279 endef
280 object-suffixes-left := $(all-object-suffixes)
281 include $(o-iterator)
282 endif
284 # Generate version maps, but wait until sysdep-subdirs is known
285 ifeq ($(sysd-sorted-done),t)
286 ifeq ($(versioning),yes)
287 -include $(common-objpfx)sysd-versions
288 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
289 common-generated += $(version-maps)
290 postclean-generated += sysd-versions Versions.all abi-versions.h \
291                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
293 ifndef avoid-generated
294 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
295 sysd-versions-force = FORCE
296 FORCE:
297 endif
298 # See %.v/%.v.i implicit rules in Makeconfig.
299 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
300                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
301 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
302                               $(common-objpfx)soversions.i \
303                               $(common-objpfx)Versions.def.v
304         { while read which lib version setname; do \
305             test x"$$which" = xDEFAULT || continue; \
306             test -z "$$setname" || echo "$$lib : $$setname"; \
307           done < $(word 2,$^); \
308           cat $(word 3,$^); \
309         } | LC_ALL=C $(AWK) -f $< > $@T
310         mv -f $@T $@
311 # See %.v/%.v.i implicit rules in Makeconfig.
312 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
313                               $(wildcard $(sysdirs:%=%/Versions)) \
314                               $(common-objpfx)abi-versions.h \
315                               $(sysd-versions-force)
316 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
317                                $(common-objpfx)Versions.v \
318                                $(..)scripts/versions.awk
319         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
320           cat $(word 2,$^) \
321           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
322                             -v move_if_change='$(move-if-change)' \
323                             -f $(word 3,$^); \
324         ) > $@T
325         mv -f $@T $@
326 endif # avoid-generated
327 endif # $(versioning) = yes
328 endif # sysd-sorted-done
330 # Generate .dT files as we compile.
331 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
332 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
333 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
334 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
336 # Like compile-mkdep-flags, but for use with $(BUILD_CC).  We don't want to
337 # track system includes here, they may spuriously trigger an install rule,
338 # and would cause the check-local-headers test to fail.
339 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
341 # GCC can grok options after the file name, and it looks nicer that way.
342 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
343 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
344 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
345                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
346 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
347 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
348                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
350 # We need this for the output to go in the right place.  It will default to
351 # empty if make was configured to work with a cc that can't grok -c and -o
352 # together.  You can't compile the C library with such a compiler.
353 OUTPUT_OPTION = -o $@
355 # This is the end of the pipeline for compiling generated C code.
356 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
358 # We need the $(CFLAGS) to be in there to have the right predefines during
359 # the dependency run for C sources.  But having it for assembly sources can
360 # get the wrong predefines.
361 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
363 define +make-deps
364 $(make-target-directory)
365 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
366              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
367 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
368 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
369 mv -f $(@:.d=.T) $@ $(generate-md5)
370 endef
372 ifneq (,$(objpfx))
373 # Continuation lines here are dangerous because they introduce spaces!
374 define sed-remove-objpfx
375 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
376 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
377 endef
378 endif
380 # Modify the list of routines we build for different targets
382 ifeq (yes,$(build-shared))
383 ifndef libc.so-version
384 # Undefine this because it can't work when we libc.so is unversioned.
385 static-only-routines =
386 endif
387 endif
389 elide-routines.oS += $(filter-out $(static-only-routines),\
390                                   $(routines) $(aux) $(sysdep_routines))
391 elide-routines.os += $(static-only-routines)
393 # If we have versioned code we don't need the old versions in any of the
394 # static libraries.
395 elide-routines.o  += $(shared-only-routines)
396 elide-routines.op += $(shared-only-routines)
397 elide-routines.og += $(shared-only-routines)
399 # Shared library building.
401 ifeq (yes,$(build-shared))
403 # Reference map file only when versioning is selected and a map file name
404 # is given.
405 ifeq ($(versioning),yes)
406 map-file = $(firstword $($(@F:.so=-map)) \
407                        $(addprefix $(common-objpfx), \
408                                    $(filter $(@F:.so=.map),$(version-maps))))
409 load-map-file = $(map-file:%=-Wl,--version-script=%)
410 endif
412 # Compiler arguments to use to link a shared object with libc and
413 # ld.so.  This is intended to be as similar as possible to a default
414 # link with an installed libc.
415 link-libc-args = -Wl,--start-group \
416                  $(libc-for-link) \
417                  $(common-objpfx)libc_nonshared.a \
418                  $(as-needed) $(elfobjdir)/ld.so $(no-as-needed) \
419                  -Wl,--end-group
421 # The corresponding shared libc to use.  This may be modified for a
422 # particular target.
423 libc-for-link = $(common-objpfx)libc.so
425 # The corresponding dependencies.  As these are used in dependencies,
426 # not just commands, they cannot use target-specific variables so need
427 # to name both possible libc.so objects.
428 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
429                  $(common-objpfx)libc_nonshared.a $(elfobjdir)/ld.so
431 # Pattern rule to build a shared object from an archive of PIC objects.
432 # This must come after the installation rules so Make doesn't try to
433 # build shared libraries in place from the installed *_pic.a files.
434 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
435 # on other shared objects.  The linking with libc and ld.so is intended
436 # to be as similar as possible to a default link with an installed libc.
437 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp) $(link-libc-deps)
438         $(build-shlib) $(link-libc-args)
440 define build-shlib-helper
441 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
442           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
443           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
444           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
445           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
446           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
447           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
448 endef
450 ifeq (yes,$(use-default-link))
451 # If the linker is good enough, we can let it use its default linker script.
452 shlib-lds =
453 shlib-lds-flags =
454 else
455 # binutils only position loadable notes into the first page for binaries,
456 # not for shared objects
457 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
458         $(LINK.o) -shared -Wl,-O1 \
459                   -nostdlib -nostartfiles \
460                   $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
461                   -Wl,--verbose 2>&1 | \
462           sed > $@T \
463               -e '/^=========/,/^=========/!d;/^=========/d' \
464               $(if $(filter yes,$(have-hash-style)), \
465                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
466                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
467                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
468                 , \
469                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
470                ) \
471               -e 's/^.*\*(\.dynbss).*$$/& \
472                  PROVIDE(__start___libc_freeres_ptrs = .); \
473                  *(__libc_freeres_ptrs) \
474                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
475               -e 's@^.*\*(\.jcr).*$$@& \
476                  PROVIDE(__start___libc_subfreeres = .);\
477                  __libc_subfreeres : { *(__libc_subfreeres) }\
478                  PROVIDE(__stop___libc_subfreeres = .);\
479                  PROVIDE(__start___libc_atexit = .);\
480                  __libc_atexit : { *(__libc_atexit) }\
481                  PROVIDE(__stop___libc_atexit = .);\
482                  PROVIDE(__start___libc_thread_subfreeres = .);\
483                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
484                  PROVIDE(__stop___libc_thread_subfreeres = .);\
485                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
486         test -s $@T
487         mv -f $@T $@
488 common-generated += shlib.lds
490 shlib-lds = $(common-objpfx)shlib.lds
491 shlib-lds-flags = -T $(shlib-lds)
492 endif
494 define build-shlib
495 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
496           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
497 endef
499 define build-module-helper
500 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
501           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
502           -B$(csu-objpfx) $(load-map-file) \
503           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
504           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
505 endef
507 # This macro is similar to build-shlib but it does not define a soname
508 # and it does not depend on the destination name to start with `lib'.
509 # binutils only position loadable notes into the first page for binaries,
510 # not for shared objects
511 define build-module
512 $(build-module-helper) -o $@ $(shlib-lds-flags) \
513           $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
514 endef
515 define build-module-asneeded
516 $(build-module-helper) -o $@ $(shlib-lds-flags) \
517           $(csu-objpfx)abi-note.o \
518           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
519           $(link-libc-args)
520 endef
522 build-module-helper-objlist = \
523         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
524                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
525                                 $(link-libc-deps),$^))
527 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
528 build-shlib-objlist = $(build-module-helper-objlist) \
529                       $(LDLIBS-$(@F:lib%.so=%).so)
531 # Don't try to use -lc when making libc.so itself.
532 # Also omits crti.o and crtn.o, which we do not want
533 # since we define our own `.init' section specially.
534 LDFLAGS-c.so = -nostdlib -nostartfiles
535 # But we still want to link libc.so against $(libc.so-gnulib).
536 LDLIBS-c.so += $(libc.so-gnulib)
537 # Give libc.so an entry point and make it directly runnable itself.
538 LDFLAGS-c.so += -e __libc_main
539 # If lazy relocation is disabled add the -z now flag.
540 ifeq ($(bind-now),yes)
541 LDFLAGS-c.so += -Wl,-z,now
542 endif
543 # Pre-link the objects of libc_pic.a so that we can locally resolve
544 # COMMON symbols before we link against ld.so.  This is because ld.so
545 # contains some of libc_pic.a already, which will prevent the COMMONs
546 # from being allocated in libc.so, which introduces evil dependencies
547 # between libc.so and ld.so, which can make it impossible to upgrade.
548 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
549         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
550         $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
552 ifeq (,$(strip $(shlib-lds-flags)))
553 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
554 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
555         $(OBJDUMP) -h $< | \
556         $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
557                 > $@T
558         mv -f $@T $@
559 # Apply those -R options.
560 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
561                                    $(common-objpfx)libc_pic.os
562         $(OBJCOPY) @$^ $@
563 generated += libc_pic.opts libc_pic.os.clean
565 libc_pic_clean := .clean
566 endif
568 # Do not filter ld.so out of libc.so link.
569 $(common-objpfx)libc.so: link-libc-deps = # empty
571 # Use our own special initializer and finalizer files for libc.so.
572 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
573                          $(common-objpfx)libc_pic.os$(libc_pic_clean) \
574                          $(elfobjdir)/sofini.os \
575                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
576                          $(shlib-lds)
577         $(build-shlib)
578 ifeq ($(versioning),yes)
579 $(common-objpfx)libc.so: $(common-objpfx)libc.map
580 endif
581 common-generated += libc.so libc_pic.os
582 ifdef libc.so-version
583 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
584         $(make-link)
585 common-generated += libc.so$(libc.so-version)
586 endif
587 endif
589 # Figure out the source filenames in this directory.
591 override sources := $(addsuffix .c,\
592                         $(filter-out $(elided-routines),\
593                             $(routines) $(aux) \
594                             $(sysdep_routines)))
595 sysdep_routines := $(sysdep_routines)
597 headers := $(headers) $(sysdep_headers)
599 # This is the list of all object files, gotten by
600 # replacing every ".c" in `sources' with a ".o".
601 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
604 # The makefile may define $(extra-libs) with `libfoo libbar'
605 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
606 ifdef extra-libs
607 # extra-lib.mk is included once for each extra lib to define rules
608 # to build it, and to add its objects to the various variables.
609 # During its evaluation, $(lib) is set to the name of the library.
610 extra-libs-left := $(extra-libs)
611 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
612 endif
615 # The makefile may define $(modules-names) to build additional modules.
616 # These are built with $(build-module), except any in $(modules-names-nobuild).
617 ifdef modules-names
618 # extra-lib.mk is included once for each extra lib to define rules
619 # to build it, and to add its objects to the various variables.
620 # During its evaluation, $(lib) is set to the name of the library.
621 extra-modules-left := $(modules-names)
622 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
624 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
625 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
626                 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
627         $(build-module)
628 endif
630 +depfiles := $(sources:.c=.d) \
631              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
632              $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
633              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
634              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
635 ifeq ($(build-programs),yes)
636 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
637 endif
638 +depfiles := $(addprefix $(objpfx),\
639                          $(filter-out $(addsuffix .d,$(omit-deps)),\
640                                       $(+depfiles)))
641 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
642 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
643              $(wildcard $(all-dt-files:.dt=.d))
645 # This is a funny rule in that it removes its input file.
646 %.d: %.dt
647         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
648          mv -f $(@:.d=.T) $@ && \
649          rm -f $<
651 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
652 # They will be generated when they're needed, and trying too early won't work.
653 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
654 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
655                                                 $(+gen-as-const)))
657 ifdef +depfiles
658 ifneq ($(no_deps),t)
659 -include $(+depfiles)
660 endif
661 endif
662 \f\f
663 # Maximize efficiency by minimizing the number of rules.
664 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
665 # Don't define any builtin rules.
666 MAKEFLAGS := $(MAKEFLAGS)r
668 # Generic rule for making directories.
670 # mkdir isn't smart enough to strip a trailing /.
671 # We always require a mkdir which supports the -p option to avoid error
672 # messages in case of races.
673         mkdir -p $(@:%/=%)
675 # Make sure that object files are not removed
676 # when they are intermediates between sources and library members.
677 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
679 # Make sure that the parent library archive is never removed.
680 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
682 # Use the verbose option of ar and tar when not running silently.
683 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
684 verbose := v
685 else                                            # -s
686 verbose :=
687 endif                                           # not -s
689 ARFLAGS := r$(verbose)
690 CREATE_ARFLAGS := cru$(verbose)
692 # This makes all the object files in the parent library archive.
694 .PHONY: lib lib-noranlib
695 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
696 lib-noranlib: libobjs
698 # For object-suffix $o, the list of objects with that suffix.
699 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
700 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
701                                                        $(elide-routines$o)),\
702                                             $(objects))) \
703             $(addprefix $(objpfx),$(o-objects$o))
705 others: $(addprefix $(objpfx),$(install-lib))
707 ifndef objects
709 # Create the stamp$o files to keep the parent makefile happy.
710 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
711 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
712         $(make-target-directory)
713         rm -f $@; > $@
714 else
716 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
717 # timestamp file; these rules (one explicit rule is generated for each
718 # object suffix) write a list of objects to update in the stamp file.
719 # The parent will then actually add them all to the archive in the
720 # archive rule, below.
721 define o-iterator-doit
722 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
723 endef
724 define do-stamp
725 $(make-target-directory)
726 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
727 mv -f $@T $@
728 endef
729 object-suffixes-left := $(object-suffixes-for-libc)
730 include $(o-iterator)
732 endif
734 # Now define explicit rules to build the library archives; these depend
735 # on the stamp files built above.
736 define o-iterator-doit
737 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
738                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
739 endef
740 define do-makelib
741 cd $(common-objdir) && \
742 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
743 endef
744 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
745 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
746 ifndef subdir
747 $(subdirs-stamps): subdir_lib;
748 endif
749 object-suffixes-left = $(object-suffixes-for-libc)
750 include $(o-iterator)
753 # This makes all the object files.
754 .PHONY: objects objs libobjs extra-objs
755 objects objs: libobjs extra-objs
756 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
757 extra-objs: $(addprefix $(objpfx),$(extra-objs))
759 # Canned sequence for building an extra library archive.
760 define build-extra-lib
761 $(patsubst %/,cd % &&,$(objpfx)) \
762 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
763       $(patsubst $(objpfx)%,%,$^)
764 endef
766 # Installation.
768 .PHONY: force-install
769 force-install:
771 # $(install-lib) are installed from the object directory into $(libdir);
772 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
773 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
774 # they are into $(datadir).  $(headers) are installed as they are in
775 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
776 # are installed from the object directory into $(bindir), $(bindir) and
777 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
778 # are absolute path names of files to install; rules to install them are
779 # defined elsewhere.
781 # The simple library name to install libc.a under.
782 # This could be defined by a sysdep Makefile.
783 ifndef libc-name
784 libc-name := c
785 endif
787 define do-install
788 $(make-target-directory)
789 $(INSTALL_DATA) $< $@
790 endef
792 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
793 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
794 define make-target-directory
795 $(addprefix $(..)./scripts/mkinstalldirs ,\
796             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
797 endef
799 # Any directory (parent or subdir) should install libc.a; this way
800 # "make install" in a subdir is guaranteed to install everything it changes.
801 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
802                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
803                                                      $(libprefix)$(libc-name)))
804 install: $(installed-libcs)
805 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
806         $(make-target-directory)
807         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
809 define do-install-program
810 $(make-target-directory)
811 $(INSTALL_PROGRAM) $< $@.new
812 mv -f $@.new $@
813 endef
815 define do-install-script
816 $(make-target-directory)
817 $(INSTALL_SCRIPT) $< $@.new
818 mv -f $@.new $@
819 endef
821 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
822 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
824 ifeq (yes,$(build-shared))
825 # Find which .so's have versions.
826 versioned := $(strip $(foreach so,$(install-lib.so),\
827                                $(patsubst %,$(so),$($(so)-version))))
829 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
830 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
832 # For versioned libraries, we install three files:
833 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
834 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
835 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
836 lib-version := $(firstword $($(subdir)-version) $(version))
837 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
838                       $(foreach L,$(install-lib.so-versioned),\
839                                 $(inst_libdir)/$L \
840                                 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
841                                 $(inst_slibdir)/$L$($L-version))
843 # Install all the unversioned shared libraries.
844 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
845     $(objpfx)%.so $(+force)
846         $(do-install-program)
848 ifneq ($(findstring -s,$(LN_S)),)
849 define make-link
850 rm -f $@.new
851 $(SHELL) $(..)scripts/rellns-sh $< $@.new
852 mv -f $@.new $@
853 endef
854 else
855 # If we have no symbolic links don't bother with rellns-sh.
856 define make-link
857 rm -f $@.new
858 $(LN_S) $< $@.new
859 mv -f $@.new $@
860 endef
861 endif
863 ifeq (yes,$(build-shared))
864 ifeq (no,$(cross-compiling))
865 symbolic-link-prog := $(common-objpfx)elf/sln
866 symbolic-link-list := $(common-objpfx)elf/symlink.list
867 define make-shlib-link
868 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
869 endef
870 else # cross-compiling
871 # We need a definition that can be used by elf/Makefile's install rules.
872 symbolic-link-prog = $(LN_S)
873 endif
874 endif
875 ifndef make-shlib-link
876 define make-shlib-link
877 rm -f $@
878 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
879 endef
880 endif
882 ifdef libc.so-version
883 # For a library specified to be version N, install three files:
884 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
885 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
887 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
888                                            $(+force)
889         $(make-shlib-link)
890 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
891         $(do-install-program)
892 install: $(inst_slibdir)/libc.so$(libc.so-version)
894 # This fragment of linker script gives the OUTPUT_FORMAT statement
895 # for the configuration we are building.  We put this statement into
896 # the linker scripts we install for -lc et al so that they will not be
897 # used by a link for a different format on a multi-architecture system.
898 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
899                             $(common-objpfx)config.make \
900                             $(common-objpfx)config.h $(..)Makerules
901 ifneq (unknown,$(output-format))
902         echo > $@.new 'OUTPUT_FORMAT($(output-format))'
903 else
904         $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
905                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
906         | sed -n -f $< > $@.new
907         test -s $@.new
908         rm -f $@.so
909 endif
910         mv -f $@.new $@
911 common-generated += format.lds
913 ifndef subdir
914 # What we install as libc.so for programs to link against is in fact a
915 # link script.  It contains references for the various libraries we need.
916 # The libc.so object is not complete since some functions are only defined
917 # in libc_nonshared.a.
918 # We need to use absolute paths since otherwise local copies (if they exist)
919 # of the files are taken by the linker.
920 install: $(inst_libdir)/libc.so
921 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
922                         $(common-objpfx)libc.so$(libc.so-version) \
923                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
924                                                   $(libprefix)$(libc-name)) \
925                         $(+force)
926         (echo '/* GNU ld script';\
927          echo '   Use the shared library, but some functions are only in';\
928          echo '   the static library, so try that secondarily.  */';\
929          cat $<; \
930          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
931               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
932               ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
933         ) > $@.new
934         mv -f $@.new $@
936 endif
938 else
939 install: $(inst_slibdir)/libc.so
940 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
941         $(do-install-program)
942 endif
944 ifneq (,$(versioned))
945 # Produce three sets of rules as above for all the smaller versioned libraries.
947 define o-iterator-doit
948 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
949 endef
950 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
951 ifneq (,$(object-suffixes-left))
952 include $(o-iterator)
953 endif
955 # Make symlinks in the build directory, because the versioned names might
956 # be referenced by a DT_NEEDED in another library.
957 define o-iterator-doit
958 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
959 endef
960 object-suffixes-left := $(versioned)
961 include $(o-iterator)
963 generated += $(foreach o,$(versioned),$o$($o-version))
965 ifeq (,$($(subdir)-version))
966 define o-iterator-doit
967 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
968                                  $(+force);
969         $$(make-shlib-link)
970 endef
971 object-suffixes-left := $(versioned)
972 include $(o-iterator)
974 define o-iterator-doit
975 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
976         $$(do-install-program)
977 endef
978 object-suffixes-left := $(versioned)
979 include $(o-iterator)
980 else
981 define o-iterator-doit
982 $(inst_slibdir)/$o$($o-version): \
983   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
984         $$(make-shlib-link)
985 endef
986 object-suffixes-left := $(versioned)
987 include $(o-iterator)
989 define o-iterator-doit
990 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
991         $$(do-install-program)
992 endef
993 object-suffixes-left := $(versioned)
994 include $(o-iterator)
995 endif
996 endif
998 define do-install-so
999 $(do-install-program)
1000 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1001            $(filter-out %.so,$@))
1002 endef
1004 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1005 $(foreach v,$(so-versions),\
1006           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1007                                                $(+force)
1008         $(do-install-so)
1009 $(foreach v,$(so-versions),\
1010           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1011         $(do-install-so)
1012 endif
1014 ifdef install-bin
1015 $(addprefix $(inst_bindir)/,$(install-bin)): \
1016     $(inst_bindir)/%: $(objpfx)% $(+force)
1017         $(do-install-program)
1018 endif
1019 ifdef install-bin-script
1020 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1021     $(inst_bindir)/%: $(objpfx)% $(+force)
1022         $(do-install-script)
1023 endif
1024 ifdef install-rootsbin
1025 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1026    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1027         $(do-install-program)
1028 endif
1029 ifdef install-sbin
1030 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1031     $(inst_sbindir)/%: $(objpfx)% $(+force)
1032         $(do-install-program)
1033 endif
1034 ifdef install-lib
1035 install-lib.a := $(filter lib%.a,$(install-lib))
1036 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1037 ifdef install-lib-non.a
1038 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1039   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1040         $(do-install)
1041 endif
1042 ifdef install-lib.a
1043 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1044   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1045         $(do-install)
1046 endif
1047 endif
1048 ifdef install-data
1049 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1050         $(do-install)
1051 endif
1052 headers := $(strip $(headers))
1053 ifdef headers
1054 # This implicit rule installs headers from the source directory.
1055 # It may be ignored in preference to rules from sysd-rules to find
1056 # headers in the sysdeps tree.
1057 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1058         $(do-install)
1059 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1060         $(do-install)
1061 $(inst_includedir)/%.h: %.h $(+force)
1062         $(do-install)
1063 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1064         $(do-install)
1065 headers-nonh := $(filter-out %.h,$(headers))
1066 ifdef headers-nonh
1067 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1068                                                  % $(+force)
1069         $(do-install)
1070 endif   # headers-nonh
1071 endif   # headers
1073 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1074         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1075         install-data-nosubdir install-headers-nosubdir
1076 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1077 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1078 install-rootsbin-nosubdir: \
1079         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1080 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1081 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1082                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1083                        $(addprefix $(libprefix),$(install-lib-non.a)))
1084 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1085 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1086 install-others-nosubdir: $(install-others)
1087 install-others-programs-nosubdir: $(install-others-programs)
1089 # We need all the `-nosubdir' targets so that `install' in the parent
1090 # doesn't depend on several things which each iterate over the subdirs.
1091 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1092 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1093 install-%:: install-%-nosubdir ;
1095 .PHONY: install install-no-libc.a-nosubdir
1096 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1097                             install-lib-nosubdir install-others-nosubdir
1098 ifeq ($(build-programs),yes)
1099 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1100                             install-rootsbin-nosubdir install-sbin-nosubdir \
1101                             install-others-programs-nosubdir
1102 endif
1103 install: install-no-libc.a-nosubdir
1105 # Command to compile $< using the native libraries.
1106 define native-compile
1107 $(make-target-directory)
1108 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1109             $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1110 endef
1112 # We always want to use configuration definitions.
1113 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1114                    -DIS_IN_build -include $(common-objpfx)config.h
1116 # Support the GNU standard name for this target.
1117 .PHONY: check
1118 check: tests
1119 # Special target to run tests which cannot be run unconditionally.
1120 # Maintainers should use this target.
1121 .PHONY: xcheck
1122 xcheck: xtests
1124 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1125 ifneq (,$(all-nonlib))
1126 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1127 lib := nonlib
1128 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1129 endif
1131 # The include magic above causes those files to use this variable for flags.
1132 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1135 ifeq ($(versioning),yes)
1136 # Generate normalized lists of symbols, versions, and data sizes.
1137 # This is handy for checking against existing library binaries.
1139 %.symlist: $(..)scripts/abilist.awk %.dynsym
1140         LC_ALL=C $(AWK) -f $^ > $@T
1141         mv -f $@T $@
1143 %.dynsym: %.so
1144         LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1145         mv -f $@T $@
1147 vpath %.abilist $(+sysdep_dirs)
1149 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1150 # target pattern is %.symlist from being considered "intermediate files"
1151 # and automatically removed.  We only want these files to be removed by
1152 # 'make clean', which is handled by the 'generated' variable.
1153 .PRECIOUS: %.symlist
1154 generated += $(extra-libs:=.symlist)
1156 check-abi-%: $(common-objpfx)config.make %.abilist $(objpfx)%.symlist
1157         $(check-abi)
1158 check-abi-%: $(common-objpfx)config.make %.abilist $(common-objpfx)%.symlist
1159         $(check-abi)
1160 define check-abi
1161         diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^)
1162 endef
1164 update-abi-%: $(objpfx)%.symlist %.abilist
1165         $(update-abi)
1166 update-abi-%: $(common-objpfx)%.symlist %.abilist
1167         $(update-abi)
1168 define update-abi
1169 @if cmp -s $^ 2> /dev/null; \
1170  then \
1171       echo '+++ $(filter %.abilist,$^) is unchanged'; \
1172  else cp -f $^; \
1173       echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1174  fi
1175 endef
1177 .PHONY: update-abi check-abi
1178 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1179 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1180 ifdef subdir
1181 subdir_check-abi: check-abi
1182 subdir_update-abi: update-abi
1183 else
1184 check-abi: subdir_check-abi
1185 update-abi: subdir_update-abi
1186 endif
1188 ifeq ($(subdir),elf)
1189 check-abi: check-abi-libc
1190 update-abi: update-abi-libc
1191 common-generated += libc.symlist
1192 endif
1194 ifeq ($(build-shared),yes)
1195 ifdef subdir
1196 tests: check-abi
1197 endif
1198 endif
1200 endif
1202 # These will have been set by sysdeps/posix/Makefile.
1203 L_tmpnam  ?= 1
1204 TMP_MAX   ?= 0
1205 L_ctermid ?= 1
1206 L_cuserid ?= 1
1208 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1210 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1211 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1212                    $(common-objpfx)config.make
1213         $(make-target-directory)
1214         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1215           echo '#define _LIBC 1';                                       \
1216           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1217         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1218               $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1219         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1220             $(@:st=dT) > $(@:st=dt)
1221         mv -f $(@:st=dt) $(@:st=d)
1222         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1223         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1224         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1225         fopen_max=$${fopen_max:-16};                                    \
1226         filename_max=$${filename_max:-1024};                            \
1227         if [ -z "$$iov_max" ]; then                                     \
1228           define_iov_max="# undef IOV_MAX";                             \
1229         else                                                            \
1230           define_iov_max="# define IOV_MAX $$iov_max";                  \
1231         fi;                                                             \
1232         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1233             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1234             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1235             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1236             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1237             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1238             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1239             $< > $(@:st=h.new)
1240         $(move-if-change) $(@:st=h.new) $(@:st=h)
1241 # Remove these last so that they can be examined if something went wrong.
1242         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1243         touch $@
1244 # Get dependencies.
1245 ifndef no_deps
1246 -include $(stdio_lim:h=d)
1247 endif
1248 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1250 FORCE:
1252 .PHONY: echo-headers
1253 echo-headers:
1254         @echo $(headers)
1256 %.bz2: %; bzip2 -9vk $<
1257 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1258 %.xz: %; xz -9evk $<
1260 # Common cleaning targets.
1262 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1263 clean: common-clean
1264 mostlyclean: common-mostlyclean
1266 do-tests-clean:
1267         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1268                                                       $(test-srcs)))
1270 # Remove the object files.
1271 common-mostlyclean:
1272         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1273                                      $(others) $(sysdep-others) stubs \
1274                                      $(addsuffix .o,$(tests) $(xtests) \
1275                                                     $(test-srcs) $(others) \
1276                                                     $(sysdep-others)) \
1277                                      $(addsuffix .out,$(tests) $(xtests) \
1278                                                       $(test-srcs)))
1279         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1280                                      $(install-lib) $(install-lib.so) \
1281                                      $(install-lib.so:%.so=%_pic.a))
1282         -rm -f core
1283         -rm -f $(objpfx)rtld-*.os
1284         $(rmobjs)
1285 define rmobjs
1286 $(foreach o,$(object-suffixes-for-libc),
1287 -rm -f $(objpfx)stamp$o $(o-objects))
1288 endef
1290 # Also remove the dependencies and generated source files.
1291 common-clean: common-mostlyclean
1292         -rm -f $(addprefix $(objpfx),$(generated))
1293         -rm -f $(objpfx)*.d $(objpfx)*.dt
1294         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1295         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1296         -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1298 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1299 # for each function which is a stub.
1301 ifdef objpfx
1302 .PHONY: stubs # The parent Makefile calls this target.
1303 stubs: $(objpfx)stubs
1304 endif
1305 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1306                   $(addprefix $(objpfx),$(extra-objs))
1307 $(objpfx)stubs: $(objs-for-stubs)
1308 ifneq (,$(strip $(objs-for-stubs)))
1309         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1310         $(AWK) '/\.gnu\.glibc-stub\./ { \
1311                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1312                   stubs[$$2] = 1; } \
1313                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1314         mv -f $@T $@
1315 else
1316         > $@
1317 endif
1319 ifneq (,$(strip $(gpl2lgpl)))
1320 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1321 # Snarf from the master source and frob the copying notice.
1322 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1323         sed -f $^ > $@-tmp
1324 # So I don't edit them by mistake.
1325         chmod a-w $@-tmp
1326         mv -f $@-tmp $@
1327 endif
1328 endif
1330 # Local Variables:
1331 # mode: makefile
1332 # End: