More strict check of AVX512 support in assembler.
[glibc.git] / Makerules
blobad9d74f66021a378096ec4962e3aa53118f50be5
1 # Copyright (C) 1991-2015 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 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
113 $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
114 $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
115                              $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
116                                          $(..)libc-abis) \
117                              $(..)Makerules
118         $(SHELL) $< \
119                  $(base-machine)-$(config-vendor)-$(config-os) \
120                  < $(word 2,$^) > $(@:.stamp=.h)T
121         $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
122         touch $@
123 common-generated += $(common-objpfx)libc-abis.h
124 endif # avoid-generated
126 ifeq (yes,$(build-shared))
127 $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
128 $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
129         $(make-target-directory)
130         echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
131                 > ${@:stamp=T}
132         $(move-if-change) ${@:stamp=T} ${@:stamp=h}
133         touch $@
134 endif
136 # Make sure the subdirectory for object files gets created.
137 ifdef objpfx
138 ifeq (,$(wildcard $(objpfx).))
139 before-compile += $(objpfx).
140 $(objpfx).:
141         $(make-target-directory)
142 endif
143 endif
145 # Remove existing files from `before-compile'.  Things are added there when
146 # they must exist for dependency generation to work right, but once they
147 # exist there is no further need for every single file to depend on them,
148 # and those gratuitous dependencies result in many gratuitous
149 # recompilations.
150 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
152 # Don't let any before-compile file be an intermediate and get removed.
153 ifdef before-compile
154 $(before-compile):
155 endif
157 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
158 # in subdirs.
159 ifdef subdir
160 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
161 else
162 common-before-compile = $(before-compile)
163 endif
165 ifndef subdir
166 # If a makefile needs to do something conditional on something that
167 # can only be figured out from headers, write a FOO.make.c input
168 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
169 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
171 # We only generate these in the top-level makefile, to avoid any weirdness
172 # from subdir-specific makefile tweaks creeping in on an update.
173 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
174         rm -f $@T $@.dT
175         (echo '# Generated from $*.make.c by Makerules.'; \
176          $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
177                -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
178          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
179          echo 'common-generated += $(@F)'; \
180          sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
181          rm -f $@.dT) > $@T
182         mv -f $@T $@
183 endif
185 ifdef subdir
186 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g' \
187                      -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
188 else
189 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g' \
190                      -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
191 endif
194 ifdef gen-as-const-headers
195 # Generating headers for assembly constants.
196 # We need this defined early to get into before-compile before
197 # it's used in sysd-rules, below.
198 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
199                                            %.sym $(common-before-compile)
200         $(AWK) -f $< $(filter %.sym,$^) \
201         | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
202                 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
203         sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
204                 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
205         rm -f $(@:.h.d=.h)T3
206         sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
207             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
208         rm -f $(@:.h=.h.d)T
209         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
210         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
211 vpath %.sym $(sysdirs)
212 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
214 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
215 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
216 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
217                             %.sym $(common-objpfx)%.h
218         ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
219          $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
220          echo '#include "$(..)test-skeleton.c"') > $@T
221         mv -f $@T $@
222 endif
224 ifeq (yes,$(build-shared))
225 # Generate the header containing the names of all shared libraries.
226 # We use a stamp file to avoid unnecessary recompilations.
227 before-compile += $(common-objpfx)gnu/lib-names.h
228 ifeq ($(soversions.mk-done),t)
229 ifndef abi-variants
230 lib-names-h-abi = gnu/lib-names.h
231 lib-names-stmp-abi = gnu/lib-names.stmp
232 else
233 lib-names-h-abi = gnu/lib-names-$(default-abi).h
234 lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
235 before-compile += $(common-objpfx)$(lib-names-h-abi)
236 common-generated += gnu/lib-names.h
237 install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
238 $(common-objpfx)gnu/lib-names.h:
239         $(make-target-directory)
240         { \
241          echo '/* This file is automatically generated.';\
242          echo '   It defines macros to allow user program to find the shared'; \
243          echo '   library files which come as part of GNU libc.  */'; \
244          echo '#ifndef __GNU_LIB_NAMES_H'; \
245          echo '#define __GNU_LIB_NAMES_H        1'; \
246          echo ''; \
247          $(if $(abi-includes), \
248           $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
249           echo '';) \
250          $(foreach v,$(abi-variants),\
251          $(if $(abi-$(v)-condition),\
252          echo '#if $(abi-$(v)-condition)'; \
253          echo '# include <gnu/lib-names-$(v).h>'); \
254          $(if $(abi-$(v)-condition),echo '#endif';)) \
255          echo ''; \
256          echo '#endif   /* gnu/lib-names.h */'; \
257         } >  $@
258 endif
259 $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
260 $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
261                                        $(common-objpfx)soversions.i
262         $(make-target-directory)
263         { \
264          $(if $(abi-variants), \
265          echo '/* This file is automatically generated.  */';\
266          echo '#ifndef __GNU_LIB_NAMES_H'; \
267          echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
268          echo '#endif';, \
269          echo '/* This file is automatically generated.';\
270          echo '   It defines macros to allow user program to find the shared'; \
271          echo '   library files which come as part of GNU libc.  */'; \
272          echo '#ifndef __GNU_LIB_NAMES_H'; \
273          echo '#define __GNU_LIB_NAMES_H        1';) \
274          echo ''; \
275          ($(foreach s,$(all-sonames), echo $(s);)) \
276          | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
277          $(if $(abi-variants),, \
278          echo ''; \
279          echo '#endif   /* gnu/lib-names.h */';) \
280         } >  ${@:stmp=T}
281         $(move-if-change) ${@:stmp=T} ${@:stmp=h}
282         touch $@
283 endif
284 common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
285 endif
287 ###############################################################################
288 # NOTE!  Everything adding to before-compile needs to come before this point! #
289 ###############################################################################
291 # Generate an ordered list of implicit rules which find the source files in
292 # each sysdep directory.  The old method was to use vpath to search all the
293 # sysdep directories.  However, that had the problem that a .S file in a
294 # later directory would be chosen over a .c file in an earlier directory,
295 # which does not preserve the desired sysdeps ordering behavior.
297 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
298 # matching sysdep directories whose assembly source files should be
299 # suppressed.
301 -include $(common-objpfx)sysd-rules
302 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
303 # The value of $(+sysdep_dirs) the sysd-rules was computed for
304 # differs from the one we are using now.  So force a rebuild of sysd-rules.
305 sysd-rules-force = FORCE
306 FORCE:
307 endif
308 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
309                             $(common-objpfx)config.make $(..)Makerules \
310                             $(sysdep-makefiles) $(sysdep-makeconfigs) \
311                             $(sysd-rules-force)
312         -@rm -f $@T
313         LC_ALL=C $(AWK) -f $< > $@T \
314                         -v all_object_suffixes='$(all-object-suffixes)' \
315                         -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
316                         -v sysd_rules_patterns='$(sysd-rules-patterns)' \
317                         -v config_sysdirs='$(config-sysdirs)'
318         mv -f $@T $@
320 ifndef sysd-rules-done
321 # Don't do deps until this exists, because it provides rules to make the deps.
322 no_deps=t
323 endif
325 define o-iterator-doit
326 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
327 endef
328 object-suffixes-left := $(all-object-suffixes)
329 include $(o-iterator)
331 define o-iterator-doit
332 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
333 endef
334 object-suffixes-left := $(all-object-suffixes)
335 include $(o-iterator)
337 define o-iterator-doit
338 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
339 endef
340 object-suffixes-left := $(all-object-suffixes)
341 include $(o-iterator)
343 # Omit the objpfx rules when building in the source tree, because
344 # objpfx is empty and so these rules just override the ones above.
345 ifdef objpfx
346 # Define first rules to find the source files in $(objpfx).
347 # Generated source files will end up there.
348 define o-iterator-doit
349 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
350 endef
351 object-suffixes-left := $(all-object-suffixes)
352 include $(o-iterator)
354 define o-iterator-doit
355 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
356 endef
357 object-suffixes-left := $(all-object-suffixes)
358 include $(o-iterator)
359 endif
361 # Generate version maps, but wait until sysdep-subdirs is known
362 ifeq ($(sysd-sorted-done),t)
363 ifeq ($(build-shared),yes)
364 -include $(common-objpfx)sysd-versions
365 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
366 common-generated += $(version-maps)
367 postclean-generated += sysd-versions Versions.all abi-versions.h \
368                        Versions.def Versions.v.i Versions.v
370 ifndef avoid-generated
371 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
372 sysd-versions-force = FORCE
373 FORCE:
374 endif
376 $(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
377                               $(common-objpfx)Versions.v
378         LC_ALL=C $(AWK) -f $^ > $@T
379         mv -f $@T $@
381 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
382                               $(common-objpfx)soversions.i \
383                               $(common-objpfx)Versions.def
384         { while read which lib version setname; do \
385             test x"$$which" = xDEFAULT || continue; \
386             test -z "$$setname" || echo "$$lib : $$setname"; \
387           done < $(word 2,$^); \
388           cat $(word 3,$^); \
389         } | LC_ALL=C $(AWK) -f $< > $@T
390         mv -f $@T $@
391 # See %.v/%.v.i implicit rules in Makeconfig.
392 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
393                               $(wildcard $(sysdirs:%=%/Versions)) \
394                               $(sysd-versions-force)
395 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
396                                $(common-objpfx)Versions.v \
397                                $(..)scripts/versions.awk
398         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
399           cat $(word 2,$^) \
400           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
401                             -v move_if_change='$(move-if-change)' \
402                             -f $(word 3,$^); \
403         ) > $@T
404         mv -f $@T $@
405 endif # avoid-generated
406 endif # $(build-shared) = yes
407 endif # sysd-sorted-done
409 # Generate .dT files as we compile.
410 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
411 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
412 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
413 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
415 # Like compile-mkdep-flags, but for use with $(BUILD_CC).  We don't want to
416 # track system includes here, they may spuriously trigger an install rule,
417 # and would cause the check-local-headers test to fail.
418 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
420 # GCC can grok options after the file name, and it looks nicer that way.
421 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
422 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
423 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
424                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
425 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
426 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
427                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
429 # We need this for the output to go in the right place.  It will default to
430 # empty if make was configured to work with a cc that can't grok -c and -o
431 # together.  You can't compile the C library with such a compiler.
432 OUTPUT_OPTION = -o $@
434 # This is the end of the pipeline for compiling generated C code.
435 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
437 # We need the $(CFLAGS) to be in there to have the right predefines during
438 # the dependency run for C sources.  But having it for assembly sources can
439 # get the wrong predefines.
440 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
442 define +make-deps
443 $(make-target-directory)
444 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
445              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
446 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
447 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
448 mv -f $(@:.d=.T) $@ $(generate-md5)
449 endef
451 ifneq (,$(objpfx))
452 # Continuation lines here are dangerous because they introduce spaces!
453 define sed-remove-objpfx
454 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
455 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
456 endef
457 endif
459 # Modify the list of routines we build for different targets
461 ifeq (yes,$(build-shared))
462 ifndef libc.so-version
463 # Undefine this because it can't work when we libc.so is unversioned.
464 static-only-routines =
465 endif
466 endif
468 elide-routines.oS += $(filter-out $(static-only-routines),\
469                                   $(routines) $(aux) $(sysdep_routines))
470 elide-routines.os += $(static-only-routines)
472 # If we have versioned code we don't need the old versions in any of the
473 # static libraries.
474 elide-routines.o  += $(shared-only-routines)
475 elide-routines.op += $(shared-only-routines)
476 elide-routines.og += $(shared-only-routines)
478 # Shared library building.
480 ifeq (yes,$(build-shared))
482 # Reference map file only when shared libraries are built and a map file name
483 # is given.
484 ifeq ($(build-shared),yes)
485 map-file = $(firstword $($(@F:.so=-map)) \
486                        $(addprefix $(common-objpfx), \
487                                    $(filter $(@F:.so=.map),$(version-maps))))
488 load-map-file = $(map-file:%=-Wl,--version-script=%)
489 endif
491 # Compiler arguments to use to link a shared object with libc and
492 # ld.so.  This is intended to be as similar as possible to a default
493 # link with an installed libc.
494 link-libc-args = -Wl,--start-group \
495                  $(libc-for-link) \
496                  $(common-objpfx)libc_nonshared.a \
497                  $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
498                  -Wl,--end-group
500 # The corresponding shared libc to use.  This may be modified for a
501 # particular target.
502 libc-for-link = $(common-objpfx)libc.so
504 # The corresponding dependencies.  As these are used in dependencies,
505 # not just commands, they cannot use target-specific variables so need
506 # to name both possible libc.so objects.
507 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
508                  $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
510 # Pattern rule to build a shared object from an archive of PIC objects.
511 # This must come after the installation rules so Make doesn't try to
512 # build shared libraries in place from the installed *_pic.a files.
513 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
514 # on other shared objects.  The linking with libc and ld.so is intended
515 # to be as similar as possible to a default link with an installed libc.
516 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
517         $(build-shlib) $(link-libc-args)
518         $(call after-link,$@)
520 define build-shlib-helper
521 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
522           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
523           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
524           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
525           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
526           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
527           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
528 endef
530 ifeq (yes,$(use-default-link))
531 # If the linker is good enough, we can let it use its default linker script.
532 shlib-lds =
533 shlib-lds-flags =
534 else
535 # binutils only position loadable notes into the first page for binaries,
536 # not for shared objects
537 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
538         $(LINK.o) -shared -Wl,-O1 \
539                   -nostdlib -nostartfiles \
540                   $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
541                   -Wl,--verbose 2>&1 | \
542           sed > $@T \
543               -e '/^=========/,/^=========/!d;/^=========/d' \
544               $(if $(filter yes,$(have-hash-style)), \
545                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
546                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
547                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
548                 , \
549                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
550                ) \
551               -e 's/^.*\*(\.dynbss).*$$/& \
552                  PROVIDE(__start___libc_freeres_ptrs = .); \
553                  *(__libc_freeres_ptrs) \
554                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
555               -e 's@^.*\*(\.jcr).*$$@& \
556                  PROVIDE(__start___libc_subfreeres = .);\
557                  __libc_subfreeres : { *(__libc_subfreeres) }\
558                  PROVIDE(__stop___libc_subfreeres = .);\
559                  PROVIDE(__start___libc_atexit = .);\
560                  __libc_atexit : { *(__libc_atexit) }\
561                  PROVIDE(__stop___libc_atexit = .);\
562                  PROVIDE(__start___libc_thread_subfreeres = .);\
563                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
564                  PROVIDE(__stop___libc_thread_subfreeres = .);\
565                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
566         test -s $@T
567         mv -f $@T $@
568 common-generated += shlib.lds
570 shlib-lds = $(common-objpfx)shlib.lds
571 shlib-lds-flags = -T $(shlib-lds)
572 endif
574 define build-shlib
575 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
576           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
577 endef
579 define build-module-helper
580 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
581           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
582           -B$(csu-objpfx) $(load-map-file) \
583           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
584           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
585 endef
587 # This macro is similar to build-shlib but it does not define a soname
588 # and it does not depend on the destination name to start with `lib'.
589 # binutils only position loadable notes into the first page for binaries,
590 # not for shared objects
591 define build-module
592 $(build-module-helper) -o $@ $(shlib-lds-flags) \
593           $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
594 $(call after-link,$@)
595 endef
596 define build-module-asneeded
597 $(build-module-helper) -o $@ $(shlib-lds-flags) \
598           $(csu-objpfx)abi-note.o \
599           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
600           $(link-libc-args)
601 $(call after-link,$@)
602 endef
604 build-module-helper-objlist = \
605         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
606                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
607                                 $(link-libc-deps),$^))
609 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
610 build-shlib-objlist = $(build-module-helper-objlist) \
611                       $(LDLIBS-$(@F:lib%.so=%).so)
613 # Don't try to use -lc when making libc.so itself.
614 # Also omits crti.o and crtn.o, which we do not want
615 # since we define our own `.init' section specially.
616 LDFLAGS-c.so = -nostdlib -nostartfiles
617 # But we still want to link libc.so against $(libc.so-gnulib).
618 LDLIBS-c.so += $(libc.so-gnulib)
619 # Give libc.so an entry point and make it directly runnable itself.
620 LDFLAGS-c.so += -e __libc_main
621 # If lazy relocation is disabled add the -z now flag.
622 ifeq ($(bind-now),yes)
623 LDFLAGS-c.so += -Wl,-z,now
624 endif
625 # Pre-link the objects of libc_pic.a so that we can locally resolve
626 # COMMON symbols before we link against ld.so.  This is because ld.so
627 # contains some of libc_pic.a already, which will prevent the COMMONs
628 # from being allocated in libc.so, which introduces evil dependencies
629 # between libc.so and ld.so, which can make it impossible to upgrade.
630 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
631         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
632         $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
634 ifeq (,$(strip $(shlib-lds-flags)))
635 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
636 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
637         $(OBJDUMP) -h $< | \
638         $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
639                 > $@T
640         mv -f $@T $@
641 # Apply those -R options.
642 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
643                                    $(common-objpfx)libc_pic.os
644         $(OBJCOPY) @$^ $@
645 generated += libc_pic.opts libc_pic.os.clean
647 libc_pic_clean := .clean
648 endif
650 # Build a possibly-modified version of libc_pic.a for use in building
651 # linkobj/libc.so.
652 ifeq (,$(filter sunrpc,$(subdirs)))
653 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
654         $(make-target-directory)
655         ln -f $< $@
656 else
657 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
658                                     $(common-objpfx)sunrpc/librpc_compat_pic.a
659         $(make-target-directory)
660         (cd $(common-objpfx)linkobj; \
661          $(AR) x ../libc_pic.a; \
662          rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
663          $(AR) x ../sunrpc/librpc_compat_pic.a; \
664          $(AR) cr libc_pic.a *.os; \
665          rm *.os)
666 endif # $(subdirs) contains sunrpc
668 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
669 # filter ld.so out of the list of linked objects.
670 $(common-objpfx)libc.so: link-libc-deps = # empty
671 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
673 # Use our own special initializer and finalizer files for the libc.so
674 # libraries.
675 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
676                          $(common-objpfx)libc_pic.os$(libc_pic_clean) \
677                          $(elf-objpfx)sofini.os \
678                          $(elf-objpfx)interp.os \
679                          $(elf-objpfx)ld.so \
680                          $(shlib-lds)
681         $(build-shlib)
682         $(call after-link,$@)
684 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
685                          $(common-objpfx)linkobj/libc_pic.a \
686                          $(elf-objpfx)sofini.os \
687                          $(elf-objpfx)interp.os \
688                          $(elf-objpfx)ld.so \
689                          $(shlib-lds)
690         $(build-shlib)
691         $(call after-link,$@)
693 ifeq ($(build-shared),yes)
694 $(common-objpfx)libc.so: $(common-objpfx)libc.map
695 endif
696 common-generated += libc.so libc_pic.os
697 ifdef libc.so-version
698 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
699         $(make-link)
700 common-generated += libc.so$(libc.so-version)
701 endif
702 endif
704 # Figure out the source filenames in this directory.
706 override sources := $(addsuffix .c,\
707                         $(filter-out $(elided-routines),\
708                             $(routines) $(aux) \
709                             $(sysdep_routines)))
710 sysdep_routines := $(sysdep_routines)
712 headers := $(headers) $(sysdep_headers)
714 # This is the list of all object files, gotten by
715 # replacing every ".c" in `sources' with a ".o".
716 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
719 # The makefile may define $(extra-libs) with `libfoo libbar'
720 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
721 ifdef extra-libs
722 # extra-lib.mk is included once for each extra lib to define rules
723 # to build it, and to add its objects to the various variables.
724 # During its evaluation, $(lib) is set to the name of the library.
725 extra-libs-left := $(extra-libs)
726 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
727 endif
730 # The makefile may define $(modules-names) to build additional modules.
731 # These are built with $(build-module), except any in $(modules-names-nobuild).
732 ifdef modules-names
733 # extra-lib.mk is included once for each extra lib to define rules
734 # to build it, and to add its objects to the various variables.
735 # During its evaluation, $(lib) is set to the name of the library.
736 extra-modules-left := $(modules-names)
737 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
739 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
740 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
741                 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
742         $(build-module)
743 endif
745 +depfiles := $(sources:.c=.d) \
746              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
747              $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
748              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
749              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
750 ifeq ($(build-programs),yes)
751 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
752 endif
753 +depfiles := $(addprefix $(objpfx),\
754                          $(filter-out $(addsuffix .d,$(omit-deps)),\
755                                       $(+depfiles)))
756 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
757 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
758              $(wildcard $(all-dt-files:.dt=.d))
760 # This is a funny rule in that it removes its input file.
761 %.d: %.dt
762         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
763          mv -f $(@:.d=.T) $@ && \
764          rm -f $<
766 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
767 # They will be generated when they're needed, and trying too early won't work.
768 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
769 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
770                                                 $(+gen-as-const)))
772 ifdef +depfiles
773 ifneq ($(no_deps),t)
774 -include $(+depfiles)
775 endif
776 endif
777 \f\f
778 # Maximize efficiency by minimizing the number of rules.
779 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
780 # Don't define any builtin rules.
781 MAKEFLAGS := $(MAKEFLAGS)r
783 # Generic rule for making directories.
785 # mkdir isn't smart enough to strip a trailing /.
786 # We always require a mkdir which supports the -p option to avoid error
787 # messages in case of races.
788         mkdir -p $(@:%/=%)
790 # Make sure that object files are not removed
791 # when they are intermediates between sources and library members.
792 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
794 # Make sure that the parent library archive is never removed.
795 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
797 # Use the verbose option of ar and tar when not running silently.
798 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
799 verbose := v
800 else                                            # -s
801 verbose :=
802 endif                                           # not -s
804 ARFLAGS := r$(verbose)
805 CREATE_ARFLAGS := cru$(verbose)
807 # This makes all the object files in the parent library archive.
809 .PHONY: lib lib-noranlib
810 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
811 lib-noranlib: libobjs
813 # For object-suffix $o, the list of objects with that suffix.
814 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
815 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
816                                                        $(elide-routines$o)),\
817                                             $(objects))) \
818             $(addprefix $(objpfx),$(o-objects$o))
820 others: $(addprefix $(objpfx),$(install-lib))
822 ifndef objects
824 # Create the stamp$o files to keep the parent makefile happy.
825 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
826 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
827         $(make-target-directory)
828         rm -f $@; > $@
829 else
831 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
832 # timestamp file; these rules (one explicit rule is generated for each
833 # object suffix) write a list of objects to update in the stamp file.
834 # The parent will then actually add them all to the archive in the
835 # archive rule, below.
836 define o-iterator-doit
837 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
838 endef
839 define do-stamp
840 $(make-target-directory)
841 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
842 mv -f $@T $@
843 endef
844 object-suffixes-left := $(object-suffixes-for-libc)
845 include $(o-iterator)
847 endif
849 # Now define explicit rules to build the library archives; these depend
850 # on the stamp files built above.
851 define o-iterator-doit
852 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
853                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
854 endef
855 define do-makelib
856 cd $(common-objdir) && \
857 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
858 endef
859 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
860 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
861 ifndef subdir
862 $(subdirs-stamps): subdir_lib;
863 endif
864 object-suffixes-left = $(object-suffixes-for-libc)
865 include $(o-iterator)
868 # This makes all the object files.
869 .PHONY: objects objs libobjs extra-objs
870 objects objs: libobjs extra-objs
871 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
872 extra-objs: $(addprefix $(objpfx),$(extra-objs))
874 # Canned sequence for building an extra library archive.
875 define build-extra-lib
876 $(patsubst %/,cd % &&,$(objpfx)) \
877 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
878       $(patsubst $(objpfx)%,%,$^)
879 endef
881 # Installation.
883 .PHONY: force-install
884 force-install:
886 # $(install-lib) are installed from the object directory into $(libdir);
887 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
888 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
889 # they are into $(datadir).  $(headers) are installed as they are in
890 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
891 # are installed from the object directory into $(bindir), $(bindir) and
892 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
893 # are absolute path names of files to install; rules to install them are
894 # defined elsewhere.
896 # The simple library name to install libc.a under.
897 # This could be defined by a sysdep Makefile.
898 ifndef libc-name
899 libc-name := c
900 endif
902 define do-install
903 $(make-target-directory)
904 $(INSTALL_DATA) $< $@
905 endef
907 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
908 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
909 define make-target-directory
910 $(addprefix $(..)./scripts/mkinstalldirs ,\
911             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
912 endef
914 # Any directory (parent or subdir) should install libc.a; this way
915 # "make install" in a subdir is guaranteed to install everything it changes.
916 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
917                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
918                                                      $(libprefix)$(libc-name)))
919 install: $(installed-libcs)
920 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
921         $(make-target-directory)
922         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
924 define do-install-program
925 $(make-target-directory)
926 $(INSTALL_PROGRAM) $< $@.new
927 mv -f $@.new $@
928 endef
930 define do-install-script
931 $(make-target-directory)
932 $(INSTALL_SCRIPT) $< $@.new
933 mv -f $@.new $@
934 endef
936 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
937 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
939 ifeq (yes,$(build-shared))
940 # Find which .so's have versions.
941 versioned := $(strip $(foreach so,$(install-lib.so),\
942                                $(patsubst %,$(so),$($(so)-version))))
944 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
945 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
947 # For versioned libraries, we install three files:
948 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
949 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
950 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
951 lib-version := $(firstword $($(subdir)-version) $(version))
952 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
953                       $(foreach L,$(install-lib.so-versioned),\
954                                 $(inst_libdir)/$L \
955                                 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
956                                 $(inst_slibdir)/$L$($L-version))
958 # Install all the unversioned shared libraries.
959 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
960     $(objpfx)%.so $(+force)
961         $(do-install-program)
963 ifneq ($(findstring -s,$(LN_S)),)
964 define make-link
965 rm -f $@.new
966 $(SHELL) $(..)scripts/rellns-sh $< $@.new
967 mv -f $@.new $@
968 endef
969 else
970 # If we have no symbolic links don't bother with rellns-sh.
971 define make-link
972 rm -f $@.new
973 $(LN_S) $< $@.new
974 mv -f $@.new $@
975 endef
976 endif
978 ifeq (yes,$(build-shared))
979 ifeq (no,$(cross-compiling))
980 symbolic-link-prog := $(elf-objpfx)sln
981 symbolic-link-list := $(elf-objpfx)symlink.list
982 define make-shlib-link
983 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
984 endef
985 else # cross-compiling
986 # We need a definition that can be used by elf/Makefile's install rules.
987 symbolic-link-prog = $(LN_S)
988 endif
989 endif
990 ifndef make-shlib-link
991 define make-shlib-link
992 rm -f $@
993 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
994 endef
995 endif
997 ifdef libc.so-version
998 # For a library specified to be version N, install three files:
999 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
1000 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
1002 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1003                                            $(+force)
1004         $(make-shlib-link)
1005 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1006         $(do-install-program)
1007 install: $(inst_slibdir)/libc.so$(libc.so-version)
1009 # This fragment of linker script gives the OUTPUT_FORMAT statement
1010 # for the configuration we are building.  We put this statement into
1011 # the linker scripts we install for -lc et al so that they will not be
1012 # used by a link for a different format on a multi-architecture system.
1013 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
1014                             $(common-objpfx)config.make \
1015                             $(common-objpfx)config.h $(..)Makerules
1016 ifneq (unknown,$(output-format))
1017         echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1018 else
1019         $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
1020                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1021         | sed -n -f $< > $@.new
1022         test -s $@.new
1023         rm -f $@.so
1024 endif
1025         mv -f $@.new $@
1026 common-generated += format.lds
1028 ifndef subdir
1029 # What we install as libc.so for programs to link against is in fact a
1030 # link script.  It contains references for the various libraries we need.
1031 # The libc.so object is not complete since some functions are only defined
1032 # in libc_nonshared.a.
1033 # We need to use absolute paths since otherwise local copies (if they exist)
1034 # of the files are taken by the linker.
1035 install: $(inst_libdir)/libc.so
1036 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1037                         $(common-objpfx)libc.so$(libc.so-version) \
1038                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1039                                                   $(libprefix)$(libc-name)) \
1040                         $(+force)
1041         (echo '/* GNU ld script';\
1042          echo '   Use the shared library, but some functions are only in';\
1043          echo '   the static library, so try that secondarily.  */';\
1044          cat $<; \
1045          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1046               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1047               ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1048         ) > $@.new
1049         mv -f $@.new $@
1051 endif
1053 else
1054 install: $(inst_slibdir)/libc.so
1055 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1056         $(do-install-program)
1057 endif
1059 ifneq (,$(versioned))
1060 # Produce three sets of rules as above for all the smaller versioned libraries.
1062 define o-iterator-doit
1063 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1064 endef
1065 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1066 ifneq (,$(object-suffixes-left))
1067 include $(o-iterator)
1068 endif
1070 # Make symlinks in the build directory, because the versioned names might
1071 # be referenced by a DT_NEEDED in another library.
1072 define o-iterator-doit
1073 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1074 endef
1075 object-suffixes-left := $(versioned)
1076 include $(o-iterator)
1078 generated += $(foreach o,$(versioned),$o$($o-version))
1080 ifeq (,$($(subdir)-version))
1081 define o-iterator-doit
1082 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1083                                  $(+force);
1084         $$(make-shlib-link)
1085 endef
1086 object-suffixes-left := $(versioned)
1087 include $(o-iterator)
1089 define o-iterator-doit
1090 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1091         $$(do-install-program)
1092 endef
1093 object-suffixes-left := $(versioned)
1094 include $(o-iterator)
1095 else
1096 define o-iterator-doit
1097 $(inst_slibdir)/$o$($o-version): \
1098   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1099         $$(make-shlib-link)
1100 endef
1101 object-suffixes-left := $(versioned)
1102 include $(o-iterator)
1104 define o-iterator-doit
1105 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1106         $$(do-install-program)
1107 endef
1108 object-suffixes-left := $(versioned)
1109 include $(o-iterator)
1110 endif
1111 endif
1113 define do-install-so
1114 $(do-install-program)
1115 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1116            $(filter-out %.so,$@))
1117 endef
1119 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1120 $(foreach v,$(so-versions),\
1121           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1122                                                $(+force)
1123         $(do-install-so)
1124 $(foreach v,$(so-versions),\
1125           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1126         $(do-install-so)
1127 endif
1129 ifdef install-bin
1130 $(addprefix $(inst_bindir)/,$(install-bin)): \
1131     $(inst_bindir)/%: $(objpfx)% $(+force)
1132         $(do-install-program)
1133 endif
1134 ifdef install-bin-script
1135 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1136     $(inst_bindir)/%: $(objpfx)% $(+force)
1137         $(do-install-script)
1138 endif
1139 ifdef install-rootsbin
1140 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1141    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1142         $(do-install-program)
1143 endif
1144 ifdef install-sbin
1145 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1146     $(inst_sbindir)/%: $(objpfx)% $(+force)
1147         $(do-install-program)
1148 endif
1149 ifdef install-lib
1150 install-lib.a := $(filter lib%.a,$(install-lib))
1151 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1152 ifdef install-lib-non.a
1153 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1154   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1155         $(do-install)
1156 endif
1157 ifdef install-lib.a
1158 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1159   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1160         $(do-install)
1161 endif
1162 endif
1163 ifdef install-data
1164 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1165         $(do-install)
1166 endif
1167 headers := $(strip $(headers))
1168 ifdef headers
1169 # This implicit rule installs headers from the source directory.
1170 # It may be ignored in preference to rules from sysd-rules to find
1171 # headers in the sysdeps tree.
1172 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1173         $(do-install)
1174 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1175         $(do-install)
1176 $(inst_includedir)/%.h: %.h $(+force)
1177         $(do-install)
1178 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1179         $(do-install)
1180 headers-nonh := $(filter-out %.h,$(headers))
1181 ifdef headers-nonh
1182 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1183                                                  % $(+force)
1184         $(do-install)
1185 endif   # headers-nonh
1186 endif   # headers
1188 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1189         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1190         install-data-nosubdir install-headers-nosubdir
1191 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1192 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1193 install-rootsbin-nosubdir: \
1194         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1195 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1196 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1197                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1198                        $(addprefix $(libprefix),$(install-lib-non.a)))
1199 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1200 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1201 install-others-nosubdir: $(install-others)
1202 install-others-programs-nosubdir: $(install-others-programs)
1204 # We need all the `-nosubdir' targets so that `install' in the parent
1205 # doesn't depend on several things which each iterate over the subdirs.
1206 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1207 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1208 install-%:: install-%-nosubdir ;
1210 .PHONY: install install-no-libc.a-nosubdir
1211 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1212                             install-lib-nosubdir install-others-nosubdir
1213 ifeq ($(build-programs),yes)
1214 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1215                             install-rootsbin-nosubdir install-sbin-nosubdir \
1216                             install-others-programs-nosubdir
1217 endif
1218 install: install-no-libc.a-nosubdir
1220 # Command to compile $< using the native libraries.
1221 define native-compile
1222 $(make-target-directory)
1223 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1224             $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1225 endef
1227 # We always want to use configuration definitions.
1228 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1229                    -DIS_IN_build -include $(common-objpfx)config.h
1231 # Support the GNU standard name for this target.
1232 .PHONY: check
1233 check: tests
1234 # Special target to run tests which cannot be run unconditionally.
1235 # Maintainers should use this target.
1236 .PHONY: xcheck
1237 xcheck: xtests
1239 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1240 ifneq (,$(all-nonlib))
1241 cpp-srcs-left = $(all-nonlib)
1242 lib := nonlib
1243 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1244 endif
1247 ifeq ($(build-shared),yes)
1248 # Generate normalized lists of symbols, versions, and data sizes.
1249 # This is handy for checking against existing library binaries.
1251 %.symlist: $(..)scripts/abilist.awk %.dynsym
1252         LC_ALL=C $(AWK) -f $^ > $@T
1253         mv -f $@T $@
1255 %.dynsym: %.so
1256         LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1257         mv -f $@T $@
1259 # A sysdeps/.../Makefile can set abilist-pattern to something like
1260 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1261 # This makes sense if multiple ABIs can be most cleanly supported by a
1262 # configuration without using separate sysdeps directories for each.
1263 ifdef abilist-pattern
1264 vpath $(abilist-pattern) $(+sysdep_dirs)
1265 endif
1267 vpath %.abilist $(+sysdep_dirs)
1269 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1270 # target pattern is %.symlist from being considered "intermediate files"
1271 # and automatically removed.  We only want these files to be removed by
1272 # 'make clean', which is handled by the 'generated' variable.
1273 .PRECIOUS: %.symlist
1274 generated += $(extra-libs:=.symlist)
1276 ifdef abilist-pattern
1277 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1278                           $(objpfx)%.symlist
1279         $(check-abi-pattern); \
1280         $(evaluate-test)
1281 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1282                           $(common-objpfx)%.symlist
1283         $(check-abi-pattern); \
1284         $(evaluate-test)
1285 endif
1286 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1287                           $(objpfx)%.symlist
1288         $(check-abi); \
1289         $(evaluate-test)
1290 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1291                           $(common-objpfx)%.symlist
1292         $(check-abi); \
1293         $(evaluate-test)
1294 define check-abi-pattern
1295         diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1296              > $@
1297 endef
1298 define check-abi
1299         diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1300 endef
1302 ifdef abilist-pattern
1303 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1304         $(update-abi-pattern)
1305 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1306         $(update-abi-pattern)
1307 endif
1308 update-abi-%: $(objpfx)%.symlist %.abilist
1309         $(update-abi)
1310 update-abi-%: $(common-objpfx)%.symlist %.abilist
1311         $(update-abi)
1312 define update-abi-pattern
1313 @if cmp -s $^ 2> /dev/null; \
1314  then \
1315       echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1316  else cp -f $^; \
1317       echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1318  fi
1319 endef
1320 define update-abi
1321 @if cmp -s $^ 2> /dev/null; \
1322  then \
1323       echo '+++ $(filter %.abilist,$^) is unchanged'; \
1324  else cp -f $^; \
1325       echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1326  fi
1327 endef
1329 .PHONY: update-abi check-abi
1330 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1331 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1332                                  $(install-lib.so-versioned))
1333 check-abi: $(check-abi-list)
1334 ifdef subdir
1335 subdir_check-abi: check-abi
1336 subdir_update-abi: update-abi
1337 else
1338 check-abi: subdir_check-abi
1339         if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1340                 cat $(objpfx)*/check-abi*.out && exit 1; fi
1341 update-abi: subdir_update-abi
1342 endif
1344 ifeq ($(subdir),elf)
1345 check-abi: $(objpfx)check-abi-libc.out
1346 tests-special += $(objpfx)check-abi-libc.out
1347 update-abi: update-abi-libc
1348 common-generated += libc.symlist
1349 endif
1351 ifeq ($(build-shared),yes)
1352 ifdef subdir
1353 tests-special += $(check-abi-list)
1354 endif
1355 endif
1357 endif
1359 # These will have been set by sysdeps/posix/Makefile.
1360 L_tmpnam  ?= 1
1361 TMP_MAX   ?= 0
1362 L_ctermid ?= 1
1363 L_cuserid ?= 1
1365 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1367 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1368 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1369                    $(common-objpfx)config.make
1370         $(make-target-directory)
1371         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1372           echo '#define _LIBC 1';                                       \
1373           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1374         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1375               $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1376         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1377             $(@:st=dT) > $(@:st=dt)
1378         mv -f $(@:st=dt) $(@:st=d)
1379         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1380         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1381         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1382         fopen_max=$${fopen_max:-16};                                    \
1383         filename_max=$${filename_max:-1024};                            \
1384         if [ -z "$$iov_max" ]; then                                     \
1385           define_iov_max="# undef IOV_MAX";                             \
1386         else                                                            \
1387           define_iov_max="# define IOV_MAX $$iov_max";                  \
1388         fi;                                                             \
1389         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1390             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1391             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1392             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1393             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1394             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1395             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1396             $< > $(@:st=h.new)
1397         $(move-if-change) $(@:st=h.new) $(@:st=h)
1398 # Remove these last so that they can be examined if something went wrong.
1399         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1400         touch $@
1401 # Get dependencies.
1402 ifndef no_deps
1403 -include $(stdio_lim:h=d)
1404 endif
1405 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1407 FORCE:
1409 .PHONY: echo-headers
1410 echo-headers:
1411         @echo $(headers)
1413 %.bz2: %; bzip2 -9vk $<
1414 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1415 %.xz: %; xz -9evk $<
1417 # Common cleaning targets.
1419 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1420 clean: common-clean
1421 mostlyclean: common-mostlyclean
1423 do-tests-clean:
1424         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1425                                                       $(test-srcs)) \
1426                                      $(addsuffix .test-result,$(tests) \
1427                                                               $(xtests) \
1428                                                               $(test-srcs)))
1430 # Remove the object files.
1431 common-mostlyclean:
1432         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1433                                      $(others) $(sysdep-others) stubs \
1434                                      $(addsuffix .o,$(tests) $(xtests) \
1435                                                     $(test-srcs) $(others) \
1436                                                     $(sysdep-others)) \
1437                                      $(addsuffix .out,$(tests) $(xtests) \
1438                                                       $(test-srcs)) \
1439                                      $(addsuffix .test-result,$(tests) \
1440                                                               $(xtests) \
1441                                                               $(test-srcs)))
1442         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1443                                      $(install-lib) $(install-lib.so) \
1444                                      $(install-lib.so:%.so=%_pic.a))
1445         -rm -f core
1446         -rm -f $(objpfx)rtld-*.os
1447         $(rmobjs)
1448 define rmobjs
1449 $(foreach o,$(object-suffixes-for-libc),
1450 -rm -f $(objpfx)stamp$o $(o-objects))
1451 endef
1453 # Also remove the dependencies and generated source files.
1454 common-clean: common-mostlyclean
1455         -rm -f $(addprefix $(objpfx),$(generated))
1456         -rm -f $(objpfx)*.d $(objpfx)*.dt
1457         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1458         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1459         -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1461 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1462 # for each function which is a stub.
1464 ifdef objpfx
1465 .PHONY: stubs # The parent Makefile calls this target.
1466 stubs: $(objpfx)stubs
1467 endif
1468 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1469                   $(addprefix $(objpfx),$(extra-objs))
1470 $(objpfx)stubs: $(objs-for-stubs)
1471 ifneq (,$(strip $(objs-for-stubs)))
1472         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1473         $(AWK) '/\.gnu\.glibc-stub\./ { \
1474                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1475                   stubs[$$2] = 1; } \
1476                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1477         mv -f $@T $@
1478 else
1479         > $@
1480 endif
1482 ifneq (,$(strip $(gpl2lgpl)))
1483 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1484 # Snarf from the master source and frob the copying notice.
1485 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1486         sed -f $^ > $@-tmp
1487 # So I don't edit them by mistake.
1488         chmod a-w $@-tmp
1489         mv -f $@-tmp $@
1490 endif
1491 endif
1493 # Local Variables:
1494 # mode: makefile
1495 # End: