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 object-suffixes-for-rules = $(object-suffixes) .oS
177 # It matters that this set of rules, for compiling from sources in
178 # the current directory (the $srcdir/$subdir) come before the
179 # generated sysdep rules in included from sysd-rules below. When
180 # compiling in the source tree, generated sources go into the current
181 # directory, and those should be chosen before any sources in sysdeps.
182 define o-iterator-doit
183 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
185 object-suffixes-left := $(object-suffixes-for-rules)
186 include $(o-iterator)
187 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
189 define o-iterator-doit
190 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
192 object-suffixes-left := $(object-suffixes-for-rules)
193 include $(o-iterator)
194 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
196 define o-iterator-doit
197 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
199 object-suffixes-left := $(object-suffixes-for-rules)
200 include $(o-iterator)
201 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
203 # Omit the objpfx rules when building in the source tree, because
204 # objpfx is empty and so these rules just override the ones above.
206 # Define first rules to find the source files in $(objpfx).
207 # Generated source files will end up there.
208 define o-iterator-doit
209 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
211 object-suffixes-left := $(object-suffixes-for-rules)
212 include $(o-iterator)
213 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
215 define o-iterator-doit
216 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
218 object-suffixes-left := $(object-suffixes-for-rules)
219 include $(o-iterator)
220 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
222 define o-iterator-doit
223 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
225 object-suffixes-left := $(object-suffixes-for-rules)
226 include $(o-iterator)
227 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
230 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
231 # patterns matching sysdep directories whose assembly source files should
233 ifdef inhibit-sysdep-asm
234 define open-check-inhibit-asm
235 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
237 close-check-inhibit-asm = ;; esac ;
240 # Don't include sysd-rules until sysd-Makefile is already there and has been
241 # included. It might define inhibit-sysdep-asm, which would affect the
242 # contents of sysd-rules.
243 ifdef sysd-Makefile-done
244 -include $(+sysdir_pfx)sysd-rules
245 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
246 # The value of $(+sysdep_dirs) the sysd-rules was computed for
247 # differs from the one we are using now. So force a rebuild of sysd-rules.
248 sysd-rules-force = FORCE
252 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
253 $(wildcard $(foreach dir,$(sysdirs),\
257 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
258 for sysdir in $(config-sysdirs); do \
260 /*) dir=$$sysdir ;; \
261 *) dir="\$$(..)$$sysdir" ;; \
263 for o in $(all-object-suffixes); do \
264 $(open-check-inhibit-asm) \
265 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
266 \$$(compile-command.S)"; \
267 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
268 \$$(compile-command.s)"; \
269 $(close-check-inhibit-asm) \
270 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
271 \$$(compile-command.c)"; \
273 $(open-check-inhibit-asm) \
274 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
275 \$$(make-dummy-dep)"; \
276 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
278 $(close-check-inhibit-asm) \
279 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
282 echo 'sysd-rules-done = t') > $@T
285 ifndef sysd-rules-done
286 # Don't do deps until this exists, because it provides rules to make the deps.
291 ifndef compile-command.S
292 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
294 ifndef compile-command.s
295 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
297 ifndef compile-command.c
298 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
301 # GCC can grok options after the file name, and it looks nicer that way.
302 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
304 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
306 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
307 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
309 # We need this for the output to go in the right place. It will default to
310 # empty if make was configured to work with a cc that can't grok -c and -o
311 # together. You can't compile the C library with such a compiler.
312 OUTPUT_OPTION = -o $@
314 S-CPPFLAGS = $(asm-CPPFLAGS)
316 $(make-target-directory)
318 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
320 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
321 $(sed-remove-objpfx) > $(@:.d=.T)
325 # Continuation lines here are dangerous because they introduce spaces!
326 define sed-remove-objpfx
327 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
328 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
332 # Shared library building.
334 ifeq (yes,$(build-shared))
336 # Reference map file only when versioning is selected and a map file name
338 ifeq ($(versioning),yes)
339 load-map-file = $($(@F:%.so=%)-map)
344 # Pattern rule to build a shared object from an archive of PIC objects.
345 # This must come after the installation rules so Make doesn't try to
346 # build shared libraries in place from the installed *_pic.a files.
347 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
348 # on other shared objects.
349 lib%.so: lib%_pic.a $(+preinit) $(+postinit)
352 ifeq ($(have-no-whole-archive),yes)
353 no-whole-archive = -Wl,--no-whole-archive
358 interp-obj = $(common-objpfx)interp.os
359 $(interp-obj): $(common-objpfx)%.os: $(..)%.c
361 common-generated += interp.os
362 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
364 $(common-objpfx)libc.so: $(interp-obj)
365 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
368 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
369 -B$(csu-objpfx) $(load-map-file:%=-Wl,--version-script=%) \
370 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
371 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
372 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
373 -Wl,--whole-archive \
374 $(filter-out $($(@F:.so=)-map) $(+preinit) $(+postinit),$^) \
375 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
378 # Don't try to use -lc when making libc.so itself.
379 # Also omits crti.o and crtn.o, which we do not want
380 # since we define our own `.init' section specially.
381 LDFLAGS-c.so = -nostdlib -nostartfiles
382 # But we still want to link libc.so against $(gnulib).
383 LDLIBS-c.so = $(gnulib)
384 # Give libc.so an entry point and make it directly runnable itself.
385 LDFLAGS-c.so += -e __libc_main
386 # We have a versioning file for libc.so.
387 libc-map = $(..)libc.map
388 # Pre-link the objects of libc_pic.a so that we can locally resolve
389 # COMMON symbols before we link against ld.so. This is because ld.so
390 # contains some of libc_pic.a already, which will prevent the COMMONs
391 # from being allocated in libc.so, which introduces evil dependencies
392 # between libc.so and ld.so, which can make it impossible to upgrade.
393 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
394 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
395 -Wl,-d -Wl,--whole-archive $^
396 # Use our own special initializer and finalizer files for libc.so.
397 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
398 $(common-objpfx)libc_pic.os \
399 $(elfobjdir)/sofini.os $(elfobjdir)/ld.so \
402 common-generated += libc.so libc_pic.os
403 ifdef libc.so-version
404 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
406 common-generated += libc.so$(libc.so-version)
410 # Some files must not be compiled with the exception handler mechanism
411 # enabled (introduced in gcc-2.8). Use $(no-exceptions) in the
412 # appropriate CFLAGS definition.
413 ifeq ($(have-no-exceptions),yes)
414 no-exceptions = -fno-exceptions
419 # Figure out the source filenames in this directory.
421 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
424 sysdep_routines := $(sysdep_routines)
426 headers := $(headers) $(sysdep_headers)
428 # This is the list of all object files, gotten by
429 # replacing every ".c" in `sources' with a ".o".
430 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
433 # The makefile may define $(extra-libs) with `libfoo libbar'
434 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
436 # extra-lib.mk is included once for each extra lib to define rules
437 # to build it, and to add its objects to the various variables.
438 # During its evaluation, $(lib) is set to the name of the library.
439 extra-libs-left := $(extra-libs)
440 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
443 ifeq ($(build-programs),yes)
444 +depfiles := $(strip $(sources:.c=.d) \
445 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
446 $(addsuffix .d,$(others) $(tests) $(test-srcs)))
448 +depfiles := $(strip $(sources:.c=.d) \
449 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
450 $(addsuffix .d,$(tests) $(test-srcs)))
452 +depfiles := $(addprefix $(objpfx),\
453 $(filter-out $(addsuffix .d,$(omit-deps)),\
458 -include $(+depfiles)
462 # Maximize efficiency by minimizing the number of rules.
463 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
464 # Don't define any builtin rules.
465 MAKEFLAGS := $(MAKEFLAGS)r
467 # Generic rule for making directories.
469 # mkdir isn't smart enough to strip a trailing /.
472 # Make sure that object files are not removed
473 # when they are intermediates between sources and library members.
474 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
476 # Make sure that the parent library archive is never removed.
477 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
479 # Use the verbose option of ar and tar when not running silently.
480 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
486 ARFLAGS := r$(verbose)
487 ifeq ($(have-ar-S),yes)
488 CREATE_ARFLAGS := Scru$(verbose)
490 CREATE_ARFLAGS := cru$(verbose)
493 # This makes all the object files in the parent library archive.
495 .PHONY: lib libobjs lib-noranlib
496 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
498 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
499 lib%.a: lib%.a($(ar-symtab-name)) ;
501 # For object-suffix $o, the list of objects with that suffix.
502 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
503 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
504 $(elide-routines$o)),\
507 libobjs: $(foreach o,$(object-suffixes),\
508 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
509 $(notdir $(o-objects))))
510 lib-noranlib: libobjs
511 others: $(addprefix $(objpfx),$(install-lib))
515 # Create the stamp$o files to keep the parent makefile happy.
516 subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o)
517 $(foreach o,$(object-suffixes),$(objpfx)stamp$o):
518 $(make-target-directory)
522 # Define a pattern rule that will match many targets libc.a(foo.%), for
523 # each foo.o in $(objects) (% will just happen always to match `o'). This is
524 # the only way to define a rule that updates many targets at once with one
525 # sequence of commands.
526 define o-iterator-doit
527 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
528 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
531 object-suffixes-left := $(object-suffixes)
532 include $(o-iterator)
534 # The pattern rule tells Make to remake $(objpfx)stamp.% as
535 # the way to update all the foo.% object files in $(objects). Now we
536 # define explicit rules to update each $(objpfx)stamp.SUFFIX
537 # timestamp file; these rules (one explicit rule is generated for each
538 # object suffix) will update the parent archive with ar. Use a static
539 # pattern rule so $* is set to the object type during the commands.
540 define o-iterator-doit
541 $(objpfx)stamp$o: $(objpfx)stamp%: $(o-objects); $$(do-ar)
543 object-suffixes-left := $(object-suffixes)
544 include $(o-iterator)
546 topdir=`cd $(..).; pwd`; \
547 $(patsubst %/,cd %;,$(objpfx)) \
548 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) $(CREATE_ARFLAGS) ${O%-lib} \
549 $(patsubst $(objpfx)%,%,$^)
553 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
557 # Rules to update the $(ar-symtab-name) member with ranlib,
558 # one for each object flavor.
559 define o-iterator-doit
560 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
561 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
562 $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
563 $(SHELL) $$(..)./autolock.sh \
564 $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
565 $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
568 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
569 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
570 $(subdirs-stamps): subdir_lib;
572 object-suffixes-left = $(object-suffixes)
573 include $(o-iterator)
576 # This makes all the object files.
578 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
579 $(addprefix $(objpfx),$(extra-objs))
581 # Canned sequence for building an extra library archive.
582 define build-extra-lib
583 $(patsubst %/,cd %;,$(objpfx)) \
584 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
585 $(patsubst $(objpfx)%,%,$^)
591 # $(install-lib) are installed from the object directory into $(libdir);
592 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
593 # unless they also appear in $(non-lib.a). $(install-data) are installed
594 # as they are into $(datadir). $(headers) are installed as they are in
595 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
596 # object directory into $(bindir) and $(sbindir), respectively.
597 # $(install-others) are absolute path names of files to install; rules to
598 # install them are defined elsewhere.
600 # The simple library name to install libc.a under.
601 # This could be defined by a sysdep Makefile.
607 $(make-target-directory)
608 $(INSTALL_DATA) $< $@
611 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
612 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
613 define make-target-directory
614 $(addprefix $(..)./mkinstalldirs ,\
615 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
618 # Any directory (parent or subdir) that has any object files to build
619 # should install libc.a; this way "make install" in a subdir is guaranteed
620 # to install everything it changes.
622 installed-libcs := $(foreach o,$(object-suffixes),\
623 $(inst_libdir)/$(patsubst %,$(libtype$o),\
624 $(libprefix)$(libc-name)))
625 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
626 ifdef libc.so-version
627 installed-libcs += $(inst_libdir)/$(patsubst %,$(libtype.oS),\
628 $(libprefix)$(libc-name))
630 install: $(installed-libcs)
631 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib
632 $(make-target-directory)
633 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
634 # Running ranlib after installing makes the __.SYMDEF time stamp up to
635 # date, which avoids messages from some linkers.
639 define do-install-program
640 $(make-target-directory)
641 $(INSTALL_PROGRAM) $< $@.new
645 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
646 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
647 ifeq (yes,$(build-shared))
649 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
651 # Find which .so's have versions.
652 versioned := $(strip $(foreach so,$(install-lib.so),\
653 $(patsubst %,$(so),$($(so)-version))))
655 # Install all the unversioned shared libraries.
656 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
657 $(inst_slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
659 ifneq ($(findstring -s,$(LN_S)),)
662 $(SHELL) $(..)rellns-sh $< $@.new
666 # If we have no symbolic links don't bother with rellns-sh.
674 # XXX The following will have to be changed when `ldconfig' is available.
675 ifneq (yes,$(cross-compiling))
676 ifeq (yes,$(has-ldconfig))
677 define make-shlib-link
682 ifndef make-shlib-link
683 define make-shlib-link
688 ifdef libc.so-version
689 # For a library specified to be version N, install three files:
690 # libc.so -> libc.so.N (e.g. libc.so.6)
691 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
693 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so
695 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so
696 $(do-install-program)
697 install: $(inst_slibdir)/libc.so$(libc.so-version)
700 # What we install as libc.so for programs to link against is in fact a
701 # link script. It contains references for the various libraries we need.
702 # The libc.so object is not complete since some functions are only defined
703 # in libc.a and the dynamic linker is an extra object.
704 install: $(inst_libdir)/libc.so
705 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
706 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
707 $(libprefix)$(libc-name))
708 (echo '/* GNU ld script';\
709 echo ' Use the shared library, but some functions are only in';\
710 echo ' the static library, so try that secondarily. */';\
711 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
712 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
720 install: $(inst_slibdir)/libc.so
721 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so
722 $(do-install-program)
725 ifneq (,$(versioned))
726 # Produce three sets of rules as above for all the smaller versioned libraries.
728 define o-iterator-doit
729 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version); $$(make-link)
731 object-suffixes-left := $(versioned)
732 include $(o-iterator)
734 # Make symlinks in the build directory, because the versioned names might
735 # be referenced by a DT_NEEDED in another library.
736 define o-iterator-doit
737 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
739 object-suffixes-left := $(versioned)
740 include $(o-iterator)
742 generated += $(foreach o,$(versioned),$o$($o-version))
744 ifeq (,$($(subdir)-version))
745 define o-iterator-doit
746 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so;
749 object-suffixes-left := $(versioned)
750 include $(o-iterator)
752 define o-iterator-doit
753 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
755 object-suffixes-left := $(versioned)
756 include $(o-iterator)
758 define o-iterator-doit
759 $(inst_slibdir)/$o$($o-version): \
760 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so;
763 object-suffixes-left := $(versioned)
764 include $(o-iterator)
766 define o-iterator-doit
767 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
768 $$(do-install-program)
770 object-suffixes-left := $(versioned)
771 include $(o-iterator)
776 $(do-install-program)
777 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
778 $(filter-out %.so,$@))
781 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
782 $(foreach v,$(so-versions),\
783 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
785 $(foreach v,$(so-versions),\
786 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
791 $(addprefix $(inst_bindir)/,$(install-bin)): $(inst_bindir)/%: $(objpfx)%
792 $(do-install-program)
794 ifdef install-rootsbin
795 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)):
796 $(inst_rootsbindir)/%: $(objpfx)%
797 $(do-install-program)
800 $(addprefix $(inst_sbindir)/,$(install-sbin)): $(inst_sbindir)/%: $(objpfx)%
801 $(do-install-program)
804 install-lib.a := $(filter lib%.a,$(install-lib))
805 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
806 ifdef install-lib-non.a
807 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
808 $(inst_libdir)/$(libprefix)%: $(objpfx)%
812 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
813 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
815 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
819 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: %;
822 headers := $(strip $(headers))
824 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: %;
828 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
829 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
830 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
831 install-rootsbin-nosubdir: \
832 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
833 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
834 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
835 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
836 $(addprefix $(libprefix),$(install-lib-non.a)))
837 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
838 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
839 install-others-nosubdir: $(install-others)
841 # We need all the `-nosubdir' targets so that `install' in the parent
842 # doesn't depend on several things which each iterate over the subdirs.
843 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
844 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
845 install-%:: install-%-nosubdir ;
847 .PHONY: install install-no-libc.a-nosubdir
848 ifeq ($(build-programs),yes)
849 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
850 install-bin-nosubdir install-lib-nosubdir \
851 install-others-nosubdir install-rootsbin-nosubdir \
852 install-sbin-nosubdir
854 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
855 install-lib-nosubdir install-others-nosubdir
857 install: install-no-libc.a-nosubdir
859 # Command to compile $< in $(objdir) using the native libraries.
860 define native-compile
861 $(make-target-directory)
862 $(patsubst %/,cd %;,$(objpfx)) \
863 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
864 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
867 # Command to compile $< in $(common-objdir) using the native libraries.
868 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
869 define common-objdir-compile
870 $(patsubst %/,cd %;,$(objpfx)) \
871 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
872 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
875 # We always want to use configuration definitions.
876 # Note that this is only used for commands running in $(objpfx).
877 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
879 # Support the GNU standard name for this target.
884 TAGS: $(objpfx)distinfo $(..)MakeTAGS
885 $(MAKE) $(addprefix -f ,$^) $@
887 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
888 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
897 # Common cleaning targets.
899 .PHONY: common-mostlyclean common-clean mostlyclean clean
901 mostlyclean: common-mostlyclean
903 # Remove the object files.
905 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
906 $(addsuffix .o,$(tests) $(test-srcs) \
908 $(addsuffix .out,$(tests) $(test-srcs)))
909 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
911 $(install-lib.so:%.so=%_pic.a))
912 -rm -f core $(common-objpfx)stub-$(subdir)
915 $(foreach o,$(object-suffixes),
916 -rm -f $(objpfx)stamp$o $(o-objects))
917 -rm -f $(objpfx)stamp.oS $(patsubst %,$(static-only-routines),$(objpfx)%.oS)
920 # Also remove the dependencies and generated source files.
921 common-clean: common-mostlyclean
922 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
923 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
924 -rm -f $(addprefix $(common-objpfx),$(common-generated))
925 -rm -f $(objpfx)distinfo
927 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
928 # for each function which is a stub. We grovel over all the .d files
929 # looking for references to <stub-tag.h>. Then we grovel over each
930 # referenced source file to see what stub function it defines.
932 .PHONY: stubs # The parent Makefile calls this target.
933 stubs: $(common-objpfx)stub-$(subdir)
934 s = $(sysdep_dir)/generic
935 $(common-objpfx)stub-$(subdir): $(+depfiles)
936 # Use /dev/null since `...` might expand to empty.
937 (s=`cd $s; /bin/pwd`; \
938 $(patsubst %/,cd %;,$(objpfx)) \
939 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
940 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
941 -e '/stub-tag\.h/{; g; p; }' \
942 $(patsubst $(objpfx)%,%,$^) /dev/null` \
946 # Make the distribution tar file.
949 dist: $(objpfx)distinfo $(..)Make-dist
950 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
952 # Avoid depending on source files found in sysdeps dirs,
953 # because the references affect implicit rule selection.
954 dist: $(filter-out %.c %.S %.s,$(distribute))
956 # We used to simply export all these variables, but that frequently made the
957 # environment get too large. Instead, we write all the information into
958 # a generated makefile fragment `distinfo', and then include it with -f in
959 # the sub-make that makes the distribution (above).
960 $(objpfx)distinfo: Makefile $(..)Makerules \
961 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
962 $(make-target-directory)
965 .PHONY: subdir_distinfo
966 subdir_distinfo: $(objpfx)distinfo
970 echo > $@.new 'subdir := $(subdir)'
971 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
972 headers sysdep_headers distribute dont_distribute generated \
973 others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
974 $(extra-libs:%=%-map) versioned \
975 $(addprefix install-,lib lib.so data bin sbin others),
976 echo >> $@.new '$(subdir)-$(var) := $($(var))'
977 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
980 ifneq (,$(strip $(gpl2lgpl)))
981 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
982 # Snarf from the master source and frob the copying notice.
983 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
985 # So I don't edit them by mistake.
988 ifeq ($(with-cvs),yes)
989 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@