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