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 # The name of the symbol table archive member. The default is suitable for
76 # BSD style archives. It can be overridden in sysdep Makefiles when SYSV
77 # style archive are used.
79 ar-symtab-name = __.SYMDEF
81 ar-symtab-name = # The null name is used in ELF archives.
84 # This variable is used in ``include $(o-iterator)'' after defining
85 # $(o-iterator-doit) to produce some desired rule using $o for the object
86 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
87 # is produced for each object suffix in use.
88 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
90 # Include any system-specific makefiles.
92 # This is here so things in sysdep Makefiles can easily depend on foo.h as
93 # appropriate and not worry about where foo.h comes from, which may be
94 # system dependent and not known by that Makefile.
95 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
96 $(+sysdep_dirs) $(..)))
98 # The same is true for RPC source files.
99 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
100 $(+sysdep_dirs) $(..)))
102 # Some sysdep makefiles use this to distinguish being included here from
103 # being included individually by a subdir makefile (hurd/Makefile needs this).
106 -include $(+sysdir_pfx)sysd-Makefile
107 ifndef avoid-generated
108 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
109 sysd-Makefile-force = FORCE
112 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
113 $(sysd-Makefile-force)
115 (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)'; \
116 for dir in $(config-sysdirs); do \
117 file=$$dir/Makefile; \
122 if [ -f $$rel$$file ]; then \
124 /*) echo include "$$file" ;; \
125 *) echo include "\$$(..)$$file" ;; \
129 echo 'sysd-Makefile-done=t') > $@T
133 ifndef sysd-Makefile-done
134 # Don't do deps until this exists, because it might change the sources list.
139 # Reorder before-compile so that mach things come first, and hurd things
140 # second, before all else. The mach and hurd subdirectories have many
141 # generated header files which the much of rest of the library depends on,
142 # so it is best to build them first (and mach before hurd, at that).
143 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
145 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
148 # Remove existing files from `before-compile'. Things are added there when
149 # they must exist for dependency generation to work right, but once they
150 # exist there is no further need for every single file to depend on them,
151 # and those gratuitous dependencies result in many gratuitous
153 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
155 # Don't let any before-compile file be an intermediate and get removed.
160 # Generate an ordered list of implicit rules which find the source files in
161 # each sysdep directory. The old method was to use vpath to search all the
162 # sysdep directories. However, that had the problem that a .S file in a
163 # later directory would be chosen over a .c file in an earlier directory,
164 # which does not preserve the desired sysdeps ordering behavior.
166 # When making the list of .d files to include, we can't know which ones
167 # have source in .s files, and thus do not in fact need a .d file.
168 # So we must define rules to make .d files for .s files.
169 define make-dummy-dep
170 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
172 $(common-objpfx)dummy.d:
173 echo '# .s files cannot contain includes, so they need no deps.' > $@
175 # It matters that this set of rules, for compiling from sources in
176 # the current directory (the $srcdir/$subdir) come before the
177 # generated sysdep rules in included from sysd-rules below. When
178 # compiling in the source tree, generated sources go into the current
179 # directory, and those should be chosen before any sources in sysdeps.
180 define o-iterator-doit
181 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
183 object-suffixes-left := $(object-suffixes)
184 include $(o-iterator)
185 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
187 define o-iterator-doit
188 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
190 object-suffixes-left := $(object-suffixes)
191 include $(o-iterator)
192 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
194 define o-iterator-doit
195 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
197 object-suffixes-left := $(object-suffixes)
198 include $(o-iterator)
199 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
201 # Omit the objpfx rules when building in the source tree, because
202 # objpfx is empty and so these rules just override the ones above.
204 # Define first rules to find the source files in $(objpfx).
205 # Generated source files will end up there.
206 define o-iterator-doit
207 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
209 object-suffixes-left := $(object-suffixes)
210 include $(o-iterator)
211 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
213 define o-iterator-doit
214 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
216 object-suffixes-left := $(object-suffixes)
217 include $(o-iterator)
218 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
220 define o-iterator-doit
221 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
223 object-suffixes-left := $(object-suffixes)
224 include $(o-iterator)
225 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
228 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
229 # patterns matching sysdep directories whose assembly source files should
231 ifdef inhibit-sysdep-asm
232 define open-check-inhibit-asm
233 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
235 close-check-inhibit-asm = ;; esac ;
238 # Don't include sysd-rules until sysd-Makefile is already there and has been
239 # included. It might define inhibit-sysdep-asm, which would affect the
240 # contents of sysd-rules.
241 ifdef sysd-Makefile-done
242 -include $(+sysdir_pfx)sysd-rules
243 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
244 # The value of $(+sysdep_dirs) the sysd-rules was computed for
245 # differs from the one we are using now. So force a rebuild of sysd-rules.
246 sysd-rules-force = FORCE
250 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
251 $(wildcard $(foreach dir,$(sysdirs),\
255 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
256 for sysdir in $(config-sysdirs); do \
258 /*) dir=$$sysdir ;; \
259 *) dir="\$$(..)$$sysdir" ;; \
261 for o in $(all-object-suffixes); do \
262 $(open-check-inhibit-asm) \
263 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
264 \$$(compile-command.S)"; \
265 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
266 \$$(compile-command.s)"; \
267 $(close-check-inhibit-asm) \
268 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
269 \$$(compile-command.c)"; \
271 $(open-check-inhibit-asm) \
272 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
273 \$$(make-dummy-dep)"; \
274 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
276 $(close-check-inhibit-asm) \
277 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
280 echo 'sysd-rules-done = t') > $@T
283 ifndef sysd-rules-done
284 # Don't do deps until this exists, because it provides rules to make the deps.
289 ifndef compile-command.S
290 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
292 ifndef compile-command.s
293 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
295 ifndef compile-command.c
296 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
299 # GCC can grok options after the file name, and it looks nicer that way.
300 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
302 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
304 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
305 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
307 # We need this for the output to go in the right place. It will default to
308 # empty if make was configured to work with a cc that can't grok -c and -o
309 # together. You can't compile the C library with such a compiler.
310 OUTPUT_OPTION = -o $@
312 S-CPPFLAGS = $(asm-CPPFLAGS)
314 $(make-target-directory)
316 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
318 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
319 $(sed-remove-objpfx) > $(@:.d=.T)
323 # Continuation lines here are dangerous because they introduce spaces!
324 define sed-remove-objpfx
325 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
326 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
330 # Shared library building.
332 ifeq (yes,$(build-shared))
334 # Reference map file only when versioning is selected and a map file name
336 ifeq ($(versioning),yes)
337 load-map-file = $($(@F:%.so=%)-map)
342 # Pattern rule to build a shared object from an archive of PIC objects.
343 # This must come after the installation rules so Make doesn't try to
344 # build shared libraries in place from the installed *_pic.a files.
345 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
346 # on other shared objects.
347 lib%.so: lib%_pic.a $(+preinit) $(+postinit)
350 ifeq ($(have-no-whole-archive),yes)
351 no-whole-archive = -Wl,--no-whole-archive
356 interp-obj = $(common-objpfx)interp.os
357 $(interp-obj): $(common-objpfx)%.os: $(..)%.c
359 common-generated += interp.os
360 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
362 $(common-objpfx)libc.so: $(interp-obj)
363 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
366 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
367 -B$(csu-objpfx) $(load-map-file:%=-Wl,--version-script=%) \
368 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
369 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
370 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
371 -Wl,--whole-archive \
372 $(filter-out $($(@F:.so=)-map) $(+preinit) $(+postinit),$^) \
373 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
376 # Don't try to use -lc when making libc.so itself.
377 # Also omits crti.o and crtn.o, which we do not want
378 # since we define our own `.init' section specially.
379 LDFLAGS-c.so = -nostdlib -nostartfiles
380 # But we still want to link libc.so against $(gnulib).
381 LDLIBS-c.so = $(gnulib)
382 # Give libc.so an entry point and make it directly runnable itself.
383 LDFLAGS-c.so += -e __libc_main
384 # We have a versioning file for libc.so.
385 libc-map = $(..)libc.map
386 # Pre-link the objects of libc_pic.a so that we can locally resolve
387 # COMMON symbols before we link against ld.so. This is because ld.so
388 # contains some of libc_pic.a already, which will prevent the COMMONs
389 # from being allocated in libc.so, which introduces evil dependencies
390 # between libc.so and ld.so, which can make it impossible to upgrade.
391 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
392 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
393 -Wl,-d -Wl,--whole-archive $^
394 # Use our own special initializer and finalizer files for libc.so.
395 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
396 $(common-objpfx)libc_pic.os \
397 $(elfobjdir)/sofini.os $(elfobjdir)/ld.so \
400 common-generated += libc.so libc_pic.os
401 ifdef libc.so-version
402 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
404 common-generated += libc.so$(libc.so-version)
408 # Some files must not be compiled with the exception handler mechanism
409 # enabled (introduced in gcc-2.8). Use $(no-exceptions) in the
410 # appropriate CFLAGS definition.
411 ifeq ($(have-no-exceptions),yes)
412 no-exceptions = -fno-exceptions
417 # Figure out the source filenames in this directory.
419 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
422 sysdep_routines := $(sysdep_routines)
424 headers := $(headers) $(sysdep_headers)
426 # This is the list of all object files, gotten by
427 # replacing every ".c" in `sources' with a ".o".
428 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
431 # The makefile may define $(extra-libs) with `libfoo libbar'
432 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
434 # extra-lib.mk is included once for each extra lib to define rules
435 # to build it, and to add its objects to the various variables.
436 # During its evaluation, $(lib) is set to the name of the library.
437 extra-libs-left := $(extra-libs)
438 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
441 ifeq ($(build-programs),yes)
442 +depfiles := $(strip $(sources:.c=.d) \
443 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
444 $(addsuffix .d,$(others) $(tests) $(test-srcs)))
446 +depfiles := $(strip $(sources:.c=.d) \
447 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
448 $(addsuffix .d,$(tests) $(test-srcs)))
450 +depfiles := $(addprefix $(objpfx),\
451 $(filter-out $(addsuffix .d,$(omit-deps)),\
456 -include $(+depfiles)
460 # Maximize efficiency by minimizing the number of rules.
461 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
463 # Generic rule for making directories.
465 # mkdir isn't smart enough to strip a trailing /.
468 # Make sure that object files are not removed
469 # when they are intermediates between sources and library members.
470 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
472 # Make sure that the parent library archive is never removed.
473 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
475 # Use the verbose option of ar and tar when not running silently.
476 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
482 ARFLAGS := r$(verbose)
484 # This makes all the object files in the parent library archive.
486 .PHONY: lib libobjs lib-noranlib
487 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
489 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
490 lib%.a: lib%.a($(ar-symtab-name)) ;
492 # For object-suffix $o, the list of objects with that suffix.
493 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
494 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
495 $(elide-routines$o)),\
498 libobjs: $(foreach o,$(object-suffixes),\
499 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
500 $(notdir $(o-objects))))
501 lib-noranlib: libobjs
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),$(objpfx)stamp$o)
508 $(foreach o,$(object-suffixes),$(objpfx)stamp$o):
509 $(make-target-directory)
513 # Define a pattern rule that will match many targets libc.a(foo.%), for
514 # each foo.o in $(objects) (% will just happen always to match `o'). This is
515 # the only way to define a rule that updates many targets at once with one
516 # sequence of commands.
517 define o-iterator-doit
518 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
519 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
522 object-suffixes-left := $(object-suffixes)
523 include $(o-iterator)
525 # The pattern rule tells Make to remake $(objpfx)stamp.% as
526 # the way to update all the foo.% object files in $(objects). Now we
527 # define explicit rules to update each $(objpfx)stamp.SUFFIX
528 # timestamp file; these rules (one explicit rule is generated for each
529 # object suffix) will update the parent archive with ar. Use a static
530 # pattern rule so $* is set to the object type during the commands.
531 define o-iterator-doit
532 $(objpfx)stamp$o: $(objpfx)stamp%: $(o-objects); $$(do-ar)
534 object-suffixes-left := $(object-suffixes)
535 include $(o-iterator)
537 topdir=`cd $(..).; pwd`; \
538 $(patsubst %/,cd %;,$(objpfx)) \
539 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
540 $(patsubst $(objpfx)%,%,$^)
544 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
548 # Rules to update the $(ar-symtab-name) member with ranlib,
549 # one for each object flavor.
550 define o-iterator-doit
551 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
552 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
553 $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
554 $(SHELL) $$(..)./autolock.sh \
555 $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
556 $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
559 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
560 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
561 $(subdirs-stamps): subdir_lib;
563 object-suffixes-left = $(object-suffixes)
564 include $(o-iterator)
567 # This makes all the object files.
569 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
570 $(addprefix $(objpfx),$(extra-objs))
572 # Canned sequence for building an extra library archive.
573 define build-extra-lib
574 $(patsubst %/,cd %;,$(objpfx)) \
575 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
576 $(patsubst $(objpfx)%,%,$^)
582 # $(install-lib) are installed from the object directory into $(libdir);
583 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
584 # unless they also appear in $(non-lib.a). $(install-data) are installed
585 # as they are into $(datadir). $(headers) are installed as they are in
586 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
587 # object directory into $(bindir) and $(sbindir), respectively.
588 # $(install-others) are absolute path names of files to install; rules to
589 # install them are defined elsewhere.
591 # The simple library name to install libc.a under.
592 # This could be defined by a sysdep Makefile.
598 $(make-target-directory)
599 $(INSTALL_DATA) $< $@
602 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
603 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
604 define make-target-directory
605 $(addprefix $(..)./mkinstalldirs ,\
606 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
609 # Any directory (parent or subdir) that has any object files to build
610 # should install libc.a; this way "make install" in a subdir is guaranteed
611 # to install everything it changes.
613 installed-libcs := $(foreach o,$(object-suffixes),\
614 $(inst_libdir)/$(patsubst %,$(libtype$o),\
615 $(libprefix)$(libc-name)))
616 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
617 install: $(installed-libcs)
618 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib
619 $(make-target-directory)
620 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
621 # Running ranlib after installing makes the __.SYMDEF time stamp up to
622 # date, which avoids messages from some linkers.
626 define do-install-program
627 $(make-target-directory)
628 $(INSTALL_PROGRAM) $< $@.new
632 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
633 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
634 ifeq (yes,$(build-shared))
636 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
638 # Find which .so's have versions.
639 versioned := $(strip $(foreach so,$(install-lib.so),\
640 $(patsubst %,$(so),$($(so)-version))))
642 # Install all the unversioned shared libraries.
643 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
644 $(inst_slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
646 ifneq ($(findstring -s,$(LN_S)),)
649 $(SHELL) $(..)rellns-sh $< $@.new
653 # If we have no symbolic links don't bother with rellns-sh.
661 # XXX The following will have to be changed when `ldconfig' is available.
662 ifneq (yes,$(cross-compiling))
663 ifeq (yes,$(has-ldconfig))
664 define make-shlib-link
669 ifndef make-shlib-link
670 define make-shlib-link
675 ifdef libc.so-version
676 # For a library specified to be version N, install three files:
677 # libc.so -> libc.so.N (e.g. libc.so.6)
678 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
680 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so
682 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so
683 $(do-install-program)
684 install: $(inst_slibdir)/libc.so$(libc.so-version)
687 # What we install as libc.so for programs to link against is in fact a
688 # link script. It contains references for the various libraries we need.
689 # The libc.so object is not complete since some functions are only defined
690 # in libc.a and the dynamic linker is an extra object.
691 install: $(inst_libdir)/libc.so
692 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
693 $(elfobjdir)/$(rtld-installed-name) \
694 $(inst_libdir)/lib$(libc-name).a
695 (echo '/* GNU ld script';\
696 echo ' Use the shared library, but some functions are only in';\
697 echo ' the static library, so try that secondarily.'; \
698 echo ' The dynamic linker defines some functions used by $(<F),';\
699 echo ' but ld uses definitions from libc.a before examining the';\
700 echo ' dependencies of $(<F) to find $(rtld-installed-name). */';\
701 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
702 '$(slibdir)/$(rtld-installed-name)' \
703 '$(libdir)/lib$(libc-name).a )' \
710 install: $(inst_slibdir)/libc.so
711 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so
712 $(do-install-program)
715 ifneq (,$(versioned))
716 # Produce three sets of rules as above for all the smaller versioned libraries.
718 define o-iterator-doit
719 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version); $$(make-link)
721 object-suffixes-left := $(versioned)
722 include $(o-iterator)
724 # Make symlinks in the build directory, because the versioned names might
725 # be referenced by a DT_NEEDED in another library.
726 define o-iterator-doit
727 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
729 object-suffixes-left := $(versioned)
730 include $(o-iterator)
732 generated += $(foreach o,$(versioned),$o$($o-version))
734 ifeq (,$($(subdir)-version))
735 define o-iterator-doit
736 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so;
739 object-suffixes-left := $(versioned)
740 include $(o-iterator)
742 define o-iterator-doit
743 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
745 object-suffixes-left := $(versioned)
746 include $(o-iterator)
748 define o-iterator-doit
749 $(inst_slibdir)/$o$($o-version): \
750 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so;
753 object-suffixes-left := $(versioned)
754 include $(o-iterator)
756 define o-iterator-doit
757 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
758 $$(do-install-program)
760 object-suffixes-left := $(versioned)
761 include $(o-iterator)
766 $(do-install-program)
767 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
768 $(filter-out %.so,$@))
771 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
772 $(foreach v,$(so-versions),\
773 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
775 $(foreach v,$(so-versions),\
776 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
781 $(addprefix $(inst_bindir)/,$(install-bin)): $(inst_bindir)/%: $(objpfx)%
782 $(do-install-program)
784 ifdef install-rootsbin
785 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)):
786 $(inst_rootsbindir)/%: $(objpfx)%
787 $(do-install-program)
790 $(addprefix $(inst_sbindir)/,$(install-sbin)): $(inst_sbindir)/%: $(objpfx)%
791 $(do-install-program)
794 install-lib.a := $(filter lib%.a,$(install-lib))
795 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
796 ifdef install-lib-non.a
797 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
798 $(inst_libdir)/$(libprefix)%: $(objpfx)%
802 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
803 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
805 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
809 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: %;
812 headers := $(strip $(headers))
814 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: %;
818 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
819 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
820 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
821 install-rootsbin-nosubdir: \
822 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
823 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
824 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
825 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
826 $(addprefix $(libprefix),$(install-lib-non.a)))
827 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
828 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
829 install-others-nosubdir: $(install-others)
831 # We need all the `-nosubdir' targets so that `install' in the parent
832 # doesn't depend on several things which each iterate over the subdirs.
833 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
834 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
835 install-%:: install-%-nosubdir ;
837 .PHONY: install install-no-libc.a-nosubdir
838 ifeq ($(build-programs),yes)
839 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
840 install-bin-nosubdir install-lib-nosubdir \
841 install-others-nosubdir install-rootsbin-nosubdir \
842 install-sbin-nosubdir
844 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
845 install-lib-nosubdir install-others-nosubdir
847 install: install-no-libc.a-nosubdir
849 # Command to compile $< in $(objdir) using the native libraries.
850 define native-compile
851 $(make-target-directory)
852 $(patsubst %/,cd %;,$(objpfx)) \
853 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
854 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
857 # Command to compile $< in $(common-objdir) using the native libraries.
858 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
859 define common-objdir-compile
860 $(patsubst %/,cd %;,$(objpfx)) \
861 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
862 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
865 # We always want to use configuration definitions.
866 # Note that this is only used for commands running in $(objpfx).
867 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
869 # Support the GNU standard name for this target.
874 TAGS: $(objpfx)distinfo $(..)MakeTAGS
875 $(MAKE) $(addprefix -f ,$^) $@
877 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
878 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
887 # Common cleaning targets.
889 .PHONY: common-mostlyclean common-clean mostlyclean clean
891 mostlyclean: common-mostlyclean
893 # Remove the object files.
895 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
896 $(addsuffix .o,$(tests) $(test-srcs) \
898 $(addsuffix .out,$(tests) $(test-srcs)))
899 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
901 $(install-lib.so:%.so=%_pic.a))
902 -rm -f core $(common-objpfx)stub-$(subdir)
905 $(foreach o,$(object-suffixes),
906 -rm -f $(objpfx)stamp$o $(o-objects))
909 # Also remove the dependencies and generated source files.
910 common-clean: common-mostlyclean
911 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
912 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
913 -rm -f $(addprefix $(common-objpfx),$(common-generated))
914 -rm -f $(objpfx)distinfo
916 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
917 # for each function which is a stub. We grovel over all the .d files
918 # looking for references to <stub-tag.h>. Then we grovel over each
919 # referenced source file to see what stub function it defines.
921 .PHONY: stubs # The parent Makefile calls this target.
922 stubs: $(common-objpfx)stub-$(subdir)
923 s = $(sysdep_dir)/generic
924 $(common-objpfx)stub-$(subdir): $(+depfiles)
925 # Use /dev/null since `...` might expand to empty.
926 (s=`cd $s; /bin/pwd`; \
927 $(patsubst %/,cd %;,$(objpfx)) \
928 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
929 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
930 -e '/stub-tag\.h/{; g; p; }' \
931 $(patsubst $(objpfx)%,%,$^) /dev/null` \
935 # Make the distribution tar file.
938 dist: $(objpfx)distinfo $(..)Make-dist
939 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
941 # Avoid depending on source files found in sysdeps dirs,
942 # because the references affect implicit rule selection.
943 dist: $(filter-out %.c %.S %.s,$(distribute))
945 # We used to simply export all these variables, but that frequently made the
946 # environment get too large. Instead, we write all the information into
947 # a generated makefile fragment `distinfo', and then include it with -f in
948 # the sub-make that makes the distribution (above).
949 $(objpfx)distinfo: Makefile $(..)Makerules \
950 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
951 $(make-target-directory)
954 .PHONY: subdir_distinfo
955 subdir_distinfo: $(objpfx)distinfo
959 echo > $@.new 'subdir := $(subdir)'
960 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
961 headers sysdep_headers distribute dont_distribute generated \
962 others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
963 $(extra-libs:%=%-map) versioned \
964 $(addprefix install-,lib lib.so data bin sbin others),
965 echo >> $@.new '$(subdir)-$(var) := $($(var))'
966 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
969 ifneq (,$(strip $(gpl2lgpl)))
970 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
971 # Snarf from the master source and frob the copying notice.
972 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
974 # So I don't edit them by mistake.
977 ifeq ($(with-cvs),yes)
978 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@