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 # Include any system-specific makefiles.
86 # This is here so things in sysdep Makefiles can easily depend on foo.h as
87 # appropriate and not worry about where foo.h comes from, which may be
88 # system dependent and not known by that Makefile.
89 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
90 $(+sysdep_dirs) $(..)))
92 # Some sysdep makefiles use this to distinguish being included here from
93 # being included individually by a subdir makefile (hurd/Makefile needs this).
96 ifndef avoid-generated
97 -include $(+sysdir_pfx)sysd-Makefile
98 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
99 sysd-Makefile-force = FORCE
102 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
103 $(sysd-Makefile-force)
105 (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)'; \
106 for dir in $(config-sysdirs); do \
107 file=$$dir/Makefile; \
112 if [ -f $$rel$$file ]; then \
114 /*) echo include "$$file" ;; \
115 *) echo include "\$$(..)$$file" ;; \
119 echo 'sysd-Makefile-done=t') > $@T
123 ifndef sysd-Makefile-done
124 # Don't do deps until this exists, because it might change the sources list.
129 # Reorder before-compile so that mach things come first, and hurd things
130 # second, before all else. The mach and hurd subdirectories have many
131 # generated header files which the much of rest of the library depends on,
132 # so it is best to build them first (and mach before hurd, at that).
133 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
135 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
138 # Remove existing files from `before-compile'. Things are added there when
139 # they must exist for dependency generation to work right, but once they
140 # exist there is no further need for every single file to depend on them,
141 # and those gratuitous dependencies result in many gratuitous
143 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
145 # Don't let any before-compile file be an intermediate and get removed.
150 # Generate an ordered list of implicit rules which find the source files in
151 # each sysdep directory. The old method was to use vpath to search all the
152 # sysdep directories. However, that had the problem that a .S file in a
153 # later directory would be chosen over a .c file in an earlier directory,
154 # which does not preserve the desired sysdeps ordering behavior.
156 # When making the list of .d files to include, we can't know which ones
157 # have source in .s files, and thus do not in fact need a .d file.
158 # So we must define rules to make .d files for .s files.
159 define make-dummy-dep
160 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
162 $(common-objpfx)dummy.d:
163 echo '# .s files cannot contain includes, so they need no deps.' > $@
165 # It matters that this set of rules, for compiling from sources in
166 # the current directory (the $srcdir/$subdir) come before the
167 # generated sysdep rules in included from sysd-rules below. When
168 # compiling in the source tree, generated sources go into the current
169 # directory, and those should be chosen before any sources in sysdeps.
170 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
171 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
172 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
173 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
174 $(objpfx)%.So: %.S $(before-compile); $(compile-command.S)
175 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
176 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
177 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
178 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
179 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
180 $(objpfx)%.So: %.s $(before-compile); $(compile-command.s)
181 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
182 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
183 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
184 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
185 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
186 $(objpfx)%.So: %.c $(before-compile); $(compile-command.c)
187 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
189 # Omit the objpfx rules when building in the source tree, because
190 # objpfx is empty and so these rules just override the ones above.
192 # Define first rules to find the source files in $(objpfx).
193 # Generated source files will end up there.
194 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
195 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
196 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
197 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
198 $(objpfx)%.So: $(objpfx)%.S $(before-compile); $(compile-command.S)
199 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
200 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
201 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
202 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
203 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
204 $(objpfx)%.So: $(objpfx)%.s $(before-compile); $(compile-command.s)
205 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
206 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
207 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
208 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
209 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
210 $(objpfx)%.So: $(objpfx)%.c $(before-compile); $(compile-command.c)
211 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
214 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
215 # patterns matching sysdep directories whose assembly source files should
217 ifdef inhibit-sysdep-asm
218 define open-check-inhibit-asm
219 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
221 close-check-inhibit-asm = ;; esac ;
224 # Don't include sysd-rules until sysd-Makefile is already there and has been
225 # included. It might define inhibit-sysdep-asm, which would affect the
226 # contents of sysd-rules.
227 ifdef sysd-Makefile-done
228 -include $(+sysdir_pfx)sysd-rules
229 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
230 # The value of $(+sysdep_dirs) the sysd-rules was computed for
231 # differs from the one we are using now. So force a rebuild of sysd-rules.
232 sysd-rules-force = FORCE
236 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
237 $(wildcard $(foreach dir,$(sysdirs),\
241 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
242 for sysdir in $(config-sysdirs); do \
244 /*) dir=$$sysdir ;; \
245 *) dir="\$$(..)$$sysdir" ;; \
247 for o in $(all-object-suffixes); do \
248 $(open-check-inhibit-asm) \
249 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
250 \$$(compile-command.S)"; \
251 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
252 \$$(compile-command.s)"; \
253 $(close-check-inhibit-asm) \
254 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
255 \$$(compile-command.c)"; \
257 $(open-check-inhibit-asm) \
258 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
259 \$$(make-dummy-dep)"; \
260 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
262 $(close-check-inhibit-asm) \
263 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
266 echo 'sysd-rules-done = t') > $@T
269 ifndef sysd-rules-done
270 # Don't do deps until this exists, because it provides rules to make the deps.
275 ifndef compile-command.S
276 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
278 ifndef compile-command.s
279 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
281 ifndef compile-command.c
282 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
285 # GCC can grok options after the file name, and it looks nicer that way.
286 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
287 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
288 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
289 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS) $(ASFLAGS-$(suffix $@))
291 # We need this for the output to go in the right place. It will default to
292 # empty if make was configured to work with a cc that can't grok -c and -o
293 # together. You can't compile the C library with such a compiler.
294 OUTPUT_OPTION = -o $@
296 S-CPPFLAGS = $(asm-CPPFLAGS)
298 $(make-target-directory)
300 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
302 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
303 $(sed-remove-objpfx) > $(@:.d=.T)
307 # Continuation lines here are dangerous because they introduce spaces!
308 define sed-remove-objpfx
309 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
310 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
314 # Shared library building.
316 ifeq (yes,$(build-shared))
318 # Pattern rule to build a shared object from an archive of PIC objects.
319 # This must come after the installation rules so Make doesn't try to
320 # build shared libraries in place from the installed *_pic.a files.
321 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
322 # on other shared objects.
323 lib%.so: lib%_pic.a; $(build-shlib)
325 ifeq ($(have-no-whole-archive),yes)
326 no-whole-archive = -Wl,--no-whole-archive
331 interp-obj = $(common-objpfx)interp.so
332 $(interp-obj): $(common-objpfx)%.so: $(..)%.c
334 common-generated += interp.so
335 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
337 $(common-objpfx)libc.so: $(interp-obj)
338 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
341 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
343 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
344 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
345 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
346 -Wl,--whole-archive $^ $(no-whole-archive) \
347 $(LDLIBS-$(@F:lib%.so=%).so)
348 test -z "$($(@F)-version)" || \
349 (rm -f $@$($(@F)-version); $(LN_S) $(@F) $@$($(@F)-version))
352 ifndef libc.so-version
353 # Undefine this because it can't work when we libc.so is unversioned.
354 static-only-routines =
356 elide-routines.So = $(filter-out $(static-only-routines),\
357 $(routines) $(aux) $(sysdep_routines))
359 ifdef static-only-routines
360 # These routines are to be omitted from the shared library object,
361 # so we replace the PIC objects for them with the empty object file.
362 $(static-only-routines:%=$(objpfx)%.so): %.so: $(common-objpfx)empty.o
367 # Don't try to use -lc when making libc.so itself.
368 # Also omits crti.o and crtn.o, which we do not want
369 # since we define our own `.init' section specially.
370 LDFLAGS-c.so = -nostdlib -nostartfiles
371 # But we still want to link libc.so against -lgcc.
373 # Give libc.so an entry point and make it directly runnable itself.
374 LDFLAGS-c.so += -e __libc_main
375 # Use our own special initializer and finalizer files for libc.so.
376 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
377 $(common-objpfx)libc_pic.a \
378 $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
382 # Some files must not be compiled with the exception handler mechanism
383 # enabled (introduced in gcc-2.8). Use $(no-exceptions) in the
384 # appropriate CFLAGS definition.
385 ifeq ($(have-no-exceptions),yes)
386 no-exceptions = -fno-exceptions
391 # Figure out the source filenames in this directory.
393 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
396 sysdep_routines := $(sysdep_routines)
398 headers := $(headers) $(sysdep_headers)
400 # This is the list of all object files, gotten by
401 # replacing every ".c" in `sources' with a ".o".
402 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
405 # This variable is used in ``include $(o-iterator)'' after defining
406 # $(o-iterator-doit) to produce some desired rule using $o for the object
407 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
408 # is produced for each object suffix in use.
409 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
411 # The makefile may define $(extra-libs) with `libfoo libbar'
412 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
414 # extra-lib.mk is included once for each extra lib to define rules
415 # to build it, and to add its objects to the various variables.
416 # During its evaluation, $(lib) is set to the name of the library.
417 extra-libs-left := $(extra-libs)
418 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
421 +depfiles := $(strip $(sources:.c=.d) \
422 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
423 $(addsuffix .d,$(others) $(tests)))
424 +depfiles := $(addprefix $(objpfx),\
425 $(filter-out $(addsuffix .d,$(omit-deps)),\
430 -include $(+depfiles)
434 # Maximize efficiency by minimizing the number of rules.
435 .SUFFIXES: # Clear the suffix list.
436 # Add the suffixes we use.
437 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
439 # Generic rule for making directories.
441 # mkdir isn't smart enough to strip a trailing /.
444 # Make sure that object files are not removed
445 # when they are intermediates between sources and library members.
446 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
448 # Make sure that the parent library archive is never removed.
449 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
451 # Use the verbose option of ar and tar when not running silently.
452 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
458 ARFLAGS := r$(verbose)
460 # This makes all the object files in the parent library archive.
462 .PHONY: lib libobjs lib-noranlib
463 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
465 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
466 lib%.a: lib%.a($(ar-symtab-name)) ;
468 # For object-suffix $o, the list of objects with that suffix.
469 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
470 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
471 $(elide-routines$o)),\
474 libobjs: $(foreach o,$(object-suffixes-for-libc),\
475 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
476 $(notdir $(o-objects))))
477 lib-noranlib: libobjs
478 others: $(addprefix $(objpfx),$(install-lib))
482 # Create the stamp$o files to keep the parent makefile happy.
483 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o-$(subdir))
484 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o-$(subdir)):
485 $(make-target-directory)
489 # Define a pattern rule that will match many targets libc.a(foo.%), for
490 # each foo.o in $(objects) (% will just happen always to match `o'). This is
491 # the only way to define a rule that updates many targets at once with one
492 # sequence of commands.
493 define o-iterator-doit
494 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
495 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
496 $(objpfx)stamp.%-$(subdir) ;
498 object-suffixes-left := $(object-suffixes-for-libc)
499 include $(o-iterator)
501 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
502 # the way to update all the foo.% object files in $(objects). Now we
503 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
504 # timestamp file; these rules (one explicit rule is generated for each
505 # object suffix) will update the parent archive with ar. Use a static
506 # pattern rule so $* is set to the object type during the commands.
507 define o-iterator-doit
508 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
510 ifdef static-only-routines
511 object-suffixes-left := $(object-suffixes-for-libc)
513 object-suffixes-left := $(object-suffixes)
515 include $(o-iterator)
517 topdir=`cd $(..).; pwd`; \
518 $(patsubst %/,cd %;,$(objpfx)) \
519 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
520 $(patsubst $(objpfx)%,%,$^)
524 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
528 # Rules to update the $(ar-symtab-name) member with ranlib,
529 # one for each object flavor.
530 define o-iterator-doit
531 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
532 $(filter-out $(common-objpfx)$(patsubst %,$(libtype$o),c)(),\
533 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
534 $(patsubst $(objpfx)%,%,$(o-objects)))) $(subdirs-stamp-o); \
535 $(SHELL) $$(..)./autolock.sh \
536 $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
537 $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
540 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
541 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
542 $(subdirs-stamps): subdir_lib;
544 object-suffixes-left = $(object-suffixes-for-libc)
545 include $(o-iterator)
548 # This makes all the object files.
550 objects objs: $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
551 $(addprefix $(objpfx),$(extra-objs))
553 # Canned sequence for building an extra library archive.
554 define build-extra-lib
555 $(patsubst %/,cd %;,$(objpfx)) \
556 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
557 $(patsubst $(objpfx)%,%,$^)
563 # $(install-lib) are installed from the object directory into $(libdir);
564 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
565 # unless they also appear in $(non-lib.a). $(install-data) are installed
566 # as they are into $(datadir). $(headers) are installed as they are in
567 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
568 # object directory into $(bindir) and $(sbindir), respectively.
569 # $(install-others) are absolute path names of files to install; rules to
570 # install them are defined elsewhere.
572 # The simple library name to install libc.a under.
573 # This could be defined by a sysdep Makefile.
579 $(make-target-directory)
580 $(INSTALL_DATA) $< $@
583 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
584 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
585 define make-target-directory
586 $(addprefix $(..)./mkinstalldirs ,\
587 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
590 # Any directory (parent or subdir) that has any object files to build
591 # should install libc.a; this way "make install" in a subdir is guaranteed
592 # to install everything it changes.
594 installed-libcs := $(foreach o,$(filter-out .so,$(object-suffixes-for-libc)),\
595 $(inst_libdir)/$(patsubst %,$(libtype$o),\
596 $(libprefix)$(libc-name)))
597 install: $(installed-libcs)
598 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib
599 $(make-target-directory)
600 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
601 # Running ranlib after installing makes the __.SYMDEF time stamp up to
602 # date, which avoids messages from some linkers.
606 define do-install-program
607 $(make-target-directory)
608 $(INSTALL_PROGRAM) $< $@.new
612 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
613 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
614 ifeq (yes,$(build-shared))
616 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
618 # Find which .so's have versions.
619 versioned := $(strip $(foreach so,$(install-lib.so),\
620 $(patsubst %,$(so),$($(so)-version))))
622 # Install all the unversioned shared libraries.
623 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
624 $(inst_slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
626 ifneq ($(findstring -s,$(LN_S)),)
629 $(SHELL) $(..)rellns-sh $< $@.new
633 # If we have no symbolic links don't bother with rellns-sh.
641 # XXX The following will have to be changed when `ldconfig' is available.
642 ifneq (yes,$(cross-compiling))
643 ifeq (yes,$(has-ldconfig))
644 define make-shlib-link
649 ifndef make-shlib-link
650 define make-shlib-link
655 ifdef libc.so-version
656 # For a library specified to be version N, install three files:
657 # libc.so -> libc.so.N (e.g. libc.so.6)
658 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
660 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so
662 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so
663 $(do-install-program)
664 install: $(inst_slibdir)/libc.so$(libc.so-version)
667 # What we install as libc.so for programs to link against is in fact a
668 # link script. It contains references for the various libraries we need.
669 # The libc.so object is not complete since some functions are only defined
670 # in libc.a and the dynamic linker is an etra object.
671 install: $(inst_libdir)/libc.so
672 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
673 $(inst_libdir)/$(patsubst %,$(libtype.So),\
674 $(libprefix)$(libc-name))
675 (echo '/* GNU ld script';\
676 echo ' Use the shared library, but some functions are only in';\
677 echo ' the static library, so try that secondarily. */';\
678 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
679 '$(libdir)/$(patsubst %,$(libtype.So),$(libprefix)$(libc-name))'\
687 install: $(inst_slibdir)/libc.so
688 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so
689 $(do-install-program)
693 ifneq (,$(versioned))
694 # Produce three sets of rules as above for all the smaller versioned libraries.
696 define o-iterator-doit
697 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version); $$(make-link)
699 object-suffixes-left := $(versioned)
700 include $(o-iterator)
702 # Make symlinks in the build directory, because the versioned names might
703 # be referenced by a DT_NEEDED in another library.
704 define o-iterator-doit
705 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
707 object-suffixes-left := $(versioned)
708 include $(o-iterator)
711 ifeq (,$($(subdir)-version))
712 define o-iterator-doit
713 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so;
716 object-suffixes-left := $(versioned)
717 include $(o-iterator)
719 define o-iterator-doit
720 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
722 object-suffixes-left := $(versioned)
723 include $(o-iterator)
725 define o-iterator-doit
726 $(inst_slibdir)/$o$($o-version): \
727 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so;
730 object-suffixes-left := $(versioned)
731 include $(o-iterator)
733 define o-iterator-doit
734 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
735 $$(do-install-program)
737 object-suffixes-left := $(versioned)
738 include $(o-iterator)
743 $(do-install-program)
744 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
745 $(filter-out %.so,$@))
748 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
749 $(foreach v,$(so-versions),\
750 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
752 $(foreach v,$(so-versions),\
753 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
758 $(addprefix $(inst_bindir)/,$(install-bin)): $(inst_bindir)/%: $(objpfx)%
759 $(do-install-program)
761 ifdef install-rootsbin
762 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)):
763 $(inst_rootsbindir)/%: $(objpfx)%
764 $(do-install-program)
767 $(addprefix $(inst_sbindir)/,$(install-sbin)): $(inst_sbindir)/%: $(objpfx)%
768 $(do-install-program)
771 install-lib.a := $(filter lib%.a,$(install-lib))
772 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
773 ifdef install-lib-non.a
774 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
775 $(inst_libdir)/$(libprefix)%: $(objpfx)%
779 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
780 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
782 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
786 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: %;
789 headers := $(strip $(headers))
791 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: %;
795 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
796 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
797 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
798 install-rootsbin-nosubdir: \
799 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
800 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
801 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
802 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
803 $(addprefix $(libprefix),$(install-lib-non.a)))
804 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
805 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
806 install-others-nosubdir: $(install-others)
808 # We need all the `-nosubdir' targets so that `install' in the parent
809 # doesn't depend on several things which each iterate over the subdirs.
810 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
811 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
812 install-%:: install-%-nosubdir ;
814 .PHONY: install install-no-libc.a-nosubdir
815 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
816 install-bin-nosubdir install-lib-nosubdir \
817 install-others-nosubdir install-rootsbin-nosubdir \
818 install-sbin-nosubdir
819 install: install-no-libc.a-nosubdir
821 # Command to compile $< in $(objdir) using the native libraries.
822 define native-compile
823 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
824 $(addprefix $$cwd/,$^) -o $(@F)
827 # Command to compile $< in $(common-objdir) using the native libraries.
828 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
829 define common-objdir-compile
831 $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=$(..)%) -o $(..)$(@F)
834 # We always want to use configuration definitions.
835 BUILD_CFLAGS = -include $(..)config.h
837 # Support the GNU standard name for this target.
842 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
843 $(MAKE) $(addprefix -f ,$^) $@
845 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
846 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
855 # Common cleaning targets.
857 .PHONY: common-mostlyclean common-clean mostlyclean clean
859 mostlyclean: common-mostlyclean
861 # Remove the object files.
863 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
864 $(addsuffix .o,$(tests) $(test-srcs) \
866 $(addsuffix .out,$(tests) $(test-srcs)))
867 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
868 -rm -f core $(common-objpfx)stub-$(subdir)
871 $(foreach o,$(object-suffixes-for-libc),
872 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
875 # Also remove the dependencies and generated source files.
876 common-clean: common-mostlyclean
877 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
878 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
879 -rm -f $(addprefix $(common-objpfx),$(common-generated))
880 -rm -f $(common-objpfx)distinfo-$(subdir)
882 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
883 # for each function which is a stub. We grovel over all the .d files
884 # looking for references to source files in sysdeps/stub. Then we grovel
885 # over each referenced source file to see what stub function it defines.
887 .PHONY: stubs # The parent Makefile calls this target.
888 stubs: $(common-objpfx)stub-$(subdir)
889 s = $(sysdep_dir)/stub
890 $(common-objpfx)stub-$(subdir): $(+depfiles)
891 # Use /dev/null since `...` might expand to empty.
892 (s=`cd $s; /bin/pwd`; \
893 $(patsubst %/,cd %;,$(objpfx)) \
894 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
895 `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
896 $(patsubst $(objpfx)%,%,$^) /dev/null` \
900 # Make the distribution tar file.
903 dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
904 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
906 # Avoid depending on source files found in sysdeps dirs,
907 # because the references affect implicit rule selection.
908 dist: $(filter-out %.c %.S %.s,$(distribute))
910 # We used to simply export all these variables, but that frequently made the
911 # environment get too large. Instead, we write all the information into
912 # a generated makefile fragment `distinfo', and then include it with -f in
913 # the sub-make that makes the distribution (above).
914 $(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules
917 .PHONY: subdir_distinfo distinfo
918 subdir_distinfo: distinfo
919 distinfo: $(common-objpfx)distinfo-$(subdir)
923 echo > $@.new 'subdir := $(subdir)'
924 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
925 headers sysdep_headers distribute dont_distribute generated \
926 others tests extra-libs $(extra-libs:%=%-routines) \
928 $(addprefix install-,lib lib.so data bin sbin others),
929 echo >> $@.new '$(subdir)-$(var) := $($(var))'
930 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
933 ifneq (,$(strip $(gpl2lgpl)))
934 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
935 # Snarf from the master source and frob the copying notice.
936 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
938 # So I don't edit them by mistake.
941 test ! -d CVS || cvs commit -m'Updated from $^' $@