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