1 # Copyright (C) 1991-1999,2000,01,02 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 # When we have no deps pass doing it, then make sure the subdirectory
129 # for object files gets created.
132 before-compile += $(objpfx).
134 $(make-target-directory)
138 # Remove existing files from `before-compile'. Things are added there when
139 # they must exist for dependency generation to work right, but once they
140 # exist there is no further need for every single file to depend on them,
141 # and those gratuitous dependencies result in many gratuitous
143 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
145 # Don't let any before-compile file be an intermediate and get removed.
150 # Generate an ordered list of implicit rules which find the source files in
151 # each sysdep directory. The old method was to use vpath to search all the
152 # sysdep directories. However, that had the problem that a .S file in a
153 # later directory would be chosen over a .c file in an earlier directory,
154 # which does not preserve the desired sysdeps ordering behavior.
156 # When making the list of .d files to include, we can't know which ones
157 # have source in .s files, and thus do not in fact need a .d file.
158 # So we must define rules to make .d files for .s files.
159 define make-dummy-dep
160 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
162 $(common-objpfx)dummy.d:
163 echo '# .s files cannot contain includes, so they need no deps.' > $@
165 # It matters that this set of rules, for compiling from sources in
166 # the current directory (the $srcdir/$subdir) come before the
167 # generated sysdep rules in included from sysd-rules below. When
168 # compiling in the source tree, generated sources go into the current
169 # directory, and those should be chosen before any sources in sysdeps.
170 define o-iterator-doit
171 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
173 object-suffixes-left := $(all-object-suffixes)
174 include $(o-iterator)
175 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
177 define o-iterator-doit
178 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
180 object-suffixes-left := $(all-object-suffixes)
181 include $(o-iterator)
182 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
184 define o-iterator-doit
185 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
187 object-suffixes-left := $(all-object-suffixes)
188 include $(o-iterator)
189 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
191 # Omit the objpfx rules when building in the source tree, because
192 # objpfx is empty and so these rules just override the ones above.
194 # Define first rules to find the source files in $(objpfx).
195 # Generated source files will end up there.
196 define o-iterator-doit
197 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
199 object-suffixes-left := $(all-object-suffixes)
200 include $(o-iterator)
201 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
203 define o-iterator-doit
204 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
206 object-suffixes-left := $(all-object-suffixes)
207 include $(o-iterator)
208 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
210 define o-iterator-doit
211 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
213 object-suffixes-left := $(all-object-suffixes)
214 include $(o-iterator)
215 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
218 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
219 # patterns matching sysdep directories whose assembly source files should
221 ifdef inhibit-sysdep-asm
222 define open-check-inhibit-asm
223 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
225 close-check-inhibit-asm = ;; esac ;
228 -include $(+sysdir_pfx)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
235 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
236 $(wildcard $(foreach dir,$(sysdirs),\
240 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
241 for dir in $(config-sysdirs:%='$$(..)%'); do \
242 for o in $(all-object-suffixes); do \
243 $(open-check-inhibit-asm) \
244 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
245 \$$(compile-command.S)"; \
246 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
247 \$$(compile-command.s)"; \
248 echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
249 \$$(compile-command.S)"; \
250 echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
251 \$$(compile-command.s)"; \
252 $(close-check-inhibit-asm) \
253 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
254 \$$(compile-command.c)"; \
255 echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
256 \$$(compile-command.c)"; \
258 $(open-check-inhibit-asm) \
259 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
260 \$$(make-dummy-dep)"; \
261 echo "\$$(objpfx)rtld-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
262 \$$(make-dummy-dep)"; \
263 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
265 echo "\$$(objpfx)rtld-%.d: $$dir/%.S \$$(before-compile); \
267 $(close-check-inhibit-asm) \
268 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
270 echo "\$$(objpfx)rtld-%.d: $$dir/%.c \$$(before-compile); \
273 echo 'sysd-rules-done = t') > $@T
276 ifndef sysd-rules-done
277 # Don't do deps until this exists, because it provides rules to make the deps.
281 # Generate version maps, but wait until sysdep-subdirs is known
282 ifeq ($(sysd-sorted-done),t)
283 ifeq ($(versioning),yes)
284 -include $(common-objpfx)sysd-versions
285 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
286 common-generated += $(version-maps)
287 postclean-generated += sysd-versions Versions.all abi-versions.h \
288 Versions.def.v.i Versions.def.v Versions.v.i Versions.v
290 ifndef avoid-generated
291 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
292 sysd-versions-force = FORCE
295 # See %.v/%.v.i implicit rules in Makeconfig.
296 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
297 $(wildcard $(add-ons:%=$(..)%/Versions.def))
298 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
299 $(common-objpfx)soversions.i \
300 $(common-objpfx)Versions.def.v
301 { while read lib version setname; do \
302 test -z "$$setname" || echo "$$lib : $$setname"; \
303 done < $(word 2,$^); \
305 } | LC_ALL=C $(AWK) -f $< > $@T
307 # See %.v/%.v.i implicit rules in Makeconfig.
308 $(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
309 $(wildcard $(sysdirs:%=%/Versions)) \
310 $(common-objpfx)abi-versions.h \
311 $(sysd-versions-force)
312 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
313 $(common-objpfx)Versions.v \
314 $(..)scripts/versions.awk
315 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
317 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
318 -v move_if_change='$(move-if-change)' \
322 endif # avoid-generated
323 endif # $(versioning) = yes
324 endif # sysd-sorted-done
327 ifndef compile-command.S
328 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
330 ifndef compile-command.s
331 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
333 ifndef compile-command.c
334 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
337 # GCC can grok options after the file name, and it looks nicer that way.
338 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
340 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
342 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
343 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
345 # If we want to generate MD5 checksums for the sources do this now.
347 generate-md5 = ; rm -f $(@:.d=.md5); \
348 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
349 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
354 # We need this for the output to go in the right place. It will default to
355 # empty if make was configured to work with a cc that can't grok -c and -o
356 # together. You can't compile the C library with such a compiler.
357 OUTPUT_OPTION = -o $@
359 # We need the $(CFLAGS) to be in there to have the right predefines during
360 # the dependency run for C sources. But having it for assembly sources can
361 # get the wrong predefines.
362 S-CPPFLAGS = $(asm-CPPFLAGS)
364 $(make-target-directory)
365 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
366 $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | sed \
367 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
368 $(sed-remove-objpfx) > $(@:.d=.T)
369 mv -f $(@:.d=.T) $@ $(generate-md5)
372 # Continuation lines here are dangerous because they introduce spaces!
373 define sed-remove-objpfx
374 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
375 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
379 # Modify the list of routines we build for different targets
381 ifeq (yesyes,$(build-shared)$(elf))
382 ifndef libc.so-version
383 # Undefine this because it can't work when we libc.so is unversioned.
384 static-only-routines =
388 # Bounded pointer thunks are only built for *.ob
389 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
391 elide-routines.oS += $(filter-out $(static-only-routines),\
392 $(routines) $(aux) $(sysdep_routines)) \
394 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
396 # If we have versioned code we don't need the old versions in any of the
398 elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
399 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
400 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
401 elide-routines.ob += $(shared-only-routines)
403 # Shared library building.
405 ifeq (yes,$(build-shared))
407 # Reference map file only when versioning is selected and a map file name
409 ifeq ($(versioning),yes)
410 map-file = $(firstword $($(@F:.so=-map)) \
411 $(addprefix $(common-objpfx), \
412 $(filter $(@F:.so=.map),$(version-maps))))
413 load-map-file = $(map-file:%=-Wl,--version-script=%)
416 # Pattern rule to build a shared object from an archive of PIC objects.
417 # This must come after the installation rules so Make doesn't try to
418 # build shared libraries in place from the installed *_pic.a files.
419 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
420 # on other shared objects.
421 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
422 ifneq (,$(findstring aix,$(config-os)))
424 dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
429 define build-shlib-helper
430 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
431 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
432 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
433 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
434 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
435 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
438 ifneq (,$(findstring aix,$(config-os)))
439 define build-shlib-helper
440 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
441 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
442 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
443 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
444 -L$(subst :, -L,$(rpath-link))
451 # binutils only position loadable notes into the first page for binaries,
452 # not for shared objects
454 $(build-shlib-helper) \
455 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
456 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
457 sed -e '/^=========/,/^=========/!d;/^=========/d' \
458 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
459 $(LDSEDCMD-$(@F:lib%.so=%).so) > $@.lds
461 $(build-shlib-helper) -o $@ -T $@.lds \
462 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
466 ifneq (,$(findstring aix,$(config-os)))
468 $(build-shlib-helper) \
470 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
471 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
474 $(build-shlib-helper) \
475 $(build-shlib-objlist)
480 ifneq (,$(findstring aix,$(config-os)))
481 define build-module-helper
482 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
483 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
485 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
486 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
489 define build-module-helper
490 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
491 -B$(csu-objpfx) $(load-map-file) \
492 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
493 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
497 # This macro is similar to build-shlib but it does not define a soname
498 # and it does not depend on the destination name to start with `lib'.
500 # binutils only position loadable notes into the first page for binaries,
501 # not for shared objects
503 $(build-module-helper) \
504 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
505 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
506 sed -e '/^=========/,/^=========/!d;/^=========/d' \
507 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
510 $(build-module-helper) -o $@ -T $@.lds \
511 $(csu-objpfx)abi-note.o $(build-module-objlist)
515 ifneq (,$(findstring aix,$(config-os)))
517 $(build-module-helper) \
519 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
520 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
525 $(build-module-helper) \
527 $(build-module-objlist)
532 build-module-helper-objlist = \
533 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
534 $(filter-out $(map-file) $(+preinit) $(+postinit),$^))
535 whole-archive := -Wl,--whole-archive
537 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
538 build-shlib-objlist = $(build-module-helper-objlist) \
539 $(LDLIBS-$(@F:lib%.so=%).so)
541 # Don't try to use -lc when making libc.so itself.
542 # Also omits crti.o and crtn.o, which we do not want
543 # since we define our own `.init' section specially.
544 LDFLAGS-c.so = -nostdlib -nostartfiles
545 # But we still want to link libc.so against $(gnulib).
546 LDLIBS-c.so += $(gnulib)
547 # Give libc.so an entry point and make it directly runnable itself.
548 LDFLAGS-c.so += -e __libc_main
549 # Force the backward compatibility EH functions to be linked.
550 LDFLAGS-c.so += -u __register_frame
551 # Pre-link the objects of libc_pic.a so that we can locally resolve
552 # COMMON symbols before we link against ld.so. This is because ld.so
553 # contains some of libc_pic.a already, which will prevent the COMMONs
554 # from being allocated in libc.so, which introduces evil dependencies
555 # between libc.so and ld.so, which can make it impossible to upgrade.
557 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
558 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
559 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
560 LDSEDCMD-c.so = -e 's/^.*\*(\.dynbss).*$$/& __start___libc_freeres_ptrs = .; *(__libc_freeres_ptrs) __stop___libc_freeres_ptrs = .;/'
561 # Use our own special initializer and finalizer files for libc.so.
562 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
563 $(common-objpfx)libc_pic.os \
564 $(elfobjdir)/sofini.os \
565 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
567 ifeq ($(versioning),yes)
568 $(common-objpfx)libc.so: $(common-objpfx)libc.map
570 common-generated += libc.so libc_pic.os
571 ifdef libc.so-version
572 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
574 common-generated += libc.so$(libc.so-version)
578 ifneq (,$(findstring aix,$(config-os)))
579 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
582 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
583 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
584 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
585 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
586 -bE:$(common-objpfx)syscalls.exp \
587 -bI:$(common-objpfx)syscalls.exp \
588 -L$(common-objpfx) -o $@ $^
589 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
590 cp $@ $(common-objpfx)shr.o
591 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
595 # Figure out the source filenames in this directory.
597 override sources := $(addsuffix .c,\
598 $(filter-out $(elided-routines),\
601 sysdep_routines := $(sysdep_routines)
603 headers := $(headers) $(sysdep_headers)
605 # This is the list of all object files, gotten by
606 # replacing every ".c" in `sources' with a ".o".
607 # We also add bounded-pointer thunks, which are later
608 # elided for all suffixes except for `.ob'.
609 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
610 $(patsubst %,$(bppfx)%.o,\
611 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
614 # The makefile may define $(extra-libs) with `libfoo libbar'
615 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
617 # extra-lib.mk is included once for each extra lib to define rules
618 # to build it, and to add its objects to the various variables.
619 # During its evaluation, $(lib) is set to the name of the library.
620 extra-libs-left := $(extra-libs)
621 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
624 +depfiles := $(sources:.c=.d) \
625 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
626 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
627 ifeq ($(build-programs),yes)
628 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
630 +depfiles := $(addprefix $(objpfx),\
631 $(filter-out $(addsuffix .d,$(omit-deps)),\
636 -include $(+depfiles)
640 # Maximize efficiency by minimizing the number of rules.
641 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
642 # Don't define any builtin rules.
643 MAKEFLAGS := $(MAKEFLAGS)r
645 # Generic rule for making directories.
647 # mkdir isn't smart enough to strip a trailing /.
650 # Make sure that object files are not removed
651 # when they are intermediates between sources and library members.
652 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
654 # Make sure that the parent library archive is never removed.
655 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
657 # Use the verbose option of ar and tar when not running silently.
658 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
664 ARFLAGS := r$(verbose)
665 CREATE_ARFLAGS := cru$(verbose)
667 # This makes all the object files in the parent library archive.
669 .PHONY: lib lib-noranlib
670 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
671 lib-noranlib: libobjs
673 # For object-suffix $o, the list of objects with that suffix.
674 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
675 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
676 $(elide-routines$o)),\
678 $(addprefix $(objpfx),$(o-objects$o))
680 others: $(addprefix $(objpfx),$(install-lib))
684 # Create the stamp$o files to keep the parent makefile happy.
685 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
686 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
687 $(make-target-directory)
691 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
692 # timestamp file; these rules (one explicit rule is generated for each
693 # object suffix) write a list of objects to update in the stamp file.
694 # The parent will then actually add them all to the archive in the
695 # archive rule, below.
696 define o-iterator-doit
697 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
700 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
703 object-suffixes-left := $(object-suffixes-for-libc)
704 include $(o-iterator)
708 # Now define explicit rules to build the library archives; these depend
709 # on the stamp files built above.
710 define o-iterator-doit
711 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
712 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
715 cd $(common-objdir) && \
716 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
719 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
720 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
722 $(subdirs-stamps): subdir_lib;
724 object-suffixes-left = $(object-suffixes-for-libc)
725 include $(o-iterator)
728 # This makes all the object files.
729 .PHONY: objects objs libobjs extra-objs
730 objects objs: libobjs extra-objs
731 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
732 extra-objs: $(addprefix $(objpfx),$(extra-objs))
734 # Canned sequence for building an extra library archive.
735 define build-extra-lib
736 $(patsubst %/,cd % &&,$(objpfx)) \
737 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
738 $(patsubst $(objpfx)%,%,$^)
744 .PHONY: force-install
747 # $(install-lib) are installed from the object directory into $(libdir);
748 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
749 # unless they also appear in $(non-lib.a). $(install-data) are installed
750 # as they are into $(datadir). $(headers) are installed as they are in
751 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
752 # are installed from the object directory into $(bindir), $(bindir) and
753 # $(sbindir), respectively. $(install-others) are absolute path names of
754 # files to install; rules to install them are defined elsewhere.
756 # The simple library name to install libc.a under.
757 # This could be defined by a sysdep Makefile.
763 $(make-target-directory)
764 $(INSTALL_DATA) $< $@
767 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
768 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
769 define make-target-directory
770 $(addprefix $(..)./scripts/mkinstalldirs ,\
771 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
774 # Any directory (parent or subdir) should install libc.a; this way
775 # "make install" in a subdir is guaranteed to install everything it changes.
776 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
777 $(inst_libdir)/$(patsubst %,$(libtype$o),\
778 $(libprefix)$(libc-name)))
779 install: $(installed-libcs)
780 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
781 $(make-target-directory)
782 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
783 # Running ranlib after installing makes the __.SYMDEF time stamp up to
784 # date, which avoids messages from some linkers.
787 define do-install-program
788 $(make-target-directory)
789 $(INSTALL_PROGRAM) $< $@.new
793 define do-install-script
794 $(make-target-directory)
795 $(INSTALL_SCRIPT) $< $@.new
799 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
800 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
802 ifeq (yes,$(build-shared))
803 # Find which .so's have versions.
804 versioned := $(strip $(foreach so,$(install-lib.so),\
805 $(patsubst %,$(so),$($(so)-version))))
807 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
808 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
810 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
811 $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
813 # Install all the unversioned shared libraries.
814 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
815 $(objpfx)%.so $(+force)
816 $(do-install-program)
818 ifneq ($(findstring -s,$(LN_S)),)
821 $(SHELL) $(..)scripts/rellns-sh $< $@.new
825 # If we have no symbolic links don't bother with rellns-sh.
833 ifeq (yes,$(build-shared))
834 ifeq (no,$(cross-compiling))
835 symbolic-link-prog := $(common-objpfx)elf/sln
836 symbolic-link-list := $(common-objpfx)elf/symlink.list
837 define make-shlib-link
838 echo $(<F) $@ >> $(symbolic-link-list)
840 else # cross-compiling
841 # We need a definition that can be used by elf/Makefile's install rules.
842 symbolic-link-prog = $(LN_S)
845 ifndef make-shlib-link
846 define make-shlib-link
852 ifdef libc.so-version
853 # For a library specified to be version N, install three files:
854 # libc.so -> libc.so.N (e.g. libc.so.6)
855 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
857 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
860 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
861 $(do-install-program)
862 install: $(inst_slibdir)/libc.so$(libc.so-version)
865 # What we install as libc.so for programs to link against is in fact a
866 # link script. It contains references for the various libraries we need.
867 # The libc.so object is not complete since some functions are only defined
868 # in libc_nonshared.a.
869 # We need to use absolute paths since otherwise local copies (if they exist)
870 # of the files are taken by the linker.
871 install: $(inst_libdir)/libc.so
872 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
873 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
874 $(libprefix)$(libc-name)) \
876 (echo '/* GNU ld script';\
877 echo ' Use the shared library, but some functions are only in';\
878 echo ' the static library, so try that secondarily. */';\
879 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
880 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
888 install: $(inst_slibdir)/libc.so
889 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
890 $(do-install-program)
893 ifneq (,$(versioned))
894 # Produce three sets of rules as above for all the smaller versioned libraries.
896 define o-iterator-doit
897 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
899 object-suffixes-left := $(versioned)
900 include $(o-iterator)
902 # Make symlinks in the build directory, because the versioned names might
903 # be referenced by a DT_NEEDED in another library.
904 define o-iterator-doit
905 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
907 object-suffixes-left := $(versioned)
908 include $(o-iterator)
910 generated += $(foreach o,$(versioned),$o$($o-version))
912 ifeq (,$($(subdir)-version))
913 define o-iterator-doit
914 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
918 object-suffixes-left := $(versioned)
919 include $(o-iterator)
921 define o-iterator-doit
922 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
923 $$(do-install-program)
925 object-suffixes-left := $(versioned)
926 include $(o-iterator)
928 define o-iterator-doit
929 $(inst_slibdir)/$o$($o-version): \
930 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
933 object-suffixes-left := $(versioned)
934 include $(o-iterator)
936 define o-iterator-doit
937 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
938 $$(do-install-program)
940 object-suffixes-left := $(versioned)
941 include $(o-iterator)
946 $(do-install-program)
947 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
948 $(filter-out %.so,$@))
951 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
952 $(foreach v,$(so-versions),\
953 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
956 $(foreach v,$(so-versions),\
957 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
962 $(addprefix $(inst_bindir)/,$(install-bin)): \
963 $(inst_bindir)/%: $(objpfx)% $(+force)
964 $(do-install-program)
966 ifdef install-bin-script
967 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
968 $(inst_bindir)/%: $(objpfx)% $(+force)
971 ifdef install-rootsbin
972 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
973 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
974 $(do-install-program)
977 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
978 $(inst_sbindir)/%: $(objpfx)% $(+force)
979 $(do-install-program)
982 install-lib.a := $(filter lib%.a,$(install-lib))
983 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
984 ifdef install-lib-non.a
985 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
986 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
990 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
991 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
993 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
997 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1000 headers := $(strip $(headers))
1002 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1006 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1007 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1008 install-data-nosubdir install-headers-nosubdir
1009 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1010 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1011 install-rootsbin-nosubdir: \
1012 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1013 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1014 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1015 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1016 $(addprefix $(libprefix),$(install-lib-non.a)))
1017 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1018 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1019 install-others-nosubdir: $(install-others)
1021 # We need all the `-nosubdir' targets so that `install' in the parent
1022 # doesn't depend on several things which each iterate over the subdirs.
1023 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1024 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1025 install-%:: install-%-nosubdir ;
1027 .PHONY: install install-no-libc.a-nosubdir
1028 ifeq ($(build-programs),yes)
1029 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1030 install-bin-nosubdir install-bin-script-nosubdir \
1031 install-lib-nosubdir install-others-nosubdir \
1032 install-rootsbin-nosubdir install-sbin-nosubdir
1034 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1035 install-lib-nosubdir install-others-nosubdir
1037 install: install-no-libc.a-nosubdir
1039 # Command to compile $< in $(objdir) using the native libraries.
1040 define native-compile
1041 $(make-target-directory)
1042 $(patsubst %/,cd % &&,$(objpfx)) \
1043 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1044 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1047 # Command to compile $< in $(common-objdir) using the native libraries.
1048 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1049 define common-objdir-compile
1050 $(patsubst %/,cd % &&,$(objpfx)) \
1051 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1052 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1055 # We always want to use configuration definitions.
1056 # Note that this is only used for commands running in $(objpfx).
1057 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1059 # Support the GNU standard name for this target.
1062 # Special target to run tests which cannot be run unconditionally.
1063 # Maintainers should use this target.
1067 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1068 ifneq (,$(all-nonlib))
1069 cpp-srcs-left = $(all-nonlib:=.c)
1071 include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
1074 # The include magic above causes those files to use this variable for flags.
1075 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1078 TAGS: $(objpfx)distinfo $(..)MakeTAGS
1079 $(MAKE) $(addprefix -f ,$^) $@
1081 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1082 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1086 .PHONY: echo-headers
1091 # Common cleaning targets.
1093 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1095 mostlyclean: common-mostlyclean
1098 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1100 $(addsuffix -bp.out,$(tests) $(xtests) \
1103 # Remove the object files.
1105 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1106 $(others) $(sysdep-others) stubs \
1107 $(addsuffix .o,$(tests) $(xtests) \
1108 $(test-srcs) $(others) \
1110 $(addsuffix -bp,$(tests) $(xtests) \
1112 $(addsuffix .out,$(tests) $(xtests) \
1114 $(addsuffix -bp.out,$(tests) $(xtests) \
1116 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1118 $(install-lib.so:%.so=%_pic.a))
1120 -rm -f $(objpfx)rtld-*.os
1123 $(foreach o,$(object-suffixes-for-libc),
1124 -rm -f $(objpfx)stamp$o $(o-objects))
1127 # Also remove the dependencies and generated source files.
1128 common-clean: common-mostlyclean
1129 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
1130 -rm -f $(objpfx)rtld-*.d
1131 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1132 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1133 -rm -f $(objpfx)distinfo
1135 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1136 # for each function which is a stub. We grovel over all the .d files
1137 # looking for references to <stub-tag.h>. Then we grovel over each
1138 # referenced source file to see what stub function it defines.
1141 .PHONY: stubs # The parent Makefile calls this target.
1142 stubs: $(objpfx)stubs
1144 s = $(sysdep_dir)/generic
1145 $(objpfx)stubs: $(+depfiles)
1146 # Use /dev/null since `...` might expand to empty.
1147 (s=`cd $s && $(PWD_P)`; \
1148 $(patsubst %/,cd % &&,$(objpfx)) \
1149 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1150 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
1151 -e '/stub-tag\.h/{; g; p; }' \
1152 $(patsubst $(objpfx)%,%,$^) /dev/null` \
1156 # Make the distribution tar file.
1159 dist: $(objpfx)distinfo $(..)Make-dist
1160 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1162 # Avoid depending on source files found in sysdeps dirs,
1163 # because the references affect implicit rule selection.
1164 dist: $(filter-out %.c %.S %.s,$(distribute))
1166 # We used to simply export all these variables, but that frequently made the
1167 # environment get too large. Instead, we write all the information into
1168 # a generated makefile fragment `distinfo', and then include it with -f in
1169 # the sub-make that makes the distribution (above).
1170 $(objpfx)distinfo: Makefile $(..)Makerules \
1171 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1172 $(make-target-directory)
1175 .PHONY: subdir_distinfo
1176 subdir_distinfo: $(objpfx)distinfo
1178 define distinfo-vars
1180 echo > $@.new 'subdir := $(subdir)'
1181 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1182 headers sysdep_headers distribute dont_distribute generated \
1183 others tests xtests test-srcs extra-libs versioned \
1184 $(extra-libs:%=%-routines) \
1185 $(addprefix install-,lib lib.so data bin bin-script sbin others),
1186 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1187 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1190 ifneq (,$(strip $(gpl2lgpl)))
1191 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1192 # Snarf from the master source and frob the copying notice.
1193 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1195 # So I don't edit them by mistake.
1198 ifeq ($(with-cvs),yes)
1199 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@