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