Quash implicit declaration warning
[platform/upstream/glibc.git] / Makerules
1 # Copyright (C) 1991-2010, 2011 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
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.
8
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.
13
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.
18
19 #
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).
23 #
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
27
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
30
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
35
36
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
40
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
46
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
54 \f
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
58
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))
64 \f
65 # Include any system-specific makefiles.
66
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) $(..)))
72
73 # The same is true for RPC source files.
74 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
75                                       $(+sysdep_dirs) $(..)))
76
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
80
81 sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
82 ifneq (,$(sysdep-makefiles))
83 include $(sysdep-makefiles)
84 endif
85
86
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))
95
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 $@
104
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
111
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
126
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
135
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))
142
143 # Don't let any before-compile file be an intermediate and get removed.
144 ifdef before-compile
145 $(before-compile):
146 endif
147
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
155
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.
161 #
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
175
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
183
184
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)
204
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
214 \f
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.
220
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
229
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 $@
266
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
271
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)
277
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)
283
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)
289
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)
295
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)
306
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)
312
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
319
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
328
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
365
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)
372
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)
381
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 $@
386
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)
391
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
400
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
408 \f
409 # Modify the list of routines we build for different targets
410
411 ifeq (yes,$(build-shared))
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
417
418 # Bounded pointer thunks are only built for *.ob
419 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
420
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)
425
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)
432 \f
433 # Shared library building.
434
435 ifeq (yes,$(build-shared))
436
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
445
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         $(build-shlib)
453
454 define build-shlib-helper
455 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
456           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
457           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
458           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
459           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
460           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
461           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
462 endef
463
464 ifeq (yes,$(use-default-link))
465 # If the linker is good enough, we can let it use its default linker script.
466 shlib-lds =
467 shlib-lds-flags =
468 else
469 # binutils only position loadable notes into the first page for binaries,
470 # not for shared objects
471 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
472         $(LINK.o) -shared -Wl,-O1 \
473                   -nostdlib -nostartfiles \
474                   $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
475                   -Wl,--verbose 2>&1 | \
476           sed > $@T \
477               -e '/^=========/,/^=========/!d;/^=========/d' \
478               $(if $(filter yes,$(have-hash-style)), \
479                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
480                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
481                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
482                 , \
483                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
484                ) \
485               -e 's/^.*\*(\.dynbss).*$$/& \
486                  PROVIDE(__start___libc_freeres_ptrs = .); \
487                  *(__libc_freeres_ptrs) \
488                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
489               -e 's@^.*\*(\.jcr).*$$@& \
490                  PROVIDE(__start___libc_subfreeres = .);\
491                  __libc_subfreeres : { *(__libc_subfreeres) }\
492                  PROVIDE(__stop___libc_subfreeres = .);\
493                  PROVIDE(__start___libc_atexit = .);\
494                  __libc_atexit : { *(__libc_atexit) }\
495                  PROVIDE(__stop___libc_atexit = .);\
496                  PROVIDE(__start___libc_thread_subfreeres = .);\
497                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
498                  PROVIDE(__stop___libc_thread_subfreeres = .);\
499                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
500         test -s $@T
501         mv -f $@T $@
502 common-generated += shlib.lds
503
504 shlib-lds = $(common-objpfx)shlib.lds
505 shlib-lds-flags = -T $(shlib-lds)
506 endif
507
508 define build-shlib
509 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
510           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
511 endef
512
513 define build-module-helper
514 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
515           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
516           -B$(csu-objpfx) $(load-map-file) \
517           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
518           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
519 endef
520
521 # This macro is similar to build-shlib but it does not define a soname
522 # and it does not depend on the destination name to start with `lib'.
523 # binutils only position loadable notes into the first page for binaries,
524 # not for shared objects
525 define build-module
526 $(build-module-helper) -o $@ $(shlib-lds-flags) \
527           $(csu-objpfx)abi-note.o $(build-module-objlist)
528 endef
529 define build-module-asneeded
530 $(build-module-helper) -o $@ $(shlib-lds-flags) \
531           $(csu-objpfx)abi-note.o \
532           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
533 endef
534
535 build-module-helper-objlist = \
536         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
537                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
538
539 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
540 build-shlib-objlist = $(build-module-helper-objlist) \
541                       $(LDLIBS-$(@F:lib%.so=%).so)
542
543 # Don't try to use -lc when making libc.so itself.
544 # Also omits crti.o and crtn.o, which we do not want
545 # since we define our own `.init' section specially.
546 LDFLAGS-c.so = -nostdlib -nostartfiles
547 # But we still want to link libc.so against $(libc.so-gnulib).
548 LDLIBS-c.so += $(libc.so-gnulib)
549 # Give libc.so an entry point and make it directly runnable itself.
550 LDFLAGS-c.so += -e __libc_main
551 # If lazy relocation is disabled add the -z now flag.
552 ifeq ($(bind-now),yes)
553 LDFLAGS-c.so += -Wl,-z,now
554 endif
555 # Pre-link the objects of libc_pic.a so that we can locally resolve
556 # COMMON symbols before we link against ld.so.  This is because ld.so
557 # contains some of libc_pic.a already, which will prevent the COMMONs
558 # from being allocated in libc.so, which introduces evil dependencies
559 # between libc.so and ld.so, which can make it impossible to upgrade.
560 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
561         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
562         $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
563
564 ifeq (,$(strip $(shlib-lds-flags)))
565 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
566 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
567         $(OBJDUMP) -h $< | \
568         $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
569                 > $@T
570         mv -f $@T $@
571 # Apply those -R options.
572 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
573                                    $(common-objpfx)libc_pic.os
574         $(OBJCOPY) @$^ $@
575 generated += libc_pic.opts libc_pic.os.clean
576
577 libc_pic_clean := .clean
578 endif
579
580 # Use our own special initializer and finalizer files for libc.so.
581 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
582                          $(common-objpfx)libc_pic.os$(libc_pic_clean) \
583                          $(elfobjdir)/sofini.os \
584                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
585                          $(shlib-lds)
586         $(build-shlib)
587 ifeq ($(versioning),yes)
588 $(common-objpfx)libc.so: $(common-objpfx)libc.map
589 endif
590 common-generated += libc.so libc_pic.os
591 ifdef libc.so-version
592 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
593         $(make-link)
594 common-generated += libc.so$(libc.so-version)
595 endif
596 endif
597 \f
598 # Figure out the source filenames in this directory.
599
600 override sources := $(addsuffix .c,\
601                         $(filter-out $(elided-routines),\
602                             $(routines) $(aux) \
603                             $(sysdep_routines)))
604 sysdep_routines := $(sysdep_routines)
605
606 headers := $(headers) $(sysdep_headers)
607
608 # This is the list of all object files, gotten by
609 # replacing every ".c" in `sources' with a ".o".
610 # We also add bounded-pointer thunks, which are later
611 # elided for all suffixes except for `.ob'.
612 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
613                       $(patsubst %,$(bppfx)%.o,\
614                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
615
616
617 # The makefile may define $(extra-libs) with `libfoo libbar'
618 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
619 ifdef extra-libs
620 # extra-lib.mk is included once for each extra lib to define rules
621 # to build it, and to add its objects to the various variables.
622 # During its evaluation, $(lib) is set to the name of the library.
623 extra-libs-left := $(extra-libs)
624 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
625 endif
626
627
628 # The makefile may define $(modules-names) to build additional modules.
629 # These are built with $(build-module), except any in $(modules-names-nobuild).
630 ifdef modules-names
631 # extra-lib.mk is included once for each extra lib to define rules
632 # to build it, and to add its objects to the various variables.
633 # During its evaluation, $(lib) is set to the name of the library.
634 extra-modules-left := $(modules-names)
635 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
636
637 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
638 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
639                 $(objpfx)%.os $(shlib-lds) \
640                 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
641         $(build-module)
642 endif
643 \f
644 +depfiles := $(sources:.c=.d) \
645              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
646              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
647              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
648 ifeq ($(build-programs),yes)
649 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
650 endif
651 +depfiles := $(addprefix $(objpfx),\
652                          $(filter-out $(addsuffix .d,$(omit-deps)),\
653                                       $(+depfiles)))
654 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
655 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
656              $(wildcard $(all-dt-files:.dt=.d))
657
658 # This is a funny rule in that it removes its input file.
659 %.d: %.dt
660         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
661          mv -f $(@:.d=.T) $@ && \
662          rm -f $<
663
664 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
665 # They will be generated when they're needed, and trying too early won't work.
666 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
667 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
668                                                 $(+gen-as-const)))
669
670 ifdef +depfiles
671 ifneq ($(no_deps),t)
672 -include $(+depfiles)
673 endif
674 endif
675 \f\f
676 # Maximize efficiency by minimizing the number of rules.
677 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
678 # Don't define any builtin rules.
679 MAKEFLAGS := $(MAKEFLAGS)r
680
681 # Generic rule for making directories.
682 %/:
683 # mkdir isn't smart enough to strip a trailing /.
684 # We always require a mkdir which supports the -p option to avoid error
685 # messages in case of races.
686         mkdir -p $(@:%/=%)
687 \f
688 # Make sure that object files are not removed
689 # when they are intermediates between sources and library members.
690 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
691
692 # Make sure that the parent library archive is never removed.
693 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
694 \f
695 # Use the verbose option of ar and tar when not running silently.
696 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
697 verbose := v
698 else                                            # -s
699 verbose :=
700 endif                                           # not -s
701
702 ARFLAGS := r$(verbose)
703 CREATE_ARFLAGS := cru$(verbose)
704 \f
705 # This makes all the object files in the parent library archive.
706
707 .PHONY: lib lib-noranlib
708 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
709 lib-noranlib: libobjs
710
711 # For object-suffix $o, the list of objects with that suffix.
712 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
713 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
714                                                        $(elide-routines$o)),\
715                                             $(objects))) \
716             $(addprefix $(objpfx),$(o-objects$o))
717
718 others: $(addprefix $(objpfx),$(install-lib))
719
720 ifndef objects
721
722 # Create the stamp$o files to keep the parent makefile happy.
723 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
724 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
725         $(make-target-directory)
726         rm -f $@; > $@
727 else
728
729 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
730 # timestamp file; these rules (one explicit rule is generated for each
731 # object suffix) write a list of objects to update in the stamp file.
732 # The parent will then actually add them all to the archive in the
733 # archive rule, below.
734 define o-iterator-doit
735 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
736 endef
737 define do-stamp
738 $(make-target-directory)
739 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
740 mv -f $@T $@
741 endef
742 object-suffixes-left := $(object-suffixes-for-libc)
743 include $(o-iterator)
744
745 endif
746
747 # Now define explicit rules to build the library archives; these depend
748 # on the stamp files built above.
749 define o-iterator-doit
750 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
751                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
752 endef
753 define do-makelib
754 cd $(common-objdir) && \
755 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
756 endef
757 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
758 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
759 ifndef subdir
760 $(subdirs-stamps): subdir_lib;
761 endif
762 object-suffixes-left = $(object-suffixes-for-libc)
763 include $(o-iterator)
764
765
766 # This makes all the object files.
767 .PHONY: objects objs libobjs extra-objs
768 objects objs: libobjs extra-objs
769 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
770 extra-objs: $(addprefix $(objpfx),$(extra-objs))
771
772 # Canned sequence for building an extra library archive.
773 define build-extra-lib
774 $(patsubst %/,cd % &&,$(objpfx)) \
775 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
776       $(patsubst $(objpfx)%,%,$^)
777 endef
778 \f
779 # Installation.
780
781 .PHONY: force-install
782 force-install:
783
784 # $(install-lib) are installed from the object directory into $(libdir);
785 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
786 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
787 # they are into $(datadir).  $(headers) are installed as they are in
788 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
789 # are installed from the object directory into $(bindir), $(bindir) and
790 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
791 # are absolute path names of files to install; rules to install them are
792 # defined elsewhere.
793
794 # The simple library name to install libc.a under.
795 # This could be defined by a sysdep Makefile.
796 ifndef libc-name
797 libc-name := c
798 endif
799
800 define do-install
801 $(make-target-directory)
802 $(INSTALL_DATA) $< $@
803 endef
804
805 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
806 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
807 define make-target-directory
808 $(addprefix $(..)./scripts/mkinstalldirs ,\
809             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
810 endef
811
812 # Any directory (parent or subdir) should install libc.a; this way
813 # "make install" in a subdir is guaranteed to install everything it changes.
814 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
815                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
816                                                      $(libprefix)$(libc-name)))
817 install: $(installed-libcs)
818 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
819         $(make-target-directory)
820         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
821
822 define do-install-program
823 $(make-target-directory)
824 $(INSTALL_PROGRAM) $< $@.new
825 mv -f $@.new $@
826 endef
827
828 define do-install-script
829 $(make-target-directory)
830 $(INSTALL_SCRIPT) $< $@.new
831 mv -f $@.new $@
832 endef
833
834 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
835 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
836
837 ifeq (yes,$(build-shared))
838 # Find which .so's have versions.
839 versioned := $(strip $(foreach so,$(install-lib.so),\
840                                $(patsubst %,$(so),$($(so)-version))))
841
842 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
843 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
844
845 # For versioned libraries, we install three files:
846 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
847 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
848 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
849 V := $(firstword $($(subdir)-version) $(version))
850 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
851                       $(foreach L,$(install-lib.so-versioned),\
852                                 $(inst_libdir)/$L \
853                                 $(inst_slibdir)/$(L:.so=)-$V.so \
854                                 $(inst_slibdir)/$L$($L-version))
855
856 # Install all the unversioned shared libraries.
857 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
858     $(objpfx)%.so $(+force)
859         $(do-install-program)
860
861 ifneq ($(findstring -s,$(LN_S)),)
862 define make-link
863 rm -f $@.new
864 $(SHELL) $(..)scripts/rellns-sh $< $@.new
865 mv -f $@.new $@
866 endef
867 else
868 # If we have no symbolic links don't bother with rellns-sh.
869 define make-link
870 rm -f $@.new
871 $(LN_S) $< $@.new
872 mv -f $@.new $@
873 endef
874 endif
875
876 ifeq (yes,$(build-shared))
877 ifeq (no,$(cross-compiling))
878 symbolic-link-prog := $(common-objpfx)elf/sln
879 symbolic-link-list := $(common-objpfx)elf/symlink.list
880 define make-shlib-link
881 echo $(<F) $@ >> $(symbolic-link-list)
882 endef
883 else # cross-compiling
884 # We need a definition that can be used by elf/Makefile's install rules.
885 symbolic-link-prog = $(LN_S)
886 endif
887 endif
888 ifndef make-shlib-link
889 define make-shlib-link
890 rm -f $@
891 $(LN_S) $(<F) $@
892 endef
893 endif
894
895 ifdef libc.so-version
896 # For a library specified to be version N, install three files:
897 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
898 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
899
900 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
901                                            $(+force)
902         $(make-shlib-link)
903 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
904         $(do-install-program)
905 install: $(inst_slibdir)/libc.so$(libc.so-version)
906
907 # This fragment of linker script gives the OUTPUT_FORMAT statement
908 # for the configuration we are building.  We put this statement into
909 # the linker scripts we install for -lc et al so that they will not be
910 # used by a link for a different format on a multi-architecture system.
911 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
912                             $(common-objpfx)config.make \
913                             $(common-objpfx)config.h $(..)Makerules
914 ifneq (unknown,$(output-format))
915         echo > $@.new 'OUTPUT_FORMAT($(output-format))'
916 else
917         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
918                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
919         | sed -n -f $< > $@.new
920         test -s $@.new
921         rm -f $@.so
922 endif
923         mv -f $@.new $@
924 common-generated += format.lds
925
926 ifndef subdir
927 # What we install as libc.so for programs to link against is in fact a
928 # link script.  It contains references for the various libraries we need.
929 # The libc.so object is not complete since some functions are only defined
930 # in libc_nonshared.a.
931 # We need to use absolute paths since otherwise local copies (if they exist)
932 # of the files are taken by the linker.
933 install: $(inst_libdir)/libc.so
934 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
935                         $(common-objpfx)libc.so$(libc.so-version) \
936                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
937                                                   $(libprefix)$(libc-name)) \
938                         $(+force)
939         (echo '/* GNU ld script';\
940          echo '   Use the shared library, but some functions are only in';\
941          echo '   the static library, so try that secondarily.  */';\
942          cat $<; \
943          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
944               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
945               ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
946         ) > $@.new
947         mv -f $@.new $@
948
949 endif
950
951 else
952 install: $(inst_slibdir)/libc.so
953 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
954         $(do-install-program)
955 endif
956
957 ifneq (,$(versioned))
958 # Produce three sets of rules as above for all the smaller versioned libraries.
959
960 define o-iterator-doit
961 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
962 endef
963 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
964 ifneq (,$(object-suffixes-left))
965 include $(o-iterator)
966 endif
967
968 # Make symlinks in the build directory, because the versioned names might
969 # be referenced by a DT_NEEDED in another library.
970 define o-iterator-doit
971 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
972 endef
973 object-suffixes-left := $(versioned)
974 include $(o-iterator)
975
976 generated += $(foreach o,$(versioned),$o$($o-version))
977
978 ifeq (,$($(subdir)-version))
979 define o-iterator-doit
980 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
981                                  $(+force);
982         $$(make-shlib-link)
983 endef
984 object-suffixes-left := $(versioned)
985 include $(o-iterator)
986
987 define o-iterator-doit
988 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
989         $$(do-install-program)
990 endef
991 object-suffixes-left := $(versioned)
992 include $(o-iterator)
993 else
994 define o-iterator-doit
995 $(inst_slibdir)/$o$($o-version): \
996   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
997         $$(make-shlib-link)
998 endef
999 object-suffixes-left := $(versioned)
1000 include $(o-iterator)
1001
1002 define o-iterator-doit
1003 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1004         $$(do-install-program)
1005 endef
1006 object-suffixes-left := $(versioned)
1007 include $(o-iterator)
1008 endif
1009 endif
1010
1011 define do-install-so
1012 $(do-install-program)
1013 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1014            $(filter-out %.so,$@))
1015 endef
1016
1017 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1018 $(foreach v,$(so-versions),\
1019           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1020                                                $(+force)
1021         $(do-install-so)
1022 $(foreach v,$(so-versions),\
1023           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1024         $(do-install-so)
1025 endif
1026
1027 ifdef install-bin
1028 $(addprefix $(inst_bindir)/,$(install-bin)): \
1029     $(inst_bindir)/%: $(objpfx)% $(+force)
1030         $(do-install-program)
1031 endif
1032 ifdef install-bin-script
1033 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1034     $(inst_bindir)/%: $(objpfx)% $(+force)
1035         $(do-install-script)
1036 endif
1037 ifdef install-rootsbin
1038 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1039    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1040         $(do-install-program)
1041 endif
1042 ifdef install-sbin
1043 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1044     $(inst_sbindir)/%: $(objpfx)% $(+force)
1045         $(do-install-program)
1046 endif
1047 ifdef install-lib
1048 install-lib.a := $(filter lib%.a,$(install-lib))
1049 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1050 ifdef install-lib-non.a
1051 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1052   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1053         $(do-install)
1054 endif
1055 ifdef install-lib.a
1056 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1057   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1058         $(do-install)
1059 endif
1060 endif
1061 ifdef install-data
1062 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1063         $(do-install)
1064 endif
1065 headers := $(strip $(headers))
1066 ifdef headers
1067 # This implicit rule installs headers from the source directory.
1068 # It may be ignored in preference to rules from sysd-rules to find
1069 # headers in the sysdeps tree.
1070 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1071         $(do-install)
1072 $(inst_includedir)/%.h: %.h $(+force)
1073         $(do-install)
1074 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1075         $(do-install)
1076 headers-nonh := $(filter-out %.h,$(headers))
1077 ifdef headers-nonh
1078 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1079                                                  % $(+force)
1080         $(do-install)
1081 endif   # headers-nonh
1082 endif   # headers
1083
1084 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1085         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1086         install-data-nosubdir install-headers-nosubdir
1087 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1088 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1089 install-rootsbin-nosubdir: \
1090         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1091 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1092 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1093                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1094                        $(addprefix $(libprefix),$(install-lib-non.a)))
1095 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1096 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1097 install-others-nosubdir: $(install-others)
1098 install-others-programs-nosubdir: $(install-others-programs)
1099
1100 # We need all the `-nosubdir' targets so that `install' in the parent
1101 # doesn't depend on several things which each iterate over the subdirs.
1102 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1103 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1104 install-%:: install-%-nosubdir ;
1105
1106 .PHONY: install install-no-libc.a-nosubdir
1107 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1108                             install-lib-nosubdir install-others-nosubdir
1109 ifeq ($(build-programs),yes)
1110 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1111                             install-rootsbin-nosubdir install-sbin-nosubdir \
1112                             install-others-programs-nosubdir
1113 endif
1114 install: install-no-libc.a-nosubdir
1115 \f
1116 # Command to compile $< in $(objdir) using the native libraries.
1117 define native-compile
1118 $(make-target-directory)
1119 $(patsubst %/,cd % &&,$(objpfx)) \
1120 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1121             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1122 endef
1123
1124 # Command to compile $< in $(common-objdir) using the native libraries.
1125 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1126 define common-objdir-compile
1127 $(patsubst %/,cd % &&,$(objpfx)) \
1128 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1129             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1130 endef
1131
1132 # We always want to use configuration definitions.
1133 # Note that this is only used for commands running in $(objpfx).
1134 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1135
1136 # Support the GNU standard name for this target.
1137 .PHONY: check
1138 check: tests
1139 # Special target to run tests which cannot be run unconditionally.
1140 # Maintainers should use this target.
1141 .PHONY: xcheck
1142 xcheck: xtests
1143
1144 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1145 ifneq (,$(all-nonlib))
1146 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1147 lib := nonlib
1148 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1149 endif
1150
1151 # The include magic above causes those files to use this variable for flags.
1152 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1153
1154
1155 ifeq ($(versioning),yes)
1156 # Generate normalized lists of symbols, versions, and data sizes.
1157 # This is handy for checking against existing library binaries.
1158
1159 %.symlist: $(..)scripts/abilist.awk %.dynsym
1160         LC_ALL=C $(AWK) -f $^ > $@T
1161         mv -f $@T $@
1162
1163 %.dynsym: %.so
1164         $(OBJDUMP) --dynamic-syms $< > $@T
1165         mv -f $@T $@
1166
1167 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1168              $(..)abilist/%.abilist $(objpfx)%.symlist
1169         $(check-abi)
1170 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1171              $(..)abilist/%.abilist $(common-objpfx)%.symlist
1172         $(check-abi)
1173 define check-abi
1174         LC_ALL=C \
1175         $(AWK) -f $< -v 'config=$(check-abi-config)' \
1176                $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1177                $(filter %.abilist,$^) \
1178         | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1179 endef
1180 ifeq ($(enable-check-abi),warn)
1181 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1182 endif
1183
1184 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1185 config-tls := thread
1186 check-abi-config := \
1187   $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1188 endif
1189
1190 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1191               $(objpfx)%.symlist
1192         $(update-abi)
1193 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1194               $(common-objpfx)%.symlist
1195         $(update-abi)
1196 ifndef update-abi-config
1197 define update-abi
1198         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1199 endef
1200 else
1201 define update-abi
1202 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1203          > $(..)abilist/$*.abilist.new
1204 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1205  then rm -f $(..)abilist/$*.abilist.new; \
1206       echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1207  else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1208       echo '*** Now check $*.abilist changes for correctness ***'; \
1209  fi
1210 endef
1211 endif
1212
1213 .PHONY: update-abi check-abi
1214 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1215 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1216 ifdef subdir
1217 subdir_check-abi: check-abi
1218 subdir_update-abi: update-abi
1219 else
1220 check-abi: subdir_check-abi
1221 update-abi: subdir_update-abi
1222 endif
1223
1224 ifeq ($(subdir),elf)
1225 check-abi: check-abi-libc
1226 update-abi: update-abi-libc
1227 common-generated += libc.symlist
1228 endif
1229
1230 ifeq ($(build-shared),yes)
1231 ifneq ($(enable-check-abi),no)
1232 ifdef subdir
1233 tests: check-abi
1234 endif
1235 endif
1236 endif
1237
1238 endif
1239
1240 # These will have been set by sysdeps/posix/Makefile.
1241 L_tmpnam  ?= 1
1242 TMP_MAX   ?= 0
1243 L_ctermid ?= 1
1244 L_cuserid ?= 1
1245
1246 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1247
1248 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1249 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1250                    $(common-objpfx)config.make
1251         $(make-target-directory)
1252         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1253           echo '#define _LIBC 1';                                       \
1254           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1255         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1256               $(+includes) -xc - -o $(@:st=hT)
1257         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1258             $(@:st=dT) > $(@:st=dt)
1259         mv -f $(@:st=dt) $(@:st=d)
1260         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1261         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1262         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1263         fopen_max=$${fopen_max:-16};                                    \
1264         filename_max=$${filename_max:-1024};                            \
1265         if [ -z "$$iov_max" ]; then                                     \
1266           define_iov_max="# undef IOV_MAX";                             \
1267         else                                                            \
1268           define_iov_max="# define IOV_MAX $$iov_max";                  \
1269         fi;                                                             \
1270         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1271             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1272             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1273             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1274             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1275             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1276             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1277             $< > $(@:st=h.new)
1278         $(move-if-change) $(@:st=h.new) $(@:st=h)
1279 # Remove these last so that they can be examined if something went wrong.
1280         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1281         touch $@
1282 # Get dependencies.
1283 ifndef no_deps
1284 -include $(stdio_lim:h=d)
1285 endif
1286 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1287 \f
1288 FORCE:
1289
1290 .PHONY: echo-headers
1291 echo-headers:
1292         @echo $(headers)
1293
1294 %.bz2: %; bzip2 -9vk $<
1295 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1296 %.xz: %; xz -9evk $<
1297 \f
1298 # Common cleaning targets.
1299
1300 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1301 clean: common-clean
1302 mostlyclean: common-mostlyclean
1303
1304 do-tests-clean:
1305         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1306                                                       $(test-srcs)) \
1307                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1308                                                          $(test-srcs)))
1309
1310 # Remove the object files.
1311 common-mostlyclean:
1312         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1313                                      $(others) $(sysdep-others) stubs \
1314                                      $(addsuffix .o,$(tests) $(xtests) \
1315                                                     $(test-srcs) $(others) \
1316                                                     $(sysdep-others)) \
1317                                      $(addsuffix -bp,$(tests) $(xtests) \
1318                                                      $(test-srcs)) \
1319                                      $(addsuffix .out,$(tests) $(xtests) \
1320                                                       $(test-srcs)) \
1321                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1322                                                          $(test-srcs)))
1323         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1324                                      $(install-lib) $(install-lib.so) \
1325                                      $(install-lib.so:%.so=%_pic.a))
1326         -rm -f core
1327         -rm -f $(objpfx)rtld-*.os
1328         $(rmobjs)
1329 define rmobjs
1330 $(foreach o,$(object-suffixes-for-libc),
1331 -rm -f $(objpfx)stamp$o $(o-objects))
1332 endef
1333
1334 # Also remove the dependencies and generated source files.
1335 common-clean: common-mostlyclean
1336         -rm -f $(addprefix $(objpfx),$(generated))
1337         -rm -f $(objpfx)*.d $(objpfx)*.dt
1338         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1339         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1340 \f
1341 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1342 # for each function which is a stub.  We grovel over all the .d files
1343 # looking for references to <stub-tag.h>.  Then we grovel over each
1344 # referenced source file to see what stub function it defines.
1345
1346 ifdef objpfx
1347 .PHONY: stubs # The parent Makefile calls this target.
1348 stubs: $(objpfx)stubs
1349 endif
1350 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1351                   $(addprefix $(objpfx),$(extra-objs))
1352 $(objpfx)stubs: $(objs-for-stubs)
1353 ifneq (,$(strip $(objs-for-stubs)))
1354         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1355         $(AWK) '/\.gnu\.glibc-stub\./ { \
1356                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1357                   stubs[$$2] = 1; } \
1358                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1359         mv -f $@T $@
1360 else
1361         > $@
1362 endif
1363 \f
1364 ifneq (,$(strip $(gpl2lgpl)))
1365 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1366 # Snarf from the master source and frob the copying notice.
1367 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1368         sed -f $^ > $@-tmp
1369 # So I don't edit them by mistake.
1370         chmod a-w $@-tmp
1371         mv -f $@-tmp $@
1372 endif
1373 endif
1374
1375 # Local Variables:
1376 # mode: makefile
1377 # End: