1 # Copyright (C) 1991-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 # Common rules for making the GNU C library. This file is included
21 # by the top-level Makefile and by all subdirectory makefiles
25 This makefile requires GNU Make.
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.
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))" ""
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.
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full_config_sysdirs))
62 +sysdir_pfx = $(common-objpfx)
64 export sysdirs := $(sysdirs)
66 +sysdep_dirs := $(full_config_sysdirs)
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
75 # This variable is used in ``include $(o-iterator)'' after defining
76 # $(o-iterator-doit) to produce some desired rule using $o for the object
77 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78 # is produced for each object suffix in use.
79 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
81 # Include any system-specific makefiles.
83 # This is here so things in sysdep Makefiles can easily depend on foo.h as
84 # appropriate and not worry about where foo.h comes from, which may be
85 # system dependent and not known by that Makefile.
86 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87 $(+sysdep_dirs) $(..)))
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91 $(+sysdep_dirs) $(..)))
93 # Some sysdep makefiles use this to distinguish being included here from
94 # being included individually by a subdir makefile (hurd/Makefile needs this).
97 sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98 ifneq (,$(sysdep-makefiles))
99 include $(sysdep-makefiles)
103 # Reorder before-compile so that mach things come first, and hurd things
104 # second, before all else. The mach and hurd subdirectories have many
105 # generated header files which the much of rest of the library depends on,
106 # so it is best to build them first (and mach before hurd, at that).
107 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
109 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
112 # Even before that, we need abi-versions.h which is generated right here.
113 ifeq ($(versioning),yes)
114 ifndef avoid-generated
115 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
116 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
117 $(common-objpfx)Versions.all
118 LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
121 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
122 sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
123 $(common-objpfx)abi-versions.h > $@T
125 endif # avoid-generated
126 endif # $(versioning) = yes
128 # Make sure the subdirectory for object files gets created.
130 ifeq (,$(wildcard $(objpfx).))
131 before-compile += $(objpfx).
133 $(make-target-directory)
137 # Remove existing files from `before-compile'. Things are added there when
138 # they must exist for dependency generation to work right, but once they
139 # exist there is no further need for every single file to depend on them,
140 # and those gratuitous dependencies result in many gratuitous
142 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
144 # Don't let any before-compile file be an intermediate and get removed.
149 # We don't want $(common-objpfx) files to depend on miscellaneous stuff
152 common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
154 common-before-compile = $(before-compile)
158 # If a makefile needs to do something conditional on something that
159 # can only be figured out from headers, write a FOO.make.c input
160 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
161 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
163 # We only generate these in the top-level makefile, to avoid any weirdness
164 # from subdir-specific makefile tweaks creeping in on an update.
165 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
167 (echo '# Generated from $*.make.c by Makerules.'; \
168 $(CC) $(CFLAGS) $(CPPFLAGS) -E $< \
169 -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
170 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
171 echo 'common-generated += $(@F)'; \
172 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
178 sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
179 -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
181 sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
182 -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
186 ifdef gen-as-const-headers
187 # Generating headers for assembly constants.
188 # We need this defined early to get into before-compile before
189 # it's used in sysd-rules, below.
190 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
191 %.sym $(common-before-compile)
192 $(AWK) -f $< $(filter %.sym,$^) \
193 | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
194 -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
195 sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
196 $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
198 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
199 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
201 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
202 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
203 vpath %.sym $(sysdirs)
204 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
206 tests += $(gen-as-const-headers:%.sym=test-as-const-%)
207 generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
208 $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
209 %.sym $(common-objpfx)%.h
210 ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
211 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
212 echo '#include "$(..)test-skeleton.c"') > $@T
216 # Generate an ordered list of implicit rules which find the source files in
217 # each sysdep directory. The old method was to use vpath to search all the
218 # sysdep directories. However, that had the problem that a .S file in a
219 # later directory would be chosen over a .c file in an earlier directory,
220 # which does not preserve the desired sysdeps ordering behavior.
222 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
223 # patterns matching sysdep directories whose assembly source files should
225 ifdef inhibit-sysdep-asm
226 define open-check-inhibit-asm
227 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
229 close-check-inhibit-asm = ;; esac ;
232 -include $(+sysdir_pfx)sysd-rules
233 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
234 # The value of $(+sysdep_dirs) the sysd-rules was computed for
235 # differs from the one we are using now. So force a rebuild of sysd-rules.
236 sysd-rules-force = FORCE
239 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
240 $(wildcard $(foreach dir,$(sysdirs),\
244 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
245 for dir in $(config-sysdirs:%='$$(..)%'); do \
246 for o in $(all-object-suffixes); do \
247 $(open-check-inhibit-asm) \
248 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
249 \$$(compile-command.S)"; \
250 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
251 \$$(compile-command.s)"; \
252 echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
253 \$$(compile-command.S)"; \
254 echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
255 \$$(compile-command.s)"; \
256 echo "\$$(objpfx)ptw-%$$o: $$dir/%.S \$$(before-compile); \
257 \$$(compile-command.S)"; \
258 echo "\$$(objpfx)ptw-%$$o: $$dir/%.s \$$(before-compile); \
259 \$$(compile-command.s)"; \
260 $(close-check-inhibit-asm) \
261 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
262 \$$(compile-command.c)"; \
263 echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
264 \$$(compile-command.c)"; \
265 echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
266 \$$(compile-command.c)"; \
268 echo "\$$(objpfx)m_%.S: $$dir/s_%.S; \$$(+make-include-of-dep)"; \
269 echo "\$$(objpfx)m_%.c: $$dir/s_%.c; \$$(+make-include-of-dep)"; \
271 echo "\$$(objpfx)m_%.c: s_%.c; \$$(+make-include-of-dep)"; \
272 echo 'sysd-rules-done = t') > $@T
275 ifndef sysd-rules-done
276 # Don't do deps until this exists, because it provides rules to make the deps.
280 # This is used by the m_%.[Sc] pattern rules in sysd-rules.
281 define +make-include-of-dep
282 echo '#include <$<>' > $@T
286 # It matters that this set of rules, for compiling from sources in
287 # the current directory (the $srcdir/$subdir) come before the
288 # generated sysdep rules in included from sysd-rules below. When
289 # compiling in the source tree, generated sources go into the current
290 # directory, and those should be chosen before any sources in sysdeps.
291 define o-iterator-doit
292 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
294 object-suffixes-left := $(all-object-suffixes)
295 include $(o-iterator)
297 define o-iterator-doit
298 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
300 object-suffixes-left := $(all-object-suffixes)
301 include $(o-iterator)
303 define o-iterator-doit
304 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
306 object-suffixes-left := $(all-object-suffixes)
307 include $(o-iterator)
309 define o-iterator-doit
310 $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
312 object-suffixes-left := $(all-object-suffixes)
313 include $(o-iterator)
315 # Omit the objpfx rules when building in the source tree, because
316 # objpfx is empty and so these rules just override the ones above.
318 # Define first rules to find the source files in $(objpfx).
319 # Generated source files will end up there.
320 define o-iterator-doit
321 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
323 object-suffixes-left := $(all-object-suffixes)
324 include $(o-iterator)
326 define o-iterator-doit
327 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
329 object-suffixes-left := $(all-object-suffixes)
330 include $(o-iterator)
332 define o-iterator-doit
333 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
335 object-suffixes-left := $(all-object-suffixes)
336 include $(o-iterator)
339 # Generate version maps, but wait until sysdep-subdirs is known
340 ifeq ($(sysd-sorted-done),t)
341 ifeq ($(versioning),yes)
342 -include $(common-objpfx)sysd-versions
343 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
344 common-generated += $(version-maps)
345 postclean-generated += sysd-versions Versions.all abi-versions.h \
346 Versions.def.v.i Versions.def.v Versions.v.i Versions.v
348 ifndef avoid-generated
349 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
350 sysd-versions-force = FORCE
353 # See %.v/%.v.i implicit rules in Makeconfig.
354 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
355 $(wildcard $(add-ons:%=$(..)%/Versions.def))
356 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
357 $(common-objpfx)soversions.i \
358 $(common-objpfx)Versions.def.v
359 { while read which lib version setname; do \
360 test x"$$which" = xDEFAULT || continue; \
361 test -z "$$setname" || echo "$$lib : $$setname"; \
362 done < $(word 2,$^); \
364 } | LC_ALL=C $(AWK) -f $< > $@T
366 # See %.v/%.v.i implicit rules in Makeconfig.
367 $(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
368 $(wildcard $(sysdirs:%=%/Versions)) \
369 $(common-objpfx)abi-versions.h \
370 $(sysd-versions-force)
371 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
372 $(common-objpfx)Versions.v \
373 $(..)scripts/versions.awk
374 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
376 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
377 -v move_if_change='$(move-if-change)' \
381 endif # avoid-generated
382 endif # $(versioning) = yes
383 endif # sysd-sorted-done
385 # Generate .dT files as we compile.
386 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
387 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
388 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
389 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
390 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
392 # GCC can grok options after the file name, and it looks nicer that way.
393 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
394 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
395 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
396 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
397 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
398 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
399 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
401 # We need this for the output to go in the right place. It will default to
402 # empty if make was configured to work with a cc that can't grok -c and -o
403 # together. You can't compile the C library with such a compiler.
404 OUTPUT_OPTION = -o $@
406 # We need the $(CFLAGS) to be in there to have the right predefines during
407 # the dependency run for C sources. But having it for assembly sources can
408 # get the wrong predefines.
409 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
412 $(make-target-directory)
413 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
414 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
415 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
416 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
417 mv -f $(@:.d=.T) $@ $(generate-md5)
421 # Continuation lines here are dangerous because they introduce spaces!
422 define sed-remove-objpfx
423 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
424 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
428 # Modify the list of routines we build for different targets
430 ifeq (yesyes,$(build-shared)$(elf))
431 ifndef libc.so-version
432 # Undefine this because it can't work when we libc.so is unversioned.
433 static-only-routines =
437 # Bounded pointer thunks are only built for *.ob
438 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
440 elide-routines.oS += $(filter-out $(static-only-routines),\
441 $(routines) $(aux) $(sysdep_routines)) \
443 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
445 # If we have versioned code we don't need the old versions in any of the
447 elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
448 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
449 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
450 elide-routines.ob += $(shared-only-routines)
452 # Shared library building.
454 ifeq (yes,$(build-shared))
456 # Reference map file only when versioning is selected and a map file name
458 ifeq ($(versioning),yes)
459 map-file = $(firstword $($(@F:.so=-map)) \
460 $(addprefix $(common-objpfx), \
461 $(filter $(@F:.so=.map),$(version-maps))))
462 load-map-file = $(map-file:%=-Wl,--version-script=%)
465 # Pattern rule to build a shared object from an archive of PIC objects.
466 # This must come after the installation rules so Make doesn't try to
467 # build shared libraries in place from the installed *_pic.a files.
468 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
469 # on other shared objects.
470 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
471 ifneq (,$(findstring aix,$(config-os)))
473 dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
478 define build-shlib-helper
479 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
480 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
481 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
482 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
483 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
484 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
485 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
488 ifneq (,$(findstring aix,$(config-os)))
489 define build-shlib-helper
490 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
491 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
492 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
493 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
494 -L$(subst :, -L,$(rpath-link))
501 # binutils only position loadable notes into the first page for binaries,
502 # not for shared objects
503 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
504 $(LINK.o) -shared -Wl,-O1 \
505 -nostdlib -nostartfiles \
506 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
507 -Wl,--verbose 2>&1 | \
509 -e '/^=========/,/^=========/!d;/^=========/d' \
510 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
511 -e 's/^.*\*(\.dynbss).*$$/& \
512 PROVIDE(__start___libc_freeres_ptrs = .); \
513 *(__libc_freeres_ptrs) \
514 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
515 -e 's@^.*\*(\.jcr).*$$@& \
516 PROVIDE(__start___libc_subfreeres = .);\
517 __libc_subfreeres : { *(__libc_subfreeres) }\
518 PROVIDE(__stop___libc_subfreeres = .);\
519 PROVIDE(__start___libc_atexit = .);\
520 __libc_atexit : { *(__libc_atexit) }\
521 PROVIDE(__stop___libc_atexit = .);\
522 PROVIDE(__start___libc_thread_subfreeres = .);\
523 __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
524 PROVIDE(__stop___libc_thread_subfreeres = .);\
525 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
527 common-generated += shlib.lds
530 $(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
531 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
534 ifneq (,$(findstring aix,$(config-os)))
536 $(build-shlib-helper) \
538 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
539 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
542 $(build-shlib-helper) \
543 $(build-shlib-objlist)
548 ifneq (,$(findstring aix,$(config-os)))
549 define build-module-helper
550 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
551 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
553 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
554 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
557 define build-module-helper
558 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
559 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
560 -B$(csu-objpfx) $(load-map-file) \
561 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
562 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
566 # This macro is similar to build-shlib but it does not define a soname
567 # and it does not depend on the destination name to start with `lib'.
569 # binutils only position loadable notes into the first page for binaries,
570 # not for shared objects
572 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
573 $(csu-objpfx)abi-note.o $(build-module-objlist)
576 ifneq (,$(findstring aix,$(config-os)))
578 $(build-module-helper) \
580 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
581 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
586 $(build-module-helper) \
588 $(build-module-objlist)
593 build-module-helper-objlist = \
594 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
595 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
596 whole-archive := -Wl,--whole-archive
598 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
599 build-shlib-objlist = $(build-module-helper-objlist) \
600 $(LDLIBS-$(@F:lib%.so=%).so)
602 # Don't try to use -lc when making libc.so itself.
603 # Also omits crti.o and crtn.o, which we do not want
604 # since we define our own `.init' section specially.
605 LDFLAGS-c.so = -nostdlib -nostartfiles
606 # But we still want to link libc.so against $(libc.so-gnulib).
607 LDLIBS-c.so += $(libc.so-gnulib)
608 # Give libc.so an entry point and make it directly runnable itself.
609 LDFLAGS-c.so += -e __libc_main
610 # If lazy relocation is disabled add the -z now flag.
611 ifeq ($(bind-now),yes)
612 LDFLAGS-c.so += -Wl,-z,now
614 # Pre-link the objects of libc_pic.a so that we can locally resolve
615 # COMMON symbols before we link against ld.so. This is because ld.so
616 # contains some of libc_pic.a already, which will prevent the COMMONs
617 # from being allocated in libc.so, which introduces evil dependencies
618 # between libc.so and ld.so, which can make it impossible to upgrade.
620 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
621 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
622 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
623 # Use our own special initializer and finalizer files for libc.so.
624 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
625 $(common-objpfx)libc_pic.os \
626 $(elfobjdir)/sofini.os \
627 $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
628 $(common-objpfx)shlib.lds
630 ifeq ($(versioning),yes)
631 $(common-objpfx)libc.so: $(common-objpfx)libc.map
633 common-generated += libc.so libc_pic.os
634 ifdef libc.so-version
635 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
637 common-generated += libc.so$(libc.so-version)
641 ifneq (,$(findstring aix,$(config-os)))
642 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
645 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
646 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
647 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
648 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
649 -bE:$(common-objpfx)syscalls.exp \
650 -bI:$(common-objpfx)syscalls.exp \
651 -L$(common-objpfx) -o $@ $^
652 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
653 cp $@ $(common-objpfx)shr.o
654 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
658 # Figure out the source filenames in this directory.
660 override sources := $(addsuffix .c,\
661 $(filter-out $(elided-routines),\
664 sysdep_routines := $(sysdep_routines)
666 headers := $(headers) $(sysdep_headers)
668 # This is the list of all object files, gotten by
669 # replacing every ".c" in `sources' with a ".o".
670 # We also add bounded-pointer thunks, which are later
671 # elided for all suffixes except for `.ob'.
672 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
673 $(patsubst %,$(bppfx)%.o,\
674 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
677 # The makefile may define $(extra-libs) with `libfoo libbar'
678 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
680 # extra-lib.mk is included once for each extra lib to define rules
681 # to build it, and to add its objects to the various variables.
682 # During its evaluation, $(lib) is set to the name of the library.
683 extra-libs-left := $(extra-libs)
684 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
688 # The makefile may define $(modules-names) to build additional modules.
689 # These are built with $(build-module), except any in $(modules-names-nobuild).
691 # extra-lib.mk is included once for each extra lib to define rules
692 # to build it, and to add its objects to the various variables.
693 # During its evaluation, $(lib) is set to the name of the library.
694 extra-modules-left := $(modules-names)
695 include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
697 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
698 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
699 $(objpfx)%.os $(common-objpfx)shlib.lds \
700 $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
704 +depfiles := $(sources:.c=.d) \
705 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
706 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
707 ifeq ($(build-programs),yes)
708 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
710 +depfiles := $(addprefix $(objpfx),\
711 $(filter-out $(addsuffix .d,$(omit-deps)),\
713 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
714 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
715 $(wildcard $(all-dt-files:.dt=.d))
717 # This is a funny rule in that it removes its input file.
719 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
720 mv -f $(@:.d=.T) $@ && \
723 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
724 # They will be generated when they're needed, and trying too early won't work.
725 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
726 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
731 -include $(+depfiles)
735 # Maximize efficiency by minimizing the number of rules.
736 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
737 # Don't define any builtin rules.
738 MAKEFLAGS := $(MAKEFLAGS)r
740 # Generic rule for making directories.
742 # mkdir isn't smart enough to strip a trailing /.
745 # Make sure that object files are not removed
746 # when they are intermediates between sources and library members.
747 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
749 # Make sure that the parent library archive is never removed.
750 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
752 # Use the verbose option of ar and tar when not running silently.
753 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
759 ARFLAGS := r$(verbose)
760 CREATE_ARFLAGS := cru$(verbose)
762 # This makes all the object files in the parent library archive.
764 .PHONY: lib lib-noranlib
765 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
766 lib-noranlib: libobjs
768 # For object-suffix $o, the list of objects with that suffix.
769 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
770 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
771 $(elide-routines$o)),\
773 $(addprefix $(objpfx),$(o-objects$o))
775 others: $(addprefix $(objpfx),$(install-lib))
779 # Create the stamp$o files to keep the parent makefile happy.
780 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
781 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
782 $(make-target-directory)
786 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
787 # timestamp file; these rules (one explicit rule is generated for each
788 # object suffix) write a list of objects to update in the stamp file.
789 # The parent will then actually add them all to the archive in the
790 # archive rule, below.
791 define o-iterator-doit
792 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
795 $(make-target-directory)
796 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
799 object-suffixes-left := $(object-suffixes-for-libc)
800 include $(o-iterator)
804 # Now define explicit rules to build the library archives; these depend
805 # on the stamp files built above.
806 define o-iterator-doit
807 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
808 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
811 cd $(common-objdir) && \
812 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
815 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
816 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
818 $(subdirs-stamps): subdir_lib;
820 object-suffixes-left = $(object-suffixes-for-libc)
821 include $(o-iterator)
824 # This makes all the object files.
825 .PHONY: objects objs libobjs extra-objs
826 objects objs: libobjs extra-objs
827 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
828 extra-objs: $(addprefix $(objpfx),$(extra-objs))
830 # Canned sequence for building an extra library archive.
831 define build-extra-lib
832 $(patsubst %/,cd % &&,$(objpfx)) \
833 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
834 $(patsubst $(objpfx)%,%,$^)
840 .PHONY: force-install
843 # $(install-lib) are installed from the object directory into $(libdir);
844 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
845 # unless they also appear in $(non-lib.a). $(install-data) are installed
846 # as they are into $(datadir). $(headers) are installed as they are in
847 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
848 # are installed from the object directory into $(bindir), $(bindir) and
849 # $(sbindir), respectively. $(install-others) are absolute path names of
850 # files to install; rules to install them are defined elsewhere.
852 # The simple library name to install libc.a under.
853 # This could be defined by a sysdep Makefile.
859 $(make-target-directory)
860 $(INSTALL_DATA) $< $@
863 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
864 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
865 define make-target-directory
866 $(addprefix $(..)./scripts/mkinstalldirs ,\
867 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
870 # Any directory (parent or subdir) should install libc.a; this way
871 # "make install" in a subdir is guaranteed to install everything it changes.
872 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
873 $(inst_libdir)/$(patsubst %,$(libtype$o),\
874 $(libprefix)$(libc-name)))
875 install: $(installed-libcs)
876 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
877 $(make-target-directory)
878 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
879 # Running ranlib after installing makes the __.SYMDEF time stamp up to
880 # date, which avoids messages from some linkers.
883 define do-install-program
884 $(make-target-directory)
885 $(INSTALL_PROGRAM) $< $@.new
889 define do-install-script
890 $(make-target-directory)
891 $(INSTALL_SCRIPT) $< $@.new
895 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
896 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
898 ifeq (yes,$(build-shared))
899 # Find which .so's have versions.
900 versioned := $(strip $(foreach so,$(install-lib.so),\
901 $(patsubst %,$(so),$($(so)-version))))
903 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
904 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
906 # For versioned libraries, we install three files:
907 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
908 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
909 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
910 V := $(firstword $($(subdir)-version) $(version))
911 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
912 $(foreach L,$(install-lib.so-versioned),\
914 $(inst_slibdir)/$(L:.so=)-$V.so \
915 $(inst_slibdir)/$L$($L-version))
917 # Install all the unversioned shared libraries.
918 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
919 $(objpfx)%.so $(+force)
920 $(do-install-program)
922 ifneq ($(findstring -s,$(LN_S)),)
925 $(SHELL) $(..)scripts/rellns-sh $< $@.new
929 # If we have no symbolic links don't bother with rellns-sh.
937 ifeq (yes,$(build-shared))
938 ifeq (no,$(cross-compiling))
939 symbolic-link-prog := $(common-objpfx)elf/sln
940 symbolic-link-list := $(common-objpfx)elf/symlink.list
941 define make-shlib-link
942 echo $(<F) $@ >> $(symbolic-link-list)
944 else # cross-compiling
945 # We need a definition that can be used by elf/Makefile's install rules.
946 symbolic-link-prog = $(LN_S)
949 ifndef make-shlib-link
950 define make-shlib-link
956 ifdef libc.so-version
957 # For a library specified to be version N, install three files:
958 # libc.so -> libc.so.N (e.g. libc.so.6)
959 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
961 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
964 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
965 $(do-install-program)
966 install: $(inst_slibdir)/libc.so$(libc.so-version)
968 # This fragment of linker script gives the OUTPUT_FORMAT statement
969 # for the configuration we are building. We put this statement into
970 # the linker scripts we install for -lc et al so that they will not be
971 # used by a link for a different format on a multi-architecture system.
972 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
973 $(common-objpfx)config.make \
974 $(common-objpfx)config.h $(..)Makerules
975 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
976 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
977 | sed -n -f $< > $@.new
980 common-generated += format.lds
983 # What we install as libc.so for programs to link against is in fact a
984 # link script. It contains references for the various libraries we need.
985 # The libc.so object is not complete since some functions are only defined
986 # in libc_nonshared.a.
987 # We need to use absolute paths since otherwise local copies (if they exist)
988 # of the files are taken by the linker.
989 install: $(inst_libdir)/libc.so
990 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
991 $(common-objpfx)libc.so$(libc.so-version) \
992 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
993 $(libprefix)$(libc-name)) \
995 (echo '/* GNU ld script';\
996 echo ' Use the shared library, but some functions are only in';\
997 echo ' the static library, so try that secondarily. */';\
999 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1000 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1001 ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
1008 install: $(inst_slibdir)/libc.so
1009 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1010 $(do-install-program)
1013 ifneq (,$(versioned))
1014 # Produce three sets of rules as above for all the smaller versioned libraries.
1016 define o-iterator-doit
1017 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1019 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1020 ifneq (,$(object-suffixes-left))
1021 include $(o-iterator)
1024 # Make symlinks in the build directory, because the versioned names might
1025 # be referenced by a DT_NEEDED in another library.
1026 define o-iterator-doit
1027 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1029 object-suffixes-left := $(versioned)
1030 include $(o-iterator)
1032 generated += $(foreach o,$(versioned),$o$($o-version))
1034 ifeq (,$($(subdir)-version))
1035 define o-iterator-doit
1036 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1040 object-suffixes-left := $(versioned)
1041 include $(o-iterator)
1043 define o-iterator-doit
1044 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1045 $$(do-install-program)
1047 object-suffixes-left := $(versioned)
1048 include $(o-iterator)
1050 define o-iterator-doit
1051 $(inst_slibdir)/$o$($o-version): \
1052 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1055 object-suffixes-left := $(versioned)
1056 include $(o-iterator)
1058 define o-iterator-doit
1059 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1060 $$(do-install-program)
1062 object-suffixes-left := $(versioned)
1063 include $(o-iterator)
1067 define do-install-so
1068 $(do-install-program)
1069 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1070 $(filter-out %.so,$@))
1073 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1074 $(foreach v,$(so-versions),\
1075 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1078 $(foreach v,$(so-versions),\
1079 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1084 $(addprefix $(inst_bindir)/,$(install-bin)): \
1085 $(inst_bindir)/%: $(objpfx)% $(+force)
1086 $(do-install-program)
1088 ifdef install-bin-script
1089 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1090 $(inst_bindir)/%: $(objpfx)% $(+force)
1091 $(do-install-script)
1093 ifdef install-rootsbin
1094 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1095 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1096 $(do-install-program)
1099 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1100 $(inst_sbindir)/%: $(objpfx)% $(+force)
1101 $(do-install-program)
1104 install-lib.a := $(filter lib%.a,$(install-lib))
1105 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1106 ifdef install-lib-non.a
1107 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1108 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1112 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1113 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1115 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1119 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1122 headers := $(strip $(headers))
1124 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1128 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1129 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1130 install-data-nosubdir install-headers-nosubdir
1131 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1132 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1133 install-rootsbin-nosubdir: \
1134 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1135 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1136 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1137 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1138 $(addprefix $(libprefix),$(install-lib-non.a)))
1139 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1140 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1141 install-others-nosubdir: $(install-others)
1143 # We need all the `-nosubdir' targets so that `install' in the parent
1144 # doesn't depend on several things which each iterate over the subdirs.
1145 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1146 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1147 install-%:: install-%-nosubdir ;
1149 .PHONY: install install-no-libc.a-nosubdir
1150 ifeq ($(build-programs),yes)
1151 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1152 install-bin-nosubdir install-bin-script-nosubdir \
1153 install-lib-nosubdir install-others-nosubdir \
1154 install-rootsbin-nosubdir install-sbin-nosubdir
1156 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1157 install-lib-nosubdir install-others-nosubdir
1159 install: install-no-libc.a-nosubdir
1161 # Command to compile $< in $(objdir) using the native libraries.
1162 define native-compile
1163 $(make-target-directory)
1164 $(patsubst %/,cd % &&,$(objpfx)) \
1165 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1166 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1169 # Command to compile $< in $(common-objdir) using the native libraries.
1170 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1171 define common-objdir-compile
1172 $(patsubst %/,cd % &&,$(objpfx)) \
1173 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1174 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1177 # We always want to use configuration definitions.
1178 # Note that this is only used for commands running in $(objpfx).
1179 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1181 # Support the GNU standard name for this target.
1184 # Special target to run tests which cannot be run unconditionally.
1185 # Maintainers should use this target.
1189 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1190 ifneq (,$(all-nonlib))
1191 cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
1193 include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
1196 # The include magic above causes those files to use this variable for flags.
1197 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1200 ifeq ($(versioning),yes)
1201 # Generate normalized lists of symbols, versions, and data sizes.
1202 # This is handy for checking against existing library binaries.
1204 %.symlist: $(..)scripts/abilist.awk %.dynsym
1205 LC_ALL=C $(AWK) -f $^ > $@T
1209 $(OBJDUMP) --dynamic-syms $< > $@T
1212 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1213 $(..)abilist/%.abilist $(objpfx)%.symlist
1215 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1216 $(..)abilist/%.abilist $(common-objpfx)%.symlist
1220 $(AWK) -f $< -v 'config=$(check-abi-config)' \
1221 $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
1222 $(filter %.abilist,$^) \
1223 | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1225 ifeq ($(enable-check-abi),warn)
1226 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1229 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1230 -include $(common-objpfx)tls.make
1232 ifeq ($(use-tls),yes)
1235 ifeq ($(use-thread),yes)
1236 config-tls := thread
1238 check-abi-config := \
1239 $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1242 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1245 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1246 $(common-objpfx)%.symlist
1248 ifndef update-abi-config
1250 @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1254 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1255 > $(..)abilist/$*.abilist.new
1256 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1257 then rm -f $(..)abilist/$*.abilist.new; \
1258 echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1259 else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1260 echo '*** Now check $*.abilist changes for correctness ***'; \
1265 .PHONY: update-abi check-abi
1266 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1267 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1269 subdir_check-abi: check-abi
1270 subdir_update-abi: update-abi
1272 check-abi: subdir_check-abi
1273 update-abi: subdir_update-abi
1276 ifeq ($(subdir),elf)
1277 check-abi: check-abi-libc
1278 update-abi: update-abi-libc
1279 common-generated += libc.symlist
1282 ifeq ($(build-shared),yes)
1283 ifneq ($(enable-check-abi),no)
1292 # There's no good place to put this - here will do.
1293 ifeq ($(filter %posix, $(sysdirs)),)
1304 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1306 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1307 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1308 $(common-objpfx)config.make
1309 $(make-target-directory)
1310 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1311 echo '#define _LIBC 1'; \
1312 echo '#include "$(..)misc/sys/uio.h"'; } | \
1313 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1314 $(+includes) -xc - -o $(@:st=hT)
1315 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1316 $(@:st=dT) > $(@:st=dt)
1317 mv -f $(@:st=dt) $(@:st=d)
1318 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1319 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1320 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1321 fopen_max=$${fopen_max:-16}; \
1322 filename_max=$${filename_max:-1024}; \
1323 if [ -z "$$iov_max" ]; then \
1324 define_iov_max="# undef IOV_MAX"; \
1326 define_iov_max="# define IOV_MAX $$iov_max"; \
1328 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1329 -e "s/@FILENAME_MAX@/$$filename_max/" \
1330 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1331 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1332 -e "s/@L_ctermid@/$(L_ctermid)/" \
1333 -e "s/@L_cuserid@/$(L_cuserid)/" \
1334 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1336 $(move-if-change) $(@:st=h.new) $(@:st=h)
1337 # Remove these last so that they can be examined if something went wrong.
1338 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1342 -include $(stdio_lim:h=d)
1344 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1347 TAGS: $(objpfx)distinfo $(..)MakeTAGS
1348 $(MAKE) $(addprefix -f ,$^) $@
1350 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1351 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1355 .PHONY: echo-headers
1359 %.bz2: %; bzip2 -9vk $<
1360 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1362 # Common cleaning targets.
1364 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1366 mostlyclean: common-mostlyclean
1369 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1371 $(addsuffix -bp.out,$(tests) $(xtests) \
1374 # Remove the object files.
1376 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1377 $(others) $(sysdep-others) stubs \
1378 $(addsuffix .o,$(tests) $(xtests) \
1379 $(test-srcs) $(others) \
1381 $(addsuffix -bp,$(tests) $(xtests) \
1383 $(addsuffix .out,$(tests) $(xtests) \
1385 $(addsuffix -bp.out,$(tests) $(xtests) \
1387 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1389 $(install-lib.so:%.so=%_pic.a))
1391 -rm -f $(objpfx)rtld-*.os
1394 $(foreach o,$(object-suffixes-for-libc),
1395 -rm -f $(objpfx)stamp$o $(o-objects))
1398 # Also remove the dependencies and generated source files.
1399 common-clean: common-mostlyclean
1400 -rm -f $(addprefix $(objpfx),$(generated))
1401 -rm -f $(objpfx)*.d $(objpfx)*.dt
1402 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1403 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1404 -rm -f $(objpfx)distinfo
1406 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1407 # for each function which is a stub. We grovel over all the .d files
1408 # looking for references to <stub-tag.h>. Then we grovel over each
1409 # referenced source file to see what stub function it defines.
1412 .PHONY: stubs # The parent Makefile calls this target.
1413 stubs: $(objpfx)stubs
1415 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1416 $(addprefix $(objpfx),$(extra-objs))
1417 $(objpfx)stubs: $(objs-for-stubs)
1418 ifneq (,$(strip $(objs-for-stubs)))
1419 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1420 $(AWK) '/\.gnu\.glibc-stub\./ { \
1421 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1423 END { for (s in stubs) print "#define __stub_" s }' > $@T
1429 # This information is not used for making distributions any more.
1430 # But it's used by MakeTAGS for making TAGS files and the .pot files.
1431 $(objpfx)distinfo: Makefile $(..)Makerules \
1432 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1433 $(make-target-directory)
1437 define distinfo-vars
1439 echo > $@.new 'subdir := $(subdir)'
1440 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1441 headers sysdep_headers distribute dont_distribute generated \
1442 others tests xtests test-srcs extra-libs versioned \
1443 $(extra-libs:%=%-routines) \
1444 $(addprefix install-,lib lib.so data bin bin-script sbin others),
1445 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1446 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1449 ifneq (,$(strip $(gpl2lgpl)))
1450 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1451 # Snarf from the master source and frob the copying notice.
1452 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1454 # So I don't edit them by mistake.
1457 ifeq ($(with-cvs),yes)
1458 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@