Fix hypot sNaN handling (bug 20940).
[glibc.git] / Makerules
blobe865782b4352a050930720b8ce0eb77a0bbf6340
1 # Copyright (C) 1991-2016 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <http://www.gnu.org/licenses/>.
19 #       Common rules for making the GNU C library.  This file is included
20 #       by the top-level Makefile and by all subdirectory makefiles
21 #       (through Rules).
23 ifneq (,)
24 This makefile requires GNU Make.
25 endif
27 REQUIRED_MAKE_VERSION = 3.74
28 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
30 ifneq ($(REQUIRED_MAKE_VERSION), \
31        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
32 Wrong GNU Make version.  See above for the version needed.
33 endif
36 ifdef   subdir
37 ..      := ../
38 endif   # subdir
40 # If `sources' was defined by the parent makefile, undefine it so
41 # we will later get it from wildcard search in this directory.
42 ifneq   "$(findstring env,$(origin sources))" ""
43 sources :=
44 endif
46 oPATH := $(PATH)
47 PATH := this definition should take precedence over $(oPATH)
48 ifeq ($(PATH),$(oPATH))
49 You must not use the -e flag when building the GNU C library.
50 else
51 PATH := $(oPATH)
52 endif
54 ifndef +included-Makeconfig
55 include $(..)Makeconfig
56 endif
58 # This variable is used in ``include $(o-iterator)'' after defining
59 # $(o-iterator-doit) to produce some desired rule using $o for the object
60 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
61 # is produced for each object suffix in use.
62 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
64 # Include any system-specific makefiles.
66 # This is here so things in sysdep Makefiles can easily depend on foo.h as
67 # appropriate and not worry about where foo.h comes from, which may be
68 # system dependent and not known by that Makefile.
69 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
70                                       $(+sysdep_dirs) $(..)))
72 # The same is true for RPC source files.
73 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
74                                       $(+sysdep_dirs) $(..)))
76 # Some sysdep makefiles use this to distinguish being included here from
77 # being included individually by a subdir makefile (hurd/Makefile needs this).
78 in-Makerules := yes
80 sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
81 ifneq (,$(sysdep-makefiles))
82 include $(sysdep-makefiles)
83 endif
86 # Reorder before-compile so that mach things come first, and hurd things
87 # second, before all else.  The mach and hurd subdirectories have many
88 # generated header files which the much of rest of the library depends on,
89 # so it is best to build them first (and mach before hurd, at that).
90 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
91                            $(before-compile)) \
92                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
93                                $(before-compile))
95 # Even before that, we need abi-versions.h which is generated right here.
96 ifeq ($(build-shared),yes)
97 ifndef avoid-generated
98 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
99 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
100                                 $(common-objpfx)Versions.all
101         LC_ALL=C $(AWK) -f $^ > $@T
102         mv -f $@T $@
104 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
105         sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
106             $(common-objpfx)abi-versions.h > $@T
107         mv -f $@T $@
108 endif # avoid-generated
109 endif # $(build-shared) = yes
111 ifndef avoid-generated
112 ifneq (,$(CXX))
113 # If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
114 # /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
115 # (instead of stdlib/stdlib.h or math/math.h in the glibc source
116 # directory), and this turns up as a make dependency.  An implicit
117 # rule will kick in and make will try to install stdlib/stdlib.h or
118 # math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
119 # the target is out of date.  We make a copy of <cstdlib> and <cmath>
120 # in the glibc build directory so that stdlib/stdlib.h and math/math.h
121 # will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
122 before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
123                   $(before-compile)
124 $(common-objpfx)cstdlib: $(c++-cstdlib-header)
125         $(INSTALL_DATA) $< $@T
126         $(move-if-change) $@T $@
127 $(common-objpfx)cmath: $(c++-cmath-header)
128         $(INSTALL_DATA) $< $@T
129         $(move-if-change) $@T $@
130 endif
132 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
133 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
134 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
135                              $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
136                                          $(..)libc-abis) \
137                              $(..)Makerules
138         $(SHELL) $< \
139                  $(base-machine)-$(config-vendor)-$(config-os) \
140                  < $(word 2,$^) > $(@:.stamp=.h)T
141         $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
142         touch $@
143 common-generated += $(common-objpfx)libc-abis.h
144 endif # avoid-generated
146 ifeq (yes,$(build-shared))
147 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
148 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
149         $(make-target-directory)
150         echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
151                 > ${@:stamp=T}
152         $(move-if-change) ${@:stamp=T} ${@:stamp=h}
153         touch $@
154 endif
156 # Make sure the subdirectory for object files gets created.
157 ifdef objpfx
158 ifeq (,$(wildcard $(objpfx).))
159 before-compile += $(objpfx).
160 $(objpfx).:
161         $(make-target-directory)
162 endif
163 endif
165 # Remove existing files from `before-compile'.  Things are added there when
166 # they must exist for dependency generation to work right, but once they
167 # exist there is no further need for every single file to depend on them,
168 # and those gratuitous dependencies result in many gratuitous
169 # recompilations.
170 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
172 # Don't let any before-compile file be an intermediate and get removed.
173 ifdef before-compile
174 $(before-compile):
175 endif
177 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
178 # in subdirs.
179 ifdef subdir
180 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
181 else
182 common-before-compile = $(before-compile)
183 endif
185 ifndef subdir
186 # If a makefile needs to do something conditional on something that
187 # can only be figured out from headers, write a FOO.make.c input
188 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
189 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
191 # We only generate these in the top-level makefile, to avoid any weirdness
192 # from subdir-specific makefile tweaks creeping in on an update.
193 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
194         rm -f $@T $@.dT
195         (echo '# Generated from $*.make.c by Makerules.'; \
196          $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
197                -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
198          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
199          echo 'common-generated += $(@F)'; \
200          sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
201          rm -f $@.dT) > $@T
202         mv -f $@T $@
203 endif
205 ifdef subdir
206 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g' \
207                      -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
208 else
209 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g' \
210                      -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
211 endif
214 ifdef gen-as-const-headers
215 # Generating headers for assembly constants.
216 # We need this defined early to get into before-compile before
217 # it's used in sysd-rules, below.
218 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
219                                            %.sym $(common-before-compile)
220         $(AWK) -f $< $(filter %.sym,$^) \
221         | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
222                 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
223         sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
224                 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
225         rm -f $(@:.h.d=.h)T3
226         sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
227             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
228         rm -f $(@:.h=.h.d)T
229         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
230         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
231 vpath %.sym $(sysdirs)
232 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
234 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
235 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
236 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
237                             %.sym $(common-objpfx)%.h
238         ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
239          $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
240          echo '#include "$(..)test-skeleton.c"') > $@T
241         mv -f $@T $@
242 endif
244 ifeq (yes,$(build-shared))
245 # Generate the header containing the names of all shared libraries.
246 # We use a stamp file to avoid unnecessary recompilations.
247 before-compile += $(common-objpfx)gnu/lib-names.h
248 ifeq ($(soversions.mk-done),t)
249 ifndef abi-variants
250 lib-names-h-abi = gnu/lib-names.h
251 lib-names-stmp-abi = gnu/lib-names.stmp
252 else
253 lib-names-h-abi = gnu/lib-names-$(default-abi).h
254 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
255 before-compile += $(common-objpfx)$(lib-names-h-abi)
256 common-generated += gnu/lib-names.h
257 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
258 $(common-objpfx)gnu/lib-names.h:
259         $(make-target-directory)
260         { \
261          echo '/* This file is automatically generated.';\
262          echo '   It defines macros to allow user program to find the shared'; \
263          echo '   library files which come as part of GNU libc.  */'; \
264          echo '#ifndef __GNU_LIB_NAMES_H'; \
265          echo '#define __GNU_LIB_NAMES_H        1'; \
266          echo ''; \
267          $(if $(abi-includes), \
268           $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
269           echo '';) \
270          $(foreach v,$(abi-variants),\
271          $(if $(abi-$(v)-condition),\
272          echo '#if $(abi-$(v)-condition)'; \
273          echo '# include <gnu/lib-names-$(v).h>'); \
274          $(if $(abi-$(v)-condition),echo '#endif';)) \
275          echo ''; \
276          echo '#endif   /* gnu/lib-names.h */'; \
277         } >  $@
278 endif
279 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
280 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
281                                        $(common-objpfx)soversions.i
282         $(make-target-directory)
283         { \
284          $(if $(abi-variants), \
285          echo '/* This file is automatically generated.  */';\
286          echo '#ifndef __GNU_LIB_NAMES_H'; \
287          echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
288          echo '#endif';, \
289          echo '/* This file is automatically generated.';\
290          echo '   It defines macros to allow user program to find the shared'; \
291          echo '   library files which come as part of GNU libc.  */'; \
292          echo '#ifndef __GNU_LIB_NAMES_H'; \
293          echo '#define __GNU_LIB_NAMES_H        1';) \
294          echo ''; \
295          ($(foreach s,$(all-sonames), echo $(s);)) \
296          | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
297          $(if $(abi-variants),, \
298          echo ''; \
299          echo '#endif   /* gnu/lib-names.h */';) \
300         } >  ${@:stmp=T}
301         $(move-if-change) ${@:stmp=T} ${@:stmp=h}
302         touch $@
303 endif
304 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
305 endif
307 ###############################################################################
308 # NOTE!  Everything adding to before-compile needs to come before this point! #
309 ###############################################################################
311 # Generate an ordered list of implicit rules which find the source files in
312 # each sysdep directory.  The old method was to use vpath to search all the
313 # sysdep directories.  However, that had the problem that a .S file in a
314 # later directory would be chosen over a .c file in an earlier directory,
315 # which does not preserve the desired sysdeps ordering behavior.
317 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
318 # matching sysdep directories whose assembly source files should be
319 # suppressed.
321 -include $(common-objpfx)sysd-rules
322 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
323 # The value of $(+sysdep_dirs) the sysd-rules was computed for
324 # differs from the one we are using now.  So force a rebuild of sysd-rules.
325 sysd-rules-force = FORCE
326 FORCE:
327 endif
328 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
329                             $(common-objpfx)config.make $(..)Makerules \
330                             $(sysdep-makefiles) $(sysdep-makeconfigs) \
331                             $(sysd-rules-force)
332         -@rm -f $@T
333         LC_ALL=C $(AWK) -f $< > $@T \
334                         -v all_object_suffixes='$(all-object-suffixes)' \
335                         -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
336                         -v sysd_rules_patterns='$(sysd-rules-patterns)' \
337                         -v config_sysdirs='$(config-sysdirs)'
338         mv -f $@T $@
340 ifndef sysd-rules-done
341 # Don't do deps until this exists, because it provides rules to make the deps.
342 no_deps=t
343 endif
345 define o-iterator-doit
346 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
347 endef
348 object-suffixes-left := $(all-object-suffixes)
349 include $(o-iterator)
351 define o-iterator-doit
352 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
353 endef
354 object-suffixes-left := $(all-object-suffixes)
355 include $(o-iterator)
357 define o-iterator-doit
358 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
359 endef
360 object-suffixes-left := $(all-object-suffixes)
361 include $(o-iterator)
363 # Omit the objpfx rules when building in the source tree, because
364 # objpfx is empty and so these rules just override the ones above.
365 ifdef objpfx
366 # Define first rules to find the source files in $(objpfx).
367 # Generated source files will end up there.
368 define o-iterator-doit
369 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
370 endef
371 object-suffixes-left := $(all-object-suffixes)
372 include $(o-iterator)
374 define o-iterator-doit
375 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
376 endef
377 object-suffixes-left := $(all-object-suffixes)
378 include $(o-iterator)
379 endif
381 # Generate version maps, but wait until sysdep-subdirs is known
382 ifeq ($(sysd-sorted-done),t)
383 ifeq ($(build-shared),yes)
384 -include $(common-objpfx)sysd-versions
385 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
386 common-generated += $(version-maps)
387 postclean-generated += sysd-versions Versions.all abi-versions.h \
388                        Versions.def Versions.v.i Versions.v
390 ifndef avoid-generated
391 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
392 sysd-versions-force = FORCE
393 FORCE:
394 endif
396 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
397                               $(common-objpfx)Versions.v
398         LC_ALL=C $(AWK) -f $^ > $@T
399         mv -f $@T $@
401 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
402                               $(common-objpfx)soversions.i \
403                               $(common-objpfx)Versions.def
404         { while read which lib version setname; do \
405             test x"$$which" = xDEFAULT || continue; \
406             test -z "$$setname" || echo "$$lib : $$setname"; \
407           done < $(word 2,$^); \
408           cat $(word 3,$^); \
409         } | LC_ALL=C $(AWK) -f $< > $@T
410         mv -f $@T $@
411 # See %.v/%.v.i implicit rules in Makeconfig.
412 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
413                               $(wildcard $(sysdirs:%=%/Versions)) \
414                               $(sysd-versions-force)
415 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
416                                $(common-objpfx)Versions.v \
417                                $(..)scripts/versions.awk
418         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
419           cat $(word 2,$^) \
420           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
421                             -v move_if_change='$(move-if-change)' \
422                             -f $(word 3,$^); \
423         ) > $@T
424         mv -f $@T $@
425 endif # avoid-generated
426 endif # $(build-shared) = yes
427 endif # sysd-sorted-done
429 # Generate .dT files as we compile.
430 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
431 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
432 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
433 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
435 # Like compile-mkdep-flags, but for use with $(BUILD_CC).  We don't want to
436 # track system includes here, they may spuriously trigger an install rule,
437 # and would cause the check-local-headers test to fail.
438 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
440 # GCC can grok options after the file name, and it looks nicer that way.
441 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
442 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
443 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
444                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
445 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
446 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
447                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
449 # We need this for the output to go in the right place.  It will default to
450 # empty if make was configured to work with a cc that can't grok -c and -o
451 # together.  You can't compile the C library with such a compiler.
452 OUTPUT_OPTION = -o $@
454 # This is the end of the pipeline for compiling generated C code.
455 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
457 # We need the $(CFLAGS) to be in there to have the right predefines during
458 # the dependency run for C sources.  But having it for assembly sources can
459 # get the wrong predefines.
460 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
462 define +make-deps
463 $(make-target-directory)
464 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
465              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
466 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
467 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
468 mv -f $(@:.d=.T) $@ $(generate-md5)
469 endef
471 ifneq (,$(objpfx))
472 # Continuation lines here are dangerous because they introduce spaces!
473 define sed-remove-objpfx
474 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
475 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
476 endef
477 endif
479 # Modify the list of routines we build for different targets
481 ifeq (yes,$(build-shared))
482 ifndef libc.so-version
483 # Undefine this because it can't work when we libc.so is unversioned.
484 static-only-routines =
485 endif
486 endif
488 elide-routines.oS += $(filter-out $(static-only-routines),\
489                                   $(routines) $(aux) $(sysdep_routines))
490 elide-routines.os += $(static-only-routines)
492 # If we have versioned code we don't need the old versions in any of the
493 # static libraries.
494 elide-routines.o  += $(shared-only-routines)
495 elide-routines.op += $(shared-only-routines)
497 # Shared library building.
499 ifeq (yes,$(build-shared))
501 # Reference map file only when shared libraries are built and a map file name
502 # is given.
503 ifeq ($(build-shared),yes)
504 map-file = $(firstword $($(@F:.so=-map)) \
505                        $(addprefix $(common-objpfx), \
506                                    $(filter $(@F:.so=.map),$(version-maps))))
507 load-map-file = $(map-file:%=-Wl,--version-script=%)
508 endif
510 # Compiler arguments to use to link a shared object with libc and
511 # ld.so.  This is intended to be as similar as possible to a default
512 # link with an installed libc.
513 link-libc-args = -Wl,--start-group \
514                  $(libc-for-link) \
515                  $(common-objpfx)libc_nonshared.a \
516                  $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
517                  -Wl,--end-group
519 # The corresponding shared libc to use.  This may be modified for a
520 # particular target.
521 libc-for-link = $(common-objpfx)libc.so
523 # The corresponding dependencies.  As these are used in dependencies,
524 # not just commands, they cannot use target-specific variables so need
525 # to name both possible libc.so objects.
526 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
527                  $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
529 # Pattern rule to build a shared object from an archive of PIC objects.
530 # This must come after the installation rules so Make doesn't try to
531 # build shared libraries in place from the installed *_pic.a files.
532 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
533 # on other shared objects.  The linking with libc and ld.so is intended
534 # to be as similar as possible to a default link with an installed libc.
535 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
536         $(build-shlib) $(link-libc-args)
537         $(call after-link,$@)
539 define build-shlib-helper
540 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
541           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
542           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
543           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
544           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
545           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
546           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
547 endef
549 ifeq (yes,$(use-default-link))
550 # If the linker is good enough, we can let it use its default linker script.
551 shlib-lds =
552 shlib-lds-flags =
553 else
554 # binutils only position loadable notes into the first page for binaries,
555 # not for shared objects
556 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
557         $(LINK.o) -shared -Wl,-O1 \
558                   -nostdlib -nostartfiles \
559                   $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
560                   -Wl,--verbose 2>&1 | \
561           sed > $@T \
562               -e '/^=========/,/^=========/!d;/^=========/d' \
563               $(if $(filter yes,$(have-hash-style)), \
564                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
565                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
566                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
567                 , \
568                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
569                ) \
570               -e 's/^.*\*(\.dynbss).*$$/& \
571                  PROVIDE(__start___libc_freeres_ptrs = .); \
572                  *(__libc_freeres_ptrs) \
573                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
574               -e 's@^.*\*(\.jcr).*$$@& \
575                  PROVIDE(__start___libc_subfreeres = .);\
576                  __libc_subfreeres : { *(__libc_subfreeres) }\
577                  PROVIDE(__stop___libc_subfreeres = .);\
578                  PROVIDE(__start___libc_atexit = .);\
579                  __libc_atexit : { *(__libc_atexit) }\
580                  PROVIDE(__stop___libc_atexit = .);\
581                  PROVIDE(__start___libc_thread_subfreeres = .);\
582                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
583                  PROVIDE(__stop___libc_thread_subfreeres = .);\
584                  PROVIDE(__start___libc_IO_vtables = .);\
585                  __libc_IO_vtables : { *(__libc_IO_vtables) }\
586                  PROVIDE(__stop___libc_IO_vtables = .);\
587                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
588         test -s $@T
589         mv -f $@T $@
590 common-generated += shlib.lds
592 shlib-lds = $(common-objpfx)shlib.lds
593 shlib-lds-flags = -T $(shlib-lds)
594 endif
596 define build-shlib
597 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
598           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
599 endef
601 define build-module-helper
602 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
603           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
604           -B$(csu-objpfx) $(load-map-file) \
605           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
606           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
607 endef
609 # This macro is similar to build-shlib but it does not define a soname
610 # and it does not depend on the destination name to start with `lib'.
611 # binutils only position loadable notes into the first page for binaries,
612 # not for shared objects
613 define build-module
614 $(build-module-helper) -o $@ $(shlib-lds-flags) \
615           $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
616 $(call after-link,$@)
617 endef
618 define build-module-asneeded
619 $(build-module-helper) -o $@ $(shlib-lds-flags) \
620           $(csu-objpfx)abi-note.o \
621           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
622           $(link-libc-args)
623 $(call after-link,$@)
624 endef
626 build-module-helper-objlist = \
627         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
628                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
629                                 $(link-libc-deps),$^))
631 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
632 build-shlib-objlist = $(build-module-helper-objlist) \
633                       $(LDLIBS-$(@F:lib%.so=%).so)
635 # Don't try to use -lc when making libc.so itself.
636 # Also omits crti.o and crtn.o, which we do not want
637 # since we define our own `.init' section specially.
638 LDFLAGS-c.so = -nostdlib -nostartfiles
639 # But we still want to link libc.so against $(libc.so-gnulib).
640 LDLIBS-c.so += $(libc.so-gnulib)
641 # Give libc.so an entry point and make it directly runnable itself.
642 LDFLAGS-c.so += -e __libc_main
643 # If lazy relocation is disabled add the -z now flag.
644 ifeq ($(bind-now),yes)
645 LDFLAGS-c.so += -Wl,-z,now
646 endif
647 # Pre-link the objects of libc_pic.a so that we can locally resolve
648 # COMMON symbols before we link against ld.so.  This is because ld.so
649 # contains some of libc_pic.a already, which will prevent the COMMONs
650 # from being allocated in libc.so, which introduces evil dependencies
651 # between libc.so and ld.so, which can make it impossible to upgrade.
652 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
653         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
654         $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
656 ifeq (,$(strip $(shlib-lds-flags)))
657 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
658 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
659         $(OBJDUMP) -h $< | \
660         $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
661                 > $@T
662         mv -f $@T $@
663 # Apply those -R options.
664 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
665                                    $(common-objpfx)libc_pic.os
666         $(OBJCOPY) @$^ $@
667 generated += libc_pic.opts libc_pic.os.clean
669 libc_pic_clean := .clean
670 endif
672 # Build a possibly-modified version of libc_pic.a for use in building
673 # linkobj/libc.so.
674 ifeq (,$(filter sunrpc,$(subdirs)))
675 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
676         $(make-target-directory)
677         ln -f $< $@
678 else
679 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
680                                     $(common-objpfx)sunrpc/librpc_compat_pic.a
681         $(make-target-directory)
682         (cd $(common-objpfx)linkobj; \
683          $(AR) x ../libc_pic.a; \
684          rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
685          $(AR) x ../sunrpc/librpc_compat_pic.a; \
686          $(AR) cr libc_pic.a *.os; \
687          rm *.os)
688 endif # $(subdirs) contains sunrpc
690 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
691 # filter ld.so out of the list of linked objects.
692 $(common-objpfx)libc.so: link-libc-deps = # empty
693 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
695 # Use our own special initializer and finalizer files for the libc.so
696 # libraries.
697 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
698                          $(common-objpfx)libc_pic.os$(libc_pic_clean) \
699                          $(elf-objpfx)sofini.os \
700                          $(elf-objpfx)interp.os \
701                          $(elf-objpfx)ld.so \
702                          $(shlib-lds)
703         $(build-shlib)
704         $(call after-link,$@)
706 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
707                          $(common-objpfx)linkobj/libc_pic.a \
708                          $(elf-objpfx)sofini.os \
709                          $(elf-objpfx)interp.os \
710                          $(elf-objpfx)ld.so \
711                          $(shlib-lds)
712         $(build-shlib)
713         $(call after-link,$@)
715 ifeq ($(build-shared),yes)
716 $(common-objpfx)libc.so: $(common-objpfx)libc.map
717 endif
718 common-generated += libc.so libc_pic.os
719 ifdef libc.so-version
720 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
721         $(make-link)
722 common-generated += libc.so$(libc.so-version)
723 endif
724 endif
726 # Figure out the source filenames in this directory.
728 override sources := $(addsuffix .c,\
729                         $(filter-out $(elided-routines),\
730                             $(routines) $(aux) \
731                             $(sysdep_routines)))
732 sysdep_routines := $(sysdep_routines)
734 headers := $(headers) $(sysdep_headers)
736 # This is the list of all object files, gotten by
737 # replacing every ".c" in `sources' with a ".o".
738 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
741 # The makefile may define $(extra-libs) with `libfoo libbar'
742 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
743 ifdef extra-libs
744 # extra-lib.mk is included once for each extra lib to define rules
745 # to build it, and to add its objects to the various variables.
746 # During its evaluation, $(lib) is set to the name of the library.
747 extra-libs-left := $(extra-libs)
748 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
749 endif
752 # The makefile may define $(modules-names) to build additional modules.
753 # These are built with $(build-module), except any in $(modules-names-nobuild).
754 ifdef modules-names
755 # extra-lib.mk is included once for each extra lib to define rules
756 # to build it, and to add its objects to the various variables.
757 # During its evaluation, $(lib) is set to the name of the library.
758 extra-modules-left := $(modules-names)
759 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
761 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
762 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
763                 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
764         $(build-module)
765 endif
767 +depfiles := $(sources:.c=.d) \
768              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
769              $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
770              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
771              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
772 ifeq ($(build-programs),yes)
773 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
774 endif
775 +depfiles := $(addprefix $(objpfx),\
776                          $(filter-out $(addsuffix .d,$(omit-deps)),\
777                                       $(+depfiles)))
778 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
779 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
780              $(wildcard $(all-dt-files:.dt=.d))
782 # This is a funny rule in that it removes its input file.
783 %.d: %.dt
784         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
785          mv -f $(@:.d=.T) $@ && \
786          rm -f $<
788 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
789 # They will be generated when they're needed, and trying too early won't work.
790 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
791 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
792                                                 $(+gen-as-const)))
794 ifdef +depfiles
795 ifneq ($(no_deps),t)
796 -include $(+depfiles)
797 endif
798 endif
799 \f\f
800 # Maximize efficiency by minimizing the number of rules.
801 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
802 # Don't define any builtin rules.
803 MAKEFLAGS := $(MAKEFLAGS)r
805 # Generic rule for making directories.
807 # mkdir isn't smart enough to strip a trailing /.
808 # We always require a mkdir which supports the -p option to avoid error
809 # messages in case of races.
810         mkdir -p $(@:%/=%)
812 # Make sure that object files are not removed
813 # when they are intermediates between sources and library members.
814 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
816 # Make sure that the parent library archive is never removed.
817 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
819 # Use the verbose option of ar and tar when not running silently.
820 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
821 verbose := v
822 else                                            # -s
823 verbose :=
824 endif                                           # not -s
826 ARFLAGS := r$(verbose)
827 CREATE_ARFLAGS := cru$(verbose)
829 # This makes all the object files in the parent library archive.
831 .PHONY: lib lib-noranlib
832 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
833 lib-noranlib: libobjs
835 # For object-suffix $o, the list of objects with that suffix.
836 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
837 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
838                                                        $(elide-routines$o)),\
839                                             $(objects))) \
840             $(addprefix $(objpfx),$(o-objects$o))
842 others: $(addprefix $(objpfx),$(install-lib))
844 ifndef objects
846 # Create the stamp$o files to keep the parent makefile happy.
847 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
848 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
849         $(make-target-directory)
850         rm -f $@; > $@
851 else
853 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
854 # timestamp file; these rules (one explicit rule is generated for each
855 # object suffix) write a list of objects to update in the stamp file.
856 # The parent will then actually add them all to the archive in the
857 # archive rule, below.
858 define o-iterator-doit
859 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
860 endef
861 define do-stamp
862 $(make-target-directory)
863 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
864 mv -f $@T $@
865 endef
866 object-suffixes-left := $(object-suffixes-for-libc)
867 include $(o-iterator)
869 endif
871 # Now define explicit rules to build the library archives; these depend
872 # on the stamp files built above.
873 define o-iterator-doit
874 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
875                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
876 endef
877 define do-makelib
878 cd $(common-objdir) && \
879 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
880 endef
881 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
882 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
883 ifndef subdir
884 $(subdirs-stamps): subdir_lib;
885 endif
886 object-suffixes-left = $(object-suffixes-for-libc)
887 include $(o-iterator)
890 # This makes all the object files.
891 .PHONY: objects objs libobjs extra-objs
892 objects objs: libobjs extra-objs
893 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
894 extra-objs: $(addprefix $(objpfx),$(extra-objs))
896 # Canned sequence for building an extra library archive.
897 define build-extra-lib
898 $(patsubst %/,cd % &&,$(objpfx)) \
899 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
900       $(patsubst $(objpfx)%,%,$^)
901 endef
903 # Installation.
905 .PHONY: force-install
906 force-install:
908 # $(install-lib) are installed from the object directory into $(libdir);
909 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
910 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
911 # they are into $(datadir).  $(headers) are installed as they are in
912 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
913 # are installed from the object directory into $(bindir), $(bindir) and
914 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
915 # are absolute path names of files to install; rules to install them are
916 # defined elsewhere.
918 # The simple library name to install libc.a under.
919 # This could be defined by a sysdep Makefile.
920 ifndef libc-name
921 libc-name := c
922 endif
924 define do-install
925 $(make-target-directory)
926 $(INSTALL_DATA) $< $@
927 endef
929 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
930 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
931 define make-target-directory
932 $(addprefix $(..)./scripts/mkinstalldirs ,\
933             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
934 endef
936 # Any directory (parent or subdir) should install libc.a; this way
937 # "make install" in a subdir is guaranteed to install everything it changes.
938 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
939                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
940                                                      $(libprefix)$(libc-name)))
942 .PHONY: check-install-supported
943 check-install-supported:
945 # Check to see if the prefix or exec_prefix GNU standard variable
946 # has been overridden on the command line and, if so, fail with
947 # an error message since doing so is not supported (set DESTDIR
948 # instead).
949 ifeq ($(origin prefix),command line)
950 check-install-supported:
951         $(error Overriding prefix is not supported. Set DESTDIR instead.)
952 endif
954 ifeq ($(origin exec_prefix),command line)
955 check-install-supported:
956         $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
957 endif
959 install: check-install-supported
961 install: $(installed-libcs)
962 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
963         $(make-target-directory)
964         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
966 define do-install-program
967 $(make-target-directory)
968 $(INSTALL_PROGRAM) $< $@.new
969 mv -f $@.new $@
970 endef
972 define do-install-script
973 $(make-target-directory)
974 $(INSTALL_SCRIPT) $< $@.new
975 mv -f $@.new $@
976 endef
978 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
979 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
981 ifeq (yes,$(build-shared))
982 # Find which .so's have versions.
983 versioned := $(strip $(foreach so,$(install-lib.so),\
984                                $(patsubst %,$(so),$($(so)-version))))
986 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
987 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
989 # For versioned libraries, we install three files:
990 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
991 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
992 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
993 lib-version := $(firstword $($(subdir)-version) $(version))
994 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
995                       $(foreach L,$(install-lib.so-versioned),\
996                                 $(inst_libdir)/$L \
997                                 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
998                                 $(inst_slibdir)/$L$($L-version))
1000 # Install all the unversioned shared libraries.
1001 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
1002     $(objpfx)%.so $(+force)
1003         $(do-install-program)
1005 ifneq ($(findstring -s,$(LN_S)),)
1006 define make-link
1007 rm -f $@.new
1008 $(SHELL) $(..)scripts/rellns-sh $< $@.new
1009 mv -f $@.new $@
1010 endef
1011 else
1012 # If we have no symbolic links don't bother with rellns-sh.
1013 define make-link
1014 rm -f $@.new
1015 $(LN_S) $< $@.new
1016 mv -f $@.new $@
1017 endef
1018 endif
1020 ifeq (yes,$(build-shared))
1021 ifeq (no,$(cross-compiling))
1022 symbolic-link-prog := $(elf-objpfx)sln
1023 symbolic-link-list := $(elf-objpfx)symlink.list
1024 define make-shlib-link
1025 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
1026 endef
1027 else # cross-compiling
1028 # We need a definition that can be used by elf/Makefile's install rules.
1029 symbolic-link-prog = $(LN_S)
1030 endif
1031 endif
1032 ifndef make-shlib-link
1033 define make-shlib-link
1034 rm -f $@
1035 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
1036 endef
1037 endif
1039 ifdef libc.so-version
1040 # For a library specified to be version N, install three files:
1041 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
1042 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
1044 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1045                                            $(+force)
1046         $(make-shlib-link)
1047 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1048         $(do-install-program)
1049 install: $(inst_slibdir)/libc.so$(libc.so-version)
1051 # This fragment of linker script gives the OUTPUT_FORMAT statement
1052 # for the configuration we are building.  We put this statement into
1053 # the linker scripts we install for -lc et al so that they will not be
1054 # used by a link for a different format on a multi-architecture system.
1055 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
1056                             $(common-objpfx)config.make \
1057                             $(common-objpfx)config.h $(..)Makerules
1058 ifneq (unknown,$(output-format))
1059         echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1060 else
1061         $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
1062                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1063         | sed -n -f $< > $@.new
1064         test -s $@.new
1065         rm -f $@.so
1066 endif
1067         mv -f $@.new $@
1068 common-generated += format.lds
1070 ifndef subdir
1071 # What we install as libc.so for programs to link against is in fact a
1072 # link script.  It contains references for the various libraries we need.
1073 # The libc.so object is not complete since some functions are only defined
1074 # in libc_nonshared.a.
1075 # We need to use absolute paths since otherwise local copies (if they exist)
1076 # of the files are taken by the linker.
1077 install: $(inst_libdir)/libc.so
1078 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1079                         $(common-objpfx)libc.so$(libc.so-version) \
1080                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1081                                                   $(libprefix)$(libc-name)) \
1082                         $(+force)
1083         (echo '/* GNU ld script';\
1084          echo '   Use the shared library, but some functions are only in';\
1085          echo '   the static library, so try that secondarily.  */';\
1086          cat $<; \
1087          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1088               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1089               ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1090         ) > $@.new
1091         mv -f $@.new $@
1093 endif
1095 else
1096 install: $(inst_slibdir)/libc.so
1097 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1098         $(do-install-program)
1099 endif
1101 ifneq (,$(versioned))
1102 # Produce three sets of rules as above for all the smaller versioned libraries.
1104 define o-iterator-doit
1105 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1106 endef
1107 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1108 ifneq (,$(object-suffixes-left))
1109 include $(o-iterator)
1110 endif
1112 # Make symlinks in the build directory, because the versioned names might
1113 # be referenced by a DT_NEEDED in another library.
1114 define o-iterator-doit
1115 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1116 endef
1117 object-suffixes-left := $(versioned)
1118 include $(o-iterator)
1120 generated += $(foreach o,$(versioned),$o$($o-version))
1122 ifeq (,$($(subdir)-version))
1123 define o-iterator-doit
1124 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1125                                  $(+force);
1126         $$(make-shlib-link)
1127 endef
1128 object-suffixes-left := $(versioned)
1129 include $(o-iterator)
1131 define o-iterator-doit
1132 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1133         $$(do-install-program)
1134 endef
1135 object-suffixes-left := $(versioned)
1136 include $(o-iterator)
1137 else
1138 define o-iterator-doit
1139 $(inst_slibdir)/$o$($o-version): \
1140   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1141         $$(make-shlib-link)
1142 endef
1143 object-suffixes-left := $(versioned)
1144 include $(o-iterator)
1146 define o-iterator-doit
1147 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1148         $$(do-install-program)
1149 endef
1150 object-suffixes-left := $(versioned)
1151 include $(o-iterator)
1152 endif
1153 endif
1155 define do-install-so
1156 $(do-install-program)
1157 $(patsubst %,$(LN_S) -f $(@F) \
1158                         $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1159            $(filter-out %.so,$@))
1160 endef
1162 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1163 $(foreach v,$(so-versions),\
1164           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1165                                                $(+force)
1166         $(do-install-so)
1167 $(foreach v,$(so-versions),\
1168           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1169         $(do-install-so)
1170 endif
1172 ifdef install-bin
1173 $(addprefix $(inst_bindir)/,$(install-bin)): \
1174     $(inst_bindir)/%: $(objpfx)% $(+force)
1175         $(do-install-program)
1176 endif
1177 ifdef install-bin-script
1178 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1179     $(inst_bindir)/%: $(objpfx)% $(+force)
1180         $(do-install-script)
1181 endif
1182 ifdef install-rootsbin
1183 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1184    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1185         $(do-install-program)
1186 endif
1187 ifdef install-sbin
1188 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1189     $(inst_sbindir)/%: $(objpfx)% $(+force)
1190         $(do-install-program)
1191 endif
1192 ifdef install-lib
1193 install-lib.a := $(filter lib%.a,$(install-lib))
1194 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1195 ifdef install-lib-non.a
1196 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1197   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1198         $(do-install)
1199 endif
1200 ifdef install-lib.a
1201 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1202   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1203         $(do-install)
1204 endif
1205 endif
1206 ifdef install-data
1207 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1208         $(do-install)
1209 endif
1210 headers := $(strip $(headers))
1211 ifdef headers
1212 # This implicit rule installs headers from the source directory.
1213 # It may be ignored in preference to rules from sysd-rules to find
1214 # headers in the sysdeps tree.
1215 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1216         $(do-install)
1217 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1218         $(do-install)
1219 $(inst_includedir)/%.h: %.h $(+force)
1220         $(do-install)
1221 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1222         $(do-install)
1223 headers-nonh := $(filter-out %.h,$(headers))
1224 ifdef headers-nonh
1225 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1226                                                  % $(+force)
1227         $(do-install)
1228 endif   # headers-nonh
1229 endif   # headers
1231 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1232         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1233         install-data-nosubdir install-headers-nosubdir
1234 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1235 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1236 install-rootsbin-nosubdir: \
1237         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1238 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1239 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1240                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1241                        $(addprefix $(libprefix),$(install-lib-non.a)))
1242 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1243 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1244 install-others-nosubdir: $(install-others)
1245 install-others-programs-nosubdir: $(install-others-programs)
1247 # We need all the `-nosubdir' targets so that `install' in the parent
1248 # doesn't depend on several things which each iterate over the subdirs.
1249 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1250 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1251 install-%:: install-%-nosubdir ;
1253 .PHONY: install install-no-libc.a-nosubdir
1254 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1255                             install-lib-nosubdir install-others-nosubdir
1256 ifeq ($(build-programs),yes)
1257 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1258                             install-rootsbin-nosubdir install-sbin-nosubdir \
1259                             install-others-programs-nosubdir
1260 endif
1261 install: install-no-libc.a-nosubdir
1263 # Command to compile $< using the native libraries.
1264 define native-compile
1265 $(make-target-directory)
1266 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1267             $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1268 endef
1270 # We always want to use configuration definitions.
1271 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1272                    -DIS_IN_build -include $(common-objpfx)config.h
1274 # Support the GNU standard name for this target.
1275 .PHONY: check
1276 check: tests
1277 # Special target to run tests which cannot be run unconditionally.
1278 # Maintainers should use this target.
1279 .PHONY: xcheck
1280 xcheck: xtests
1282 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1283 ifneq (,$(all-nonlib))
1284 cpp-srcs-left = $(all-nonlib)
1285 lib := nonlib
1286 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1287 endif
1290 ifeq ($(build-shared),yes)
1291 # Generate normalized lists of symbols, versions, and data sizes.
1292 # This is handy for checking against existing library binaries.
1294 %.symlist: $(..)scripts/abilist.awk %.dynsym
1295         LC_ALL=C $(AWK) -f $^ > $@T
1296         mv -f $@T $@
1298 %.dynsym: %.so
1299         LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1300         mv -f $@T $@
1302 # A sysdeps/.../Makefile can set abilist-pattern to something like
1303 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1304 # This makes sense if multiple ABIs can be most cleanly supported by a
1305 # configuration without using separate sysdeps directories for each.
1306 ifdef abilist-pattern
1307 vpath $(abilist-pattern) $(+sysdep_dirs)
1308 endif
1310 vpath %.abilist $(+sysdep_dirs)
1312 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1313 # target pattern is %.symlist from being considered "intermediate files"
1314 # and automatically removed.  We only want these files to be removed by
1315 # 'make clean', which is handled by the 'generated' variable.
1316 .PRECIOUS: %.symlist
1317 generated += $(extra-libs:=.symlist)
1319 ifdef abilist-pattern
1320 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1321                           $(objpfx)%.symlist
1322         $(check-abi-pattern); \
1323         $(evaluate-test)
1324 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1325                           $(common-objpfx)%.symlist
1326         $(check-abi-pattern); \
1327         $(evaluate-test)
1328 endif
1329 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1330                           $(objpfx)%.symlist
1331         $(check-abi); \
1332         $(evaluate-test)
1333 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1334                           $(common-objpfx)%.symlist
1335         $(check-abi); \
1336         $(evaluate-test)
1337 define check-abi-pattern
1338         diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1339              > $@
1340 endef
1341 define check-abi
1342         diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1343 endef
1345 ifdef abilist-pattern
1346 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1347         $(update-abi-pattern)
1348 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1349         $(update-abi-pattern)
1350 endif
1351 update-abi-%: $(objpfx)%.symlist %.abilist
1352         $(update-abi)
1353 update-abi-%: $(common-objpfx)%.symlist %.abilist
1354         $(update-abi)
1355 define update-abi-pattern
1356 @if cmp -s $^ 2> /dev/null; \
1357  then \
1358       echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1359  else cp -f $^; \
1360       echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1361  fi
1362 endef
1363 define update-abi
1364 @if cmp -s $^ 2> /dev/null; \
1365  then \
1366       echo '+++ $(filter %.abilist,$^) is unchanged'; \
1367  else cp -f $^; \
1368       echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1369  fi
1370 endef
1372 # Patch all .abilist files for one DSO.  The find command locates
1373 # abilist files for all architectures.  The regular expression in the
1374 # find invocation is needed to separate libc.abilist and
1375 # libcrypt.abilist, for example.  It assumes that abilist-pattern, if
1376 # set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
1377 # a non-alphanumeric seperator between the pattern and the suffix
1378 # added.  The abilist files in /generic/ are filtered out because
1379 # these are expected to remain empty.
1380 define update-all-abi
1381 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1382   $$(find $(..)sysdeps \
1383     -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
1384     \! -regex '.*/generic/.*')
1385 endef
1386 ifdef abilist-pattern
1387 update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
1388         $(update-all-abi)
1389 update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
1390         $(update-all-abi)
1391 endif
1392 update-all-abi-%: %.abilist $(objpfx)%.symlist
1393         $(update-all-abi)
1394 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1395         $(update-all-abi)
1397 .PHONY: update-abi update-all-abi check-abi
1398 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1399 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1400 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1401                                  $(install-lib.so-versioned))
1402 check-abi: $(check-abi-list)
1403 ifdef subdir
1404 subdir_check-abi: check-abi
1405 subdir_update-abi: update-abi
1406 subdir_update-all-abi: update-all-abi
1407 else
1408 check-abi: subdir_check-abi
1409         if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1410                 cat $(objpfx)*/check-abi*.out && exit 1; fi
1411 update-abi: subdir_update-abi
1412 update-all-abi: subdir_update-all-abi
1413 endif
1415 ifeq ($(subdir),elf)
1416 check-abi: $(objpfx)check-abi-libc.out
1417 tests-special += $(objpfx)check-abi-libc.out
1418 update-abi: update-abi-libc
1419 update-all-abi: update-all-abi-libc
1420 common-generated += libc.symlist
1421 endif
1423 ifeq ($(build-shared),yes)
1424 ifdef subdir
1425 tests-special += $(check-abi-list)
1426 endif
1427 endif
1429 endif
1431 # These will have been set by sysdeps/posix/Makefile.
1432 L_tmpnam  ?= 1
1433 TMP_MAX   ?= 0
1434 L_ctermid ?= 1
1435 L_cuserid ?= 1
1437 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1439 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1440 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1441                    $(common-objpfx)config.make
1442         $(make-target-directory)
1443         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1444           echo '#define _LIBC 1';                                       \
1445           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1446         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1447               $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1448         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1449             $(@:st=dT) > $(@:st=dt)
1450         mv -f $(@:st=dt) $(@:st=d)
1451         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1452         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1453         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1454         fopen_max=$${fopen_max:-16};                                    \
1455         filename_max=$${filename_max:-1024};                            \
1456         if [ -z "$$iov_max" ]; then                                     \
1457           define_iov_max="# undef IOV_MAX";                             \
1458         else                                                            \
1459           define_iov_max="# define IOV_MAX $$iov_max";                  \
1460         fi;                                                             \
1461         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1462             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1463             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1464             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1465             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1466             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1467             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1468             $< > $(@:st=h.new)
1469         $(move-if-change) $(@:st=h.new) $(@:st=h)
1470 # Remove these last so that they can be examined if something went wrong.
1471         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1472         touch $@
1473 # Get dependencies.
1474 ifndef no_deps
1475 -include $(stdio_lim:h=d)
1476 endif
1477 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1479 FORCE:
1481 .PHONY: echo-headers
1482 echo-headers:
1483         @echo $(headers)
1485 %.bz2: %; bzip2 -9vk $<
1486 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1487 %.xz: %; xz -9evk $<
1489 # Common cleaning targets.
1491 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1492 clean: common-clean
1493 mostlyclean: common-mostlyclean
1495 do-tests-clean:
1496         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1497                                                       $(test-srcs)) \
1498                                      $(addsuffix .test-result,$(tests) \
1499                                                               $(xtests) \
1500                                                               $(test-srcs)))
1502 # Remove the object files.
1503 common-mostlyclean:
1504         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1505                                      $(others) $(sysdep-others) stubs \
1506                                      $(addsuffix .o,$(tests) $(xtests) \
1507                                                     $(test-srcs) $(others) \
1508                                                     $(sysdep-others)) \
1509                                      $(addsuffix .out,$(tests) $(xtests) \
1510                                                       $(test-srcs)) \
1511                                      $(addsuffix .test-result,$(tests) \
1512                                                               $(xtests) \
1513                                                               $(test-srcs)))
1514         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1515                                      $(install-lib) $(install-lib.so) \
1516                                      $(install-lib.so:%.so=%_pic.a))
1517         -rm -f core
1518         -rm -f $(objpfx)rtld-*.os
1519         $(rmobjs)
1520 define rmobjs
1521 $(foreach o,$(object-suffixes-for-libc),
1522 -rm -f $(objpfx)stamp$o $(o-objects))
1523 endef
1525 # Also remove the dependencies and generated source files.
1526 common-clean: common-mostlyclean
1527         -rm -f $(addprefix $(objpfx),$(generated))
1528         -rm -f $(objpfx)*.d $(objpfx)*.dt
1529         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1530         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1531         -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1533 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1534 # for each function which is a stub.
1536 ifdef objpfx
1537 .PHONY: stubs # The parent Makefile calls this target.
1538 stubs: $(objpfx)stubs
1539 endif
1540 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1541                   $(addprefix $(objpfx),$(extra-objs))
1542 $(objpfx)stubs: $(objs-for-stubs)
1543 ifneq (,$(strip $(objs-for-stubs)))
1544         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1545         $(AWK) '/\.gnu\.glibc-stub\./ { \
1546                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1547                   stubs[$$2] = 1; } \
1548                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1549         mv -f $@T $@
1550 else
1551         > $@
1552 endif
1554 ifneq (,$(strip $(gpl2lgpl)))
1555 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1556 # Snarf from the master source and frob the copying notice.
1557 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1558         sed -f $^ > $@-tmp
1559 # So I don't edit them by mistake.
1560         chmod a-w $@-tmp
1561         mv -f $@-tmp $@
1562 endif
1563 endif
1565 # Local Variables:
1566 # mode: makefile
1567 # End: