Fix ARM NAN fraction bits.
[glibc.git] / Makerules
blobc2324366df5a8d4e66e7b87248f2f614d335bcb0
1 # Copyright (C) 1991-2014 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) -v oldest_abi=$(oldest-abi) -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 # Generate an ordered list of implicit rules which find the source files in
215 # each sysdep directory.  The old method was to use vpath to search all the
216 # sysdep directories.  However, that had the problem that a .S file in a
217 # later directory would be chosen over a .c file in an earlier directory,
218 # which does not preserve the desired sysdeps ordering behavior.
220 # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
221 # matching sysdep directories whose assembly source files should be
222 # suppressed.
224 -include $(common-objpfx)sysd-rules
225 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
226 # The value of $(+sysdep_dirs) the sysd-rules was computed for
227 # differs from the one we are using now.  So force a rebuild of sysd-rules.
228 sysd-rules-force = FORCE
229 FORCE:
230 endif
231 $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
232                             $(common-objpfx)config.make $(..)Makerules \
233                             $(sysdep-makefiles) $(sysdep-makeconfigs) \
234                             $(sysd-rules-force)
235         -@rm -f $@T
236         LC_ALL=C $(AWK) -f $< > $@T \
237                         -v all_object_suffixes='$(all-object-suffixes)' \
238                         -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
239                         -v sysd_rules_patterns='$(sysd-rules-patterns)' \
240                         -v config_sysdirs='$(config-sysdirs)'
241         mv -f $@T $@
243 ifndef sysd-rules-done
244 # Don't do deps until this exists, because it provides rules to make the deps.
245 no_deps=t
246 endif
248 define o-iterator-doit
249 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
250 endef
251 object-suffixes-left := $(all-object-suffixes)
252 include $(o-iterator)
254 define o-iterator-doit
255 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
256 endef
257 object-suffixes-left := $(all-object-suffixes)
258 include $(o-iterator)
260 define o-iterator-doit
261 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
262 endef
263 object-suffixes-left := $(all-object-suffixes)
264 include $(o-iterator)
266 # Omit the objpfx rules when building in the source tree, because
267 # objpfx is empty and so these rules just override the ones above.
268 ifdef objpfx
269 # Define first rules to find the source files in $(objpfx).
270 # Generated source files will end up there.
271 define o-iterator-doit
272 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
273 endef
274 object-suffixes-left := $(all-object-suffixes)
275 include $(o-iterator)
277 define o-iterator-doit
278 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
279 endef
280 object-suffixes-left := $(all-object-suffixes)
281 include $(o-iterator)
282 endif
284 # Generate version maps, but wait until sysdep-subdirs is known
285 ifeq ($(sysd-sorted-done),t)
286 ifeq ($(build-shared),yes)
287 -include $(common-objpfx)sysd-versions
288 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
289 common-generated += $(version-maps)
290 postclean-generated += sysd-versions Versions.all abi-versions.h \
291                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
293 ifndef avoid-generated
294 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
295 sysd-versions-force = FORCE
296 FORCE:
297 endif
298 # See %.v/%.v.i implicit rules in Makeconfig.
299 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
300                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
301 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
302                               $(common-objpfx)soversions.i \
303                               $(common-objpfx)Versions.def.v
304         { while read which lib version setname; do \
305             test x"$$which" = xDEFAULT || continue; \
306             test -z "$$setname" || echo "$$lib : $$setname"; \
307           done < $(word 2,$^); \
308           cat $(word 3,$^); \
309         } | LC_ALL=C $(AWK) -f $< > $@T
310         mv -f $@T $@
311 # See %.v/%.v.i implicit rules in Makeconfig.
312 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
313                               $(wildcard $(sysdirs:%=%/Versions)) \
314                               $(sysd-versions-force)
315 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
316                                $(common-objpfx)Versions.v \
317                                $(..)scripts/versions.awk
318         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
319           cat $(word 2,$^) \
320           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
321                             -v move_if_change='$(move-if-change)' \
322                             -f $(word 3,$^); \
323         ) > $@T
324         mv -f $@T $@
325 endif # avoid-generated
326 endif # $(build-shared) = yes
327 endif # sysd-sorted-done
329 # Generate .dT files as we compile.
330 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
331 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
332 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
333 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
335 # Like compile-mkdep-flags, but for use with $(BUILD_CC).  We don't want to
336 # track system includes here, they may spuriously trigger an install rule,
337 # and would cause the check-local-headers test to fail.
338 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
340 # GCC can grok options after the file name, and it looks nicer that way.
341 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
342 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
343 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
344                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
345 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
346 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
347                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
349 # We need this for the output to go in the right place.  It will default to
350 # empty if make was configured to work with a cc that can't grok -c and -o
351 # together.  You can't compile the C library with such a compiler.
352 OUTPUT_OPTION = -o $@
354 # This is the end of the pipeline for compiling generated C code.
355 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
357 # We need the $(CFLAGS) to be in there to have the right predefines during
358 # the dependency run for C sources.  But having it for assembly sources can
359 # get the wrong predefines.
360 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
362 define +make-deps
363 $(make-target-directory)
364 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
365              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
366 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
367 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
368 mv -f $(@:.d=.T) $@ $(generate-md5)
369 endef
371 ifneq (,$(objpfx))
372 # Continuation lines here are dangerous because they introduce spaces!
373 define sed-remove-objpfx
374 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
375 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
376 endef
377 endif
379 # Modify the list of routines we build for different targets
381 ifeq (yes,$(build-shared))
382 ifndef libc.so-version
383 # Undefine this because it can't work when we libc.so is unversioned.
384 static-only-routines =
385 endif
386 endif
388 elide-routines.oS += $(filter-out $(static-only-routines),\
389                                   $(routines) $(aux) $(sysdep_routines))
390 elide-routines.os += $(static-only-routines)
392 # If we have versioned code we don't need the old versions in any of the
393 # static libraries.
394 elide-routines.o  += $(shared-only-routines)
395 elide-routines.op += $(shared-only-routines)
396 elide-routines.og += $(shared-only-routines)
398 # Shared library building.
400 ifeq (yes,$(build-shared))
402 # Reference map file only when shared libraries are built and a map file name
403 # is given.
404 ifeq ($(build-shared),yes)
405 map-file = $(firstword $($(@F:.so=-map)) \
406                        $(addprefix $(common-objpfx), \
407                                    $(filter $(@F:.so=.map),$(version-maps))))
408 load-map-file = $(map-file:%=-Wl,--version-script=%)
409 endif
411 # Compiler arguments to use to link a shared object with libc and
412 # ld.so.  This is intended to be as similar as possible to a default
413 # link with an installed libc.
414 link-libc-args = -Wl,--start-group \
415                  $(libc-for-link) \
416                  $(common-objpfx)libc_nonshared.a \
417                  $(as-needed) $(elfobjdir)/ld.so $(no-as-needed) \
418                  -Wl,--end-group
420 # The corresponding shared libc to use.  This may be modified for a
421 # particular target.
422 libc-for-link = $(common-objpfx)libc.so
424 # The corresponding dependencies.  As these are used in dependencies,
425 # not just commands, they cannot use target-specific variables so need
426 # to name both possible libc.so objects.
427 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
428                  $(common-objpfx)libc_nonshared.a $(elfobjdir)/ld.so
430 # Pattern rule to build a shared object from an archive of PIC objects.
431 # This must come after the installation rules so Make doesn't try to
432 # build shared libraries in place from the installed *_pic.a files.
433 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
434 # on other shared objects.  The linking with libc and ld.so is intended
435 # to be as similar as possible to a default link with an installed libc.
436 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp) $(link-libc-deps)
437         $(build-shlib) $(link-libc-args)
439 define build-shlib-helper
440 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
441           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
442           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
443           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
444           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
445           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
446           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
447 endef
449 ifeq (yes,$(use-default-link))
450 # If the linker is good enough, we can let it use its default linker script.
451 shlib-lds =
452 shlib-lds-flags =
453 else
454 # binutils only position loadable notes into the first page for binaries,
455 # not for shared objects
456 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
457         $(LINK.o) -shared -Wl,-O1 \
458                   -nostdlib -nostartfiles \
459                   $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
460                   -Wl,--verbose 2>&1 | \
461           sed > $@T \
462               -e '/^=========/,/^=========/!d;/^=========/d' \
463               $(if $(filter yes,$(have-hash-style)), \
464                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
465                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
466                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
467                 , \
468                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
469                ) \
470               -e 's/^.*\*(\.dynbss).*$$/& \
471                  PROVIDE(__start___libc_freeres_ptrs = .); \
472                  *(__libc_freeres_ptrs) \
473                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
474               -e 's@^.*\*(\.jcr).*$$@& \
475                  PROVIDE(__start___libc_subfreeres = .);\
476                  __libc_subfreeres : { *(__libc_subfreeres) }\
477                  PROVIDE(__stop___libc_subfreeres = .);\
478                  PROVIDE(__start___libc_atexit = .);\
479                  __libc_atexit : { *(__libc_atexit) }\
480                  PROVIDE(__stop___libc_atexit = .);\
481                  PROVIDE(__start___libc_thread_subfreeres = .);\
482                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
483                  PROVIDE(__stop___libc_thread_subfreeres = .);\
484                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
485         test -s $@T
486         mv -f $@T $@
487 common-generated += shlib.lds
489 shlib-lds = $(common-objpfx)shlib.lds
490 shlib-lds-flags = -T $(shlib-lds)
491 endif
493 define build-shlib
494 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
495           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
496 endef
498 define build-module-helper
499 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
500           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
501           -B$(csu-objpfx) $(load-map-file) \
502           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
503           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
504 endef
506 # This macro is similar to build-shlib but it does not define a soname
507 # and it does not depend on the destination name to start with `lib'.
508 # binutils only position loadable notes into the first page for binaries,
509 # not for shared objects
510 define build-module
511 $(build-module-helper) -o $@ $(shlib-lds-flags) \
512           $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
513 endef
514 define build-module-asneeded
515 $(build-module-helper) -o $@ $(shlib-lds-flags) \
516           $(csu-objpfx)abi-note.o \
517           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
518           $(link-libc-args)
519 endef
521 build-module-helper-objlist = \
522         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
523                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
524                                 $(link-libc-deps),$^))
526 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
527 build-shlib-objlist = $(build-module-helper-objlist) \
528                       $(LDLIBS-$(@F:lib%.so=%).so)
530 # Don't try to use -lc when making libc.so itself.
531 # Also omits crti.o and crtn.o, which we do not want
532 # since we define our own `.init' section specially.
533 LDFLAGS-c.so = -nostdlib -nostartfiles
534 # But we still want to link libc.so against $(libc.so-gnulib).
535 LDLIBS-c.so += $(libc.so-gnulib)
536 # Give libc.so an entry point and make it directly runnable itself.
537 LDFLAGS-c.so += -e __libc_main
538 # If lazy relocation is disabled add the -z now flag.
539 ifeq ($(bind-now),yes)
540 LDFLAGS-c.so += -Wl,-z,now
541 endif
542 # Pre-link the objects of libc_pic.a so that we can locally resolve
543 # COMMON symbols before we link against ld.so.  This is because ld.so
544 # contains some of libc_pic.a already, which will prevent the COMMONs
545 # from being allocated in libc.so, which introduces evil dependencies
546 # between libc.so and ld.so, which can make it impossible to upgrade.
547 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
548         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
549         $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
551 ifeq (,$(strip $(shlib-lds-flags)))
552 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
553 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
554         $(OBJDUMP) -h $< | \
555         $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
556                 > $@T
557         mv -f $@T $@
558 # Apply those -R options.
559 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
560                                    $(common-objpfx)libc_pic.os
561         $(OBJCOPY) @$^ $@
562 generated += libc_pic.opts libc_pic.os.clean
564 libc_pic_clean := .clean
565 endif
567 # Build a possibly-modified version of libc_pic.a for use in building
568 # linkobj/libc.so.
569 ifeq (,$(filter sunrpc,$(subdirs)))
570 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
571         $(make-target-directory)
572         ln -f $< $@
573 else
574 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
575                                     $(common-objpfx)sunrpc/librpc_compat_pic.a
576         $(make-target-directory)
577         (cd $(common-objpfx)linkobj; \
578          $(AR) x ../libc_pic.a; \
579          rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
580          $(AR) x ../sunrpc/librpc_compat_pic.a; \
581          $(AR) cr libc_pic.a *.os; \
582          rm *.os)
583 endif # $(subdirs) contains sunrpc
585 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
586 # filter ld.so out of the list of linked objects.
587 $(common-objpfx)libc.so: link-libc-deps = # empty
588 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
590 # Use our own special initializer and finalizer files for the libc.so
591 # libraries.
592 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
593                          $(common-objpfx)libc_pic.os$(libc_pic_clean) \
594                          $(elfobjdir)/sofini.os \
595                          $(elfobjdir)/interp.os \
596                          $(elfobjdir)/ld.so \
597                          $(shlib-lds)
598         $(build-shlib)
600 $(common-objpfx)linkobj/libc.so: $(elfobjdir)/soinit.os \
601                          $(common-objpfx)linkobj/libc_pic.a \
602                          $(elfobjdir)/sofini.os \
603                          $(elfobjdir)/interp.os \
604                          $(elfobjdir)/ld.so \
605                          $(shlib-lds)
606         $(build-shlib)
608 ifeq ($(build-shared),yes)
609 $(common-objpfx)libc.so: $(common-objpfx)libc.map
610 endif
611 common-generated += libc.so libc_pic.os
612 ifdef libc.so-version
613 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
614         $(make-link)
615 common-generated += libc.so$(libc.so-version)
616 endif
617 endif
619 # Figure out the source filenames in this directory.
621 override sources := $(addsuffix .c,\
622                         $(filter-out $(elided-routines),\
623                             $(routines) $(aux) \
624                             $(sysdep_routines)))
625 sysdep_routines := $(sysdep_routines)
627 headers := $(headers) $(sysdep_headers)
629 # This is the list of all object files, gotten by
630 # replacing every ".c" in `sources' with a ".o".
631 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
634 # The makefile may define $(extra-libs) with `libfoo libbar'
635 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
636 ifdef extra-libs
637 # extra-lib.mk is included once for each extra lib to define rules
638 # to build it, and to add its objects to the various variables.
639 # During its evaluation, $(lib) is set to the name of the library.
640 extra-libs-left := $(extra-libs)
641 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
642 endif
645 # The makefile may define $(modules-names) to build additional modules.
646 # These are built with $(build-module), except any in $(modules-names-nobuild).
647 ifdef modules-names
648 # extra-lib.mk is included once for each extra lib to define rules
649 # to build it, and to add its objects to the various variables.
650 # During its evaluation, $(lib) is set to the name of the library.
651 extra-modules-left := $(modules-names)
652 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
654 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
655 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
656                 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
657         $(build-module)
658 endif
660 +depfiles := $(sources:.c=.d) \
661              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
662              $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
663              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
664              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
665 ifeq ($(build-programs),yes)
666 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
667 endif
668 +depfiles := $(addprefix $(objpfx),\
669                          $(filter-out $(addsuffix .d,$(omit-deps)),\
670                                       $(+depfiles)))
671 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
672 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
673              $(wildcard $(all-dt-files:.dt=.d))
675 # This is a funny rule in that it removes its input file.
676 %.d: %.dt
677         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
678          mv -f $(@:.d=.T) $@ && \
679          rm -f $<
681 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
682 # They will be generated when they're needed, and trying too early won't work.
683 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
684 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
685                                                 $(+gen-as-const)))
687 ifdef +depfiles
688 ifneq ($(no_deps),t)
689 -include $(+depfiles)
690 endif
691 endif
692 \f\f
693 # Maximize efficiency by minimizing the number of rules.
694 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
695 # Don't define any builtin rules.
696 MAKEFLAGS := $(MAKEFLAGS)r
698 # Generic rule for making directories.
700 # mkdir isn't smart enough to strip a trailing /.
701 # We always require a mkdir which supports the -p option to avoid error
702 # messages in case of races.
703         mkdir -p $(@:%/=%)
705 # Make sure that object files are not removed
706 # when they are intermediates between sources and library members.
707 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
709 # Make sure that the parent library archive is never removed.
710 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
712 # Use the verbose option of ar and tar when not running silently.
713 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
714 verbose := v
715 else                                            # -s
716 verbose :=
717 endif                                           # not -s
719 ARFLAGS := r$(verbose)
720 CREATE_ARFLAGS := cru$(verbose)
722 # This makes all the object files in the parent library archive.
724 .PHONY: lib lib-noranlib
725 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
726 lib-noranlib: libobjs
728 # For object-suffix $o, the list of objects with that suffix.
729 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
730 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
731                                                        $(elide-routines$o)),\
732                                             $(objects))) \
733             $(addprefix $(objpfx),$(o-objects$o))
735 others: $(addprefix $(objpfx),$(install-lib))
737 ifndef objects
739 # Create the stamp$o files to keep the parent makefile happy.
740 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
741 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
742         $(make-target-directory)
743         rm -f $@; > $@
744 else
746 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
747 # timestamp file; these rules (one explicit rule is generated for each
748 # object suffix) write a list of objects to update in the stamp file.
749 # The parent will then actually add them all to the archive in the
750 # archive rule, below.
751 define o-iterator-doit
752 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
753 endef
754 define do-stamp
755 $(make-target-directory)
756 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
757 mv -f $@T $@
758 endef
759 object-suffixes-left := $(object-suffixes-for-libc)
760 include $(o-iterator)
762 endif
764 # Now define explicit rules to build the library archives; these depend
765 # on the stamp files built above.
766 define o-iterator-doit
767 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
768                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
769 endef
770 define do-makelib
771 cd $(common-objdir) && \
772 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
773 endef
774 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
775 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
776 ifndef subdir
777 $(subdirs-stamps): subdir_lib;
778 endif
779 object-suffixes-left = $(object-suffixes-for-libc)
780 include $(o-iterator)
783 # This makes all the object files.
784 .PHONY: objects objs libobjs extra-objs
785 objects objs: libobjs extra-objs
786 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
787 extra-objs: $(addprefix $(objpfx),$(extra-objs))
789 # Canned sequence for building an extra library archive.
790 define build-extra-lib
791 $(patsubst %/,cd % &&,$(objpfx)) \
792 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
793       $(patsubst $(objpfx)%,%,$^)
794 endef
796 # Installation.
798 .PHONY: force-install
799 force-install:
801 # $(install-lib) are installed from the object directory into $(libdir);
802 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
803 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
804 # they are into $(datadir).  $(headers) are installed as they are in
805 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
806 # are installed from the object directory into $(bindir), $(bindir) and
807 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
808 # are absolute path names of files to install; rules to install them are
809 # defined elsewhere.
811 # The simple library name to install libc.a under.
812 # This could be defined by a sysdep Makefile.
813 ifndef libc-name
814 libc-name := c
815 endif
817 define do-install
818 $(make-target-directory)
819 $(INSTALL_DATA) $< $@
820 endef
822 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
823 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
824 define make-target-directory
825 $(addprefix $(..)./scripts/mkinstalldirs ,\
826             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
827 endef
829 # Any directory (parent or subdir) should install libc.a; this way
830 # "make install" in a subdir is guaranteed to install everything it changes.
831 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
832                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
833                                                      $(libprefix)$(libc-name)))
834 install: $(installed-libcs)
835 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
836         $(make-target-directory)
837         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
839 define do-install-program
840 $(make-target-directory)
841 $(INSTALL_PROGRAM) $< $@.new
842 mv -f $@.new $@
843 endef
845 define do-install-script
846 $(make-target-directory)
847 $(INSTALL_SCRIPT) $< $@.new
848 mv -f $@.new $@
849 endef
851 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
852 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
854 ifeq (yes,$(build-shared))
855 # Find which .so's have versions.
856 versioned := $(strip $(foreach so,$(install-lib.so),\
857                                $(patsubst %,$(so),$($(so)-version))))
859 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
860 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
862 # For versioned libraries, we install three files:
863 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
864 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
865 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
866 lib-version := $(firstword $($(subdir)-version) $(version))
867 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
868                       $(foreach L,$(install-lib.so-versioned),\
869                                 $(inst_libdir)/$L \
870                                 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
871                                 $(inst_slibdir)/$L$($L-version))
873 # Install all the unversioned shared libraries.
874 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
875     $(objpfx)%.so $(+force)
876         $(do-install-program)
878 ifneq ($(findstring -s,$(LN_S)),)
879 define make-link
880 rm -f $@.new
881 $(SHELL) $(..)scripts/rellns-sh $< $@.new
882 mv -f $@.new $@
883 endef
884 else
885 # If we have no symbolic links don't bother with rellns-sh.
886 define make-link
887 rm -f $@.new
888 $(LN_S) $< $@.new
889 mv -f $@.new $@
890 endef
891 endif
893 ifeq (yes,$(build-shared))
894 ifeq (no,$(cross-compiling))
895 symbolic-link-prog := $(common-objpfx)elf/sln
896 symbolic-link-list := $(common-objpfx)elf/symlink.list
897 define make-shlib-link
898 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
899 endef
900 else # cross-compiling
901 # We need a definition that can be used by elf/Makefile's install rules.
902 symbolic-link-prog = $(LN_S)
903 endif
904 endif
905 ifndef make-shlib-link
906 define make-shlib-link
907 rm -f $@
908 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
909 endef
910 endif
912 ifdef libc.so-version
913 # For a library specified to be version N, install three files:
914 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
915 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
917 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
918                                            $(+force)
919         $(make-shlib-link)
920 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
921         $(do-install-program)
922 install: $(inst_slibdir)/libc.so$(libc.so-version)
924 # This fragment of linker script gives the OUTPUT_FORMAT statement
925 # for the configuration we are building.  We put this statement into
926 # the linker scripts we install for -lc et al so that they will not be
927 # used by a link for a different format on a multi-architecture system.
928 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
929                             $(common-objpfx)config.make \
930                             $(common-objpfx)config.h $(..)Makerules
931 ifneq (unknown,$(output-format))
932         echo > $@.new 'OUTPUT_FORMAT($(output-format))'
933 else
934         $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
935                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
936         | sed -n -f $< > $@.new
937         test -s $@.new
938         rm -f $@.so
939 endif
940         mv -f $@.new $@
941 common-generated += format.lds
943 ifndef subdir
944 # What we install as libc.so for programs to link against is in fact a
945 # link script.  It contains references for the various libraries we need.
946 # The libc.so object is not complete since some functions are only defined
947 # in libc_nonshared.a.
948 # We need to use absolute paths since otherwise local copies (if they exist)
949 # of the files are taken by the linker.
950 install: $(inst_libdir)/libc.so
951 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
952                         $(common-objpfx)libc.so$(libc.so-version) \
953                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
954                                                   $(libprefix)$(libc-name)) \
955                         $(+force)
956         (echo '/* GNU ld script';\
957          echo '   Use the shared library, but some functions are only in';\
958          echo '   the static library, so try that secondarily.  */';\
959          cat $<; \
960          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
961               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
962               ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
963         ) > $@.new
964         mv -f $@.new $@
966 endif
968 else
969 install: $(inst_slibdir)/libc.so
970 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
971         $(do-install-program)
972 endif
974 ifneq (,$(versioned))
975 # Produce three sets of rules as above for all the smaller versioned libraries.
977 define o-iterator-doit
978 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
979 endef
980 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
981 ifneq (,$(object-suffixes-left))
982 include $(o-iterator)
983 endif
985 # Make symlinks in the build directory, because the versioned names might
986 # be referenced by a DT_NEEDED in another library.
987 define o-iterator-doit
988 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
989 endef
990 object-suffixes-left := $(versioned)
991 include $(o-iterator)
993 generated += $(foreach o,$(versioned),$o$($o-version))
995 ifeq (,$($(subdir)-version))
996 define o-iterator-doit
997 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
998                                  $(+force);
999         $$(make-shlib-link)
1000 endef
1001 object-suffixes-left := $(versioned)
1002 include $(o-iterator)
1004 define o-iterator-doit
1005 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1006         $$(do-install-program)
1007 endef
1008 object-suffixes-left := $(versioned)
1009 include $(o-iterator)
1010 else
1011 define o-iterator-doit
1012 $(inst_slibdir)/$o$($o-version): \
1013   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1014         $$(make-shlib-link)
1015 endef
1016 object-suffixes-left := $(versioned)
1017 include $(o-iterator)
1019 define o-iterator-doit
1020 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1021         $$(do-install-program)
1022 endef
1023 object-suffixes-left := $(versioned)
1024 include $(o-iterator)
1025 endif
1026 endif
1028 define do-install-so
1029 $(do-install-program)
1030 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1031            $(filter-out %.so,$@))
1032 endef
1034 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1035 $(foreach v,$(so-versions),\
1036           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1037                                                $(+force)
1038         $(do-install-so)
1039 $(foreach v,$(so-versions),\
1040           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1041         $(do-install-so)
1042 endif
1044 ifdef install-bin
1045 $(addprefix $(inst_bindir)/,$(install-bin)): \
1046     $(inst_bindir)/%: $(objpfx)% $(+force)
1047         $(do-install-program)
1048 endif
1049 ifdef install-bin-script
1050 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1051     $(inst_bindir)/%: $(objpfx)% $(+force)
1052         $(do-install-script)
1053 endif
1054 ifdef install-rootsbin
1055 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1056    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1057         $(do-install-program)
1058 endif
1059 ifdef install-sbin
1060 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1061     $(inst_sbindir)/%: $(objpfx)% $(+force)
1062         $(do-install-program)
1063 endif
1064 ifdef install-lib
1065 install-lib.a := $(filter lib%.a,$(install-lib))
1066 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1067 ifdef install-lib-non.a
1068 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1069   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1070         $(do-install)
1071 endif
1072 ifdef install-lib.a
1073 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1074   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1075         $(do-install)
1076 endif
1077 endif
1078 ifdef install-data
1079 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1080         $(do-install)
1081 endif
1082 headers := $(strip $(headers))
1083 ifdef headers
1084 # This implicit rule installs headers from the source directory.
1085 # It may be ignored in preference to rules from sysd-rules to find
1086 # headers in the sysdeps tree.
1087 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1088         $(do-install)
1089 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1090         $(do-install)
1091 $(inst_includedir)/%.h: %.h $(+force)
1092         $(do-install)
1093 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1094         $(do-install)
1095 headers-nonh := $(filter-out %.h,$(headers))
1096 ifdef headers-nonh
1097 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1098                                                  % $(+force)
1099         $(do-install)
1100 endif   # headers-nonh
1101 endif   # headers
1103 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1104         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1105         install-data-nosubdir install-headers-nosubdir
1106 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1107 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1108 install-rootsbin-nosubdir: \
1109         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1110 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1111 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1112                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1113                        $(addprefix $(libprefix),$(install-lib-non.a)))
1114 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1115 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1116 install-others-nosubdir: $(install-others)
1117 install-others-programs-nosubdir: $(install-others-programs)
1119 # We need all the `-nosubdir' targets so that `install' in the parent
1120 # doesn't depend on several things which each iterate over the subdirs.
1121 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1122 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1123 install-%:: install-%-nosubdir ;
1125 .PHONY: install install-no-libc.a-nosubdir
1126 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1127                             install-lib-nosubdir install-others-nosubdir
1128 ifeq ($(build-programs),yes)
1129 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1130                             install-rootsbin-nosubdir install-sbin-nosubdir \
1131                             install-others-programs-nosubdir
1132 endif
1133 install: install-no-libc.a-nosubdir
1135 # Command to compile $< using the native libraries.
1136 define native-compile
1137 $(make-target-directory)
1138 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1139             $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1140 endef
1142 # We always want to use configuration definitions.
1143 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1144                    -DIS_IN_build -include $(common-objpfx)config.h
1146 # Support the GNU standard name for this target.
1147 .PHONY: check
1148 check: tests
1149 # Special target to run tests which cannot be run unconditionally.
1150 # Maintainers should use this target.
1151 .PHONY: xcheck
1152 xcheck: xtests
1154 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1155 ifneq (,$(all-nonlib))
1156 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1157 lib := nonlib
1158 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1159 endif
1161 # The include magic above causes those files to use this variable for flags.
1162 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1165 ifeq ($(build-shared),yes)
1166 # Generate normalized lists of symbols, versions, and data sizes.
1167 # This is handy for checking against existing library binaries.
1169 %.symlist: $(..)scripts/abilist.awk %.dynsym
1170         LC_ALL=C $(AWK) -f $^ > $@T
1171         mv -f $@T $@
1173 %.dynsym: %.so
1174         LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1175         mv -f $@T $@
1177 # A sysdeps/.../Makefile can set abilist-pattern to something like
1178 # %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
1179 # This makes sense if multiple ABIs can be most cleanly supported by a
1180 # configuration without using separate sysdeps directories for each.
1181 ifdef abilist-pattern
1182 vpath $(abilist-pattern) $(+sysdep_dirs)
1183 endif
1185 vpath %.abilist $(+sysdep_dirs)
1187 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1188 # target pattern is %.symlist from being considered "intermediate files"
1189 # and automatically removed.  We only want these files to be removed by
1190 # 'make clean', which is handled by the 'generated' variable.
1191 .PRECIOUS: %.symlist
1192 generated += $(extra-libs:=.symlist)
1194 ifdef abilist-pattern
1195 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1196                           $(objpfx)%.symlist
1197         $(check-abi-pattern); \
1198         $(evaluate-test)
1199 $(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
1200                           $(common-objpfx)%.symlist
1201         $(check-abi-pattern); \
1202         $(evaluate-test)
1203 endif
1204 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1205                           $(objpfx)%.symlist
1206         $(check-abi); \
1207         $(evaluate-test)
1208 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1209                           $(common-objpfx)%.symlist
1210         $(check-abi); \
1211         $(evaluate-test)
1212 define check-abi-pattern
1213         diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
1214              > $@
1215 endef
1216 define check-abi
1217         diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1218 endef
1220 ifdef abilist-pattern
1221 update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
1222         $(update-abi-pattern)
1223 update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
1224         $(update-abi-pattern)
1225 endif
1226 update-abi-%: $(objpfx)%.symlist %.abilist
1227         $(update-abi)
1228 update-abi-%: $(common-objpfx)%.symlist %.abilist
1229         $(update-abi)
1230 define update-abi-pattern
1231 @if cmp -s $^ 2> /dev/null; \
1232  then \
1233       echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
1234  else cp -f $^; \
1235       echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
1236  fi
1237 endef
1238 define update-abi
1239 @if cmp -s $^ 2> /dev/null; \
1240  then \
1241       echo '+++ $(filter %.abilist,$^) is unchanged'; \
1242  else cp -f $^; \
1243       echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1244  fi
1245 endef
1247 .PHONY: update-abi check-abi
1248 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1249 check-abi: $(patsubst %.so,$(objpfx)check-abi-%.out,$(install-lib.so-versioned))
1250 ifdef subdir
1251 subdir_check-abi: check-abi
1252 subdir_update-abi: update-abi
1253 else
1254 check-abi: subdir_check-abi
1255 update-abi: subdir_update-abi
1256 endif
1258 ifeq ($(subdir),elf)
1259 check-abi: $(objpfx)check-abi-libc.out
1260 update-abi: update-abi-libc
1261 common-generated += libc.symlist
1262 endif
1264 ifeq ($(build-shared),yes)
1265 ifdef subdir
1266 tests: check-abi
1267 endif
1268 endif
1270 endif
1272 # These will have been set by sysdeps/posix/Makefile.
1273 L_tmpnam  ?= 1
1274 TMP_MAX   ?= 0
1275 L_ctermid ?= 1
1276 L_cuserid ?= 1
1278 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1280 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1281 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1282                    $(common-objpfx)config.make
1283         $(make-target-directory)
1284         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1285           echo '#define _LIBC 1';                                       \
1286           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1287         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1288               $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1289         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1290             $(@:st=dT) > $(@:st=dt)
1291         mv -f $(@:st=dt) $(@:st=d)
1292         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1293         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1294         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1295         fopen_max=$${fopen_max:-16};                                    \
1296         filename_max=$${filename_max:-1024};                            \
1297         if [ -z "$$iov_max" ]; then                                     \
1298           define_iov_max="# undef IOV_MAX";                             \
1299         else                                                            \
1300           define_iov_max="# define IOV_MAX $$iov_max";                  \
1301         fi;                                                             \
1302         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1303             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1304             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1305             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1306             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1307             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1308             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1309             $< > $(@:st=h.new)
1310         $(move-if-change) $(@:st=h.new) $(@:st=h)
1311 # Remove these last so that they can be examined if something went wrong.
1312         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1313         touch $@
1314 # Get dependencies.
1315 ifndef no_deps
1316 -include $(stdio_lim:h=d)
1317 endif
1318 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1320 FORCE:
1322 .PHONY: echo-headers
1323 echo-headers:
1324         @echo $(headers)
1326 %.bz2: %; bzip2 -9vk $<
1327 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1328 %.xz: %; xz -9evk $<
1330 # Common cleaning targets.
1332 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1333 clean: common-clean
1334 mostlyclean: common-mostlyclean
1336 do-tests-clean:
1337         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1338                                                       $(test-srcs)) \
1339                                      $(addsuffix .test-result,$(tests) \
1340                                                               $(xtests) \
1341                                                               $(test-srcs)))
1343 # Remove the object files.
1344 common-mostlyclean:
1345         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1346                                      $(others) $(sysdep-others) stubs \
1347                                      $(addsuffix .o,$(tests) $(xtests) \
1348                                                     $(test-srcs) $(others) \
1349                                                     $(sysdep-others)) \
1350                                      $(addsuffix .out,$(tests) $(xtests) \
1351                                                       $(test-srcs)) \
1352                                      $(addsuffix .test-result,$(tests) \
1353                                                               $(xtests) \
1354                                                               $(test-srcs)))
1355         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1356                                      $(install-lib) $(install-lib.so) \
1357                                      $(install-lib.so:%.so=%_pic.a))
1358         -rm -f core
1359         -rm -f $(objpfx)rtld-*.os
1360         $(rmobjs)
1361 define rmobjs
1362 $(foreach o,$(object-suffixes-for-libc),
1363 -rm -f $(objpfx)stamp$o $(o-objects))
1364 endef
1366 # Also remove the dependencies and generated source files.
1367 common-clean: common-mostlyclean
1368         -rm -f $(addprefix $(objpfx),$(generated))
1369         -rm -f $(objpfx)*.d $(objpfx)*.dt
1370         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1371         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1372         -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1374 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1375 # for each function which is a stub.
1377 ifdef objpfx
1378 .PHONY: stubs # The parent Makefile calls this target.
1379 stubs: $(objpfx)stubs
1380 endif
1381 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1382                   $(addprefix $(objpfx),$(extra-objs))
1383 $(objpfx)stubs: $(objs-for-stubs)
1384 ifneq (,$(strip $(objs-for-stubs)))
1385         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1386         $(AWK) '/\.gnu\.glibc-stub\./ { \
1387                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1388                   stubs[$$2] = 1; } \
1389                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1390         mv -f $@T $@
1391 else
1392         > $@
1393 endif
1395 ifneq (,$(strip $(gpl2lgpl)))
1396 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1397 # Snarf from the master source and frob the copying notice.
1398 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1399         sed -f $^ > $@-tmp
1400 # So I don't edit them by mistake.
1401         chmod a-w $@-tmp
1402         mv -f $@-tmp $@
1403 endif
1404 endif
1406 # Local Variables:
1407 # mode: makefile
1408 # End: