1 # Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98 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 Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # 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 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB. If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 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
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 -include $(+sysdir_pfx)sysd-Makefile
98 ifndef avoid-generated
99 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
100 sysd-Makefile-force = FORCE
103 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
104 $(sysd-Makefile-force)
106 (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)'; \
107 for dir in $(config-sysdirs); do \
108 file=$$dir/Makefile; \
113 if [ -f $$rel$$file ]; then \
115 /*) echo include "$$file" ;; \
116 *) echo include "\$$(..)$$file" ;; \
120 echo 'sysd-Makefile-done=t') > $@T
124 ifndef sysd-Makefile-done
125 # Don't do deps until this exists, because it might change the sources list.
130 # Reorder before-compile so that mach things come first, and hurd things
131 # second, before all else. The mach and hurd subdirectories have many
132 # generated header files which the much of rest of the library depends on,
133 # so it is best to build them first (and mach before hurd, at that).
134 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
136 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
139 # Remove existing files from `before-compile'. Things are added there when
140 # they must exist for dependency generation to work right, but once they
141 # exist there is no further need for every single file to depend on them,
142 # and those gratuitous dependencies result in many gratuitous
144 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
146 # Don't let any before-compile file be an intermediate and get removed.
151 # Generate an ordered list of implicit rules which find the source files in
152 # each sysdep directory. The old method was to use vpath to search all the
153 # sysdep directories. However, that had the problem that a .S file in a
154 # later directory would be chosen over a .c file in an earlier directory,
155 # which does not preserve the desired sysdeps ordering behavior.
157 # When making the list of .d files to include, we can't know which ones
158 # have source in .s files, and thus do not in fact need a .d file.
159 # So we must define rules to make .d files for .s files.
160 define make-dummy-dep
161 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
163 $(common-objpfx)dummy.d:
164 echo '# .s files cannot contain includes, so they need no deps.' > $@
166 # It matters that this set of rules, for compiling from sources in
167 # the current directory (the $srcdir/$subdir) come before the
168 # generated sysdep rules in included from sysd-rules below. When
169 # compiling in the source tree, generated sources go into the current
170 # directory, and those should be chosen before any sources in sysdeps.
171 define o-iterator-doit
172 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
174 object-suffixes-left := $(object-suffixes-for-libc)
175 include $(o-iterator)
176 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
178 define o-iterator-doit
179 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
181 object-suffixes-left := $(object-suffixes-for-libc)
182 include $(o-iterator)
183 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
185 define o-iterator-doit
186 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
188 object-suffixes-left := $(object-suffixes-for-libc)
189 include $(o-iterator)
190 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
192 # Omit the objpfx rules when building in the source tree, because
193 # objpfx is empty and so these rules just override the ones above.
195 # Define first rules to find the source files in $(objpfx).
196 # Generated source files will end up there.
197 define o-iterator-doit
198 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
200 object-suffixes-left := $(object-suffixes-for-libc)
201 include $(o-iterator)
202 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
204 define o-iterator-doit
205 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
207 object-suffixes-left := $(object-suffixes-for-libc)
208 include $(o-iterator)
209 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
211 define o-iterator-doit
212 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
214 object-suffixes-left := $(object-suffixes-for-libc)
215 include $(o-iterator)
216 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
219 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
220 # patterns matching sysdep directories whose assembly source files should
222 ifdef inhibit-sysdep-asm
223 define open-check-inhibit-asm
224 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
226 close-check-inhibit-asm = ;; esac ;
229 # Don't include sysd-rules until sysd-Makefile is already there and has been
230 # included. It might define inhibit-sysdep-asm, which would affect the
231 # contents of sysd-rules.
232 ifdef sysd-Makefile-done
233 -include $(+sysdir_pfx)sysd-rules
234 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
235 # The value of $(+sysdep_dirs) the sysd-rules was computed for
236 # differs from the one we are using now. So force a rebuild of sysd-rules.
237 sysd-rules-force = FORCE
241 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
242 $(wildcard $(foreach dir,$(sysdirs),\
246 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
247 for sysdir in $(config-sysdirs); do \
249 /*) dir=$$sysdir ;; \
250 *) dir="\$$(..)$$sysdir" ;; \
252 for o in $(all-object-suffixes); do \
253 $(open-check-inhibit-asm) \
254 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
255 \$$(compile-command.S)"; \
256 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
257 \$$(compile-command.s)"; \
258 $(close-check-inhibit-asm) \
259 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
260 \$$(compile-command.c)"; \
262 $(open-check-inhibit-asm) \
263 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
264 \$$(make-dummy-dep)"; \
265 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
267 $(close-check-inhibit-asm) \
268 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
271 echo 'sysd-rules-done = t') > $@T
274 ifndef sysd-rules-done
275 # Don't do deps until this exists, because it provides rules to make the deps.
280 ifndef compile-command.S
281 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
283 ifndef compile-command.s
284 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
286 ifndef compile-command.c
287 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
290 # GCC can grok options after the file name, and it looks nicer that way.
291 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
293 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
295 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
296 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
298 # We need this for the output to go in the right place. It will default to
299 # empty if make was configured to work with a cc that can't grok -c and -o
300 # together. You can't compile the C library with such a compiler.
301 OUTPUT_OPTION = -o $@
303 S-CPPFLAGS = $(asm-CPPFLAGS)
305 $(make-target-directory)
307 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
309 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
310 $(sed-remove-objpfx) > $(@:.d=.T)
314 # Continuation lines here are dangerous because they introduce spaces!
315 define sed-remove-objpfx
316 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
317 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
321 # Shared library building.
323 ifeq (yes,$(build-shared))
325 # Reference map file only when versioning is selected and a map file name
327 ifeq ($(versioning),yes)
328 load-map-file = $($(@F:%.so=%)-map)
333 # Pattern rule to build a shared object from an archive of PIC objects.
334 # This must come after the installation rules so Make doesn't try to
335 # build shared libraries in place from the installed *_pic.a files.
336 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
337 # on other shared objects.
338 lib%.so: lib%_pic.a $(+preinit) $(+postinit)
341 ifeq ($(have-no-whole-archive),yes)
342 no-whole-archive = -Wl,--no-whole-archive
347 interp-obj = $(common-objpfx)interp.os
348 $(interp-obj): $(common-objpfx)%.os: $(..)%.c
350 common-generated += interp.os
351 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
353 $(common-objpfx)libc.so: $(interp-obj)
354 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
357 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
358 -B$(csu-objpfx) $(load-map-file:%=-Wl,--version-script=%) \
359 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
360 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
361 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
362 -Wl,--whole-archive \
363 $(filter-out $($(@F:.so=)-map) $(+preinit) $(+postinit),$^) \
364 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
367 ifndef libc.so-version
368 # Undefine this because it can't work when we libc.so is unversioned.
369 static-only-routines =
372 elide-routines.oS += $(filter-out $(static-only-routines),\
373 $(routines) $(aux) $(sysdep_routines))
374 elide-routines.os += $(static-only-routines)
376 # If we have versioned code we don't need the old versions in any of the
378 elide-routines.o += $(shared-only-routines)
379 elide-routines.op += $(shared-only-routines)
380 elide-routines.og += $(shared-only-routines)
381 elide-routines.ob += $(shared-only-routines)
383 # Don't try to use -lc when making libc.so itself.
384 # Also omits crti.o and crtn.o, which we do not want
385 # since we define our own `.init' section specially.
386 LDFLAGS-c.so = -nostdlib -nostartfiles
387 # But we still want to link libc.so against $(gnulib).
388 LDLIBS-c.so = $(gnulib)
389 # Give libc.so an entry point and make it directly runnable itself.
390 LDFLAGS-c.so += -e __libc_main
391 # We have a versioning file for libc.so.
392 libc-map = $(..)libc.map
393 # Pre-link the objects of libc_pic.a so that we can locally resolve
394 # COMMON symbols before we link against ld.so. This is because ld.so
395 # contains some of libc_pic.a already, which will prevent the COMMONs
396 # from being allocated in libc.so, which introduces evil dependencies
397 # between libc.so and ld.so, which can make it impossible to upgrade.
398 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
399 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
400 -Wl,-d -Wl,--whole-archive $^
401 # Use our own special initializer and finalizer files for libc.so.
402 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
403 $(common-objpfx)libc_pic.os \
404 $(elfobjdir)/sofini.os $(elfobjdir)/ld.so \
407 common-generated += libc.so libc_pic.os
408 ifdef libc.so-version
409 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
411 common-generated += libc.so$(libc.so-version)
415 # Some files must not be compiled with the exception handler mechanism
416 # enabled (introduced in gcc-2.8). Use $(no-exceptions) in the
417 # appropriate CFLAGS definition.
418 ifeq ($(have-no-exceptions),yes)
419 no-exceptions = -fno-exceptions
424 # Figure out the source filenames in this directory.
426 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
429 sysdep_routines := $(sysdep_routines)
431 headers := $(headers) $(sysdep_headers)
433 # This is the list of all object files, gotten by
434 # replacing every ".c" in `sources' with a ".o".
435 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
438 # The makefile may define $(extra-libs) with `libfoo libbar'
439 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
441 # extra-lib.mk is included once for each extra lib to define rules
442 # to build it, and to add its objects to the various variables.
443 # During its evaluation, $(lib) is set to the name of the library.
444 extra-libs-left := $(extra-libs)
445 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
448 +depfiles := $(sources:.c=.d) \
449 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
450 $(addsuffix .d,$(tests) $(test-srcs) $(tests-static))
451 ifeq ($(build-programs),yes)
452 +depfiles += $(addsuffix .d,$(others))
454 +depfiles := $(addprefix $(objpfx),\
455 $(filter-out $(addsuffix .d,$(omit-deps)),\
460 -include $(+depfiles)
464 # Maximize efficiency by minimizing the number of rules.
465 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
466 # Don't define any builtin rules.
467 MAKEFLAGS := $(MAKEFLAGS)r
469 # Generic rule for making directories.
471 # mkdir isn't smart enough to strip a trailing /.
474 # Make sure that object files are not removed
475 # when they are intermediates between sources and library members.
476 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
478 # Make sure that the parent library archive is never removed.
479 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
481 # Use the verbose option of ar and tar when not running silently.
482 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
488 ARFLAGS := r$(verbose)
489 CREATE_ARFLAGS := cru$(verbose)
491 # This makes all the object files in the parent library archive.
493 .PHONY: lib lib-noranlib
494 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
495 lib-noranlib: libobjs
497 # For object-suffix $o, the list of objects with that suffix.
498 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
499 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
500 $(elide-routines$o)),\
502 others: $(addprefix $(objpfx),$(install-lib))
506 # Create the stamp$o files to keep the parent makefile happy.
507 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
508 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
509 $(make-target-directory)
513 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
514 # timestamp file; these rules (one explicit rule is generated for each
515 # object suffix) write a list of objects to update in the stamp file.
516 # The parent will then actually add them all to the archive in the
517 # archive rule, below.
518 define o-iterator-doit
519 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
522 echo '$(patsubst $(common-objpfx)%,%,$^)' > $@T
525 object-suffixes-left := $(object-suffixes-for-libc)
526 include $(o-iterator)
530 # Now define explicit rules to build the library archives; these depend
531 # on the stamp files built above. The rule always destroys and recreates
532 # the library from scratch; it's faster that way.
533 define o-iterator-doit
534 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
535 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
538 cd $(common-objdir) && \
539 $(AR) $(CREATE_ARFLAGS) $(@F)T `cat $(patsubst $(common-objpfx)%,%,$^)`
543 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
544 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
546 $(subdirs-stamps): subdir_lib;
548 object-suffixes-left = $(object-suffixes-for-libc)
549 include $(o-iterator)
552 # This makes all the object files.
553 .PHONY: objects objs libobjs extra-objs
554 objects objs: libobjs extra-objs
555 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
556 extra-objs: $(addprefix $(objpfx),$(extra-objs))
558 # Canned sequence for building an extra library archive.
559 define build-extra-lib
560 $(patsubst %/,cd % &&,$(objpfx)) \
561 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
562 $(patsubst $(objpfx)%,%,$^)
568 .PHONY: force-install
571 # $(install-lib) are installed from the object directory into $(libdir);
572 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
573 # unless they also appear in $(non-lib.a). $(install-data) are installed
574 # as they are into $(datadir). $(headers) are installed as they are in
575 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
576 # object directory into $(bindir) and $(sbindir), respectively.
577 # $(install-others) are absolute path names of files to install; rules to
578 # install them are defined elsewhere.
580 # The simple library name to install libc.a under.
581 # This could be defined by a sysdep Makefile.
587 $(make-target-directory)
588 $(INSTALL_DATA) $< $@
591 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
592 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
593 define make-target-directory
594 $(addprefix $(..)./mkinstalldirs ,\
595 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
598 # Any directory (parent or subdir) that has any object files to build
599 # should install libc.a; this way "make install" in a subdir is guaranteed
600 # to install everything it changes.
602 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
603 $(inst_libdir)/$(patsubst %,$(libtype$o),\
604 $(libprefix)$(libc-name)))
605 install: $(installed-libcs)
606 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
607 $(make-target-directory)
608 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
609 # Running ranlib after installing makes the __.SYMDEF time stamp up to
610 # date, which avoids messages from some linkers.
614 define do-install-program
615 $(make-target-directory)
616 $(INSTALL_PROGRAM) $< $@.new
620 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
621 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
622 ifeq (yes,$(build-shared))
624 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
626 # Find which .so's have versions.
627 versioned := $(strip $(foreach so,$(install-lib.so),\
628 $(patsubst %,$(so),$($(so)-version))))
630 # Install all the unversioned shared libraries.
631 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
632 $(inst_slibdir)/%.so: $(objpfx)%.so $(+force); $(do-install-program)
634 ifneq ($(findstring -s,$(LN_S)),)
637 $(SHELL) $(..)rellns-sh $< $@.new
641 # If we have no symbolic links don't bother with rellns-sh.
649 # XXX The following will have to be changed when `ldconfig' is available.
650 ifneq (yes,$(cross-compiling))
651 ifeq (yes,$(has-ldconfig))
652 define make-shlib-link
657 ifndef make-shlib-link
658 define make-shlib-link
663 ifdef libc.so-version
664 # For a library specified to be version N, install three files:
665 # libc.so -> libc.so.N (e.g. libc.so.6)
666 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
668 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
671 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
672 $(do-install-program)
673 install: $(inst_slibdir)/libc.so$(libc.so-version)
676 # What we install as libc.so for programs to link against is in fact a
677 # link script. It contains references for the various libraries we need.
678 # The libc.so object is not complete since some functions are only defined
679 # in libc_nonshared.a.
680 install: $(inst_libdir)/libc.so
681 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
682 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
683 $(libprefix)$(libc-name)) \
685 (echo '/* GNU ld script';\
686 echo ' Use the shared library, but some functions are only in';\
687 echo ' the static library, so try that secondarily. */';\
688 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
689 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
697 install: $(inst_slibdir)/libc.so
698 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
699 $(do-install-program)
702 ifneq (,$(versioned))
703 # Produce three sets of rules as above for all the smaller versioned libraries.
705 define o-iterator-doit
706 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
708 object-suffixes-left := $(versioned)
709 include $(o-iterator)
711 # Make symlinks in the build directory, because the versioned names might
712 # be referenced by a DT_NEEDED in another library.
713 define o-iterator-doit
714 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
716 object-suffixes-left := $(versioned)
717 include $(o-iterator)
719 generated += $(foreach o,$(versioned),$o$($o-version))
721 ifeq (,$($(subdir)-version))
722 define o-iterator-doit
723 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
727 object-suffixes-left := $(versioned)
728 include $(o-iterator)
730 define o-iterator-doit
731 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
732 $$(do-install-program)
734 object-suffixes-left := $(versioned)
735 include $(o-iterator)
737 define o-iterator-doit
738 $(inst_slibdir)/$o$($o-version): \
739 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
742 object-suffixes-left := $(versioned)
743 include $(o-iterator)
745 define o-iterator-doit
746 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
747 $$(do-install-program)
749 object-suffixes-left := $(versioned)
750 include $(o-iterator)
755 $(do-install-program)
756 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
757 $(filter-out %.so,$@))
760 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
761 $(foreach v,$(so-versions),\
762 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
765 $(foreach v,$(so-versions),\
766 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
771 $(addprefix $(inst_bindir)/,$(install-bin)): \
772 $(inst_bindir)/%: $(objpfx)% $(+force)
773 $(do-install-program)
775 ifdef install-rootsbin
776 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
777 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
778 $(do-install-program)
781 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
782 $(inst_sbindir)/%: $(objpfx)% $(+force)
783 $(do-install-program)
786 install-lib.a := $(filter lib%.a,$(install-lib))
787 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
788 ifdef install-lib-non.a
789 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
790 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
794 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
795 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
797 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
801 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
804 headers := $(strip $(headers))
806 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
810 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
811 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
812 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
813 install-rootsbin-nosubdir: \
814 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
815 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
816 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
817 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
818 $(addprefix $(libprefix),$(install-lib-non.a)))
819 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
820 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
821 install-others-nosubdir: $(install-others)
823 # We need all the `-nosubdir' targets so that `install' in the parent
824 # doesn't depend on several things which each iterate over the subdirs.
825 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
826 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
827 install-%:: install-%-nosubdir ;
829 .PHONY: install install-no-libc.a-nosubdir
830 ifeq ($(build-programs),yes)
831 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
832 install-bin-nosubdir install-lib-nosubdir \
833 install-others-nosubdir install-rootsbin-nosubdir \
834 install-sbin-nosubdir
836 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
837 install-lib-nosubdir install-others-nosubdir
839 install: install-no-libc.a-nosubdir
841 # Command to compile $< in $(objdir) using the native libraries.
842 define native-compile
843 $(make-target-directory)
844 $(patsubst %/,cd % &&,$(objpfx)) \
845 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
846 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
849 # Command to compile $< in $(common-objdir) using the native libraries.
850 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
851 define common-objdir-compile
852 $(patsubst %/,cd % &&,$(objpfx)) \
853 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
854 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
857 # We always want to use configuration definitions.
858 # Note that this is only used for commands running in $(objpfx).
859 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
861 # Support the GNU standard name for this target.
866 TAGS: $(objpfx)distinfo $(..)MakeTAGS
867 $(MAKE) $(addprefix -f ,$^) $@
869 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
870 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
879 # Common cleaning targets.
881 .PHONY: common-mostlyclean common-clean mostlyclean clean
883 mostlyclean: common-mostlyclean
885 # Remove the object files.
887 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
888 $(tests-static) stubs \
889 $(addsuffix .o,$(tests) $(test-srcs) \
892 $(addsuffix .out,$(tests) $(test-srcs)) \
893 $(addsuffix .sout,$(tests-static)))
894 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
896 $(install-lib.so:%.so=%_pic.a))
900 $(foreach o,$(object-suffixes-for-libc),
901 -rm -f $(objpfx)stamp$o $(o-objects))
904 # Also remove the dependencies and generated source files.
905 common-clean: common-mostlyclean
906 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
907 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
908 -rm -f $(addprefix $(common-objpfx),$(common-generated))
909 -rm -f $(objpfx)distinfo
911 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
912 # for each function which is a stub. We grovel over all the .d files
913 # looking for references to <stub-tag.h>. Then we grovel over each
914 # referenced source file to see what stub function it defines.
917 .PHONY: stubs # The parent Makefile calls this target.
918 stubs: $(objpfx)stubs
920 s = $(sysdep_dir)/generic
921 $(objpfx)stubs: $(+depfiles)
922 # Use /dev/null since `...` might expand to empty.
923 (s=`cd $s && /bin/pwd`; \
924 $(patsubst %/,cd % &&,$(objpfx)) \
925 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
926 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
927 -e '/stub-tag\.h/{; g; p; }' \
928 $(patsubst $(objpfx)%,%,$^) /dev/null` \
932 # Make the distribution tar file.
935 dist: $(objpfx)distinfo $(..)Make-dist
936 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
938 # Avoid depending on source files found in sysdeps dirs,
939 # because the references affect implicit rule selection.
940 dist: $(filter-out %.c %.S %.s,$(distribute))
942 # We used to simply export all these variables, but that frequently made the
943 # environment get too large. Instead, we write all the information into
944 # a generated makefile fragment `distinfo', and then include it with -f in
945 # the sub-make that makes the distribution (above).
946 $(objpfx)distinfo: Makefile $(..)Makerules \
947 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
948 $(make-target-directory)
951 .PHONY: subdir_distinfo
952 subdir_distinfo: $(objpfx)distinfo
956 echo > $@.new 'subdir := $(subdir)'
957 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
958 headers sysdep_headers distribute dont_distribute generated \
959 others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
960 $(extra-libs:%=%-map) versioned \
961 $(addprefix install-,lib lib.so data bin sbin others),
962 echo >> $@.new '$(subdir)-$(var) := $($(var))'
963 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
966 ifneq (,$(strip $(gpl2lgpl)))
967 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
968 # Snarf from the master source and frob the copying notice.
969 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
971 # So I don't edit them by mistake.
974 ifeq ($(with-cvs),yes)
975 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@