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