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