* sysdeps/ieee754/ldbl-opt/nldbl-compat.h (NLDBL_DECL): Don't try
[glibc.git] / Makerules
blob027beef31b083bed737c6fc81d1980e02e154062
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              $(close-check-inhibit-asm) \
261              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
262                   \$$(compile-command.c)";                                    \
263              echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
264                   \$$(compile-command.c)";                                    \
265              echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
266                   \$$(compile-command.c)";                                    \
267            done; \
268            echo "\$$(objpfx)m_%.S: $$dir/s_%.S; \$$(+make-include-of-dep)";   \
269            echo "\$$(objpfx)m_%.c: $$dir/s_%.c; \$$(+make-include-of-dep)";   \
270          done;                                                                \
271          echo "\$$(objpfx)m_%.c: s_%.c; \$$(+make-include-of-dep)";   \
272          echo 'sysd-rules-done = t') > $@T
273         mv -f $@T $@
275 ifndef sysd-rules-done
276 # Don't do deps until this exists, because it provides rules to make the deps.
277 no_deps=t
278 endif
280 # This is used by the m_%.[Sc] pattern rules in sysd-rules.
281 define +make-include-of-dep
282 echo '#include <$<>' > $@T
283 mv -f $@T $@
284 endef
286 # It matters that this set of rules, for compiling from sources in
287 # the current directory (the $srcdir/$subdir) come before the
288 # generated sysdep rules in included from sysd-rules below.  When
289 # compiling in the source tree, generated sources go into the current
290 # directory, and those should be chosen before any sources in sysdeps.
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: %.s $(before-compile); $$(compile-command.s)
299 endef
300 object-suffixes-left := $(all-object-suffixes)
301 include $(o-iterator)
303 define o-iterator-doit
304 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
305 endef
306 object-suffixes-left := $(all-object-suffixes)
307 include $(o-iterator)
309 define o-iterator-doit
310 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
311 endef
312 object-suffixes-left := $(all-object-suffixes)
313 include $(o-iterator)
315 # Omit the objpfx rules when building in the source tree, because
316 # objpfx is empty and so these rules just override the ones above.
317 ifdef objpfx
318 # Define first rules to find the source files in $(objpfx).
319 # Generated source files will end up there.
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)%.s $(before-compile); $$(compile-command.s)
328 endef
329 object-suffixes-left := $(all-object-suffixes)
330 include $(o-iterator)
332 define o-iterator-doit
333 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
334 endef
335 object-suffixes-left := $(all-object-suffixes)
336 include $(o-iterator)
337 endif
339 # Generate version maps, but wait until sysdep-subdirs is known
340 ifeq ($(sysd-sorted-done),t)
341 ifeq ($(versioning),yes)
342 -include $(common-objpfx)sysd-versions
343 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
344 common-generated += $(version-maps)
345 postclean-generated += sysd-versions Versions.all abi-versions.h \
346                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
348 ifndef avoid-generated
349 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
350 sysd-versions-force = FORCE
351 FORCE:
352 endif
353 # See %.v/%.v.i implicit rules in Makeconfig.
354 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
355                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
356 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
357                               $(common-objpfx)soversions.i \
358                               $(common-objpfx)Versions.def.v
359         { while read which lib version setname; do \
360             test x"$$which" = xDEFAULT || continue; \
361             test -z "$$setname" || echo "$$lib : $$setname"; \
362           done < $(word 2,$^); \
363           cat $(word 3,$^); \
364         } | LC_ALL=C $(AWK) -f $< > $@T
365         mv -f $@T $@
366 # See %.v/%.v.i implicit rules in Makeconfig.
367 $(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
368                               $(wildcard $(sysdirs:%=%/Versions)) \
369                               $(common-objpfx)abi-versions.h \
370                               $(sysd-versions-force)
371 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
372                                $(common-objpfx)Versions.v \
373                                $(..)scripts/versions.awk
374         ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
375           cat $(word 2,$^) \
376           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
377                             -v move_if_change='$(move-if-change)' \
378                             -f $(word 3,$^); \
379         ) > $@T
380         mv -f $@T $@
381 endif # avoid-generated
382 endif # $(versioning) = yes
383 endif # sysd-sorted-done
385 # Generate .dT files as we compile.
386 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
387 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
388 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
389 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
390 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
392 # GCC can grok options after the file name, and it looks nicer that way.
393 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
394 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
395 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
396                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
397 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
398                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
399 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
401 # We need this for the output to go in the right place.  It will default to
402 # empty if make was configured to work with a cc that can't grok -c and -o
403 # together.  You can't compile the C library with such a compiler.
404 OUTPUT_OPTION = -o $@
406 # We need the $(CFLAGS) to be in there to have the right predefines during
407 # the dependency run for C sources.  But having it for assembly sources can
408 # get the wrong predefines.
409 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
411 define +make-deps
412 $(make-target-directory)
413 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
414              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
415 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
416 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
417 mv -f $(@:.d=.T) $@ $(generate-md5)
418 endef
420 ifneq (,$(objpfx))
421 # Continuation lines here are dangerous because they introduce spaces!
422 define sed-remove-objpfx
423 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
424 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
425 endef
426 endif
428 # Modify the list of routines we build for different targets
430 ifeq (yesyes,$(build-shared)$(elf))
431 ifndef libc.so-version
432 # Undefine this because it can't work when we libc.so is unversioned.
433 static-only-routines =
434 endif
435 endif
437 # Bounded pointer thunks are only built for *.ob
438 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
440 elide-routines.oS += $(filter-out $(static-only-routines),\
441                                   $(routines) $(aux) $(sysdep_routines)) \
442                      $(elide-bp-thunks)
443 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
445 # If we have versioned code we don't need the old versions in any of the
446 # static libraries.
447 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
448 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
449 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
450 elide-routines.ob += $(shared-only-routines)
452 # Shared library building.
454 ifeq (yes,$(build-shared))
456 # Reference map file only when versioning is selected and a map file name
457 # is given.
458 ifeq ($(versioning),yes)
459 map-file = $(firstword $($(@F:.so=-map)) \
460                        $(addprefix $(common-objpfx), \
461                                    $(filter $(@F:.so=.map),$(version-maps))))
462 load-map-file = $(map-file:%=-Wl,--version-script=%)
463 endif
465 # Pattern rule to build a shared object from an archive of PIC objects.
466 # This must come after the installation rules so Make doesn't try to
467 # build shared libraries in place from the installed *_pic.a files.
468 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
469 # on other shared objects.
470 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
471 ifneq (,$(findstring aix,$(config-os)))
472         (echo '#!'; \
473          dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
474 endif
475         $(build-shlib)
477 ifeq ($(elf),yes)
478 define build-shlib-helper
479 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
480           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
481           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
482           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
483           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
484           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
485           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
486 endef
487 else
488 ifneq (,$(findstring aix,$(config-os)))
489 define build-shlib-helper
490 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
491           $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
492           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
493           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
494           -L$(subst :, -L,$(rpath-link))
495 endef
496 else
497 endif
498 endif
500 ifeq (yes,$(elf))
501 # binutils only position loadable notes into the first page for binaries,
502 # not for shared objects
503 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
504         $(LINK.o) -shared -Wl,-O1 \
505                   -nostdlib -nostartfiles \
506                   $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
507                   -Wl,--verbose 2>&1 | \
508           sed > $@T \
509               -e '/^=========/,/^=========/!d;/^=========/d' \
510               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
511               -e 's/^.*\*(\.dynbss).*$$/& \
512                  PROVIDE(__start___libc_freeres_ptrs = .); \
513                  *(__libc_freeres_ptrs) \
514                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
515               -e 's@^.*\*(\.jcr).*$$@& \
516                  PROVIDE(__start___libc_subfreeres = .);\
517                  __libc_subfreeres : { *(__libc_subfreeres) }\
518                  PROVIDE(__stop___libc_subfreeres = .);\
519                  PROVIDE(__start___libc_atexit = .);\
520                  __libc_atexit : { *(__libc_atexit) }\
521                  PROVIDE(__stop___libc_atexit = .);\
522                  PROVIDE(__start___libc_thread_subfreeres = .);\
523                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
524                  PROVIDE(__stop___libc_thread_subfreeres = .);\
525                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
526         mv -f $@T $@
527 common-generated += shlib.lds
529 define build-shlib
530 $(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
531           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
532 endef
533 else
534 ifneq (,$(findstring aix,$(config-os)))
535 define build-shlib
536 $(build-shlib-helper) \
537         -o $@ \
538         $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
539         $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
540 endef
541 define build-shlib
542 $(build-shlib-helper) \
543           $(build-shlib-objlist)
544 endef
545 endif
546 endif
548 ifneq (,$(findstring aix,$(config-os)))
549 define build-module-helper
550 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
551           $(sysdep-LDFLAGS) $(config-LDFLAGS) \
552           $(load-map-file) \
553           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
554           -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
555 endef
556 else
557 define build-module-helper
558 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
559           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
560           -B$(csu-objpfx) $(load-map-file) \
561           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
562           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
563 endef
564 endif
566 # This macro is similar to build-shlib but it does not define a soname
567 # and it does not depend on the destination name to start with `lib'.
568 ifeq (yes,$(elf))
569 # binutils only position loadable notes into the first page for binaries,
570 # not for shared objects
571 define build-module
572 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
573           $(csu-objpfx)abi-note.o $(build-module-objlist)
574 endef
575 define build-module-asneeded
576 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
577           $(csu-objpfx)abi-note.o \
578           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
579 endef
580 else
581 ifneq (,$(findstring aix,$(config-os)))
582 define build-module
583 $(build-module-helper) \
584           -o $@ \
585           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
586           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
587 endef
588 else
589 define build-module
590 define build-module
591 $(build-module-helper) \
592           -o $@ \
593           $(build-module-objlist)
594 endef
595 endif
596 endif
598 build-module-helper-objlist = \
599         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
600                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
601 whole-archive := -Wl,--whole-archive
603 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
604 build-shlib-objlist = $(build-module-helper-objlist) \
605                       $(LDLIBS-$(@F:lib%.so=%).so)
607 # Don't try to use -lc when making libc.so itself.
608 # Also omits crti.o and crtn.o, which we do not want
609 # since we define our own `.init' section specially.
610 LDFLAGS-c.so = -nostdlib -nostartfiles
611 # But we still want to link libc.so against $(libc.so-gnulib).
612 LDLIBS-c.so += $(libc.so-gnulib)
613 # Give libc.so an entry point and make it directly runnable itself.
614 LDFLAGS-c.so += -e __libc_main
615 # If lazy relocation is disabled add the -z now flag.
616 ifeq ($(bind-now),yes)
617 LDFLAGS-c.so += -Wl,-z,now
618 endif
619 # Pre-link the objects of libc_pic.a so that we can locally resolve
620 # COMMON symbols before we link against ld.so.  This is because ld.so
621 # contains some of libc_pic.a already, which will prevent the COMMONs
622 # from being allocated in libc.so, which introduces evil dependencies
623 # between libc.so and ld.so, which can make it impossible to upgrade.
624 ifeq ($(elf),yes)
625 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
626         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
627         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
628 # Use our own special initializer and finalizer files for libc.so.
629 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
630                          $(common-objpfx)libc_pic.os \
631                          $(elfobjdir)/sofini.os \
632                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
633                          $(common-objpfx)shlib.lds
634         $(build-shlib)
635 ifeq ($(versioning),yes)
636 $(common-objpfx)libc.so: $(common-objpfx)libc.map
637 endif
638 common-generated += libc.so libc_pic.os
639 ifdef libc.so-version
640 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
641         $(make-link)
642 common-generated += libc.so$(libc.so-version)
643 endif
644 endif
645 else
646 ifneq (,$(findstring aix,$(config-os)))
647 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
648         @rm -f $@
649         (echo '#!'; \
650          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
651         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
652             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
653         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
654                   -bE:$(common-objpfx)syscalls.exp \
655                   -bI:$(common-objpfx)syscalls.exp \
656                   -L$(common-objpfx) -o $@ $^
657 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
658         cp $@ $(common-objpfx)shr.o
659         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
660 endif
661 endif
663 # Figure out the source filenames in this directory.
665 override sources := $(addsuffix .c,\
666                         $(filter-out $(elided-routines),\
667                             $(routines) $(aux) \
668                             $(sysdep_routines)))
669 sysdep_routines := $(sysdep_routines)
671 headers := $(headers) $(sysdep_headers)
673 # This is the list of all object files, gotten by
674 # replacing every ".c" in `sources' with a ".o".
675 # We also add bounded-pointer thunks, which are later
676 # elided for all suffixes except for `.ob'.
677 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
678                       $(patsubst %,$(bppfx)%.o,\
679                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
682 # The makefile may define $(extra-libs) with `libfoo libbar'
683 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
684 ifdef extra-libs
685 # extra-lib.mk is included once for each extra lib to define rules
686 # to build it, and to add its objects to the various variables.
687 # During its evaluation, $(lib) is set to the name of the library.
688 extra-libs-left := $(extra-libs)
689 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
690 endif
693 # The makefile may define $(modules-names) to build additional modules.
694 # These are built with $(build-module), except any in $(modules-names-nobuild).
695 ifdef modules-names
696 # extra-lib.mk is included once for each extra lib to define rules
697 # to build it, and to add its objects to the various variables.
698 # During its evaluation, $(lib) is set to the name of the library.
699 extra-modules-left := $(modules-names)
700 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
702 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
703 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
704                 $(objpfx)%.os $(common-objpfx)shlib.lds \
705                 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
706         $(build-module)
707 endif
709 +depfiles := $(sources:.c=.d) \
710              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
711              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
712 ifeq ($(build-programs),yes)
713 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
714 endif
715 +depfiles := $(addprefix $(objpfx),\
716                          $(filter-out $(addsuffix .d,$(omit-deps)),\
717                                       $(+depfiles)))
718 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
719 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
720              $(wildcard $(all-dt-files:.dt=.d))
722 # This is a funny rule in that it removes its input file.
723 %.d: %.dt
724         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
725          mv -f $(@:.d=.T) $@ && \
726          rm -f $<
728 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
729 # They will be generated when they're needed, and trying too early won't work.
730 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
731 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
732                                                 $(+gen-as-const)))
734 ifdef +depfiles
735 ifneq ($(no_deps),t)
736 -include $(+depfiles)
737 endif
738 endif
739 \f\f
740 # Maximize efficiency by minimizing the number of rules.
741 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
742 # Don't define any builtin rules.
743 MAKEFLAGS := $(MAKEFLAGS)r
745 # Generic rule for making directories.
747 # mkdir isn't smart enough to strip a trailing /.
748         mkdir $(@:%/=%)
750 # Make sure that object files are not removed
751 # when they are intermediates between sources and library members.
752 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
754 # Make sure that the parent library archive is never removed.
755 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
757 # Use the verbose option of ar and tar when not running silently.
758 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
759 verbose := v
760 else                                            # -s
761 verbose :=
762 endif                                           # not -s
764 ARFLAGS := r$(verbose)
765 CREATE_ARFLAGS := cru$(verbose)
767 # This makes all the object files in the parent library archive.
769 .PHONY: lib lib-noranlib
770 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
771 lib-noranlib: libobjs
773 # For object-suffix $o, the list of objects with that suffix.
774 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
775 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
776                                                        $(elide-routines$o)),\
777                                             $(objects))) \
778             $(addprefix $(objpfx),$(o-objects$o))
780 others: $(addprefix $(objpfx),$(install-lib))
782 ifndef objects
784 # Create the stamp$o files to keep the parent makefile happy.
785 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
786 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
787         $(make-target-directory)
788         rm -f $@; > $@
789 else
791 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
792 # timestamp file; these rules (one explicit rule is generated for each
793 # object suffix) write a list of objects to update in the stamp file.
794 # The parent will then actually add them all to the archive in the
795 # archive rule, below.
796 define o-iterator-doit
797 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
798 endef
799 define do-stamp
800 $(make-target-directory)
801 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
802 mv -f $@T $@
803 endef
804 object-suffixes-left := $(object-suffixes-for-libc)
805 include $(o-iterator)
807 endif
809 # Now define explicit rules to build the library archives; these depend
810 # on the stamp files built above.
811 define o-iterator-doit
812 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
813                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
814 endef
815 define do-makelib
816 cd $(common-objdir) && \
817 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
818 $(RANLIB) $@
819 endef
820 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
821 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
822 ifndef subdir
823 $(subdirs-stamps): subdir_lib;
824 endif
825 object-suffixes-left = $(object-suffixes-for-libc)
826 include $(o-iterator)
829 # This makes all the object files.
830 .PHONY: objects objs libobjs extra-objs
831 objects objs: libobjs extra-objs
832 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
833 extra-objs: $(addprefix $(objpfx),$(extra-objs))
835 # Canned sequence for building an extra library archive.
836 define build-extra-lib
837 $(patsubst %/,cd % &&,$(objpfx)) \
838 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
839       $(patsubst $(objpfx)%,%,$^)
840 $(RANLIB) $@
841 endef
843 # Installation.
845 .PHONY: force-install
846 force-install:
848 # $(install-lib) are installed from the object directory into $(libdir);
849 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
850 # unless they also appear in $(non-lib.a).  $(install-data) are installed
851 # as they are into $(datadir).  $(headers) are installed as they are in
852 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
853 # are installed from the object directory into $(bindir), $(bindir) and
854 # $(sbindir), respectively.  $(install-others) are absolute path names of
855 # files to install; rules to install them are defined elsewhere.
857 # The simple library name to install libc.a under.
858 # This could be defined by a sysdep Makefile.
859 ifndef libc-name
860 libc-name := c
861 endif
863 define do-install
864 $(make-target-directory)
865 $(INSTALL_DATA) $< $@
866 endef
868 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
869 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
870 define make-target-directory
871 $(addprefix $(..)./scripts/mkinstalldirs ,\
872             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
873 endef
875 # Any directory (parent or subdir) should install libc.a; this way
876 # "make install" in a subdir is guaranteed to install everything it changes.
877 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
878                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
879                                                      $(libprefix)$(libc-name)))
880 install: $(installed-libcs)
881 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
882         $(make-target-directory)
883         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
884 # Running ranlib after installing makes the __.SYMDEF time stamp up to
885 # date, which avoids messages from some linkers.
886         $(RANLIB) $@
888 define do-install-program
889 $(make-target-directory)
890 $(INSTALL_PROGRAM) $< $@.new
891 mv -f $@.new $@
892 endef
894 define do-install-script
895 $(make-target-directory)
896 $(INSTALL_SCRIPT) $< $@.new
897 mv -f $@.new $@
898 endef
900 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
901 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
903 ifeq (yes,$(build-shared))
904 # Find which .so's have versions.
905 versioned := $(strip $(foreach so,$(install-lib.so),\
906                                $(patsubst %,$(so),$($(so)-version))))
908 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
909 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
911 # For versioned libraries, we install three files:
912 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
913 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
914 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
915 V := $(firstword $($(subdir)-version) $(version))
916 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
917                       $(foreach L,$(install-lib.so-versioned),\
918                                 $(inst_libdir)/$L \
919                                 $(inst_slibdir)/$(L:.so=)-$V.so \
920                                 $(inst_slibdir)/$L$($L-version))
922 # Install all the unversioned shared libraries.
923 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
924     $(objpfx)%.so $(+force)
925         $(do-install-program)
927 ifneq ($(findstring -s,$(LN_S)),)
928 define make-link
929 rm -f $@.new
930 $(SHELL) $(..)scripts/rellns-sh $< $@.new
931 mv -f $@.new $@
932 endef
933 else
934 # If we have no symbolic links don't bother with rellns-sh.
935 define make-link
936 rm -f $@.new
937 $(LN_S) $< $@.new
938 mv -f $@.new $@
939 endef
940 endif
942 ifeq (yes,$(build-shared))
943 ifeq (no,$(cross-compiling))
944 symbolic-link-prog := $(common-objpfx)elf/sln
945 symbolic-link-list := $(common-objpfx)elf/symlink.list
946 define make-shlib-link
947 echo $(<F) $@ >> $(symbolic-link-list)
948 endef
949 else # cross-compiling
950 # We need a definition that can be used by elf/Makefile's install rules.
951 symbolic-link-prog = $(LN_S)
952 endif
953 endif
954 ifndef make-shlib-link
955 define make-shlib-link
956 rm -f $@
957 $(LN_S) $(<F) $@
958 endef
959 endif
961 ifdef libc.so-version
962 # For a library specified to be version N, install three files:
963 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
964 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
966 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
967                                            $(+force)
968         $(make-shlib-link)
969 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
970         $(do-install-program)
971 install: $(inst_slibdir)/libc.so$(libc.so-version)
973 # This fragment of linker script gives the OUTPUT_FORMAT statement
974 # for the configuration we are building.  We put this statement into
975 # the linker scripts we install for -lc et al so that they will not be
976 # used by a link for a different format on a multi-architecture system.
977 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
978                             $(common-objpfx)config.make \
979                             $(common-objpfx)config.h $(..)Makerules
980         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
981                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
982         | sed -n -f $< > $@.new
983         rm -f $@.so
984         mv -f $@.new $@
985 common-generated += format.lds
987 ifndef subdir
988 # What we install as libc.so for programs to link against is in fact a
989 # link script.  It contains references for the various libraries we need.
990 # The libc.so object is not complete since some functions are only defined
991 # in libc_nonshared.a.
992 # We need to use absolute paths since otherwise local copies (if they exist)
993 # of the files are taken by the linker.
994 install: $(inst_libdir)/libc.so
995 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
996                         $(common-objpfx)libc.so$(libc.so-version) \
997                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
998                                                   $(libprefix)$(libc-name)) \
999                         $(+force)
1000         (echo '/* GNU ld script';\
1001          echo '   Use the shared library, but some functions are only in';\
1002          echo '   the static library, so try that secondarily.  */';\
1003          cat $<; \
1004          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1005               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1006               ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1007         ) > $@.new
1008         mv -f $@.new $@
1010 endif
1012 else
1013 install: $(inst_slibdir)/libc.so
1014 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1015         $(do-install-program)
1016 endif
1018 ifneq (,$(versioned))
1019 # Produce three sets of rules as above for all the smaller versioned libraries.
1021 define o-iterator-doit
1022 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1023 endef
1024 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1025 ifneq (,$(object-suffixes-left))
1026 include $(o-iterator)
1027 endif
1029 # Make symlinks in the build directory, because the versioned names might
1030 # be referenced by a DT_NEEDED in another library.
1031 define o-iterator-doit
1032 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1033 endef
1034 object-suffixes-left := $(versioned)
1035 include $(o-iterator)
1037 generated += $(foreach o,$(versioned),$o$($o-version))
1039 ifeq (,$($(subdir)-version))
1040 define o-iterator-doit
1041 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1042                                  $(+force);
1043         $$(make-shlib-link)
1044 endef
1045 object-suffixes-left := $(versioned)
1046 include $(o-iterator)
1048 define o-iterator-doit
1049 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1050         $$(do-install-program)
1051 endef
1052 object-suffixes-left := $(versioned)
1053 include $(o-iterator)
1054 else
1055 define o-iterator-doit
1056 $(inst_slibdir)/$o$($o-version): \
1057   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1058         $$(make-shlib-link)
1059 endef
1060 object-suffixes-left := $(versioned)
1061 include $(o-iterator)
1063 define o-iterator-doit
1064 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1065         $$(do-install-program)
1066 endef
1067 object-suffixes-left := $(versioned)
1068 include $(o-iterator)
1069 endif
1070 endif
1072 define do-install-so
1073 $(do-install-program)
1074 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1075            $(filter-out %.so,$@))
1076 endef
1078 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1079 $(foreach v,$(so-versions),\
1080           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1081                                                $(+force)
1082         $(do-install-so)
1083 $(foreach v,$(so-versions),\
1084           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1085         $(do-install-so)
1086 endif
1088 ifdef install-bin
1089 $(addprefix $(inst_bindir)/,$(install-bin)): \
1090     $(inst_bindir)/%: $(objpfx)% $(+force)
1091         $(do-install-program)
1092 endif
1093 ifdef install-bin-script
1094 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1095     $(inst_bindir)/%: $(objpfx)% $(+force)
1096         $(do-install-script)
1097 endif
1098 ifdef install-rootsbin
1099 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1100    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1101         $(do-install-program)
1102 endif
1103 ifdef install-sbin
1104 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1105     $(inst_sbindir)/%: $(objpfx)% $(+force)
1106         $(do-install-program)
1107 endif
1108 ifdef install-lib
1109 install-lib.a := $(filter lib%.a,$(install-lib))
1110 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1111 ifdef install-lib-non.a
1112 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1113   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1114         $(do-install)
1115 endif
1116 ifdef install-lib.a
1117 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1118   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1119         $(do-install)
1120         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1121 endif
1122 endif
1123 ifdef install-data
1124 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1125         $(do-install)
1126 endif
1127 headers := $(strip $(headers))
1128 ifdef headers
1129 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1130         $(do-install)
1131 endif   # headers
1133 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1134         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1135         install-data-nosubdir install-headers-nosubdir
1136 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1137 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1138 install-rootsbin-nosubdir: \
1139         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1140 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1141 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1142                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1143                        $(addprefix $(libprefix),$(install-lib-non.a)))
1144 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1145 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1146 install-others-nosubdir: $(install-others)
1148 # We need all the `-nosubdir' targets so that `install' in the parent
1149 # doesn't depend on several things which each iterate over the subdirs.
1150 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1151 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1152 install-%:: install-%-nosubdir ;
1154 .PHONY: install install-no-libc.a-nosubdir
1155 ifeq ($(build-programs),yes)
1156 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1157                             install-bin-nosubdir install-bin-script-nosubdir \
1158                             install-lib-nosubdir install-others-nosubdir \
1159                             install-rootsbin-nosubdir install-sbin-nosubdir
1160 else
1161 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1162                             install-lib-nosubdir install-others-nosubdir
1163 endif
1164 install: install-no-libc.a-nosubdir
1166 # Command to compile $< in $(objdir) using the native libraries.
1167 define native-compile
1168 $(make-target-directory)
1169 $(patsubst %/,cd % &&,$(objpfx)) \
1170 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1171             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1172 endef
1174 # Command to compile $< in $(common-objdir) using the native libraries.
1175 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1176 define common-objdir-compile
1177 $(patsubst %/,cd % &&,$(objpfx)) \
1178 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1179             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1180 endef
1182 # We always want to use configuration definitions.
1183 # Note that this is only used for commands running in $(objpfx).
1184 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1186 # Support the GNU standard name for this target.
1187 .PHONY: check
1188 check: tests
1189 # Special target to run tests which cannot be run unconditionally.
1190 # Maintainers should use this target.
1191 .PHONY: xcheck
1192 xcheck: xtests
1194 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1195 ifneq (,$(all-nonlib))
1196 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1197 lib := nonlib
1198 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1199 endif
1201 # The include magic above causes those files to use this variable for flags.
1202 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1205 ifeq ($(versioning),yes)
1206 # Generate normalized lists of symbols, versions, and data sizes.
1207 # This is handy for checking against existing library binaries.
1209 %.symlist: $(..)scripts/abilist.awk %.dynsym
1210         LC_ALL=C $(AWK) -f $^ > $@T
1211         mv -f $@T $@
1213 %.dynsym: %.so
1214         $(OBJDUMP) --dynamic-syms $< > $@T
1215         mv -f $@T $@
1217 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1218              $(..)abilist/%.abilist $(objpfx)%.symlist
1219         $(check-abi)
1220 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1221              $(..)abilist/%.abilist $(common-objpfx)%.symlist
1222         $(check-abi)
1223 define check-abi
1224         LC_ALL=C \
1225         $(AWK) -f $< -v 'config=$(check-abi-config)' \
1226                $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1227                $(filter %.abilist,$^) \
1228         | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1229 endef
1230 ifeq ($(enable-check-abi),warn)
1231 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1232 endif
1234 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1235 -include $(common-objpfx)tls.make
1236 config-tls := notls
1237 ifeq ($(use-tls),yes)
1238 config-tls := tls
1239 endif
1240 ifeq ($(use-thread),yes)
1241 config-tls := thread
1242 endif
1243 check-abi-config := \
1244   $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1245 endif
1247 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1248               $(objpfx)%.symlist
1249         $(update-abi)
1250 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1251               $(common-objpfx)%.symlist
1252         $(update-abi)
1253 ifndef update-abi-config
1254 define update-abi
1255         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1256 endef
1257 else
1258 define update-abi
1259 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1260          > $(..)abilist/$*.abilist.new
1261 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1262  then rm -f $(..)abilist/$*.abilist.new; \
1263       echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1264  else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1265       echo '*** Now check $*.abilist changes for correctness ***'; \
1266  fi
1267 endef
1268 endif
1270 .PHONY: update-abi check-abi
1271 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1272 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1273 ifdef subdir
1274 subdir_check-abi: check-abi
1275 subdir_update-abi: update-abi
1276 else
1277 check-abi: subdir_check-abi
1278 update-abi: subdir_update-abi
1279 endif
1281 ifeq ($(subdir),elf)
1282 check-abi: check-abi-libc
1283 update-abi: update-abi-libc
1284 common-generated += libc.symlist
1285 endif
1287 ifeq ($(build-shared),yes)
1288 ifneq ($(enable-check-abi),no)
1289 ifdef subdir
1290 tests: check-abi
1291 endif
1292 endif
1293 endif
1295 endif
1297 # There's no good place to put this - here will do.
1298 ifeq ($(filter %posix, $(sysdirs)),)
1299 L_tmpnam  = 1
1300 TMP_MAX   = 0
1301 L_ctermid = 1
1302 L_cuserid = 1
1303 else
1304 L_tmpnam  = 20
1305 TMP_MAX   = 238328
1306 L_ctermid = 9
1307 L_cuserid = 9
1308 endif
1309 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1311 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1312 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1313                    $(common-objpfx)config.make
1314         $(make-target-directory)
1315         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1316           echo '#define _LIBC 1';                                       \
1317           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1318         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1319               $(+includes) -xc - -o $(@:st=hT)
1320         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1321             $(@:st=dT) > $(@:st=dt)
1322         mv -f $(@:st=dt) $(@:st=d)
1323         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1324         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1325         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1326         fopen_max=$${fopen_max:-16};                                    \
1327         filename_max=$${filename_max:-1024};                            \
1328         if [ -z "$$iov_max" ]; then                                     \
1329           define_iov_max="# undef IOV_MAX";                             \
1330         else                                                            \
1331           define_iov_max="# define IOV_MAX $$iov_max";                  \
1332         fi;                                                             \
1333         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1334             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1335             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1336             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1337             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1338             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1339             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1340             $< > $(@:st=h.new)
1341         $(move-if-change) $(@:st=h.new) $(@:st=h)
1342 # Remove these last so that they can be examined if something went wrong.
1343         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1344         touch $@
1345 # Get dependencies.
1346 ifndef no_deps
1347 -include $(stdio_lim:h=d)
1348 endif
1349 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1351 FORCE:
1353 .PHONY: echo-headers
1354 echo-headers:
1355         @echo $(headers)
1357 %.bz2: %; bzip2 -9vk $<
1358 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1360 # Common cleaning targets.
1362 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1363 clean: common-clean
1364 mostlyclean: common-mostlyclean
1366 do-tests-clean:
1367         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1368                                                       $(test-srcs)) \
1369                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1370                                                          $(test-srcs)))
1372 # Remove the object files.
1373 common-mostlyclean:
1374         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1375                                      $(others) $(sysdep-others) stubs \
1376                                      $(addsuffix .o,$(tests) $(xtests) \
1377                                                     $(test-srcs) $(others) \
1378                                                     $(sysdep-others)) \
1379                                      $(addsuffix -bp,$(tests) $(xtests) \
1380                                                      $(test-srcs)) \
1381                                      $(addsuffix .out,$(tests) $(xtests) \
1382                                                       $(test-srcs)) \
1383                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1384                                                          $(test-srcs)))
1385         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1386                                      $(install-lib.so) \
1387                                      $(install-lib.so:%.so=%_pic.a))
1388         -rm -f core
1389         -rm -f $(objpfx)rtld-*.os
1390         $(rmobjs)
1391 define rmobjs
1392 $(foreach o,$(object-suffixes-for-libc),
1393 -rm -f $(objpfx)stamp$o $(o-objects))
1394 endef
1396 # Also remove the dependencies and generated source files.
1397 common-clean: common-mostlyclean
1398         -rm -f $(addprefix $(objpfx),$(generated))
1399         -rm -f $(objpfx)*.d $(objpfx)*.dt
1400         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1401         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1403 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1404 # for each function which is a stub.  We grovel over all the .d files
1405 # looking for references to <stub-tag.h>.  Then we grovel over each
1406 # referenced source file to see what stub function it defines.
1408 ifdef objpfx
1409 .PHONY: stubs # The parent Makefile calls this target.
1410 stubs: $(objpfx)stubs
1411 endif
1412 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1413                   $(addprefix $(objpfx),$(extra-objs))
1414 $(objpfx)stubs: $(objs-for-stubs)
1415 ifneq (,$(strip $(objs-for-stubs)))
1416         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1417         $(AWK) '/\.gnu\.glibc-stub\./ { \
1418                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1419                   stubs[$$2] = 1; } \
1420                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1421         mv -f $@T $@
1422 else
1423         > $@
1424 endif
1426 ifneq (,$(strip $(gpl2lgpl)))
1427 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1428 # Snarf from the master source and frob the copying notice.
1429 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1430         sed -f $^ > $@-tmp
1431 # So I don't edit them by mistake.
1432         chmod a-w $@-tmp
1433         mv -f $@-tmp $@
1434 ifeq ($(with-cvs),yes)
1435         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1436 endif
1437 endif
1438 endif
1440 # Local Variables:
1441 # mode: makefile
1442 # End: