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