[BZ #3018]
[glibc.git] / Makerules
blobf50f7a4884954f86ccbbc4eaf84474f07ac878d8
1 # Copyright (C) 1991-2002,2003,2004,2005,2006 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 # 02111-1307 USA.
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version.  See above for the version needed.
34 endif
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq   "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
59 # This variable is used in ``include $(o-iterator)'' after defining
60 # $(o-iterator-doit) to produce some desired rule using $o for the object
61 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
62 # is produced for each object suffix in use.
63 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
65 # Include any system-specific makefiles.
67 # This is here so things in sysdep Makefiles can easily depend on foo.h as
68 # appropriate and not worry about where foo.h comes from, which may be
69 # system dependent and not known by that Makefile.
70 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
71                                       $(+sysdep_dirs) $(..)))
73 # The same is true for RPC source files.
74 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
75                                       $(+sysdep_dirs) $(..)))
77 # Some sysdep makefiles use this to distinguish being included here from
78 # being included individually by a subdir makefile (hurd/Makefile needs this).
79 in-Makerules := yes
81 sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
82 ifneq (,$(sysdep-makefiles))
83 include $(sysdep-makefiles)
84 endif
87 # Reorder before-compile so that mach things come first, and hurd things
88 # second, before all else.  The mach and hurd subdirectories have many
89 # generated header files which the much of rest of the library depends on,
90 # so it is best to build them first (and mach before hurd, at that).
91 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
92                            $(before-compile)) \
93                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
94                                $(before-compile))
96 # Even before that, we need abi-versions.h which is generated right here.
97 ifeq ($(versioning),yes)
98 ifndef avoid-generated
99 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
100 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
101                                 $(common-objpfx)Versions.all
102         LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
103         mv -f $@T $@
105 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
106         sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
107             $(common-objpfx)abi-versions.h > $@T
108         mv -f $@T $@
109 endif # avoid-generated
110 endif # $(versioning) = yes
112 # Make sure the subdirectory for object files gets created.
113 ifdef objpfx
114 ifeq (,$(wildcard $(objpfx).))
115 before-compile += $(objpfx).
116 $(objpfx).:
117         $(make-target-directory)
118 endif
119 endif
121 # Remove existing files from `before-compile'.  Things are added there when
122 # they must exist for dependency generation to work right, but once they
123 # exist there is no further need for every single file to depend on them,
124 # and those gratuitous dependencies result in many gratuitous
125 # recompilations.
126 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
128 # Don't let any before-compile file be an intermediate and get removed.
129 ifdef before-compile
130 $(before-compile):
131 endif
133 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
134 # in subdirs.
135 ifdef subdir
136 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
137 else
138 common-before-compile = $(before-compile)
139 endif
141 ifndef subdir
142 # If a makefile needs to do something conditional on something that
143 # can only be figured out from headers, write a FOO.make.c input
144 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
145 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
147 # We only generate these in the top-level makefile, to avoid any weirdness
148 # from subdir-specific makefile tweaks creeping in on an update.
149 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
150         rm -f $@T $@.dT
151         (echo '# Generated from $*.make.c by Makerules.'; \
152          $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
153                -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
154          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
155          echo 'common-generated += $(@F)'; \
156          sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
157          rm -f $@.dT) > $@T
158         mv -f $@T $@
159 endif
161 ifdef subdir
162 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g' \
163                      -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
164 else
165 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g' \
166                      -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
167 endif
170 ifdef gen-as-const-headers
171 # Generating headers for assembly constants.
172 # We need this defined early to get into before-compile before
173 # it's used in sysd-rules, below.
174 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
175                                            %.sym $(common-before-compile)
176         $(AWK) -f $< $(filter %.sym,$^) \
177         | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
178                 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
179         sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
180                 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
181         rm -f $(@:.h.d=.h)T3
182         sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
183             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
184         rm -f $(@:.h=.h.d)T
185         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
186         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
187 vpath %.sym $(sysdirs)
188 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
190 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
191 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
192 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
193                             %.sym $(common-objpfx)%.h
194         ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
195          $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
196          echo '#include "$(..)test-skeleton.c"') > $@T
197         mv -f $@T $@
198 endif
200 # Generate an ordered list of implicit rules which find the source files in
201 # each sysdep directory.  The old method was to use vpath to search all the
202 # sysdep directories.  However, that had the problem that a .S file in a
203 # later directory would be chosen over a .c file in an earlier directory,
204 # which does not preserve the desired sysdeps ordering behavior.
206 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
207 # patterns matching sysdep directories whose assembly source files should
208 # be suppressed.
209 ifdef inhibit-sysdep-asm
210 define open-check-inhibit-asm
211 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
212 endef
213 close-check-inhibit-asm = ;; esac ;
214 endif
216 -include $(common-objpfx)sysd-rules
217 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
218 # The value of $(+sysdep_dirs) the sysd-rules was computed for
219 # differs from the one we are using now.  So force a rebuild of sysd-rules.
220 sysd-rules-force = FORCE
221 FORCE:
222 endif
223 $(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
224                             $(sysdep-makefiles) $(sysd-rules-force)
225         -@rm -f $@T
226         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
227          for dir in $(config-sysdirs); do                                     \
228            case "$$dir" in                                                    \
229            /*) ;;                                                             \
230            *) dir="\$$(..)$$dir" ;;                                           \
231            esac;                                                              \
232            for o in $(all-object-suffixes); do \
233              $(open-check-inhibit-asm) \
234              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
235                   \$$(compile-command.S)";                                    \
236              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
237                   \$$(compile-command.s)";                                    \
238              echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
239                   \$$(compile-command.S)";                                    \
240              echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
241                   \$$(compile-command.s)";                                    \
242              echo "\$$(objpfx)ptw-%$$o: $$dir/%.S \$$(before-compile); \
243                   \$$(compile-command.S)";                                    \
244              echo "\$$(objpfx)ptw-%$$o: $$dir/%.s \$$(before-compile); \
245                   \$$(compile-command.s)";                                    \
246              echo "\$$(objpfx)m_%$$o: $$dir/s_%.S \$$(before-compile); \
247                   \$$(compile-command.S)";                                    \
248              echo "\$$(objpfx)m_%$$o: $$dir/s_%.s \$$(before-compile); \
249                   \$$(compile-command.s)";                                    \
250              $(close-check-inhibit-asm) \
251              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
252                   \$$(compile-command.c)";                                    \
253              echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
254                   \$$(compile-command.c)";                                    \
255              echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
256                   \$$(compile-command.c)";                                    \
257              echo "\$$(objpfx)m_%$$o: $$dir/s_%.c \$$(before-compile); \
258                   \$$(compile-command.c)";                                    \
259            done; \
260            echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force); \
261                         \$$(do-install)";                                     \
262          done;                                                                \
263          echo 'sysd-rules-done = t') > $@T
264         mv -f $@T $@
266 ifndef sysd-rules-done
267 # Don't do deps until this exists, because it provides rules to make the deps.
268 no_deps=t
269 endif
271 define o-iterator-doit
272 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
273 endef
274 object-suffixes-left := $(all-object-suffixes)
275 include $(o-iterator)
277 define o-iterator-doit
278 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
279 endef
280 object-suffixes-left := $(all-object-suffixes)
281 include $(o-iterator)
283 define o-iterator-doit
284 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
285 endef
286 object-suffixes-left := $(all-object-suffixes)
287 include $(o-iterator)
289 define o-iterator-doit
290 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
291 endef
292 object-suffixes-left := $(all-object-suffixes)
293 include $(o-iterator)
295 # Omit the objpfx rules when building in the source tree, because
296 # objpfx is empty and so these rules just override the ones above.
297 ifdef objpfx
298 # Define first rules to find the source files in $(objpfx).
299 # Generated source files will end up there.
300 define o-iterator-doit
301 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
302 endef
303 object-suffixes-left := $(all-object-suffixes)
304 include $(o-iterator)
306 define o-iterator-doit
307 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
308 endef
309 object-suffixes-left := $(all-object-suffixes)
310 include $(o-iterator)
312 define o-iterator-doit
313 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
314 endef
315 object-suffixes-left := $(all-object-suffixes)
316 include $(o-iterator)
317 endif
319 # Generate version maps, but wait until sysdep-subdirs is known
320 ifeq ($(sysd-sorted-done),t)
321 ifeq ($(versioning),yes)
322 -include $(common-objpfx)sysd-versions
323 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
324 common-generated += $(version-maps)
325 postclean-generated += sysd-versions Versions.all abi-versions.h \
326                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
328 ifndef avoid-generated
329 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
330 sysd-versions-force = FORCE
331 FORCE:
332 endif
333 # See %.v/%.v.i implicit rules in Makeconfig.
334 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
335                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
336 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
337                               $(common-objpfx)soversions.i \
338                               $(common-objpfx)Versions.def.v
339         { while read which lib version setname; do \
340             test x"$$which" = xDEFAULT || continue; \
341             test -z "$$setname" || echo "$$lib : $$setname"; \
342           done < $(word 2,$^); \
343           cat $(word 3,$^); \
344         } | LC_ALL=C $(AWK) -f $< > $@T
345         mv -f $@T $@
346 # See %.v/%.v.i implicit rules in Makeconfig.
347 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
348                               $(wildcard $(sysdirs:%=%/Versions)) \
349                               $(common-objpfx)abi-versions.h \
350                               $(sysd-versions-force)
351 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
352                                $(common-objpfx)Versions.v \
353                                $(..)scripts/versions.awk
354         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
355           cat $(word 2,$^) \
356           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
357                             -v move_if_change='$(move-if-change)' \
358                             -f $(word 3,$^); \
359         ) > $@T
360         mv -f $@T $@
361 endif # avoid-generated
362 endif # $(versioning) = yes
363 endif # sysd-sorted-done
365 # Generate .dT files as we compile.
366 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
367 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
368 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
369 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
370 compile-command.cc = $(compile.cc) $(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.cc = $(CXX) $< -c $(CXXFLAGS) $(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 define build-module-asneeded
556 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
557           $(csu-objpfx)abi-note.o \
558           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
559 endef
560 else
561 ifneq (,$(findstring aix,$(config-os)))
562 define build-module
563 $(build-module-helper) \
564           -o $@ \
565           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
566           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
567 endef
568 else
569 define build-module
570 define build-module
571 $(build-module-helper) \
572           -o $@ \
573           $(build-module-objlist)
574 endef
575 endif
576 endif
578 build-module-helper-objlist = \
579         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
580                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
581 whole-archive := -Wl,--whole-archive
583 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
584 build-shlib-objlist = $(build-module-helper-objlist) \
585                       $(LDLIBS-$(@F:lib%.so=%).so)
587 # Don't try to use -lc when making libc.so itself.
588 # Also omits crti.o and crtn.o, which we do not want
589 # since we define our own `.init' section specially.
590 LDFLAGS-c.so = -nostdlib -nostartfiles
591 # But we still want to link libc.so against $(libc.so-gnulib).
592 LDLIBS-c.so += $(libc.so-gnulib)
593 # Give libc.so an entry point and make it directly runnable itself.
594 LDFLAGS-c.so += -e __libc_main
595 # If lazy relocation is disabled add the -z now flag.
596 ifeq ($(bind-now),yes)
597 LDFLAGS-c.so += -Wl,-z,now
598 endif
599 # Pre-link the objects of libc_pic.a so that we can locally resolve
600 # COMMON symbols before we link against ld.so.  This is because ld.so
601 # contains some of libc_pic.a already, which will prevent the COMMONs
602 # from being allocated in libc.so, which introduces evil dependencies
603 # between libc.so and ld.so, which can make it impossible to upgrade.
604 ifeq ($(elf),yes)
605 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
606         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
607         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
608 # Use our own special initializer and finalizer files for libc.so.
609 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
610                          $(common-objpfx)libc_pic.os \
611                          $(elfobjdir)/sofini.os \
612                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
613                          $(common-objpfx)shlib.lds
614         $(build-shlib)
615 ifeq ($(versioning),yes)
616 $(common-objpfx)libc.so: $(common-objpfx)libc.map
617 endif
618 common-generated += libc.so libc_pic.os
619 ifdef libc.so-version
620 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
621         $(make-link)
622 common-generated += libc.so$(libc.so-version)
623 endif
624 endif
625 else
626 ifneq (,$(findstring aix,$(config-os)))
627 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
628         @rm -f $@
629         (echo '#!'; \
630          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
631         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
632             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
633         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
634                   -bE:$(common-objpfx)syscalls.exp \
635                   -bI:$(common-objpfx)syscalls.exp \
636                   -L$(common-objpfx) -o $@ $^
637 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
638         cp $@ $(common-objpfx)shr.o
639         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
640 endif
641 endif
643 # Figure out the source filenames in this directory.
645 override sources := $(addsuffix .c,\
646                         $(filter-out $(elided-routines),\
647                             $(routines) $(aux) \
648                             $(sysdep_routines)))
649 sysdep_routines := $(sysdep_routines)
651 headers := $(headers) $(sysdep_headers)
653 # This is the list of all object files, gotten by
654 # replacing every ".c" in `sources' with a ".o".
655 # We also add bounded-pointer thunks, which are later
656 # elided for all suffixes except for `.ob'.
657 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
658                       $(patsubst %,$(bppfx)%.o,\
659                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
662 # The makefile may define $(extra-libs) with `libfoo libbar'
663 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
664 ifdef extra-libs
665 # extra-lib.mk is included once for each extra lib to define rules
666 # to build it, and to add its objects to the various variables.
667 # During its evaluation, $(lib) is set to the name of the library.
668 extra-libs-left := $(extra-libs)
669 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
670 endif
673 # The makefile may define $(modules-names) to build additional modules.
674 # These are built with $(build-module), except any in $(modules-names-nobuild).
675 ifdef modules-names
676 # extra-lib.mk is included once for each extra lib to define rules
677 # to build it, and to add its objects to the various variables.
678 # During its evaluation, $(lib) is set to the name of the library.
679 extra-modules-left := $(modules-names)
680 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
682 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
683 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
684                 $(objpfx)%.os $(common-objpfx)shlib.lds \
685                 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
686         $(build-module)
687 endif
689 +depfiles := $(sources:.c=.d) \
690              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
691              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
692              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
693 ifeq ($(build-programs),yes)
694 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
695 endif
696 +depfiles := $(addprefix $(objpfx),\
697                          $(filter-out $(addsuffix .d,$(omit-deps)),\
698                                       $(+depfiles)))
699 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
700 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
701              $(wildcard $(all-dt-files:.dt=.d))
703 # This is a funny rule in that it removes its input file.
704 %.d: %.dt
705         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
706          mv -f $(@:.d=.T) $@ && \
707          rm -f $<
709 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
710 # They will be generated when they're needed, and trying too early won't work.
711 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
712 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
713                                                 $(+gen-as-const)))
715 ifdef +depfiles
716 ifneq ($(no_deps),t)
717 -include $(+depfiles)
718 endif
719 endif
720 \f\f
721 # Maximize efficiency by minimizing the number of rules.
722 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
723 # Don't define any builtin rules.
724 MAKEFLAGS := $(MAKEFLAGS)r
726 # Generic rule for making directories.
728 # mkdir isn't smart enough to strip a trailing /.
729         mkdir $(@:%/=%)
731 # Make sure that object files are not removed
732 # when they are intermediates between sources and library members.
733 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
735 # Make sure that the parent library archive is never removed.
736 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
738 # Use the verbose option of ar and tar when not running silently.
739 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
740 verbose := v
741 else                                            # -s
742 verbose :=
743 endif                                           # not -s
745 ARFLAGS := r$(verbose)
746 CREATE_ARFLAGS := cru$(verbose)
748 # This makes all the object files in the parent library archive.
750 .PHONY: lib lib-noranlib
751 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
752 lib-noranlib: libobjs
754 # For object-suffix $o, the list of objects with that suffix.
755 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
756 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
757                                                        $(elide-routines$o)),\
758                                             $(objects))) \
759             $(addprefix $(objpfx),$(o-objects$o))
761 others: $(addprefix $(objpfx),$(install-lib))
763 ifndef objects
765 # Create the stamp$o files to keep the parent makefile happy.
766 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
767 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
768         $(make-target-directory)
769         rm -f $@; > $@
770 else
772 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
773 # timestamp file; these rules (one explicit rule is generated for each
774 # object suffix) write a list of objects to update in the stamp file.
775 # The parent will then actually add them all to the archive in the
776 # archive rule, below.
777 define o-iterator-doit
778 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
779 endef
780 define do-stamp
781 $(make-target-directory)
782 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
783 mv -f $@T $@
784 endef
785 object-suffixes-left := $(object-suffixes-for-libc)
786 include $(o-iterator)
788 endif
790 # Now define explicit rules to build the library archives; these depend
791 # on the stamp files built above.
792 define o-iterator-doit
793 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
794                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
795 endef
796 define do-makelib
797 cd $(common-objdir) && \
798 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
799 $(RANLIB) $@
800 endef
801 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
802 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
803 ifndef subdir
804 $(subdirs-stamps): subdir_lib;
805 endif
806 object-suffixes-left = $(object-suffixes-for-libc)
807 include $(o-iterator)
810 # This makes all the object files.
811 .PHONY: objects objs libobjs extra-objs
812 objects objs: libobjs extra-objs
813 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
814 extra-objs: $(addprefix $(objpfx),$(extra-objs))
816 # Canned sequence for building an extra library archive.
817 define build-extra-lib
818 $(patsubst %/,cd % &&,$(objpfx)) \
819 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
820       $(patsubst $(objpfx)%,%,$^)
821 $(RANLIB) $@
822 endef
824 # Installation.
826 .PHONY: force-install
827 force-install:
829 # $(install-lib) are installed from the object directory into $(libdir);
830 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
831 # unless they also appear in $(non-lib.a).  $(install-data) are installed
832 # as they are into $(datadir).  $(headers) are installed as they are in
833 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
834 # are installed from the object directory into $(bindir), $(bindir) and
835 # $(sbindir), respectively.  $(install-others) are absolute path names of
836 # files to install; rules to install them are defined elsewhere.
838 # The simple library name to install libc.a under.
839 # This could be defined by a sysdep Makefile.
840 ifndef libc-name
841 libc-name := c
842 endif
844 define do-install
845 $(make-target-directory)
846 $(INSTALL_DATA) $< $@
847 endef
849 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
850 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
851 define make-target-directory
852 $(addprefix $(..)./scripts/mkinstalldirs ,\
853             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
854 endef
856 # Any directory (parent or subdir) should install libc.a; this way
857 # "make install" in a subdir is guaranteed to install everything it changes.
858 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
859                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
860                                                      $(libprefix)$(libc-name)))
861 install: $(installed-libcs)
862 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
863         $(make-target-directory)
864         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
865 # Running ranlib after installing makes the __.SYMDEF time stamp up to
866 # date, which avoids messages from some linkers.
867         $(RANLIB) $@
869 define do-install-program
870 $(make-target-directory)
871 $(INSTALL_PROGRAM) $< $@.new
872 mv -f $@.new $@
873 endef
875 define do-install-script
876 $(make-target-directory)
877 $(INSTALL_SCRIPT) $< $@.new
878 mv -f $@.new $@
879 endef
881 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
882 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
884 ifeq (yes,$(build-shared))
885 # Find which .so's have versions.
886 versioned := $(strip $(foreach so,$(install-lib.so),\
887                                $(patsubst %,$(so),$($(so)-version))))
889 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
890 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
892 # For versioned libraries, we install three files:
893 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
894 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
895 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
896 V := $(firstword $($(subdir)-version) $(version))
897 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
898                       $(foreach L,$(install-lib.so-versioned),\
899                                 $(inst_libdir)/$L \
900                                 $(inst_slibdir)/$(L:.so=)-$V.so \
901                                 $(inst_slibdir)/$L$($L-version))
903 # Install all the unversioned shared libraries.
904 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
905     $(objpfx)%.so $(+force)
906         $(do-install-program)
908 ifneq ($(findstring -s,$(LN_S)),)
909 define make-link
910 rm -f $@.new
911 $(SHELL) $(..)scripts/rellns-sh $< $@.new
912 mv -f $@.new $@
913 endef
914 else
915 # If we have no symbolic links don't bother with rellns-sh.
916 define make-link
917 rm -f $@.new
918 $(LN_S) $< $@.new
919 mv -f $@.new $@
920 endef
921 endif
923 ifeq (yes,$(build-shared))
924 ifeq (no,$(cross-compiling))
925 symbolic-link-prog := $(common-objpfx)elf/sln
926 symbolic-link-list := $(common-objpfx)elf/symlink.list
927 define make-shlib-link
928 echo $(<F) $@ >> $(symbolic-link-list)
929 endef
930 else # cross-compiling
931 # We need a definition that can be used by elf/Makefile's install rules.
932 symbolic-link-prog = $(LN_S)
933 endif
934 endif
935 ifndef make-shlib-link
936 define make-shlib-link
937 rm -f $@
938 $(LN_S) $(<F) $@
939 endef
940 endif
942 ifdef libc.so-version
943 # For a library specified to be version N, install three files:
944 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
945 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
947 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
948                                            $(+force)
949         $(make-shlib-link)
950 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
951         $(do-install-program)
952 install: $(inst_slibdir)/libc.so$(libc.so-version)
954 # This fragment of linker script gives the OUTPUT_FORMAT statement
955 # for the configuration we are building.  We put this statement into
956 # the linker scripts we install for -lc et al so that they will not be
957 # used by a link for a different format on a multi-architecture system.
958 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
959                             $(common-objpfx)config.make \
960                             $(common-objpfx)config.h $(..)Makerules
961         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
962                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
963         | sed -n -f $< > $@.new
964         rm -f $@.so
965         mv -f $@.new $@
966 common-generated += format.lds
968 ifndef subdir
969 # What we install as libc.so for programs to link against is in fact a
970 # link script.  It contains references for the various libraries we need.
971 # The libc.so object is not complete since some functions are only defined
972 # in libc_nonshared.a.
973 # We need to use absolute paths since otherwise local copies (if they exist)
974 # of the files are taken by the linker.
975 install: $(inst_libdir)/libc.so
976 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
977                         $(common-objpfx)libc.so$(libc.so-version) \
978                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
979                                                   $(libprefix)$(libc-name)) \
980                         $(+force)
981         (echo '/* GNU ld script';\
982          echo '   Use the shared library, but some functions are only in';\
983          echo '   the static library, so try that secondarily.  */';\
984          cat $<; \
985          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
986               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
987               ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
988         ) > $@.new
989         mv -f $@.new $@
991 endif
993 else
994 install: $(inst_slibdir)/libc.so
995 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
996         $(do-install-program)
997 endif
999 ifneq (,$(versioned))
1000 # Produce three sets of rules as above for all the smaller versioned libraries.
1002 define o-iterator-doit
1003 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1004 endef
1005 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1006 ifneq (,$(object-suffixes-left))
1007 include $(o-iterator)
1008 endif
1010 # Make symlinks in the build directory, because the versioned names might
1011 # be referenced by a DT_NEEDED in another library.
1012 define o-iterator-doit
1013 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1014 endef
1015 object-suffixes-left := $(versioned)
1016 include $(o-iterator)
1018 generated += $(foreach o,$(versioned),$o$($o-version))
1020 ifeq (,$($(subdir)-version))
1021 define o-iterator-doit
1022 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1023                                  $(+force);
1024         $$(make-shlib-link)
1025 endef
1026 object-suffixes-left := $(versioned)
1027 include $(o-iterator)
1029 define o-iterator-doit
1030 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1031         $$(do-install-program)
1032 endef
1033 object-suffixes-left := $(versioned)
1034 include $(o-iterator)
1035 else
1036 define o-iterator-doit
1037 $(inst_slibdir)/$o$($o-version): \
1038   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1039         $$(make-shlib-link)
1040 endef
1041 object-suffixes-left := $(versioned)
1042 include $(o-iterator)
1044 define o-iterator-doit
1045 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1046         $$(do-install-program)
1047 endef
1048 object-suffixes-left := $(versioned)
1049 include $(o-iterator)
1050 endif
1051 endif
1053 define do-install-so
1054 $(do-install-program)
1055 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1056            $(filter-out %.so,$@))
1057 endef
1059 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1060 $(foreach v,$(so-versions),\
1061           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1062                                                $(+force)
1063         $(do-install-so)
1064 $(foreach v,$(so-versions),\
1065           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1066         $(do-install-so)
1067 endif
1069 ifdef install-bin
1070 $(addprefix $(inst_bindir)/,$(install-bin)): \
1071     $(inst_bindir)/%: $(objpfx)% $(+force)
1072         $(do-install-program)
1073 endif
1074 ifdef install-bin-script
1075 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1076     $(inst_bindir)/%: $(objpfx)% $(+force)
1077         $(do-install-script)
1078 endif
1079 ifdef install-rootsbin
1080 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1081    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1082         $(do-install-program)
1083 endif
1084 ifdef install-sbin
1085 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1086     $(inst_sbindir)/%: $(objpfx)% $(+force)
1087         $(do-install-program)
1088 endif
1089 ifdef install-lib
1090 install-lib.a := $(filter lib%.a,$(install-lib))
1091 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1092 ifdef install-lib-non.a
1093 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1094   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1095         $(do-install)
1096 endif
1097 ifdef install-lib.a
1098 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1099   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1100         $(do-install)
1101         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1102 endif
1103 endif
1104 ifdef install-data
1105 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1106         $(do-install)
1107 endif
1108 headers := $(strip $(headers))
1109 ifdef headers
1110 # This implicit rule installs headers from the source directory.
1111 # It may be ignored in preference to rules from sysd-rules to find
1112 # headers in the sysdeps tree.
1113 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1114         $(do-install)
1115 $(inst_includedir)/%.h: %.h $(+force)
1116         $(do-install)
1117 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1118         $(do-install)
1119 headers-nonh := $(filter-out %.h,$(headers))
1120 ifdef headers-nonh
1121 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1122                                                  % $(+force)
1123         $(do-install)
1124 endif   # headers-nonh
1125 endif   # headers
1127 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1128         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1129         install-data-nosubdir install-headers-nosubdir
1130 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1131 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1132 install-rootsbin-nosubdir: \
1133         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1134 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1135 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1136                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1137                        $(addprefix $(libprefix),$(install-lib-non.a)))
1138 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1139 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1140 install-others-nosubdir: $(install-others)
1142 # We need all the `-nosubdir' targets so that `install' in the parent
1143 # doesn't depend on several things which each iterate over the subdirs.
1144 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1145 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1146 install-%:: install-%-nosubdir ;
1148 .PHONY: install install-no-libc.a-nosubdir
1149 ifeq ($(build-programs),yes)
1150 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1151                             install-bin-nosubdir install-bin-script-nosubdir \
1152                             install-lib-nosubdir install-others-nosubdir \
1153                             install-rootsbin-nosubdir install-sbin-nosubdir
1154 else
1155 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1156                             install-lib-nosubdir install-others-nosubdir
1157 endif
1158 install: install-no-libc.a-nosubdir
1160 # Command to compile $< in $(objdir) using the native libraries.
1161 define native-compile
1162 $(make-target-directory)
1163 $(patsubst %/,cd % &&,$(objpfx)) \
1164 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1165             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1166 endef
1168 # Command to compile $< in $(common-objdir) using the native libraries.
1169 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1170 define common-objdir-compile
1171 $(patsubst %/,cd % &&,$(objpfx)) \
1172 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1173             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1174 endef
1176 # We always want to use configuration definitions.
1177 # Note that this is only used for commands running in $(objpfx).
1178 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1180 # Support the GNU standard name for this target.
1181 .PHONY: check
1182 check: tests
1183 # Special target to run tests which cannot be run unconditionally.
1184 # Maintainers should use this target.
1185 .PHONY: xcheck
1186 xcheck: xtests
1188 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1189 ifneq (,$(all-nonlib))
1190 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1191 lib := nonlib
1192 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1193 endif
1195 # The include magic above causes those files to use this variable for flags.
1196 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1199 ifeq ($(versioning),yes)
1200 # Generate normalized lists of symbols, versions, and data sizes.
1201 # This is handy for checking against existing library binaries.
1203 %.symlist: $(..)scripts/abilist.awk %.dynsym
1204         LC_ALL=C $(AWK) -f $^ > $@T
1205         mv -f $@T $@
1207 %.dynsym: %.so
1208         $(OBJDUMP) --dynamic-syms $< > $@T
1209         mv -f $@T $@
1211 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1212              $(..)abilist/%.abilist $(objpfx)%.symlist
1213         $(check-abi)
1214 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1215              $(..)abilist/%.abilist $(common-objpfx)%.symlist
1216         $(check-abi)
1217 define check-abi
1218         LC_ALL=C \
1219         $(AWK) -f $< -v 'config=$(check-abi-config)' \
1220                $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1221                $(filter %.abilist,$^) \
1222         | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1223 endef
1224 ifeq ($(enable-check-abi),warn)
1225 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1226 endif
1228 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1229 -include $(common-objpfx)tls.make
1230 config-tls := notls
1231 ifeq ($(use-tls),yes)
1232 config-tls := tls
1233 endif
1234 ifeq ($(use-thread),yes)
1235 config-tls := thread
1236 endif
1237 check-abi-config := \
1238   $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1239 endif
1241 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1242               $(objpfx)%.symlist
1243         $(update-abi)
1244 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1245               $(common-objpfx)%.symlist
1246         $(update-abi)
1247 ifndef update-abi-config
1248 define update-abi
1249         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1250 endef
1251 else
1252 define update-abi
1253 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1254          > $(..)abilist/$*.abilist.new
1255 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1256  then rm -f $(..)abilist/$*.abilist.new; \
1257       echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1258  else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1259       echo '*** Now check $*.abilist changes for correctness ***'; \
1260  fi
1261 endef
1262 endif
1264 .PHONY: update-abi check-abi
1265 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1266 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1267 ifdef subdir
1268 subdir_check-abi: check-abi
1269 subdir_update-abi: update-abi
1270 else
1271 check-abi: subdir_check-abi
1272 update-abi: subdir_update-abi
1273 endif
1275 ifeq ($(subdir),elf)
1276 check-abi: check-abi-libc
1277 update-abi: update-abi-libc
1278 common-generated += libc.symlist
1279 endif
1281 ifeq ($(build-shared),yes)
1282 ifneq ($(enable-check-abi),no)
1283 ifdef subdir
1284 tests: check-abi
1285 endif
1286 endif
1287 endif
1289 endif
1291 # These will have been set by sysdeps/posix/Makefile.
1292 L_tmpnam  ?= 1
1293 TMP_MAX   ?= 0
1294 L_ctermid ?= 1
1295 L_cuserid ?= 1
1297 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1299 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1300 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1301                    $(common-objpfx)config.make
1302         $(make-target-directory)
1303         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1304           echo '#define _LIBC 1';                                       \
1305           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1306         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1307               $(+includes) -xc - -o $(@:st=hT)
1308         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1309             $(@:st=dT) > $(@:st=dt)
1310         mv -f $(@:st=dt) $(@:st=d)
1311         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1312         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1313         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1314         fopen_max=$${fopen_max:-16};                                    \
1315         filename_max=$${filename_max:-1024};                            \
1316         if [ -z "$$iov_max" ]; then                                     \
1317           define_iov_max="# undef IOV_MAX";                             \
1318         else                                                            \
1319           define_iov_max="# define IOV_MAX $$iov_max";                  \
1320         fi;                                                             \
1321         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1322             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1323             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1324             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1325             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1326             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1327             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1328             $< > $(@:st=h.new)
1329         $(move-if-change) $(@:st=h.new) $(@:st=h)
1330 # Remove these last so that they can be examined if something went wrong.
1331         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1332         touch $@
1333 # Get dependencies.
1334 ifndef no_deps
1335 -include $(stdio_lim:h=d)
1336 endif
1337 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1339 FORCE:
1341 .PHONY: echo-headers
1342 echo-headers:
1343         @echo $(headers)
1345 %.bz2: %; bzip2 -9vk $<
1346 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1348 # Common cleaning targets.
1350 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1351 clean: common-clean
1352 mostlyclean: common-mostlyclean
1354 do-tests-clean:
1355         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1356                                                       $(test-srcs)) \
1357                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1358                                                          $(test-srcs)))
1360 # Remove the object files.
1361 common-mostlyclean:
1362         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1363                                      $(others) $(sysdep-others) stubs \
1364                                      $(addsuffix .o,$(tests) $(xtests) \
1365                                                     $(test-srcs) $(others) \
1366                                                     $(sysdep-others)) \
1367                                      $(addsuffix -bp,$(tests) $(xtests) \
1368                                                      $(test-srcs)) \
1369                                      $(addsuffix .out,$(tests) $(xtests) \
1370                                                       $(test-srcs)) \
1371                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1372                                                          $(test-srcs)))
1373         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1374                                      $(install-lib) $(install-lib.so) \
1375                                      $(install-lib.so:%.so=%_pic.a))
1376         -rm -f core
1377         -rm -f $(objpfx)rtld-*.os
1378         $(rmobjs)
1379 define rmobjs
1380 $(foreach o,$(object-suffixes-for-libc),
1381 -rm -f $(objpfx)stamp$o $(o-objects))
1382 endef
1384 # Also remove the dependencies and generated source files.
1385 common-clean: common-mostlyclean
1386         -rm -f $(addprefix $(objpfx),$(generated))
1387         -rm -f $(objpfx)*.d $(objpfx)*.dt
1388         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1389         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1391 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1392 # for each function which is a stub.  We grovel over all the .d files
1393 # looking for references to <stub-tag.h>.  Then we grovel over each
1394 # referenced source file to see what stub function it defines.
1396 ifdef objpfx
1397 .PHONY: stubs # The parent Makefile calls this target.
1398 stubs: $(objpfx)stubs
1399 endif
1400 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1401                   $(addprefix $(objpfx),$(extra-objs))
1402 $(objpfx)stubs: $(objs-for-stubs)
1403 ifneq (,$(strip $(objs-for-stubs)))
1404         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1405         $(AWK) '/\.gnu\.glibc-stub\./ { \
1406                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1407                   stubs[$$2] = 1; } \
1408                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1409         mv -f $@T $@
1410 else
1411         > $@
1412 endif
1414 ifneq (,$(strip $(gpl2lgpl)))
1415 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1416 # Snarf from the master source and frob the copying notice.
1417 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1418         sed -f $^ > $@-tmp
1419 # So I don't edit them by mistake.
1420         chmod a-w $@-tmp
1421         mv -f $@-tmp $@
1422 ifeq ($(with-cvs),yes)
1423         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1424 endif
1425 endif
1426 endif
1428 # Local Variables:
1429 # mode: makefile
1430 # End: