* sysdeps/unix/sysv/linux/alpha/fpu/Implies: New file.
[glibc.git] / Makerules
bloba96a03eee413568753af02e22375499bc114d0f4
1 # Copyright (C) 1991-2002,2003,2004,2005,2006 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, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 # 02111-1307 USA.
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version.  See above for the version needed.
34 endif
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq   "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full_config_sysdirs))
62 +sysdir_pfx = $(common-objpfx)
64 export sysdirs := $(sysdirs)
66 +sysdep_dirs := $(full_config_sysdirs)
67 ifdef objdir
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
69 endif
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
75 # This variable is used in ``include $(o-iterator)'' after defining
76 # $(o-iterator-doit) to produce some desired rule using $o for the object
77 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78 # is produced for each object suffix in use.
79 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
81 # Include any system-specific makefiles.
83 # This is here so things in sysdep Makefiles can easily depend on foo.h as
84 # appropriate and not worry about where foo.h comes from, which may be
85 # system dependent and not known by that Makefile.
86 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87                                       $(+sysdep_dirs) $(..)))
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91                                       $(+sysdep_dirs) $(..)))
93 # Some sysdep makefiles use this to distinguish being included here from
94 # being included individually by a subdir makefile (hurd/Makefile needs this).
95 in-Makerules := yes
97 sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98 ifneq (,$(sysdep-makefiles))
99 include $(sysdep-makefiles)
100 endif
103 # Reorder before-compile so that mach things come first, and hurd things
104 # second, before all else.  The mach and hurd subdirectories have many
105 # generated header files which the much of rest of the library depends on,
106 # so it is best to build them first (and mach before hurd, at that).
107 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
108                            $(before-compile)) \
109                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
110                                $(before-compile))
112 # Even before that, we need abi-versions.h which is generated right here.
113 ifeq ($(versioning),yes)
114 ifndef avoid-generated
115 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
116 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
117                                 $(common-objpfx)Versions.all
118         LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
119         mv -f $@T $@
121 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
122         sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
123             $(common-objpfx)abi-versions.h > $@T
124         mv -f $@T $@
125 endif # avoid-generated
126 endif # $(versioning) = yes
128 # Make sure the subdirectory for object files gets created.
129 ifdef objpfx
130 ifeq (,$(wildcard $(objpfx).))
131 before-compile += $(objpfx).
132 $(objpfx).:
133         $(make-target-directory)
134 endif
135 endif
137 # Remove existing files from `before-compile'.  Things are added there when
138 # they must exist for dependency generation to work right, but once they
139 # exist there is no further need for every single file to depend on them,
140 # and those gratuitous dependencies result in many gratuitous
141 # recompilations.
142 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
144 # Don't let any before-compile file be an intermediate and get removed.
145 ifdef before-compile
146 $(before-compile):
147 endif
149 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
150 # in subdirs.
151 ifdef subdir
152 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
153 else
154 common-before-compile = $(before-compile)
155 endif
157 ifndef subdir
158 # If a makefile needs to do something conditional on something that
159 # can only be figured out from headers, write a FOO.make.c input
160 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
161 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
163 # We only generate these in the top-level makefile, to avoid any weirdness
164 # from subdir-specific makefile tweaks creeping in on an update.
165 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
166         rm -f $@T $@.dT
167         (echo '# Generated from $*.make.c by Makerules.'; \
168          $(CC) $(CFLAGS) $(CPPFLAGS) -E $< \
169                -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
170          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
171          echo 'common-generated += $(@F)'; \
172          sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
173          rm -f $@.dT) > $@T
174         mv -f $@T $@
175 endif
177 ifdef subdir
178 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g' \
179                      -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
180 else
181 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g' \
182                      -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
183 endif
186 ifdef gen-as-const-headers
187 # Generating headers for assembly constants.
188 # We need this defined early to get into before-compile before
189 # it's used in sysd-rules, below.
190 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
191                                            %.sym $(common-before-compile)
192         $(AWK) -f $< $(filter %.sym,$^) \
193         | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
194                 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
195         sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
196                 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
197         rm -f $(@:.h.d=.h)T3
198         sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
199             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
200         rm -f $(@:.h=.h.d)T
201         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
202         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
203 vpath %.sym $(sysdirs)
204 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
206 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
207 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
208 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
209                             %.sym $(common-objpfx)%.h
210         ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
211          $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
212          echo '#include "$(..)test-skeleton.c"') > $@T
213         mv -f $@T $@
214 endif
216 # Generate an ordered list of implicit rules which find the source files in
217 # each sysdep directory.  The old method was to use vpath to search all the
218 # sysdep directories.  However, that had the problem that a .S file in a
219 # later directory would be chosen over a .c file in an earlier directory,
220 # which does not preserve the desired sysdeps ordering behavior.
222 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
223 # patterns matching sysdep directories whose assembly source files should
224 # be suppressed.
225 ifdef inhibit-sysdep-asm
226 define open-check-inhibit-asm
227 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
228 endef
229 close-check-inhibit-asm = ;; esac ;
230 endif
232 -include $(+sysdir_pfx)sysd-rules
233 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
234 # The value of $(+sysdep_dirs) the sysd-rules was computed for
235 # differs from the one we are using now.  So force a rebuild of sysd-rules.
236 sysd-rules-force = FORCE
237 FORCE:
238 endif
239 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
240                           $(wildcard $(foreach dir,$(sysdirs),\
241                                                $(dir)/Makefile))\
242                           $(sysd-rules-force)
243         -@rm -f $@T
244         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
245          for dir in $(config-sysdirs:%='$$(..)%'); do                         \
246            for o in $(all-object-suffixes); do \
247              $(open-check-inhibit-asm) \
248              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
249                   \$$(compile-command.S)";                                    \
250              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
251                   \$$(compile-command.s)";                                    \
252              echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
253                   \$$(compile-command.S)";                                    \
254              echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
255                   \$$(compile-command.s)";                                    \
256              echo "\$$(objpfx)ptw-%$$o: $$dir/%.S \$$(before-compile); \
257                   \$$(compile-command.S)";                                    \
258              echo "\$$(objpfx)ptw-%$$o: $$dir/%.s \$$(before-compile); \
259                   \$$(compile-command.s)";                                    \
260              echo "\$$(objpfx)m_%$$o: $$dir/s_%.S \$$(before-compile); \
261                   \$$(compile-command.S)";                                    \
262              echo "\$$(objpfx)m_%$$o: $$dir/s_%.s \$$(before-compile); \
263                   \$$(compile-command.s)";                                    \
264              $(close-check-inhibit-asm) \
265              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
266                   \$$(compile-command.c)";                                    \
267              echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
268                   \$$(compile-command.c)";                                    \
269              echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
270                   \$$(compile-command.c)";                                    \
271              echo "\$$(objpfx)m_%$$o: $$dir/s_%.c \$$(before-compile); \
272                   \$$(compile-command.c)";                                    \
273            done; \
274            echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force); \
275                         \$$(do-install)";                                     \
276          done;                                                                \
277          echo 'sysd-rules-done = t') > $@T
278         mv -f $@T $@
280 ifndef sysd-rules-done
281 # Don't do deps until this exists, because it provides rules to make the deps.
282 no_deps=t
283 endif
285 define o-iterator-doit
286 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
287 endef
288 object-suffixes-left := $(all-object-suffixes)
289 include $(o-iterator)
291 define o-iterator-doit
292 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
293 endef
294 object-suffixes-left := $(all-object-suffixes)
295 include $(o-iterator)
297 define o-iterator-doit
298 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
299 endef
300 object-suffixes-left := $(all-object-suffixes)
301 include $(o-iterator)
303 define o-iterator-doit
304 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
305 endef
306 object-suffixes-left := $(all-object-suffixes)
307 include $(o-iterator)
309 # Omit the objpfx rules when building in the source tree, because
310 # objpfx is empty and so these rules just override the ones above.
311 ifdef objpfx
312 # Define first rules to find the source files in $(objpfx).
313 # Generated source files will end up there.
314 define o-iterator-doit
315 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
316 endef
317 object-suffixes-left := $(all-object-suffixes)
318 include $(o-iterator)
320 define o-iterator-doit
321 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
322 endef
323 object-suffixes-left := $(all-object-suffixes)
324 include $(o-iterator)
326 define o-iterator-doit
327 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
328 endef
329 object-suffixes-left := $(all-object-suffixes)
330 include $(o-iterator)
331 endif
333 # Generate version maps, but wait until sysdep-subdirs is known
334 ifeq ($(sysd-sorted-done),t)
335 ifeq ($(versioning),yes)
336 -include $(common-objpfx)sysd-versions
337 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
338 common-generated += $(version-maps)
339 postclean-generated += sysd-versions Versions.all abi-versions.h \
340                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
342 ifndef avoid-generated
343 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
344 sysd-versions-force = FORCE
345 FORCE:
346 endif
347 # See %.v/%.v.i implicit rules in Makeconfig.
348 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
349                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
350 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
351                               $(common-objpfx)soversions.i \
352                               $(common-objpfx)Versions.def.v
353         { while read which lib version setname; do \
354             test x"$$which" = xDEFAULT || continue; \
355             test -z "$$setname" || echo "$$lib : $$setname"; \
356           done < $(word 2,$^); \
357           cat $(word 3,$^); \
358         } | LC_ALL=C $(AWK) -f $< > $@T
359         mv -f $@T $@
360 # See %.v/%.v.i implicit rules in Makeconfig.
361 $(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
362                               $(wildcard $(sysdirs:%=%/Versions)) \
363                               $(common-objpfx)abi-versions.h \
364                               $(sysd-versions-force)
365 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
366                                $(common-objpfx)Versions.v \
367                                $(..)scripts/versions.awk
368         ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
369           cat $(word 2,$^) \
370           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
371                             -v move_if_change='$(move-if-change)' \
372                             -f $(word 3,$^); \
373         ) > $@T
374         mv -f $@T $@
375 endif # avoid-generated
376 endif # $(versioning) = yes
377 endif # sysd-sorted-done
379 # Generate .dT files as we compile.
380 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
381 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
382 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
383 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
384 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
386 # GCC can grok options after the file name, and it looks nicer that way.
387 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
388 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
389 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
390                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
391 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
392                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
393 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
395 # We need this for the output to go in the right place.  It will default to
396 # empty if make was configured to work with a cc that can't grok -c and -o
397 # together.  You can't compile the C library with such a compiler.
398 OUTPUT_OPTION = -o $@
400 # We need the $(CFLAGS) to be in there to have the right predefines during
401 # the dependency run for C sources.  But having it for assembly sources can
402 # get the wrong predefines.
403 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
405 define +make-deps
406 $(make-target-directory)
407 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
408              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
409 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
410 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
411 mv -f $(@:.d=.T) $@ $(generate-md5)
412 endef
414 ifneq (,$(objpfx))
415 # Continuation lines here are dangerous because they introduce spaces!
416 define sed-remove-objpfx
417 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
418 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
419 endef
420 endif
422 # Modify the list of routines we build for different targets
424 ifeq (yesyes,$(build-shared)$(elf))
425 ifndef libc.so-version
426 # Undefine this because it can't work when we libc.so is unversioned.
427 static-only-routines =
428 endif
429 endif
431 # Bounded pointer thunks are only built for *.ob
432 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
434 elide-routines.oS += $(filter-out $(static-only-routines),\
435                                   $(routines) $(aux) $(sysdep_routines)) \
436                      $(elide-bp-thunks)
437 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
439 # If we have versioned code we don't need the old versions in any of the
440 # static libraries.
441 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
442 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
443 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
444 elide-routines.ob += $(shared-only-routines)
446 # Shared library building.
448 ifeq (yes,$(build-shared))
450 # Reference map file only when versioning is selected and a map file name
451 # is given.
452 ifeq ($(versioning),yes)
453 map-file = $(firstword $($(@F:.so=-map)) \
454                        $(addprefix $(common-objpfx), \
455                                    $(filter $(@F:.so=.map),$(version-maps))))
456 load-map-file = $(map-file:%=-Wl,--version-script=%)
457 endif
459 # Pattern rule to build a shared object from an archive of PIC objects.
460 # This must come after the installation rules so Make doesn't try to
461 # build shared libraries in place from the installed *_pic.a files.
462 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
463 # on other shared objects.
464 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
465 ifneq (,$(findstring aix,$(config-os)))
466         (echo '#!'; \
467          dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
468 endif
469         $(build-shlib)
471 ifeq ($(elf),yes)
472 define build-shlib-helper
473 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
474           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
475           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
476           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
477           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
478           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
479           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
480 endef
481 else
482 ifneq (,$(findstring aix,$(config-os)))
483 define build-shlib-helper
484 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
485           $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
486           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
487           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
488           -L$(subst :, -L,$(rpath-link))
489 endef
490 else
491 endif
492 endif
494 ifeq (yes,$(elf))
495 # binutils only position loadable notes into the first page for binaries,
496 # not for shared objects
497 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
498         $(LINK.o) -shared -Wl,-O1 \
499                   -nostdlib -nostartfiles \
500                   $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
501                   -Wl,--verbose 2>&1 | \
502           sed > $@T \
503               -e '/^=========/,/^=========/!d;/^=========/d' \
504               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
505               -e 's/^.*\*(\.dynbss).*$$/& \
506                  PROVIDE(__start___libc_freeres_ptrs = .); \
507                  *(__libc_freeres_ptrs) \
508                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
509               -e 's@^.*\*(\.jcr).*$$@& \
510                  PROVIDE(__start___libc_subfreeres = .);\
511                  __libc_subfreeres : { *(__libc_subfreeres) }\
512                  PROVIDE(__stop___libc_subfreeres = .);\
513                  PROVIDE(__start___libc_atexit = .);\
514                  __libc_atexit : { *(__libc_atexit) }\
515                  PROVIDE(__stop___libc_atexit = .);\
516                  PROVIDE(__start___libc_thread_subfreeres = .);\
517                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
518                  PROVIDE(__stop___libc_thread_subfreeres = .);\
519                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
520         mv -f $@T $@
521 common-generated += shlib.lds
523 define build-shlib
524 $(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
525           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
526 endef
527 else
528 ifneq (,$(findstring aix,$(config-os)))
529 define build-shlib
530 $(build-shlib-helper) \
531         -o $@ \
532         $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
533         $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
534 endef
535 define build-shlib
536 $(build-shlib-helper) \
537           $(build-shlib-objlist)
538 endef
539 endif
540 endif
542 ifneq (,$(findstring aix,$(config-os)))
543 define build-module-helper
544 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
545           $(sysdep-LDFLAGS) $(config-LDFLAGS) \
546           $(load-map-file) \
547           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
548           -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
549 endef
550 else
551 define build-module-helper
552 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
553           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
554           -B$(csu-objpfx) $(load-map-file) \
555           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
556           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
557 endef
558 endif
560 # This macro is similar to build-shlib but it does not define a soname
561 # and it does not depend on the destination name to start with `lib'.
562 ifeq (yes,$(elf))
563 # binutils only position loadable notes into the first page for binaries,
564 # not for shared objects
565 define build-module
566 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
567           $(csu-objpfx)abi-note.o $(build-module-objlist)
568 endef
569 define build-module-asneeded
570 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
571           $(csu-objpfx)abi-note.o \
572           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
573 endef
574 else
575 ifneq (,$(findstring aix,$(config-os)))
576 define build-module
577 $(build-module-helper) \
578           -o $@ \
579           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
580           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
581 endef
582 else
583 define build-module
584 define build-module
585 $(build-module-helper) \
586           -o $@ \
587           $(build-module-objlist)
588 endef
589 endif
590 endif
592 build-module-helper-objlist = \
593         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
594                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
595 whole-archive := -Wl,--whole-archive
597 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
598 build-shlib-objlist = $(build-module-helper-objlist) \
599                       $(LDLIBS-$(@F:lib%.so=%).so)
601 # Don't try to use -lc when making libc.so itself.
602 # Also omits crti.o and crtn.o, which we do not want
603 # since we define our own `.init' section specially.
604 LDFLAGS-c.so = -nostdlib -nostartfiles
605 # But we still want to link libc.so against $(libc.so-gnulib).
606 LDLIBS-c.so += $(libc.so-gnulib)
607 # Give libc.so an entry point and make it directly runnable itself.
608 LDFLAGS-c.so += -e __libc_main
609 # If lazy relocation is disabled add the -z now flag.
610 ifeq ($(bind-now),yes)
611 LDFLAGS-c.so += -Wl,-z,now
612 endif
613 # Pre-link the objects of libc_pic.a so that we can locally resolve
614 # COMMON symbols before we link against ld.so.  This is because ld.so
615 # contains some of libc_pic.a already, which will prevent the COMMONs
616 # from being allocated in libc.so, which introduces evil dependencies
617 # between libc.so and ld.so, which can make it impossible to upgrade.
618 ifeq ($(elf),yes)
619 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
620         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
621         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
622 # Use our own special initializer and finalizer files for libc.so.
623 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
624                          $(common-objpfx)libc_pic.os \
625                          $(elfobjdir)/sofini.os \
626                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
627                          $(common-objpfx)shlib.lds
628         $(build-shlib)
629 ifeq ($(versioning),yes)
630 $(common-objpfx)libc.so: $(common-objpfx)libc.map
631 endif
632 common-generated += libc.so libc_pic.os
633 ifdef libc.so-version
634 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
635         $(make-link)
636 common-generated += libc.so$(libc.so-version)
637 endif
638 endif
639 else
640 ifneq (,$(findstring aix,$(config-os)))
641 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
642         @rm -f $@
643         (echo '#!'; \
644          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
645         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
646             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
647         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
648                   -bE:$(common-objpfx)syscalls.exp \
649                   -bI:$(common-objpfx)syscalls.exp \
650                   -L$(common-objpfx) -o $@ $^
651 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
652         cp $@ $(common-objpfx)shr.o
653         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
654 endif
655 endif
657 # Figure out the source filenames in this directory.
659 override sources := $(addsuffix .c,\
660                         $(filter-out $(elided-routines),\
661                             $(routines) $(aux) \
662                             $(sysdep_routines)))
663 sysdep_routines := $(sysdep_routines)
665 headers := $(headers) $(sysdep_headers)
667 # This is the list of all object files, gotten by
668 # replacing every ".c" in `sources' with a ".o".
669 # We also add bounded-pointer thunks, which are later
670 # elided for all suffixes except for `.ob'.
671 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
672                       $(patsubst %,$(bppfx)%.o,\
673                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
676 # The makefile may define $(extra-libs) with `libfoo libbar'
677 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
678 ifdef extra-libs
679 # extra-lib.mk is included once for each extra lib to define rules
680 # to build it, and to add its objects to the various variables.
681 # During its evaluation, $(lib) is set to the name of the library.
682 extra-libs-left := $(extra-libs)
683 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
684 endif
687 # The makefile may define $(modules-names) to build additional modules.
688 # These are built with $(build-module), except any in $(modules-names-nobuild).
689 ifdef modules-names
690 # extra-lib.mk is included once for each extra lib to define rules
691 # to build it, and to add its objects to the various variables.
692 # During its evaluation, $(lib) is set to the name of the library.
693 extra-modules-left := $(modules-names)
694 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
696 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
697 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
698                 $(objpfx)%.os $(common-objpfx)shlib.lds \
699                 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
700         $(build-module)
701 endif
703 +depfiles := $(sources:.c=.d) \
704              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
705              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
706 ifeq ($(build-programs),yes)
707 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
708 endif
709 +depfiles := $(addprefix $(objpfx),\
710                          $(filter-out $(addsuffix .d,$(omit-deps)),\
711                                       $(+depfiles)))
712 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
713 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
714              $(wildcard $(all-dt-files:.dt=.d))
716 # This is a funny rule in that it removes its input file.
717 %.d: %.dt
718         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
719          mv -f $(@:.d=.T) $@ && \
720          rm -f $<
722 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
723 # They will be generated when they're needed, and trying too early won't work.
724 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
725 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
726                                                 $(+gen-as-const)))
728 ifdef +depfiles
729 ifneq ($(no_deps),t)
730 -include $(+depfiles)
731 endif
732 endif
733 \f\f
734 # Maximize efficiency by minimizing the number of rules.
735 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
736 # Don't define any builtin rules.
737 MAKEFLAGS := $(MAKEFLAGS)r
739 # Generic rule for making directories.
741 # mkdir isn't smart enough to strip a trailing /.
742         mkdir $(@:%/=%)
744 # Make sure that object files are not removed
745 # when they are intermediates between sources and library members.
746 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
748 # Make sure that the parent library archive is never removed.
749 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
751 # Use the verbose option of ar and tar when not running silently.
752 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
753 verbose := v
754 else                                            # -s
755 verbose :=
756 endif                                           # not -s
758 ARFLAGS := r$(verbose)
759 CREATE_ARFLAGS := cru$(verbose)
761 # This makes all the object files in the parent library archive.
763 .PHONY: lib lib-noranlib
764 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
765 lib-noranlib: libobjs
767 # For object-suffix $o, the list of objects with that suffix.
768 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
769 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
770                                                        $(elide-routines$o)),\
771                                             $(objects))) \
772             $(addprefix $(objpfx),$(o-objects$o))
774 others: $(addprefix $(objpfx),$(install-lib))
776 ifndef objects
778 # Create the stamp$o files to keep the parent makefile happy.
779 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
780 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
781         $(make-target-directory)
782         rm -f $@; > $@
783 else
785 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
786 # timestamp file; these rules (one explicit rule is generated for each
787 # object suffix) write a list of objects to update in the stamp file.
788 # The parent will then actually add them all to the archive in the
789 # archive rule, below.
790 define o-iterator-doit
791 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
792 endef
793 define do-stamp
794 $(make-target-directory)
795 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
796 mv -f $@T $@
797 endef
798 object-suffixes-left := $(object-suffixes-for-libc)
799 include $(o-iterator)
801 endif
803 # Now define explicit rules to build the library archives; these depend
804 # on the stamp files built above.
805 define o-iterator-doit
806 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
807                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
808 endef
809 define do-makelib
810 cd $(common-objdir) && \
811 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
812 $(RANLIB) $@
813 endef
814 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
815 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
816 ifndef subdir
817 $(subdirs-stamps): subdir_lib;
818 endif
819 object-suffixes-left = $(object-suffixes-for-libc)
820 include $(o-iterator)
823 # This makes all the object files.
824 .PHONY: objects objs libobjs extra-objs
825 objects objs: libobjs extra-objs
826 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
827 extra-objs: $(addprefix $(objpfx),$(extra-objs))
829 # Canned sequence for building an extra library archive.
830 define build-extra-lib
831 $(patsubst %/,cd % &&,$(objpfx)) \
832 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
833       $(patsubst $(objpfx)%,%,$^)
834 $(RANLIB) $@
835 endef
837 # Installation.
839 .PHONY: force-install
840 force-install:
842 # $(install-lib) are installed from the object directory into $(libdir);
843 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
844 # unless they also appear in $(non-lib.a).  $(install-data) are installed
845 # as they are into $(datadir).  $(headers) are installed as they are in
846 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
847 # are installed from the object directory into $(bindir), $(bindir) and
848 # $(sbindir), respectively.  $(install-others) are absolute path names of
849 # files to install; rules to install them are defined elsewhere.
851 # The simple library name to install libc.a under.
852 # This could be defined by a sysdep Makefile.
853 ifndef libc-name
854 libc-name := c
855 endif
857 define do-install
858 $(make-target-directory)
859 $(INSTALL_DATA) $< $@
860 endef
862 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
863 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
864 define make-target-directory
865 $(addprefix $(..)./scripts/mkinstalldirs ,\
866             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
867 endef
869 # Any directory (parent or subdir) should install libc.a; this way
870 # "make install" in a subdir is guaranteed to install everything it changes.
871 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
872                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
873                                                      $(libprefix)$(libc-name)))
874 install: $(installed-libcs)
875 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
876         $(make-target-directory)
877         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
878 # Running ranlib after installing makes the __.SYMDEF time stamp up to
879 # date, which avoids messages from some linkers.
880         $(RANLIB) $@
882 define do-install-program
883 $(make-target-directory)
884 $(INSTALL_PROGRAM) $< $@.new
885 mv -f $@.new $@
886 endef
888 define do-install-script
889 $(make-target-directory)
890 $(INSTALL_SCRIPT) $< $@.new
891 mv -f $@.new $@
892 endef
894 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
895 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
897 ifeq (yes,$(build-shared))
898 # Find which .so's have versions.
899 versioned := $(strip $(foreach so,$(install-lib.so),\
900                                $(patsubst %,$(so),$($(so)-version))))
902 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
903 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
905 # For versioned libraries, we install three files:
906 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
907 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
908 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
909 V := $(firstword $($(subdir)-version) $(version))
910 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
911                       $(foreach L,$(install-lib.so-versioned),\
912                                 $(inst_libdir)/$L \
913                                 $(inst_slibdir)/$(L:.so=)-$V.so \
914                                 $(inst_slibdir)/$L$($L-version))
916 # Install all the unversioned shared libraries.
917 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
918     $(objpfx)%.so $(+force)
919         $(do-install-program)
921 ifneq ($(findstring -s,$(LN_S)),)
922 define make-link
923 rm -f $@.new
924 $(SHELL) $(..)scripts/rellns-sh $< $@.new
925 mv -f $@.new $@
926 endef
927 else
928 # If we have no symbolic links don't bother with rellns-sh.
929 define make-link
930 rm -f $@.new
931 $(LN_S) $< $@.new
932 mv -f $@.new $@
933 endef
934 endif
936 ifeq (yes,$(build-shared))
937 ifeq (no,$(cross-compiling))
938 symbolic-link-prog := $(common-objpfx)elf/sln
939 symbolic-link-list := $(common-objpfx)elf/symlink.list
940 define make-shlib-link
941 echo $(<F) $@ >> $(symbolic-link-list)
942 endef
943 else # cross-compiling
944 # We need a definition that can be used by elf/Makefile's install rules.
945 symbolic-link-prog = $(LN_S)
946 endif
947 endif
948 ifndef make-shlib-link
949 define make-shlib-link
950 rm -f $@
951 $(LN_S) $(<F) $@
952 endef
953 endif
955 ifdef libc.so-version
956 # For a library specified to be version N, install three files:
957 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
958 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
960 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
961                                            $(+force)
962         $(make-shlib-link)
963 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
964         $(do-install-program)
965 install: $(inst_slibdir)/libc.so$(libc.so-version)
967 # This fragment of linker script gives the OUTPUT_FORMAT statement
968 # for the configuration we are building.  We put this statement into
969 # the linker scripts we install for -lc et al so that they will not be
970 # used by a link for a different format on a multi-architecture system.
971 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
972                             $(common-objpfx)config.make \
973                             $(common-objpfx)config.h $(..)Makerules
974         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
975                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
976         | sed -n -f $< > $@.new
977         rm -f $@.so
978         mv -f $@.new $@
979 common-generated += format.lds
981 ifndef subdir
982 # What we install as libc.so for programs to link against is in fact a
983 # link script.  It contains references for the various libraries we need.
984 # The libc.so object is not complete since some functions are only defined
985 # in libc_nonshared.a.
986 # We need to use absolute paths since otherwise local copies (if they exist)
987 # of the files are taken by the linker.
988 install: $(inst_libdir)/libc.so
989 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
990                         $(common-objpfx)libc.so$(libc.so-version) \
991                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
992                                                   $(libprefix)$(libc-name)) \
993                         $(+force)
994         (echo '/* GNU ld script';\
995          echo '   Use the shared library, but some functions are only in';\
996          echo '   the static library, so try that secondarily.  */';\
997          cat $<; \
998          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
999               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1000               ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1001         ) > $@.new
1002         mv -f $@.new $@
1004 endif
1006 else
1007 install: $(inst_slibdir)/libc.so
1008 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1009         $(do-install-program)
1010 endif
1012 ifneq (,$(versioned))
1013 # Produce three sets of rules as above for all the smaller versioned libraries.
1015 define o-iterator-doit
1016 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1017 endef
1018 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1019 ifneq (,$(object-suffixes-left))
1020 include $(o-iterator)
1021 endif
1023 # Make symlinks in the build directory, because the versioned names might
1024 # be referenced by a DT_NEEDED in another library.
1025 define o-iterator-doit
1026 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1027 endef
1028 object-suffixes-left := $(versioned)
1029 include $(o-iterator)
1031 generated += $(foreach o,$(versioned),$o$($o-version))
1033 ifeq (,$($(subdir)-version))
1034 define o-iterator-doit
1035 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1036                                  $(+force);
1037         $$(make-shlib-link)
1038 endef
1039 object-suffixes-left := $(versioned)
1040 include $(o-iterator)
1042 define o-iterator-doit
1043 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1044         $$(do-install-program)
1045 endef
1046 object-suffixes-left := $(versioned)
1047 include $(o-iterator)
1048 else
1049 define o-iterator-doit
1050 $(inst_slibdir)/$o$($o-version): \
1051   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1052         $$(make-shlib-link)
1053 endef
1054 object-suffixes-left := $(versioned)
1055 include $(o-iterator)
1057 define o-iterator-doit
1058 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1059         $$(do-install-program)
1060 endef
1061 object-suffixes-left := $(versioned)
1062 include $(o-iterator)
1063 endif
1064 endif
1066 define do-install-so
1067 $(do-install-program)
1068 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1069            $(filter-out %.so,$@))
1070 endef
1072 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1073 $(foreach v,$(so-versions),\
1074           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1075                                                $(+force)
1076         $(do-install-so)
1077 $(foreach v,$(so-versions),\
1078           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1079         $(do-install-so)
1080 endif
1082 ifdef install-bin
1083 $(addprefix $(inst_bindir)/,$(install-bin)): \
1084     $(inst_bindir)/%: $(objpfx)% $(+force)
1085         $(do-install-program)
1086 endif
1087 ifdef install-bin-script
1088 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1089     $(inst_bindir)/%: $(objpfx)% $(+force)
1090         $(do-install-script)
1091 endif
1092 ifdef install-rootsbin
1093 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1094    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1095         $(do-install-program)
1096 endif
1097 ifdef install-sbin
1098 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1099     $(inst_sbindir)/%: $(objpfx)% $(+force)
1100         $(do-install-program)
1101 endif
1102 ifdef install-lib
1103 install-lib.a := $(filter lib%.a,$(install-lib))
1104 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1105 ifdef install-lib-non.a
1106 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1107   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1108         $(do-install)
1109 endif
1110 ifdef install-lib.a
1111 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1112   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1113         $(do-install)
1114         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1115 endif
1116 endif
1117 ifdef install-data
1118 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1119         $(do-install)
1120 endif
1121 headers := $(strip $(headers))
1122 ifdef headers
1123 # This implicit rule installs headers from the source directory.
1124 # It may be ignored in preference to rules from sysd-rules to find
1125 # headers in the sysdeps tree.
1126 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1127         $(do-install)
1128 $(inst_includedir)/%.h: %.h $(+force)
1129         $(do-install)
1130 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1131         $(do-install)
1132 headers-nonh := $(filter-out %.h,$(headers))
1133 ifdef headers-nonh
1134 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1135                                                  % $(+force)
1136         $(do-install)
1137 endif   # headers-nonh
1138 endif   # headers
1140 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1141         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1142         install-data-nosubdir install-headers-nosubdir
1143 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1144 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1145 install-rootsbin-nosubdir: \
1146         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1147 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1148 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1149                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1150                        $(addprefix $(libprefix),$(install-lib-non.a)))
1151 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1152 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1153 install-others-nosubdir: $(install-others)
1155 # We need all the `-nosubdir' targets so that `install' in the parent
1156 # doesn't depend on several things which each iterate over the subdirs.
1157 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1158 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1159 install-%:: install-%-nosubdir ;
1161 .PHONY: install install-no-libc.a-nosubdir
1162 ifeq ($(build-programs),yes)
1163 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1164                             install-bin-nosubdir install-bin-script-nosubdir \
1165                             install-lib-nosubdir install-others-nosubdir \
1166                             install-rootsbin-nosubdir install-sbin-nosubdir
1167 else
1168 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1169                             install-lib-nosubdir install-others-nosubdir
1170 endif
1171 install: install-no-libc.a-nosubdir
1173 # Command to compile $< in $(objdir) using the native libraries.
1174 define native-compile
1175 $(make-target-directory)
1176 $(patsubst %/,cd % &&,$(objpfx)) \
1177 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1178             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1179 endef
1181 # Command to compile $< in $(common-objdir) using the native libraries.
1182 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1183 define common-objdir-compile
1184 $(patsubst %/,cd % &&,$(objpfx)) \
1185 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1186             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1187 endef
1189 # We always want to use configuration definitions.
1190 # Note that this is only used for commands running in $(objpfx).
1191 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1193 # Support the GNU standard name for this target.
1194 .PHONY: check
1195 check: tests
1196 # Special target to run tests which cannot be run unconditionally.
1197 # Maintainers should use this target.
1198 .PHONY: xcheck
1199 xcheck: xtests
1201 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1202 ifneq (,$(all-nonlib))
1203 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1204 lib := nonlib
1205 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1206 endif
1208 # The include magic above causes those files to use this variable for flags.
1209 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1212 ifeq ($(versioning),yes)
1213 # Generate normalized lists of symbols, versions, and data sizes.
1214 # This is handy for checking against existing library binaries.
1216 %.symlist: $(..)scripts/abilist.awk %.dynsym
1217         LC_ALL=C $(AWK) -f $^ > $@T
1218         mv -f $@T $@
1220 %.dynsym: %.so
1221         $(OBJDUMP) --dynamic-syms $< > $@T
1222         mv -f $@T $@
1224 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1225              $(..)abilist/%.abilist $(objpfx)%.symlist
1226         $(check-abi)
1227 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1228              $(..)abilist/%.abilist $(common-objpfx)%.symlist
1229         $(check-abi)
1230 define check-abi
1231         LC_ALL=C \
1232         $(AWK) -f $< -v 'config=$(check-abi-config)' \
1233                $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1234                $(filter %.abilist,$^) \
1235         | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1236 endef
1237 ifeq ($(enable-check-abi),warn)
1238 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1239 endif
1241 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1242 -include $(common-objpfx)tls.make
1243 config-tls := notls
1244 ifeq ($(use-tls),yes)
1245 config-tls := tls
1246 endif
1247 ifeq ($(use-thread),yes)
1248 config-tls := thread
1249 endif
1250 check-abi-config := \
1251   $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1252 endif
1254 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1255               $(objpfx)%.symlist
1256         $(update-abi)
1257 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1258               $(common-objpfx)%.symlist
1259         $(update-abi)
1260 ifndef update-abi-config
1261 define update-abi
1262         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1263 endef
1264 else
1265 define update-abi
1266 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1267          > $(..)abilist/$*.abilist.new
1268 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1269  then rm -f $(..)abilist/$*.abilist.new; \
1270       echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1271  else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1272       echo '*** Now check $*.abilist changes for correctness ***'; \
1273  fi
1274 endef
1275 endif
1277 .PHONY: update-abi check-abi
1278 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1279 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1280 ifdef subdir
1281 subdir_check-abi: check-abi
1282 subdir_update-abi: update-abi
1283 else
1284 check-abi: subdir_check-abi
1285 update-abi: subdir_update-abi
1286 endif
1288 ifeq ($(subdir),elf)
1289 check-abi: check-abi-libc
1290 update-abi: update-abi-libc
1291 common-generated += libc.symlist
1292 endif
1294 ifeq ($(build-shared),yes)
1295 ifneq ($(enable-check-abi),no)
1296 ifdef subdir
1297 tests: check-abi
1298 endif
1299 endif
1300 endif
1302 endif
1304 # There's no good place to put this - here will do.
1305 ifeq ($(filter %posix, $(sysdirs)),)
1306 L_tmpnam  = 1
1307 TMP_MAX   = 0
1308 L_ctermid = 1
1309 L_cuserid = 1
1310 else
1311 L_tmpnam  = 20
1312 TMP_MAX   = 238328
1313 L_ctermid = 9
1314 L_cuserid = 9
1315 endif
1316 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1318 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1319 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1320                    $(common-objpfx)config.make
1321         $(make-target-directory)
1322         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1323           echo '#define _LIBC 1';                                       \
1324           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1325         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1326               $(+includes) -xc - -o $(@:st=hT)
1327         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1328             $(@:st=dT) > $(@:st=dt)
1329         mv -f $(@:st=dt) $(@:st=d)
1330         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1331         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1332         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1333         fopen_max=$${fopen_max:-16};                                    \
1334         filename_max=$${filename_max:-1024};                            \
1335         if [ -z "$$iov_max" ]; then                                     \
1336           define_iov_max="# undef IOV_MAX";                             \
1337         else                                                            \
1338           define_iov_max="# define IOV_MAX $$iov_max";                  \
1339         fi;                                                             \
1340         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1341             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1342             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1343             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1344             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1345             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1346             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1347             $< > $(@:st=h.new)
1348         $(move-if-change) $(@:st=h.new) $(@:st=h)
1349 # Remove these last so that they can be examined if something went wrong.
1350         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1351         touch $@
1352 # Get dependencies.
1353 ifndef no_deps
1354 -include $(stdio_lim:h=d)
1355 endif
1356 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1358 FORCE:
1360 .PHONY: echo-headers
1361 echo-headers:
1362         @echo $(headers)
1364 %.bz2: %; bzip2 -9vk $<
1365 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1367 # Common cleaning targets.
1369 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1370 clean: common-clean
1371 mostlyclean: common-mostlyclean
1373 do-tests-clean:
1374         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1375                                                       $(test-srcs)) \
1376                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1377                                                          $(test-srcs)))
1379 # Remove the object files.
1380 common-mostlyclean:
1381         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1382                                      $(others) $(sysdep-others) stubs \
1383                                      $(addsuffix .o,$(tests) $(xtests) \
1384                                                     $(test-srcs) $(others) \
1385                                                     $(sysdep-others)) \
1386                                      $(addsuffix -bp,$(tests) $(xtests) \
1387                                                      $(test-srcs)) \
1388                                      $(addsuffix .out,$(tests) $(xtests) \
1389                                                       $(test-srcs)) \
1390                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1391                                                          $(test-srcs)))
1392         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1393                                      $(install-lib.so) \
1394                                      $(install-lib.so:%.so=%_pic.a))
1395         -rm -f core
1396         -rm -f $(objpfx)rtld-*.os
1397         $(rmobjs)
1398 define rmobjs
1399 $(foreach o,$(object-suffixes-for-libc),
1400 -rm -f $(objpfx)stamp$o $(o-objects))
1401 endef
1403 # Also remove the dependencies and generated source files.
1404 common-clean: common-mostlyclean
1405         -rm -f $(addprefix $(objpfx),$(generated))
1406         -rm -f $(objpfx)*.d $(objpfx)*.dt
1407         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1408         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1410 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1411 # for each function which is a stub.  We grovel over all the .d files
1412 # looking for references to <stub-tag.h>.  Then we grovel over each
1413 # referenced source file to see what stub function it defines.
1415 ifdef objpfx
1416 .PHONY: stubs # The parent Makefile calls this target.
1417 stubs: $(objpfx)stubs
1418 endif
1419 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1420                   $(addprefix $(objpfx),$(extra-objs))
1421 $(objpfx)stubs: $(objs-for-stubs)
1422 ifneq (,$(strip $(objs-for-stubs)))
1423         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1424         $(AWK) '/\.gnu\.glibc-stub\./ { \
1425                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1426                   stubs[$$2] = 1; } \
1427                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1428         mv -f $@T $@
1429 else
1430         > $@
1431 endif
1433 ifneq (,$(strip $(gpl2lgpl)))
1434 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1435 # Snarf from the master source and frob the copying notice.
1436 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1437         sed -f $^ > $@-tmp
1438 # So I don't edit them by mistake.
1439         chmod a-w $@-tmp
1440         mv -f $@-tmp $@
1441 ifeq ($(with-cvs),yes)
1442         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1443 endif
1444 endif
1445 endif
1447 # Local Variables:
1448 # mode: makefile
1449 # End: