Fix non-add-on handling of libc-abis.
[glibc.git] / Makerules
blob9c15a27a5df041644789387e3e29dccd40fc19bf
1 # Copyright (C) 1991-2006,2007,2008,2009,2010 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 ifndef avoid-generated
113 before-compile := $(common-objpfx)libc-abis.h $(before-compile)
114 libc-abis := $(firstword $(wildcard $(foreach D,$(add-ons), \
115                                     $(..)$D/libc-abis)) \
116                          $(..)libc-abis)
117 $(common-objpfx)libc-abis.h: $(..)scripts/gen-libc-abis $(libc-abis)
118         $(SHELL) $(..)scripts/gen-libc-abis \
119                  $(base-machine)-$(config-vendor)-$(config-os) \
120                  < $(libc-abis) > $@T
121         $(move-if-change) $@T $@
122 common-generated += $(common-objpfx)libc-abis.h
123 endif # avoid-generated
125 # Make sure the subdirectory for object files gets created.
126 ifdef objpfx
127 ifeq (,$(wildcard $(objpfx).))
128 before-compile += $(objpfx).
129 $(objpfx).:
130         $(make-target-directory)
131 endif
132 endif
134 # Remove existing files from `before-compile'.  Things are added there when
135 # they must exist for dependency generation to work right, but once they
136 # exist there is no further need for every single file to depend on them,
137 # and those gratuitous dependencies result in many gratuitous
138 # recompilations.
139 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
141 # Don't let any before-compile file be an intermediate and get removed.
142 ifdef before-compile
143 $(before-compile):
144 endif
146 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
147 # in subdirs.
148 ifdef subdir
149 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
150 else
151 common-before-compile = $(before-compile)
152 endif
154 ifndef subdir
155 # If a makefile needs to do something conditional on something that
156 # can only be figured out from headers, write a FOO.make.c input
157 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
158 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
160 # We only generate these in the top-level makefile, to avoid any weirdness
161 # from subdir-specific makefile tweaks creeping in on an update.
162 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
163         rm -f $@T $@.dT
164         (echo '# Generated from $*.make.c by Makerules.'; \
165          $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
166                -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
167          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
168          echo 'common-generated += $(@F)'; \
169          sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
170          rm -f $@.dT) > $@T
171         mv -f $@T $@
172 endif
174 ifdef subdir
175 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g' \
176                      -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
177 else
178 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g' \
179                      -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
180 endif
183 ifdef gen-as-const-headers
184 # Generating headers for assembly constants.
185 # We need this defined early to get into before-compile before
186 # it's used in sysd-rules, below.
187 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
188                                            %.sym $(common-before-compile)
189         $(AWK) -f $< $(filter %.sym,$^) \
190         | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
191                 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
192         sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
193                 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
194         rm -f $(@:.h.d=.h)T3
195         sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
196             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
197         rm -f $(@:.h=.h.d)T
198         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
199         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
200 vpath %.sym $(sysdirs)
201 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
203 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
204 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
205 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
206                             %.sym $(common-objpfx)%.h
207         ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
208          $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
209          echo '#include "$(..)test-skeleton.c"') > $@T
210         mv -f $@T $@
211 endif
213 # Generate an ordered list of implicit rules which find the source files in
214 # each sysdep directory.  The old method was to use vpath to search all the
215 # sysdep directories.  However, that had the problem that a .S file in a
216 # later directory would be chosen over a .c file in an earlier directory,
217 # which does not preserve the desired sysdeps ordering behavior.
219 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
220 # patterns matching sysdep directories whose assembly source files should
221 # be suppressed.
222 ifdef inhibit-sysdep-asm
223 define check-inhibit-asm
224 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) asm= ;; esac;
225 endef
226 endif
228 -include $(common-objpfx)sysd-rules
229 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
230 # The value of $(+sysdep_dirs) the sysd-rules was computed for
231 # differs from the one we are using now.  So force a rebuild of sysd-rules.
232 sysd-rules-force = FORCE
233 FORCE:
234 endif
235 $(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
236                             $(sysdep-makefiles) $(sysdep-makeconfigs) \
237                             $(sysd-rules-force)
238         -@rm -f $@T
239         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
240          for dir in $(config-sysdirs); do                                     \
241            case "$$dir" in                                                    \
242            /*) ;;                                                             \
243            *) dir="\$$(..)$$dir" ;;                                           \
244            esac;                                                              \
245            asm='.S .s';                                                       \
246            $(check-inhibit-asm)                                               \
247            for o in $(all-object-suffixes); do                                \
248              set $(subst :, ,$(sysd-rules-patterns));                         \
249              while [ $$# -ge 2 ]; do                                          \
250                t=$$1; shift;                                                  \
251                d=$$1; shift;                                                  \
252                v=$${t%%%}; [ x"$$v" = x ] || v="\$$($${v}CPPFLAGS)";          \
253                for s in $$asm .c; do                                          \
254                  echo "\$$(objpfx)$$t$$o: $$dir/$$d$$s \$$(before-compile)";  \
255                  echo " \$$(compile-command$$s) $$v";                         \
256                done;                                                          \
257              done;                                                            \
258            done;                                                              \
259            echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force)";            \
260            echo "       \$$(do-install)";                                     \
261          done;                                                                \
262          echo 'sysd-rules-done = t') > $@T
263         mv -f $@T $@
265 ifndef sysd-rules-done
266 # Don't do deps until this exists, because it provides rules to make the deps.
267 no_deps=t
268 endif
270 define o-iterator-doit
271 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
272 endef
273 object-suffixes-left := $(all-object-suffixes)
274 include $(o-iterator)
276 define o-iterator-doit
277 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
278 endef
279 object-suffixes-left := $(all-object-suffixes)
280 include $(o-iterator)
282 define o-iterator-doit
283 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
284 endef
285 object-suffixes-left := $(all-object-suffixes)
286 include $(o-iterator)
288 define o-iterator-doit
289 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
290 endef
291 object-suffixes-left := $(all-object-suffixes)
292 include $(o-iterator)
294 # Omit the objpfx rules when building in the source tree, because
295 # objpfx is empty and so these rules just override the ones above.
296 ifdef objpfx
297 # Define first rules to find the source files in $(objpfx).
298 # Generated source files will end up there.
299 define o-iterator-doit
300 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
301 endef
302 object-suffixes-left := $(all-object-suffixes)
303 include $(o-iterator)
305 define o-iterator-doit
306 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
307 endef
308 object-suffixes-left := $(all-object-suffixes)
309 include $(o-iterator)
311 define o-iterator-doit
312 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
313 endef
314 object-suffixes-left := $(all-object-suffixes)
315 include $(o-iterator)
316 endif
318 # Generate version maps, but wait until sysdep-subdirs is known
319 ifeq ($(sysd-sorted-done),t)
320 ifeq ($(versioning),yes)
321 -include $(common-objpfx)sysd-versions
322 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
323 common-generated += $(version-maps)
324 postclean-generated += sysd-versions Versions.all abi-versions.h \
325                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
327 ifndef avoid-generated
328 ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
329 sysd-versions-force = FORCE
330 FORCE:
331 endif
332 # See %.v/%.v.i implicit rules in Makeconfig.
333 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
334                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
335 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
336                               $(common-objpfx)soversions.i \
337                               $(common-objpfx)Versions.def.v
338         { while read which lib version setname; do \
339             test x"$$which" = xDEFAULT || continue; \
340             test -z "$$setname" || echo "$$lib : $$setname"; \
341           done < $(word 2,$^); \
342           cat $(word 3,$^); \
343         } | LC_ALL=C $(AWK) -f $< > $@T
344         mv -f $@T $@
345 # See %.v/%.v.i implicit rules in Makeconfig.
346 $(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
347                               $(wildcard $(sysdirs:%=%/Versions)) \
348                               $(common-objpfx)abi-versions.h \
349                               $(sysd-versions-force)
350 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
351                                $(common-objpfx)Versions.v \
352                                $(..)scripts/versions.awk
353         ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
354           cat $(word 2,$^) \
355           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
356                             -v move_if_change='$(move-if-change)' \
357                             -f $(word 3,$^); \
358         ) > $@T
359         mv -f $@T $@
360 endif # avoid-generated
361 endif # $(versioning) = yes
362 endif # sysd-sorted-done
364 # Generate .dT files as we compile.
365 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
366 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
367 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
368 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
369 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
371 # GCC can grok options after the file name, and it looks nicer that way.
372 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
373 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(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               $(if $(filter yes,$(have-hash-style)), \
490                    -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
491                    -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
492                    -e '/DATA_SEGMENT_ALIGN/{H;g}' \
493                 , \
494                    -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
495                ) \
496               -e 's/^.*\*(\.dynbss).*$$/& \
497                  PROVIDE(__start___libc_freeres_ptrs = .); \
498                  *(__libc_freeres_ptrs) \
499                  PROVIDE(__stop___libc_freeres_ptrs = .);/'\
500               -e 's@^.*\*(\.jcr).*$$@& \
501                  PROVIDE(__start___libc_subfreeres = .);\
502                  __libc_subfreeres : { *(__libc_subfreeres) }\
503                  PROVIDE(__stop___libc_subfreeres = .);\
504                  PROVIDE(__start___libc_atexit = .);\
505                  __libc_atexit : { *(__libc_atexit) }\
506                  PROVIDE(__stop___libc_atexit = .);\
507                  PROVIDE(__start___libc_thread_subfreeres = .);\
508                  __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
509                  PROVIDE(__stop___libc_thread_subfreeres = .);\
510                  /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
511         mv -f $@T $@
512 common-generated += shlib.lds
514 define build-shlib
515 $(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
516           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
517 endef
518 else
519 ifneq (,$(findstring aix,$(config-os)))
520 define build-shlib
521 $(build-shlib-helper) \
522         -o $@ \
523         $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
524         $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
525 endef
526 define build-shlib
527 $(build-shlib-helper) \
528           $(build-shlib-objlist)
529 endef
530 endif
531 endif
533 ifneq (,$(findstring aix,$(config-os)))
534 define build-module-helper
535 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
536           $(sysdep-LDFLAGS) $(config-LDFLAGS) \
537           $(load-map-file) \
538           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
539           -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
540 endef
541 else
542 define build-module-helper
543 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
544           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
545           -B$(csu-objpfx) $(load-map-file) \
546           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
547           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
548 endef
549 endif
551 # This macro is similar to build-shlib but it does not define a soname
552 # and it does not depend on the destination name to start with `lib'.
553 ifeq (yes,$(elf))
554 # binutils only position loadable notes into the first page for binaries,
555 # not for shared objects
556 define build-module
557 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
558           $(csu-objpfx)abi-note.o $(build-module-objlist)
559 endef
560 define build-module-asneeded
561 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
562           $(csu-objpfx)abi-note.o \
563           -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
564 endef
565 else
566 ifneq (,$(findstring aix,$(config-os)))
567 define build-module
568 $(build-module-helper) \
569           -o $@ \
570           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
571           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
572 endef
573 else
574 define build-module
575 define build-module
576 $(build-module-helper) \
577           -o $@ \
578           $(build-module-objlist)
579 endef
580 endif
581 endif
583 build-module-helper-objlist = \
584         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
585                    $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
586 whole-archive := -Wl,--whole-archive
588 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
589 build-shlib-objlist = $(build-module-helper-objlist) \
590                       $(LDLIBS-$(@F:lib%.so=%).so)
592 # Don't try to use -lc when making libc.so itself.
593 # Also omits crti.o and crtn.o, which we do not want
594 # since we define our own `.init' section specially.
595 LDFLAGS-c.so = -nostdlib -nostartfiles
596 # But we still want to link libc.so against $(libc.so-gnulib).
597 LDLIBS-c.so += $(libc.so-gnulib)
598 # Give libc.so an entry point and make it directly runnable itself.
599 LDFLAGS-c.so += -e __libc_main
600 # If lazy relocation is disabled add the -z now flag.
601 ifeq ($(bind-now),yes)
602 LDFLAGS-c.so += -Wl,-z,now
603 endif
604 # Pre-link the objects of libc_pic.a so that we can locally resolve
605 # COMMON symbols before we link against ld.so.  This is because ld.so
606 # contains some of libc_pic.a already, which will prevent the COMMONs
607 # from being allocated in libc.so, which introduces evil dependencies
608 # between libc.so and ld.so, which can make it impossible to upgrade.
609 ifeq ($(elf),yes)
610 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
611         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
612         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
613 # Use our own special initializer and finalizer files for libc.so.
614 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
615                          $(common-objpfx)libc_pic.os \
616                          $(elfobjdir)/sofini.os \
617                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
618                          $(common-objpfx)shlib.lds
619         $(build-shlib)
620 ifeq ($(versioning),yes)
621 $(common-objpfx)libc.so: $(common-objpfx)libc.map
622 endif
623 common-generated += libc.so libc_pic.os
624 ifdef libc.so-version
625 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
626         $(make-link)
627 common-generated += libc.so$(libc.so-version)
628 endif
629 endif
630 else
631 ifneq (,$(findstring aix,$(config-os)))
632 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
633         @rm -f $@
634         (echo '#!'; \
635          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
636         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
637             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
638         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
639                   -bE:$(common-objpfx)syscalls.exp \
640                   -bI:$(common-objpfx)syscalls.exp \
641                   -L$(common-objpfx) -o $@ $^
642 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
643         cp $@ $(common-objpfx)shr.o
644         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
645 endif
646 endif
648 # Figure out the source filenames in this directory.
650 override sources := $(addsuffix .c,\
651                         $(filter-out $(elided-routines),\
652                             $(routines) $(aux) \
653                             $(sysdep_routines)))
654 sysdep_routines := $(sysdep_routines)
656 headers := $(headers) $(sysdep_headers)
658 # This is the list of all object files, gotten by
659 # replacing every ".c" in `sources' with a ".o".
660 # We also add bounded-pointer thunks, which are later
661 # elided for all suffixes except for `.ob'.
662 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
663                       $(patsubst %,$(bppfx)%.o,\
664                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
667 # The makefile may define $(extra-libs) with `libfoo libbar'
668 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
669 ifdef extra-libs
670 # extra-lib.mk is included once for each extra lib to define rules
671 # to build it, and to add its objects to the various variables.
672 # During its evaluation, $(lib) is set to the name of the library.
673 extra-libs-left := $(extra-libs)
674 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
675 endif
678 # The makefile may define $(modules-names) to build additional modules.
679 # These are built with $(build-module), except any in $(modules-names-nobuild).
680 ifdef modules-names
681 # extra-lib.mk is included once for each extra lib to define rules
682 # to build it, and to add its objects to the various variables.
683 # During its evaluation, $(lib) is set to the name of the library.
684 extra-modules-left := $(modules-names)
685 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
687 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
688 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
689                 $(objpfx)%.os $(common-objpfx)shlib.lds \
690                 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
691         $(build-module)
692 endif
694 +depfiles := $(sources:.c=.d) \
695              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
696              $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
697              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
698 ifeq ($(build-programs),yes)
699 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
700 endif
701 +depfiles := $(addprefix $(objpfx),\
702                          $(filter-out $(addsuffix .d,$(omit-deps)),\
703                                       $(+depfiles)))
704 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
705 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
706              $(wildcard $(all-dt-files:.dt=.d))
708 # This is a funny rule in that it removes its input file.
709 %.d: %.dt
710         @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
711          mv -f $(@:.d=.T) $@ && \
712          rm -f $<
714 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
715 # They will be generated when they're needed, and trying too early won't work.
716 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
717 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
718                                                 $(+gen-as-const)))
720 ifdef +depfiles
721 ifneq ($(no_deps),t)
722 -include $(+depfiles)
723 endif
724 endif
725 \f\f
726 # Maximize efficiency by minimizing the number of rules.
727 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
728 # Don't define any builtin rules.
729 MAKEFLAGS := $(MAKEFLAGS)r
731 # Generic rule for making directories.
733 # mkdir isn't smart enough to strip a trailing /.
734 # We always require a mkdir which supports the -p option to avoid error
735 # messages in case of races.
736         mkdir -p $(@:%/=%)
738 # Make sure that object files are not removed
739 # when they are intermediates between sources and library members.
740 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
742 # Make sure that the parent library archive is never removed.
743 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
745 # Use the verbose option of ar and tar when not running silently.
746 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
747 verbose := v
748 else                                            # -s
749 verbose :=
750 endif                                           # not -s
752 ARFLAGS := r$(verbose)
753 CREATE_ARFLAGS := cru$(verbose)
755 # This makes all the object files in the parent library archive.
757 .PHONY: lib lib-noranlib
758 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
759 lib-noranlib: libobjs
761 # For object-suffix $o, the list of objects with that suffix.
762 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
763 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
764                                                        $(elide-routines$o)),\
765                                             $(objects))) \
766             $(addprefix $(objpfx),$(o-objects$o))
768 others: $(addprefix $(objpfx),$(install-lib))
770 ifndef objects
772 # Create the stamp$o files to keep the parent makefile happy.
773 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
774 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
775         $(make-target-directory)
776         rm -f $@; > $@
777 else
779 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
780 # timestamp file; these rules (one explicit rule is generated for each
781 # object suffix) write a list of objects to update in the stamp file.
782 # The parent will then actually add them all to the archive in the
783 # archive rule, below.
784 define o-iterator-doit
785 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
786 endef
787 define do-stamp
788 $(make-target-directory)
789 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
790 mv -f $@T $@
791 endef
792 object-suffixes-left := $(object-suffixes-for-libc)
793 include $(o-iterator)
795 endif
797 # Now define explicit rules to build the library archives; these depend
798 # on the stamp files built above.
799 define o-iterator-doit
800 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
801                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
802 endef
803 define do-makelib
804 cd $(common-objdir) && \
805 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
806 $(RANLIB) $@
807 endef
808 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
809 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
810 ifndef subdir
811 $(subdirs-stamps): subdir_lib;
812 endif
813 object-suffixes-left = $(object-suffixes-for-libc)
814 include $(o-iterator)
817 # This makes all the object files.
818 .PHONY: objects objs libobjs extra-objs
819 objects objs: libobjs extra-objs
820 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
821 extra-objs: $(addprefix $(objpfx),$(extra-objs))
823 # Canned sequence for building an extra library archive.
824 define build-extra-lib
825 $(patsubst %/,cd % &&,$(objpfx)) \
826 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
827       $(patsubst $(objpfx)%,%,$^)
828 $(RANLIB) $@
829 endef
831 # Installation.
833 .PHONY: force-install
834 force-install:
836 # $(install-lib) are installed from the object directory into $(libdir);
837 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
838 # unless they also appear in $(non-lib.a).  $(install-data) are installed as
839 # they are into $(datadir).  $(headers) are installed as they are in
840 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
841 # are installed from the object directory into $(bindir), $(bindir) and
842 # $(sbindir), respectively.  $(install-others) and $(install-others-programs)
843 # are absolute path names of files to install; rules to install them are
844 # defined elsewhere.
846 # The simple library name to install libc.a under.
847 # This could be defined by a sysdep Makefile.
848 ifndef libc-name
849 libc-name := c
850 endif
852 define do-install
853 $(make-target-directory)
854 $(INSTALL_DATA) $< $@
855 endef
857 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
858 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
859 define make-target-directory
860 $(addprefix $(..)./scripts/mkinstalldirs ,\
861             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
862 endef
864 # Any directory (parent or subdir) should install libc.a; this way
865 # "make install" in a subdir is guaranteed to install everything it changes.
866 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
867                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
868                                                      $(libprefix)$(libc-name)))
869 install: $(installed-libcs)
870 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
871         $(make-target-directory)
872         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
873 # Running ranlib after installing makes the __.SYMDEF time stamp up to
874 # date, which avoids messages from some linkers.
875         $(RANLIB) $@
877 define do-install-program
878 $(make-target-directory)
879 $(INSTALL_PROGRAM) $< $@.new
880 mv -f $@.new $@
881 endef
883 define do-install-script
884 $(make-target-directory)
885 $(INSTALL_SCRIPT) $< $@.new
886 mv -f $@.new $@
887 endef
889 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
890 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
892 ifeq (yes,$(build-shared))
893 # Find which .so's have versions.
894 versioned := $(strip $(foreach so,$(install-lib.so),\
895                                $(patsubst %,$(so),$($(so)-version))))
897 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
898 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
900 # For versioned libraries, we install three files:
901 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
902 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
903 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
904 V := $(firstword $($(subdir)-version) $(version))
905 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
906                       $(foreach L,$(install-lib.so-versioned),\
907                                 $(inst_libdir)/$L \
908                                 $(inst_slibdir)/$(L:.so=)-$V.so \
909                                 $(inst_slibdir)/$L$($L-version))
911 # Install all the unversioned shared libraries.
912 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
913     $(objpfx)%.so $(+force)
914         $(do-install-program)
916 ifneq ($(findstring -s,$(LN_S)),)
917 define make-link
918 rm -f $@.new
919 $(SHELL) $(..)scripts/rellns-sh $< $@.new
920 mv -f $@.new $@
921 endef
922 else
923 # If we have no symbolic links don't bother with rellns-sh.
924 define make-link
925 rm -f $@.new
926 $(LN_S) $< $@.new
927 mv -f $@.new $@
928 endef
929 endif
931 ifeq (yes,$(build-shared))
932 ifeq (no,$(cross-compiling))
933 symbolic-link-prog := $(common-objpfx)elf/sln
934 symbolic-link-list := $(common-objpfx)elf/symlink.list
935 define make-shlib-link
936 echo $(<F) $@ >> $(symbolic-link-list)
937 endef
938 else # cross-compiling
939 # We need a definition that can be used by elf/Makefile's install rules.
940 symbolic-link-prog = $(LN_S)
941 endif
942 endif
943 ifndef make-shlib-link
944 define make-shlib-link
945 rm -f $@
946 $(LN_S) $(<F) $@
947 endef
948 endif
950 ifdef libc.so-version
951 # For a library specified to be version N, install three files:
952 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
953 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
955 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
956                                            $(+force)
957         $(make-shlib-link)
958 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
959         $(do-install-program)
960 install: $(inst_slibdir)/libc.so$(libc.so-version)
962 # This fragment of linker script gives the OUTPUT_FORMAT statement
963 # for the configuration we are building.  We put this statement into
964 # the linker scripts we install for -lc et al so that they will not be
965 # used by a link for a different format on a multi-architecture system.
966 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
967                             $(common-objpfx)config.make \
968                             $(common-objpfx)config.h $(..)Makerules
969         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
970                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
971         | sed -n -f $< > $@.new
972         rm -f $@.so
973         mv -f $@.new $@
974 common-generated += format.lds
976 ifndef subdir
977 # What we install as libc.so for programs to link against is in fact a
978 # link script.  It contains references for the various libraries we need.
979 # The libc.so object is not complete since some functions are only defined
980 # in libc_nonshared.a.
981 # We need to use absolute paths since otherwise local copies (if they exist)
982 # of the files are taken by the linker.
983 install: $(inst_libdir)/libc.so
984 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
985                         $(common-objpfx)libc.so$(libc.so-version) \
986                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
987                                                   $(libprefix)$(libc-name)) \
988                         $(+force)
989         (echo '/* GNU ld script';\
990          echo '   Use the shared library, but some functions are only in';\
991          echo '   the static library, so try that secondarily.  */';\
992          cat $<; \
993          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
994               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
995               ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
996         ) > $@.new
997         mv -f $@.new $@
999 endif
1001 else
1002 install: $(inst_slibdir)/libc.so
1003 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1004         $(do-install-program)
1005 endif
1007 ifneq (,$(versioned))
1008 # Produce three sets of rules as above for all the smaller versioned libraries.
1010 define o-iterator-doit
1011 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1012 endef
1013 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1014 ifneq (,$(object-suffixes-left))
1015 include $(o-iterator)
1016 endif
1018 # Make symlinks in the build directory, because the versioned names might
1019 # be referenced by a DT_NEEDED in another library.
1020 define o-iterator-doit
1021 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1022 endef
1023 object-suffixes-left := $(versioned)
1024 include $(o-iterator)
1026 generated += $(foreach o,$(versioned),$o$($o-version))
1028 ifeq (,$($(subdir)-version))
1029 define o-iterator-doit
1030 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1031                                  $(+force);
1032         $$(make-shlib-link)
1033 endef
1034 object-suffixes-left := $(versioned)
1035 include $(o-iterator)
1037 define o-iterator-doit
1038 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1039         $$(do-install-program)
1040 endef
1041 object-suffixes-left := $(versioned)
1042 include $(o-iterator)
1043 else
1044 define o-iterator-doit
1045 $(inst_slibdir)/$o$($o-version): \
1046   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1047         $$(make-shlib-link)
1048 endef
1049 object-suffixes-left := $(versioned)
1050 include $(o-iterator)
1052 define o-iterator-doit
1053 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1054         $$(do-install-program)
1055 endef
1056 object-suffixes-left := $(versioned)
1057 include $(o-iterator)
1058 endif
1059 endif
1061 define do-install-so
1062 $(do-install-program)
1063 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1064            $(filter-out %.so,$@))
1065 endef
1067 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1068 $(foreach v,$(so-versions),\
1069           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1070                                                $(+force)
1071         $(do-install-so)
1072 $(foreach v,$(so-versions),\
1073           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1074         $(do-install-so)
1075 endif
1077 ifdef install-bin
1078 $(addprefix $(inst_bindir)/,$(install-bin)): \
1079     $(inst_bindir)/%: $(objpfx)% $(+force)
1080         $(do-install-program)
1081 endif
1082 ifdef install-bin-script
1083 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1084     $(inst_bindir)/%: $(objpfx)% $(+force)
1085         $(do-install-script)
1086 endif
1087 ifdef install-rootsbin
1088 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1089    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1090         $(do-install-program)
1091 endif
1092 ifdef install-sbin
1093 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1094     $(inst_sbindir)/%: $(objpfx)% $(+force)
1095         $(do-install-program)
1096 endif
1097 ifdef install-lib
1098 install-lib.a := $(filter lib%.a,$(install-lib))
1099 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1100 ifdef install-lib-non.a
1101 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1102   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1103         $(do-install)
1104 endif
1105 ifdef install-lib.a
1106 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1107   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1108         $(do-install)
1109         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1110 endif
1111 endif
1112 ifdef install-data
1113 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1114         $(do-install)
1115 endif
1116 headers := $(strip $(headers))
1117 ifdef headers
1118 # This implicit rule installs headers from the source directory.
1119 # It may be ignored in preference to rules from sysd-rules to find
1120 # headers in the sysdeps tree.
1121 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1122         $(do-install)
1123 $(inst_includedir)/%.h: %.h $(+force)
1124         $(do-install)
1125 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1126         $(do-install)
1127 headers-nonh := $(filter-out %.h,$(headers))
1128 ifdef headers-nonh
1129 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1130                                                  % $(+force)
1131         $(do-install)
1132 endif   # headers-nonh
1133 endif   # headers
1135 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1136         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1137         install-data-nosubdir install-headers-nosubdir
1138 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1139 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1140 install-rootsbin-nosubdir: \
1141         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1142 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1143 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1144                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1145                        $(addprefix $(libprefix),$(install-lib-non.a)))
1146 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1147 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1148 install-others-nosubdir: $(install-others)
1149 install-others-programs-nosubdir: $(install-others-programs)
1151 # We need all the `-nosubdir' targets so that `install' in the parent
1152 # doesn't depend on several things which each iterate over the subdirs.
1153 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1154 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1155 install-%:: install-%-nosubdir ;
1157 .PHONY: install install-no-libc.a-nosubdir
1158 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1159                             install-lib-nosubdir install-others-nosubdir
1160 ifeq ($(build-programs),yes)
1161 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1162                             install-rootsbin-nosubdir install-sbin-nosubdir \
1163                             install-others-programs-nosubdir
1164 endif
1165 install: install-no-libc.a-nosubdir
1167 # Command to compile $< in $(objdir) using the native libraries.
1168 define native-compile
1169 $(make-target-directory)
1170 $(patsubst %/,cd % &&,$(objpfx)) \
1171 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1172             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1173 endef
1175 # Command to compile $< in $(common-objdir) using the native libraries.
1176 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1177 define common-objdir-compile
1178 $(patsubst %/,cd % &&,$(objpfx)) \
1179 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1180             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1181 endef
1183 # We always want to use configuration definitions.
1184 # Note that this is only used for commands running in $(objpfx).
1185 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1187 # Support the GNU standard name for this target.
1188 .PHONY: check
1189 check: tests
1190 # Special target to run tests which cannot be run unconditionally.
1191 # Maintainers should use this target.
1192 .PHONY: xcheck
1193 xcheck: xtests
1195 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1196 ifneq (,$(all-nonlib))
1197 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1198 lib := nonlib
1199 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1200 endif
1202 # The include magic above causes those files to use this variable for flags.
1203 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1206 ifeq ($(versioning),yes)
1207 # Generate normalized lists of symbols, versions, and data sizes.
1208 # This is handy for checking against existing library binaries.
1210 %.symlist: $(..)scripts/abilist.awk %.dynsym
1211         LC_ALL=C $(AWK) -f $^ > $@T
1212         mv -f $@T $@
1214 %.dynsym: %.so
1215         $(OBJDUMP) --dynamic-syms $< > $@T
1216         mv -f $@T $@
1218 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1219              $(..)abilist/%.abilist $(objpfx)%.symlist
1220         $(check-abi)
1221 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1222              $(..)abilist/%.abilist $(common-objpfx)%.symlist
1223         $(check-abi)
1224 define check-abi
1225         LC_ALL=C \
1226         $(AWK) -f $< -v 'config=$(check-abi-config)' \
1227                $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1228                $(filter %.abilist,$^) \
1229         | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1230 endef
1231 ifeq ($(enable-check-abi),warn)
1232 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1233 endif
1235 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1236 -include $(common-objpfx)tls.make
1237 config-tls := tls
1238 ifeq ($(use-thread),yes)
1239 config-tls := thread
1240 endif
1241 check-abi-config := \
1242   $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1243 endif
1245 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1246               $(objpfx)%.symlist
1247         $(update-abi)
1248 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1249               $(common-objpfx)%.symlist
1250         $(update-abi)
1251 ifndef update-abi-config
1252 define update-abi
1253         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1254 endef
1255 else
1256 define update-abi
1257 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1258          > $(..)abilist/$*.abilist.new
1259 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1260  then rm -f $(..)abilist/$*.abilist.new; \
1261       echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1262  else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1263       echo '*** Now check $*.abilist changes for correctness ***'; \
1264  fi
1265 endef
1266 endif
1268 .PHONY: update-abi check-abi
1269 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1270 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1271 ifdef subdir
1272 subdir_check-abi: check-abi
1273 subdir_update-abi: update-abi
1274 else
1275 check-abi: subdir_check-abi
1276 update-abi: subdir_update-abi
1277 endif
1279 ifeq ($(subdir),elf)
1280 check-abi: check-abi-libc
1281 update-abi: update-abi-libc
1282 common-generated += libc.symlist
1283 endif
1285 ifeq ($(build-shared),yes)
1286 ifneq ($(enable-check-abi),no)
1287 ifdef subdir
1288 tests: check-abi
1289 endif
1290 endif
1291 endif
1293 endif
1295 # These will have been set by sysdeps/posix/Makefile.
1296 L_tmpnam  ?= 1
1297 TMP_MAX   ?= 0
1298 L_ctermid ?= 1
1299 L_cuserid ?= 1
1301 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1303 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1304 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1305                    $(common-objpfx)config.make
1306         $(make-target-directory)
1307         { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
1308           echo '#define _LIBC 1';                                       \
1309           echo '#include "$(..)misc/sys/uio.h"'; } |                    \
1310         $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
1311               $(+includes) -xc - -o $(@:st=hT)
1312         sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
1313             $(@:st=dT) > $(@:st=dt)
1314         mv -f $(@:st=dt) $(@:st=d)
1315         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1316         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1317         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1318         fopen_max=$${fopen_max:-16};                                    \
1319         filename_max=$${filename_max:-1024};                            \
1320         if [ -z "$$iov_max" ]; then                                     \
1321           define_iov_max="# undef IOV_MAX";                             \
1322         else                                                            \
1323           define_iov_max="# define IOV_MAX $$iov_max";                  \
1324         fi;                                                             \
1325         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1326             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1327             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1328             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1329             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1330             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1331             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1332             $< > $(@:st=h.new)
1333         $(move-if-change) $(@:st=h.new) $(@:st=h)
1334 # Remove these last so that they can be examined if something went wrong.
1335         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1336         touch $@
1337 # Get dependencies.
1338 ifndef no_deps
1339 -include $(stdio_lim:h=d)
1340 endif
1341 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1343 FORCE:
1345 .PHONY: echo-headers
1346 echo-headers:
1347         @echo $(headers)
1349 %.bz2: %; bzip2 -9vk $<
1350 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1351 %.xz: %; xz -9evk $<
1353 # Common cleaning targets.
1355 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1356 clean: common-clean
1357 mostlyclean: common-mostlyclean
1359 do-tests-clean:
1360         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1361                                                       $(test-srcs)) \
1362                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1363                                                          $(test-srcs)))
1365 # Remove the object files.
1366 common-mostlyclean:
1367         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1368                                      $(others) $(sysdep-others) stubs \
1369                                      $(addsuffix .o,$(tests) $(xtests) \
1370                                                     $(test-srcs) $(others) \
1371                                                     $(sysdep-others)) \
1372                                      $(addsuffix -bp,$(tests) $(xtests) \
1373                                                      $(test-srcs)) \
1374                                      $(addsuffix .out,$(tests) $(xtests) \
1375                                                       $(test-srcs)) \
1376                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1377                                                          $(test-srcs)))
1378         -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1379                                      $(install-lib) $(install-lib.so) \
1380                                      $(install-lib.so:%.so=%_pic.a))
1381         -rm -f core
1382         -rm -f $(objpfx)rtld-*.os
1383         $(rmobjs)
1384 define rmobjs
1385 $(foreach o,$(object-suffixes-for-libc),
1386 -rm -f $(objpfx)stamp$o $(o-objects))
1387 endef
1389 # Also remove the dependencies and generated source files.
1390 common-clean: common-mostlyclean
1391         -rm -f $(addprefix $(objpfx),$(generated))
1392         -rm -f $(objpfx)*.d $(objpfx)*.dt
1393         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1394         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1396 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1397 # for each function which is a stub.  We grovel over all the .d files
1398 # looking for references to <stub-tag.h>.  Then we grovel over each
1399 # referenced source file to see what stub function it defines.
1401 ifdef objpfx
1402 .PHONY: stubs # The parent Makefile calls this target.
1403 stubs: $(objpfx)stubs
1404 endif
1405 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1406                   $(addprefix $(objpfx),$(extra-objs))
1407 $(objpfx)stubs: $(objs-for-stubs)
1408 ifneq (,$(strip $(objs-for-stubs)))
1409         (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1410         $(AWK) '/\.gnu\.glibc-stub\./ { \
1411                   sub(/\.gnu\.glibc-stub\./, "", $$2); \
1412                   stubs[$$2] = 1; } \
1413                 END { for (s in stubs) print "#define __stub_" s }' > $@T
1414         mv -f $@T $@
1415 else
1416         > $@
1417 endif
1419 ifneq (,$(strip $(gpl2lgpl)))
1420 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1421 # Snarf from the master source and frob the copying notice.
1422 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1423         sed -f $^ > $@-tmp
1424 # So I don't edit them by mistake.
1425         chmod a-w $@-tmp
1426         mv -f $@-tmp $@
1427 ifeq ($(with-cvs),yes)
1428         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1429 endif
1430 endif
1431 endif
1433 # Local Variables:
1434 # mode: makefile
1435 # End: