Bug fixes for ____longjmp_chk on sparc.
[glibc.git] / Makerules
bloba8b575c019c1c4673375631ae40f595b2cbf928a
1 # Copyright (C) 1991-2010, 2011 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 # 02111-1307 USA.
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version.  See above for the version needed.
34 endif
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq   "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
59 # This variable is used in ``include $(o-iterator)'' after defining
60 # $(o-iterator-doit) to produce some desired rule using $o for the object
61 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
62 # is produced for each object suffix in use.
63 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
65 # Include any system-specific makefiles.
67 # This is here so things in sysdep Makefiles can easily depend on foo.h as
68 # appropriate and not worry about where foo.h comes from, which may be
69 # system dependent and not known by that Makefile.
70 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
71                                       $(+sysdep_dirs) $(..)))
73 # The same is true for RPC source files.
74 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
75                                       $(+sysdep_dirs) $(..)))
77 # Some sysdep makefiles use this to distinguish being included here from
78 # being included individually by a subdir makefile (hurd/Makefile needs this).
79 in-Makerules := yes
81 sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
82 ifneq (,$(sysdep-makefiles))
83 include $(sysdep-makefiles)
84 endif
87 # Reorder before-compile so that mach things come first, and hurd things
88 # second, before all else.  The mach and hurd subdirectories have many
89 # generated header files which the much of rest of the library depends on,
90 # so it is best to build them first (and mach before hurd, at that).
91 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
92                            $(before-compile)) \
93                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
94                                $(before-compile))
96 # Even before that, we need abi-versions.h which is generated right here.
97 ifeq ($(versioning),yes)
98 ifndef avoid-generated
99 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
100 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
101                                 $(common-objpfx)Versions.all
102         LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
103         mv -f $@T $@
105 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
106         sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
107             $(common-objpfx)abi-versions.h > $@T
108         mv -f $@T $@
109 endif # avoid-generated
110 endif # $(versioning) = yes
112 ifndef avoid-generated
113 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
114 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
115 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
116                              $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
117                                          $(..)libc-abis) \
118                              $(..)Makerules
119         $(SHELL) $< \
120                  $(base-machine)-$(config-vendor)-$(config-os) \
121                  < $(word 2,$^) > $(@:.stamp=.h)T
122         $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
123         touch $@
124 common-generated += $(common-objpfx)libc-abis.h
125 endif # avoid-generated
127 # Make sure the subdirectory for object files gets created.
128 ifdef objpfx
129 ifeq (,$(wildcard $(objpfx).))
130 before-compile += $(objpfx).
131 $(objpfx).:
132         $(make-target-directory)
133 endif
134 endif
136 # Remove existing files from `before-compile'.  Things are added there when
137 # they must exist for dependency generation to work right, but once they
138 # exist there is no further need for every single file to depend on them,
139 # and those gratuitous dependencies result in many gratuitous
140 # recompilations.
141 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
143 # Don't let any before-compile file be an intermediate and get removed.
144 ifdef before-compile
145 $(before-compile):
146 endif
148 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
149 # in subdirs.
150 ifdef subdir
151 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
152 else
153 common-before-compile = $(before-compile)
154 endif
156 ifndef subdir
157 # If a makefile needs to do something conditional on something that
158 # can only be figured out from headers, write a FOO.make.c input
159 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
160 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
162 # We only generate these in the top-level makefile, to avoid any weirdness
163 # from subdir-specific makefile tweaks creeping in on an update.
164 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
165         rm -f $@T $@.dT
166         (echo '# Generated from $*.make.c by Makerules.'; \
167          $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
168                -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
169          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
170          echo 'common-generated += $(@F)'; \
171          sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
172          rm -f $@.dT) > $@T
173         mv -f $@T $@
174 endif
176 ifdef subdir
177 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g' \
178                      -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
179 else
180 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g' \
181                      -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
182 endif
185 ifdef gen-as-const-headers
186 # Generating headers for assembly constants.
187 # We need this defined early to get into before-compile before
188 # it's used in sysd-rules, below.
189 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
190                                            %.sym $(common-before-compile)
191         $(AWK) -f $< $(filter %.sym,$^) \
192         | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
193                 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
194         sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
195                 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
196         rm -f $(@:.h.d=.h)T3
197         sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
198             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
199         rm -f $(@:.h=.h.d)T
200         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
201         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
202 vpath %.sym $(sysdirs)
203 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
205 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
206 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
207 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
208                             %.sym $(common-objpfx)%.h
209         ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
210          $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
211          echo '#include "$(..)test-skeleton.c"') > $@T
212         mv -f $@T $@
213 endif
215 # Generate an ordered list of implicit rules which find the source files in
216 # each sysdep directory.  The old method was to use vpath to search all the
217 # sysdep directories.  However, that had the problem that a .S file in a
218 # later directory would be chosen over a .c file in an earlier directory,
219 # which does not preserve the desired sysdeps ordering behavior.
221 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
222 # patterns matching sysdep directories whose assembly source files should
223 # be suppressed.
224 ifdef inhibit-sysdep-asm
225 define check-inhibit-asm
226 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) asm= ;; esac;
227 endef
228 endif
230 -include $(common-objpfx)sysd-rules
231 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
232 # The value of $(+sysdep_dirs) the sysd-rules was computed for
233 # differs from the one we are using now.  So force a rebuild of sysd-rules.
234 sysd-rules-force = FORCE
235 FORCE:
236 endif
237 $(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
238                             $(sysdep-makefiles) $(sysdep-makeconfigs) \
239                             $(sysd-rules-force)
240         -@rm -f $@T
241         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
242          for dir in $(config-sysdirs); do                                     \
243            case "$$dir" in                                                    \
244            /*) ;;                                                             \
245            *) dir="\$$(..)$$dir" ;;                                           \
246            esac;                                                              \
247            asm='.S .s';                                                       \
248            $(check-inhibit-asm)                                               \
249            for o in $(all-object-suffixes); do                                \
250              set $(subst :, ,$(sysd-rules-patterns));                         \
251              while [ $$# -ge 2 ]; do                                          \
252                t=$$1; shift;                                                  \
253                d=$$1; shift;                                                  \
254                v=$${t%%%}; [ x"$$v" = x ] || v="\$$($${v}CPPFLAGS)";          \
255                for s in $$asm .c; do                                          \
256                  echo "\$$(objpfx)$$t$$o: $$dir/$$d$$s \$$(before-compile)";  \
257                  echo " \$$(compile-command$$s) $$v";                         \
258                done;                                                          \
259              done;                                                            \
260            done;                                                              \
261            echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force)";            \
262            echo "       \$$(do-install)";                                     \
263          done;                                                                \
264          echo 'sysd-rules-done = t') > $@T
265         mv -f $@T $@
267 ifndef sysd-rules-done
268 # Don't do deps until this exists, because it provides rules to make the deps.
269 no_deps=t
270 endif
272 define o-iterator-doit
273 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
274 endef
275 object-suffixes-left := $(all-object-suffixes)
276 include $(o-iterator)
278 define o-iterator-doit
279 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
280 endef
281 object-suffixes-left := $(all-object-suffixes)
282 include $(o-iterator)
284 define o-iterator-doit
285 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
286 endef
287 object-suffixes-left := $(all-object-suffixes)
288 include $(o-iterator)
290 define o-iterator-doit
291 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
292 endef
293 object-suffixes-left := $(all-object-suffixes)
294 include $(o-iterator)
296 # Omit the objpfx rules when building in the source tree, because
297 # objpfx is empty and so these rules just override the ones above.
298 ifdef objpfx
299 # Define first rules to find the source files in $(objpfx).
300 # Generated source files will end up there.
301 define o-iterator-doit
302 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
303 endef
304 object-suffixes-left := $(all-object-suffixes)
305 include $(o-iterator)
307 define o-iterator-doit
308 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
309 endef
310 object-suffixes-left := $(all-object-suffixes)
311 include $(o-iterator)
313 define o-iterator-doit
314 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
315 endef
316 object-suffixes-left := $(all-object-suffixes)
317 include $(o-iterator)
318 endif
320 # Generate version maps, but wait until sysdep-subdirs is known
321 ifeq ($(sysd-sorted-done),t)
322 ifeq ($(versioning),yes)
323 -include $(common-objpfx)sysd-versions
324 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
325 common-generated += $(version-maps)
326 postclean-generated += sysd-versions Versions.all abi-versions.h \
327                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
329 ifndef avoid-generated
330 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
331 sysd-versions-force = FORCE
332 FORCE:
333 endif
334 # See %.v/%.v.i implicit rules in Makeconfig.
335 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
336                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
337 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
338                               $(common-objpfx)soversions.i \
339                               $(common-objpfx)Versions.def.v
340         { while read which lib version setname; do \
341             test x"$$which" = xDEFAULT || continue; \
342             test -z "$$setname" || echo "$$lib : $$setname"; \
343           done < $(word 2,$^); \
344           cat $(word 3,$^); \
345         } | LC_ALL=C $(AWK) -f $< > $@T
346         mv -f $@T $@
347 # See %.v/%.v.i implicit rules in Makeconfig.
348 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
349                               $(wildcard $(sysdirs:%=%/Versions)) \
350                               $(common-objpfx)abi-versions.h \
351                               $(sysd-versions-force)
352 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
353                                $(common-objpfx)Versions.v \
354                                $(..)scripts/versions.awk
355         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
356           cat $(word 2,$^) \
357           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
358                             -v move_if_change='$(move-if-change)' \
359                             -f $(word 3,$^); \
360         ) > $@T
361         mv -f $@T $@
362 endif # avoid-generated
363 endif # $(versioning) = yes
364 endif # sysd-sorted-done
366 # Generate .dT files as we compile.
367 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
368 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
369 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
370 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
371 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
373 # GCC can grok options after the file name, and it looks nicer that way.
374 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
375 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
376 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
377                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
378 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
379                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
380 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
382 # We need this for the output to go in the right place.  It will default to
383 # empty if make was configured to work with a cc that can't grok -c and -o
384 # together.  You can't compile the C library with such a compiler.
385 OUTPUT_OPTION = -o $@
387 # We need the $(CFLAGS) to be in there to have the right predefines during
388 # the dependency run for C sources.  But having it for assembly sources can
389 # get the wrong predefines.
390 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
392 define +make-deps
393 $(make-target-directory)
394 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
395              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
396 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
397 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
398 mv -f $(@:.d=.T) $@ $(generate-md5)
399 endef
401 ifneq (,$(objpfx))
402 # Continuation lines here are dangerous because they introduce spaces!
403 define sed-remove-objpfx
404 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
405 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
406 endef
407 endif
409 # Modify the list of routines we build for different targets
411 ifeq (yesyes,$(build-shared)$(elf))
412 ifndef libc.so-version
413 # Undefine this because it can't work when we libc.so is unversioned.
414 static-only-routines =
415 endif
416 endif
418 # Bounded pointer thunks are only built for *.ob
419 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
421 elide-routines.oS += $(filter-out $(static-only-routines),\
422                                   $(routines) $(aux) $(sysdep_routines)) \
423                      $(elide-bp-thunks)
424 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
426 # If we have versioned code we don't need the old versions in any of the
427 # static libraries.
428 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
429 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
430 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
431 elide-routines.ob += $(shared-only-routines)
433 # Shared library building.
435 ifeq (yes,$(build-shared))
437 # Reference map file only when versioning is selected and a map file name
438 # is given.
439 ifeq ($(versioning),yes)
440 map-file = $(firstword $($(@F:.so=-map)) \
441                        $(addprefix $(common-objpfx), \
442                                    $(filter $(@F:.so=.map),$(version-maps))))
443 load-map-file = $(map-file:%=-Wl,--version-script=%)
444 endif
446 # Pattern rule to build a shared object from an archive of PIC objects.
447 # This must come after the installation rules so Make doesn't try to
448 # build shared libraries in place from the installed *_pic.a files.
449 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
450 # on other shared objects.
451 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
452 ifneq (,$(findstring aix,$(config-os)))
453         (echo '#!'; \
454          dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
455 endif
456         $(build-shlib)
458 ifeq ($(elf),yes)
459 define build-shlib-helper
460 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
461           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
462           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
463           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
464           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
465           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
466           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
467 endef
468 else
469 ifneq (,$(findstring aix,$(config-os)))
470 define build-shlib-helper
471 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
472           $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
473           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
474           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
475           -L$(subst :, -L,$(rpath-link))
476 endef
477 else
478 endif
479 endif
481 ifeq (yes,$(elf))
482 ifeq (yes,$(use-default-link))
483 # If the linker is good enough, we can let it use its default linker script.
484 shlib-lds =
485 shlib-lds-flags =
486 else
487 # binutils only position loadable notes into the first page for binaries,
488 # not for shared objects
489 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
490         $(LINK.o) -shared -Wl,-O1 \
491                   -nostdlib -nostartfiles \
492                   $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
493                   -Wl,--verbose 2>&1 | \
494           sed > $@T \
495               -e '/^=========/,/^=========/!d;/^=========/d' \
496               $(if $(filter yes,$(have-hash-style)), \
497                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
498                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
499                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
500                 , \
501                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
502                ) \
503               -e 's/^.*\*(\.dynbss).*$$/& \
504                  PROVIDE(__start___libc_freeres_ptrs = .); \
505                  *(__libc_freeres_ptrs) \
506                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
507               -e 's@^.*\*(\.jcr).*$$@& \
508                  PROVIDE(__start___libc_subfreeres = .);\
509                  __libc_subfreeres : { *(__libc_subfreeres) }\
510                  PROVIDE(__stop___libc_subfreeres = .);\
511                  PROVIDE(__start___libc_atexit = .);\
512                  __libc_atexit : { *(__libc_atexit) }\
513                  PROVIDE(__stop___libc_atexit = .);\
514                  PROVIDE(__start___libc_thread_subfreeres = .);\
515                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
516                  PROVIDE(__stop___libc_thread_subfreeres = .);\
517                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
518         test -s $@T
519         mv -f $@T $@
520 common-generated += shlib.lds
522 shlib-lds = $(common-objpfx)shlib.lds
523 shlib-lds-flags = -T $(shlib-lds)
524 endif
526 define build-shlib
527 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
528           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
529 endef
530 else
531 ifneq (,$(findstring aix,$(config-os)))
532 define build-shlib
533 $(build-shlib-helper) \
534         -o $@ \
535         $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
536         $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
537 endef
538 define build-shlib
539 $(build-shlib-helper) \
540           $(build-shlib-objlist)
541 endef
542 endif
543 endif
545 ifneq (,$(findstring aix,$(config-os)))
546 define build-module-helper
547 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
548           $(sysdep-LDFLAGS) $(config-LDFLAGS) \
549           $(load-map-file) \
550           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
551           -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
552 endef
553 else
554 define build-module-helper
555 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
556           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
557           -B$(csu-objpfx) $(load-map-file) \
558           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
559           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
560 endef
561 endif
563 # This macro is similar to build-shlib but it does not define a soname
564 # and it does not depend on the destination name to start with `lib'.
565 ifeq (yes,$(elf))
566 # binutils only position loadable notes into the first page for binaries,
567 # not for shared objects
568 define build-module
569 $(build-module-helper) -o $@ $(shlib-lds-flags) \
570           $(csu-objpfx)abi-note.o $(build-module-objlist)
571 endef
572 define build-module-asneeded
573 $(build-module-helper) -o $@ $(shlib-lds-flags) \
574           $(csu-objpfx)abi-note.o \
575           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
576 endef
577 else
578 ifneq (,$(findstring aix,$(config-os)))
579 define build-module
580 $(build-module-helper) \
581           -o $@ \
582           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
583           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
584 endef
585 else
586 define build-module
587 define build-module
588 $(build-module-helper) \
589           -o $@ \
590           $(build-module-objlist)
591 endef
592 endif
593 endif
595 build-module-helper-objlist = \
596         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
597                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
598 whole-archive := -Wl,--whole-archive
600 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
601 build-shlib-objlist = $(build-module-helper-objlist) \
602                       $(LDLIBS-$(@F:lib%.so=%).so)
604 # Don't try to use -lc when making libc.so itself.
605 # Also omits crti.o and crtn.o, which we do not want
606 # since we define our own `.init' section specially.
607 LDFLAGS-c.so = -nostdlib -nostartfiles
608 # But we still want to link libc.so against $(libc.so-gnulib).
609 LDLIBS-c.so += $(libc.so-gnulib)
610 # Give libc.so an entry point and make it directly runnable itself.
611 LDFLAGS-c.so += -e __libc_main
612 # If lazy relocation is disabled add the -z now flag.
613 ifeq ($(bind-now),yes)
614 LDFLAGS-c.so += -Wl,-z,now
615 endif
616 # Pre-link the objects of libc_pic.a so that we can locally resolve
617 # COMMON symbols before we link against ld.so.  This is because ld.so
618 # contains some of libc_pic.a already, which will prevent the COMMONs
619 # from being allocated in libc.so, which introduces evil dependencies
620 # between libc.so and ld.so, which can make it impossible to upgrade.
621 ifeq ($(elf),yes)
622 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
623         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
624         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^ -o $@
626 ifeq (,$(strip $(shlib-lds-flags)))
627 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
628 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
629         $(OBJDUMP) -h $< | \
630         $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
631                 > $@T
632         mv -f $@T $@
633 # Apply those -R options.
634 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
635                                    $(common-objpfx)libc_pic.os
636         $(OBJCOPY) @$^ $@
637 generated += libc_pic.opts libc_pic.os.clean
639 libc_pic_clean := .clean
640 endif
642 # Use our own special initializer and finalizer files for libc.so.
643 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
644                          $(common-objpfx)libc_pic.os$(libc_pic_clean) \
645                          $(elfobjdir)/sofini.os \
646                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
647                          $(shlib-lds)
648         $(build-shlib)
649 ifeq ($(versioning),yes)
650 $(common-objpfx)libc.so: $(common-objpfx)libc.map
651 endif
652 common-generated += libc.so libc_pic.os
653 ifdef libc.so-version
654 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
655         $(make-link)
656 common-generated += libc.so$(libc.so-version)
657 endif
658 endif
659 else
660 ifneq (,$(findstring aix,$(config-os)))
661 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
662         @rm -f $@
663         (echo '#!'; \
664          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
665         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
666             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
667         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
668                   -bE:$(common-objpfx)syscalls.exp \
669                   -bI:$(common-objpfx)syscalls.exp \
670                   -L$(common-objpfx) -o $@ $^
671 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
672         cp $@ $(common-objpfx)shr.o
673         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
674 endif
675 endif
677 # Figure out the source filenames in this directory.
679 override sources := $(addsuffix .c,\
680                         $(filter-out $(elided-routines),\
681                             $(routines) $(aux) \
682                             $(sysdep_routines)))
683 sysdep_routines := $(sysdep_routines)
685 headers := $(headers) $(sysdep_headers)
687 # This is the list of all object files, gotten by
688 # replacing every ".c" in `sources' with a ".o".
689 # We also add bounded-pointer thunks, which are later
690 # elided for all suffixes except for `.ob'.
691 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
692                       $(patsubst %,$(bppfx)%.o,\
693                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
696 # The makefile may define $(extra-libs) with `libfoo libbar'
697 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
698 ifdef extra-libs
699 # extra-lib.mk is included once for each extra lib to define rules
700 # to build it, and to add its objects to the various variables.
701 # During its evaluation, $(lib) is set to the name of the library.
702 extra-libs-left := $(extra-libs)
703 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
704 endif
707 # The makefile may define $(modules-names) to build additional modules.
708 # These are built with $(build-module), except any in $(modules-names-nobuild).
709 ifdef modules-names
710 # extra-lib.mk is included once for each extra lib to define rules
711 # to build it, and to add its objects to the various variables.
712 # During its evaluation, $(lib) is set to the name of the library.
713 extra-modules-left := $(modules-names)
714 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
716 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
717 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
718                 $(objpfx)%.os $(shlib-lds) \
719                 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
720         $(build-module)
721 endif
723 +depfiles := $(sources:.c=.d) \
724              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
725              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
726              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
727 ifeq ($(build-programs),yes)
728 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
729 endif
730 +depfiles := $(addprefix $(objpfx),\
731                          $(filter-out $(addsuffix .d,$(omit-deps)),\
732                                       $(+depfiles)))
733 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
734 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
735              $(wildcard $(all-dt-files:.dt=.d))
737 # This is a funny rule in that it removes its input file.
738 %.d: %.dt
739         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
740          mv -f $(@:.d=.T) $@ && \
741          rm -f $<
743 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
744 # They will be generated when they're needed, and trying too early won't work.
745 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
746 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
747                                                 $(+gen-as-const)))
749 ifdef +depfiles
750 ifneq ($(no_deps),t)
751 -include $(+depfiles)
752 endif
753 endif
754 \f\f
755 # Maximize efficiency by minimizing the number of rules.
756 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
757 # Don't define any builtin rules.
758 MAKEFLAGS := $(MAKEFLAGS)r
760 # Generic rule for making directories.
762 # mkdir isn't smart enough to strip a trailing /.
763 # We always require a mkdir which supports the -p option to avoid error
764 # messages in case of races.
765         mkdir -p $(@:%/=%)
767 # Make sure that object files are not removed
768 # when they are intermediates between sources and library members.
769 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
771 # Make sure that the parent library archive is never removed.
772 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
774 # Use the verbose option of ar and tar when not running silently.
775 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
776 verbose := v
777 else                                            # -s
778 verbose :=
779 endif                                           # not -s
781 ARFLAGS := r$(verbose)
782 CREATE_ARFLAGS := cru$(verbose)
784 # This makes all the object files in the parent library archive.
786 .PHONY: lib lib-noranlib
787 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
788 lib-noranlib: libobjs
790 # For object-suffix $o, the list of objects with that suffix.
791 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
792 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
793                                                        $(elide-routines$o)),\
794                                             $(objects))) \
795             $(addprefix $(objpfx),$(o-objects$o))
797 others: $(addprefix $(objpfx),$(install-lib))
799 ifndef objects
801 # Create the stamp$o files to keep the parent makefile happy.
802 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
803 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
804         $(make-target-directory)
805         rm -f $@; > $@
806 else
808 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
809 # timestamp file; these rules (one explicit rule is generated for each
810 # object suffix) write a list of objects to update in the stamp file.
811 # The parent will then actually add them all to the archive in the
812 # archive rule, below.
813 define o-iterator-doit
814 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
815 endef
816 define do-stamp
817 $(make-target-directory)
818 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
819 mv -f $@T $@
820 endef
821 object-suffixes-left := $(object-suffixes-for-libc)
822 include $(o-iterator)
824 endif
826 # Now define explicit rules to build the library archives; these depend
827 # on the stamp files built above.
828 define o-iterator-doit
829 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
830                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
831 endef
832 define do-makelib
833 cd $(common-objdir) && \
834 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
835 endef
836 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
837 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
838 ifndef subdir
839 $(subdirs-stamps): subdir_lib;
840 endif
841 object-suffixes-left = $(object-suffixes-for-libc)
842 include $(o-iterator)
845 # This makes all the object files.
846 .PHONY: objects objs libobjs extra-objs
847 objects objs: libobjs extra-objs
848 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
849 extra-objs: $(addprefix $(objpfx),$(extra-objs))
851 # Canned sequence for building an extra library archive.
852 define build-extra-lib
853 $(patsubst %/,cd % &&,$(objpfx)) \
854 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
855       $(patsubst $(objpfx)%,%,$^)
856 endef
858 # Installation.
860 .PHONY: force-install
861 force-install:
863 # $(install-lib) are installed from the object directory into $(libdir);
864 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
865 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
866 # they are into $(datadir).  $(headers) are installed as they are in
867 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
868 # are installed from the object directory into $(bindir), $(bindir) and
869 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
870 # are absolute path names of files to install; rules to install them are
871 # defined elsewhere.
873 # The simple library name to install libc.a under.
874 # This could be defined by a sysdep Makefile.
875 ifndef libc-name
876 libc-name := c
877 endif
879 define do-install
880 $(make-target-directory)
881 $(INSTALL_DATA) $< $@
882 endef
884 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
885 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
886 define make-target-directory
887 $(addprefix $(..)./scripts/mkinstalldirs ,\
888             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
889 endef
891 # Any directory (parent or subdir) should install libc.a; this way
892 # "make install" in a subdir is guaranteed to install everything it changes.
893 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
894                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
895                                                      $(libprefix)$(libc-name)))
896 install: $(installed-libcs)
897 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
898         $(make-target-directory)
899         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
901 define do-install-program
902 $(make-target-directory)
903 $(INSTALL_PROGRAM) $< $@.new
904 mv -f $@.new $@
905 endef
907 define do-install-script
908 $(make-target-directory)
909 $(INSTALL_SCRIPT) $< $@.new
910 mv -f $@.new $@
911 endef
913 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
914 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
916 ifeq (yes,$(build-shared))
917 # Find which .so's have versions.
918 versioned := $(strip $(foreach so,$(install-lib.so),\
919                                $(patsubst %,$(so),$($(so)-version))))
921 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
922 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
924 # For versioned libraries, we install three files:
925 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
926 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
927 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
928 V := $(firstword $($(subdir)-version) $(version))
929 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
930                       $(foreach L,$(install-lib.so-versioned),\
931                                 $(inst_libdir)/$L \
932                                 $(inst_slibdir)/$(L:.so=)-$V.so \
933                                 $(inst_slibdir)/$L$($L-version))
935 # Install all the unversioned shared libraries.
936 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
937     $(objpfx)%.so $(+force)
938         $(do-install-program)
940 ifneq ($(findstring -s,$(LN_S)),)
941 define make-link
942 rm -f $@.new
943 $(SHELL) $(..)scripts/rellns-sh $< $@.new
944 mv -f $@.new $@
945 endef
946 else
947 # If we have no symbolic links don't bother with rellns-sh.
948 define make-link
949 rm -f $@.new
950 $(LN_S) $< $@.new
951 mv -f $@.new $@
952 endef
953 endif
955 ifeq (yes,$(build-shared))
956 ifeq (no,$(cross-compiling))
957 symbolic-link-prog := $(common-objpfx)elf/sln
958 symbolic-link-list := $(common-objpfx)elf/symlink.list
959 define make-shlib-link
960 echo $(<F) $@ >> $(symbolic-link-list)
961 endef
962 else # cross-compiling
963 # We need a definition that can be used by elf/Makefile's install rules.
964 symbolic-link-prog = $(LN_S)
965 endif
966 endif
967 ifndef make-shlib-link
968 define make-shlib-link
969 rm -f $@
970 $(LN_S) $(<F) $@
971 endef
972 endif
974 ifdef libc.so-version
975 # For a library specified to be version N, install three files:
976 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
977 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
979 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
980                                            $(+force)
981         $(make-shlib-link)
982 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
983         $(do-install-program)
984 install: $(inst_slibdir)/libc.so$(libc.so-version)
986 # This fragment of linker script gives the OUTPUT_FORMAT statement
987 # for the configuration we are building.  We put this statement into
988 # the linker scripts we install for -lc et al so that they will not be
989 # used by a link for a different format on a multi-architecture system.
990 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
991                             $(common-objpfx)config.make \
992                             $(common-objpfx)config.h $(..)Makerules
993 ifneq (unknown,$(output-format))
994         echo > $@.new 'OUTPUT_FORMAT($(output-format))'
995 else
996         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
997                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
998         | sed -n -f $< > $@.new
999         test -s $@.new
1000         rm -f $@.so
1001 endif
1002         mv -f $@.new $@
1003 common-generated += format.lds
1005 ifndef subdir
1006 # What we install as libc.so for programs to link against is in fact a
1007 # link script.  It contains references for the various libraries we need.
1008 # The libc.so object is not complete since some functions are only defined
1009 # in libc_nonshared.a.
1010 # We need to use absolute paths since otherwise local copies (if they exist)
1011 # of the files are taken by the linker.
1012 install: $(inst_libdir)/libc.so
1013 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1014                         $(common-objpfx)libc.so$(libc.so-version) \
1015                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1016                                                   $(libprefix)$(libc-name)) \
1017                         $(+force)
1018         (echo '/* GNU ld script';\
1019          echo '   Use the shared library, but some functions are only in';\
1020          echo '   the static library, so try that secondarily.  */';\
1021          cat $<; \
1022          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1023               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1024               ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1025         ) > $@.new
1026         mv -f $@.new $@
1028 endif
1030 else
1031 install: $(inst_slibdir)/libc.so
1032 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1033         $(do-install-program)
1034 endif
1036 ifneq (,$(versioned))
1037 # Produce three sets of rules as above for all the smaller versioned libraries.
1039 define o-iterator-doit
1040 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1041 endef
1042 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1043 ifneq (,$(object-suffixes-left))
1044 include $(o-iterator)
1045 endif
1047 # Make symlinks in the build directory, because the versioned names might
1048 # be referenced by a DT_NEEDED in another library.
1049 define o-iterator-doit
1050 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1051 endef
1052 object-suffixes-left := $(versioned)
1053 include $(o-iterator)
1055 generated += $(foreach o,$(versioned),$o$($o-version))
1057 ifeq (,$($(subdir)-version))
1058 define o-iterator-doit
1059 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1060                                  $(+force);
1061         $$(make-shlib-link)
1062 endef
1063 object-suffixes-left := $(versioned)
1064 include $(o-iterator)
1066 define o-iterator-doit
1067 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1068         $$(do-install-program)
1069 endef
1070 object-suffixes-left := $(versioned)
1071 include $(o-iterator)
1072 else
1073 define o-iterator-doit
1074 $(inst_slibdir)/$o$($o-version): \
1075   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1076         $$(make-shlib-link)
1077 endef
1078 object-suffixes-left := $(versioned)
1079 include $(o-iterator)
1081 define o-iterator-doit
1082 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1083         $$(do-install-program)
1084 endef
1085 object-suffixes-left := $(versioned)
1086 include $(o-iterator)
1087 endif
1088 endif
1090 define do-install-so
1091 $(do-install-program)
1092 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1093            $(filter-out %.so,$@))
1094 endef
1096 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1097 $(foreach v,$(so-versions),\
1098           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1099                                                $(+force)
1100         $(do-install-so)
1101 $(foreach v,$(so-versions),\
1102           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1103         $(do-install-so)
1104 endif
1106 ifdef install-bin
1107 $(addprefix $(inst_bindir)/,$(install-bin)): \
1108     $(inst_bindir)/%: $(objpfx)% $(+force)
1109         $(do-install-program)
1110 endif
1111 ifdef install-bin-script
1112 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1113     $(inst_bindir)/%: $(objpfx)% $(+force)
1114         $(do-install-script)
1115 endif
1116 ifdef install-rootsbin
1117 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1118    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1119         $(do-install-program)
1120 endif
1121 ifdef install-sbin
1122 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1123     $(inst_sbindir)/%: $(objpfx)% $(+force)
1124         $(do-install-program)
1125 endif
1126 ifdef install-lib
1127 install-lib.a := $(filter lib%.a,$(install-lib))
1128 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1129 ifdef install-lib-non.a
1130 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1131   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1132         $(do-install)
1133 endif
1134 ifdef install-lib.a
1135 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1136   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1137         $(do-install)
1138 endif
1139 endif
1140 ifdef install-data
1141 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1142         $(do-install)
1143 endif
1144 headers := $(strip $(headers))
1145 ifdef headers
1146 # This implicit rule installs headers from the source directory.
1147 # It may be ignored in preference to rules from sysd-rules to find
1148 # headers in the sysdeps tree.
1149 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1150         $(do-install)
1151 $(inst_includedir)/%.h: %.h $(+force)
1152         $(do-install)
1153 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1154         $(do-install)
1155 headers-nonh := $(filter-out %.h,$(headers))
1156 ifdef headers-nonh
1157 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1158                                                  % $(+force)
1159         $(do-install)
1160 endif   # headers-nonh
1161 endif   # headers
1163 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1164         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1165         install-data-nosubdir install-headers-nosubdir
1166 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1167 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1168 install-rootsbin-nosubdir: \
1169         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1170 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1171 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1172                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1173                        $(addprefix $(libprefix),$(install-lib-non.a)))
1174 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1175 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1176 install-others-nosubdir: $(install-others)
1177 install-others-programs-nosubdir: $(install-others-programs)
1179 # We need all the `-nosubdir' targets so that `install' in the parent
1180 # doesn't depend on several things which each iterate over the subdirs.
1181 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1182 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1183 install-%:: install-%-nosubdir ;
1185 .PHONY: install install-no-libc.a-nosubdir
1186 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1187                             install-lib-nosubdir install-others-nosubdir
1188 ifeq ($(build-programs),yes)
1189 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1190                             install-rootsbin-nosubdir install-sbin-nosubdir \
1191                             install-others-programs-nosubdir
1192 endif
1193 install: install-no-libc.a-nosubdir
1195 # Command to compile $< in $(objdir) using the native libraries.
1196 define native-compile
1197 $(make-target-directory)
1198 $(patsubst %/,cd % &&,$(objpfx)) \
1199 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1200             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1201 endef
1203 # Command to compile $< in $(common-objdir) using the native libraries.
1204 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1205 define common-objdir-compile
1206 $(patsubst %/,cd % &&,$(objpfx)) \
1207 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1208             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1209 endef
1211 # We always want to use configuration definitions.
1212 # Note that this is only used for commands running in $(objpfx).
1213 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1215 # Support the GNU standard name for this target.
1216 .PHONY: check
1217 check: tests
1218 # Special target to run tests which cannot be run unconditionally.
1219 # Maintainers should use this target.
1220 .PHONY: xcheck
1221 xcheck: xtests
1223 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1224 ifneq (,$(all-nonlib))
1225 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1226 lib := nonlib
1227 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1228 endif
1230 # The include magic above causes those files to use this variable for flags.
1231 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1234 ifeq ($(versioning),yes)
1235 # Generate normalized lists of symbols, versions, and data sizes.
1236 # This is handy for checking against existing library binaries.
1238 %.symlist: $(..)scripts/abilist.awk %.dynsym
1239         LC_ALL=C $(AWK) -f $^ > $@T
1240         mv -f $@T $@
1242 %.dynsym: %.so
1243         $(OBJDUMP) --dynamic-syms $< > $@T
1244         mv -f $@T $@
1246 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1247              $(..)abilist/%.abilist $(objpfx)%.symlist
1248         $(check-abi)
1249 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1250              $(..)abilist/%.abilist $(common-objpfx)%.symlist
1251         $(check-abi)
1252 define check-abi
1253         LC_ALL=C \
1254         $(AWK) -f $< -v 'config=$(check-abi-config)' \
1255                $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1256                $(filter %.abilist,$^) \
1257         | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1258 endef
1259 ifeq ($(enable-check-abi),warn)
1260 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1261 endif
1263 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1264 -include $(common-objpfx)tls.make
1265 config-tls := tls
1266 ifeq ($(use-thread),yes)
1267 config-tls := thread
1268 endif
1269 check-abi-config := \
1270   $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1271 endif
1273 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1274               $(objpfx)%.symlist
1275         $(update-abi)
1276 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1277               $(common-objpfx)%.symlist
1278         $(update-abi)
1279 ifndef update-abi-config
1280 define update-abi
1281         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1282 endef
1283 else
1284 define update-abi
1285 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1286          > $(..)abilist/$*.abilist.new
1287 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1288  then rm -f $(..)abilist/$*.abilist.new; \
1289       echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1290  else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1291       echo '*** Now check $*.abilist changes for correctness ***'; \
1292  fi
1293 endef
1294 endif
1296 .PHONY: update-abi check-abi
1297 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1298 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1299 ifdef subdir
1300 subdir_check-abi: check-abi
1301 subdir_update-abi: update-abi
1302 else
1303 check-abi: subdir_check-abi
1304 update-abi: subdir_update-abi
1305 endif
1307 ifeq ($(subdir),elf)
1308 check-abi: check-abi-libc
1309 update-abi: update-abi-libc
1310 common-generated += libc.symlist
1311 endif
1313 ifeq ($(build-shared),yes)
1314 ifneq ($(enable-check-abi),no)
1315 ifdef subdir
1316 tests: check-abi
1317 endif
1318 endif
1319 endif
1321 endif
1323 # These will have been set by sysdeps/posix/Makefile.
1324 L_tmpnam  ?= 1
1325 TMP_MAX   ?= 0
1326 L_ctermid ?= 1
1327 L_cuserid ?= 1
1329 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1331 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1332 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1333                    $(common-objpfx)config.make
1334         $(make-target-directory)
1335         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1336           echo '#define _LIBC 1';                                       \
1337           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1338         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1339               $(+includes) -xc - -o $(@:st=hT)
1340         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1341             $(@:st=dT) > $(@:st=dt)
1342         mv -f $(@:st=dt) $(@:st=d)
1343         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1344         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1345         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1346         fopen_max=$${fopen_max:-16};                                    \
1347         filename_max=$${filename_max:-1024};                            \
1348         if [ -z "$$iov_max" ]; then                                     \
1349           define_iov_max="# undef IOV_MAX";                             \
1350         else                                                            \
1351           define_iov_max="# define IOV_MAX $$iov_max";                  \
1352         fi;                                                             \
1353         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1354             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1355             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1356             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1357             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1358             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1359             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1360             $< > $(@:st=h.new)
1361         $(move-if-change) $(@:st=h.new) $(@:st=h)
1362 # Remove these last so that they can be examined if something went wrong.
1363         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1364         touch $@
1365 # Get dependencies.
1366 ifndef no_deps
1367 -include $(stdio_lim:h=d)
1368 endif
1369 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1371 FORCE:
1373 .PHONY: echo-headers
1374 echo-headers:
1375         @echo $(headers)
1377 %.bz2: %; bzip2 -9vk $<
1378 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1379 %.xz: %; xz -9evk $<
1381 # Common cleaning targets.
1383 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1384 clean: common-clean
1385 mostlyclean: common-mostlyclean
1387 do-tests-clean:
1388         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1389                                                       $(test-srcs)) \
1390                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1391                                                          $(test-srcs)))
1393 # Remove the object files.
1394 common-mostlyclean:
1395         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1396                                      $(others) $(sysdep-others) stubs \
1397                                      $(addsuffix .o,$(tests) $(xtests) \
1398                                                     $(test-srcs) $(others) \
1399                                                     $(sysdep-others)) \
1400                                      $(addsuffix -bp,$(tests) $(xtests) \
1401                                                      $(test-srcs)) \
1402                                      $(addsuffix .out,$(tests) $(xtests) \
1403                                                       $(test-srcs)) \
1404                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1405                                                          $(test-srcs)))
1406         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1407                                      $(install-lib) $(install-lib.so) \
1408                                      $(install-lib.so:%.so=%_pic.a))
1409         -rm -f core
1410         -rm -f $(objpfx)rtld-*.os
1411         $(rmobjs)
1412 define rmobjs
1413 $(foreach o,$(object-suffixes-for-libc),
1414 -rm -f $(objpfx)stamp$o $(o-objects))
1415 endef
1417 # Also remove the dependencies and generated source files.
1418 common-clean: common-mostlyclean
1419         -rm -f $(addprefix $(objpfx),$(generated))
1420         -rm -f $(objpfx)*.d $(objpfx)*.dt
1421         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1422         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1424 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1425 # for each function which is a stub.  We grovel over all the .d files
1426 # looking for references to <stub-tag.h>.  Then we grovel over each
1427 # referenced source file to see what stub function it defines.
1429 ifdef objpfx
1430 .PHONY: stubs # The parent Makefile calls this target.
1431 stubs: $(objpfx)stubs
1432 endif
1433 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1434                   $(addprefix $(objpfx),$(extra-objs))
1435 $(objpfx)stubs: $(objs-for-stubs)
1436 ifneq (,$(strip $(objs-for-stubs)))
1437         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1438         $(AWK) '/\.gnu\.glibc-stub\./ { \
1439                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1440                   stubs[$$2] = 1; } \
1441                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1442         mv -f $@T $@
1443 else
1444         > $@
1445 endif
1447 ifneq (,$(strip $(gpl2lgpl)))
1448 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1449 # Snarf from the master source and frob the copying notice.
1450 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1451         sed -f $^ > $@-tmp
1452 # So I don't edit them by mistake.
1453         chmod a-w $@-tmp
1454         mv -f $@-tmp $@
1455 ifeq ($(with-cvs),yes)
1456         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1457 endif
1458 endif
1459 endif
1461 # Local Variables:
1462 # mode: makefile
1463 # End: