1 # Copyright (C) 1991, 92, 93, 94, 95, 96 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
16 # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 # Cambridge, MA 02139, 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
30 ifneq ($(REQUIRED_MAKE_VERSION), \
31 $(firstword $(sort $(MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
32 Wrong GNU Make version. See above for the version needed.
40 # If `sources' was defined by the parent makefile, undefine it so
41 # we will later get it from wildcard search in this directory.
42 ifneq "$(findstring env,$(origin sources))" ""
47 PATH := this definition should take precedence over $(oPATH)
48 ifeq ($(PATH),$(oPATH))
49 You must not use the -e flag when building the GNU C library.
54 ifndef +included-Makeconfig
55 include $(..)Makeconfig
58 # `configure' writes a definition of `config-sysdirs' in `config.make'.
59 sysdirs = $(strip $(full-config-sysdirs))
61 +sysdir_pfx = $(common-objpfx)
63 export sysdirs := $(sysdirs)
65 +sysdep_dirs := $(full-config-sysdirs)
67 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
70 # Add -I switches to get the right sysdep directories.
71 # `+includes' in Makeconfig references $(+sysdep-includes).
72 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
74 # The name of the symbol table archive member. The default is suitable for
75 # BSD style archives. It can be overridden in sysdep Makefiles when SYSV
76 # style archive are used.
78 ar-symtab-name = __.SYMDEF
80 ar-symtab-name = # The null name is used in ELF archives.
83 # Include any system-specific makefiles.
85 # This is here so things in sysdep Makefiles can easily depend on foo.h as
86 # appropriate and not worry about where foo.h comes from, which may be
87 # system dependent and not known by that Makefile.
88 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
89 $(+sysdep_dirs) $(..)))
91 # Some sysdep makefiles use this to distinguish being included here from
92 # being included individually by a subdir makefile (hurd/Makefile needs this).
95 ifndef avoid-generated
96 -include $(+sysdir_pfx)sysd-Makefile
97 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
98 sysd-Makefile-force = FORCE
101 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
102 $(sysd-Makefile-force)
104 (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)'; \
105 for dir in $(config-sysdirs); do \
106 file=$$dir/Makefile; \
111 if [ -f $$rel$$file ]; then \
113 /*) echo include "$$file" ;; \
114 *) echo include "\$$(..)$$file" ;; \
118 echo 'sysd-Makefile-done=t') > $@T
122 ifndef sysd-Makefile-done
123 # Don't do deps until this exists, because it might change the sources list.
128 # Reorder before-compile so that mach things come first, and hurd things
129 # second, before all else. The mach and hurd subdirectories have many
130 # generated header files which the much of rest of the library depends on,
131 # so it is best to build them first (and mach before hurd, at that).
132 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
134 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
137 # Remove existing files from `before-compile'. Things are added there when
138 # they must exist for dependency generation to work right, but once they
139 # exist there is no further need for every single file to depend on them,
140 # and those gratuitous dependencies result in many gratuitous
142 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
144 # Don't let any before-compile file be an intermediate and get removed.
149 # Generate an ordered list of implicit rules which find the source files in
150 # each sysdep directory. The old method was to use vpath to search all the
151 # sysdep directories. However, that had the problem that a .S file in a
152 # later directory would be chosen over a .c file in an earlier directory,
153 # which does not preserve the desired sysdeps ordering behavior.
155 # When making the list of .d files to include, we can't know which ones
156 # have source in .s files, and thus do not in fact need a .d file.
157 # So we must define rules to make .d files for .s files.
158 define make-dummy-dep
159 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
161 $(common-objpfx)dummy.d:
162 echo '# .s files cannot contain includes, so they need no deps.' > $@
164 # It matters that this set of rules, for compiling from sources in
165 # the current directory (the $srcdir/$subdir) come before the
166 # generated sysdep rules in included from sysd-rules below. When
167 # compiling in the source tree, generated sources go into the current
168 # directory, and those should be chosen before any sources in sysdeps.
169 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
170 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
171 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
172 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
173 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
174 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
175 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
176 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
177 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
178 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
179 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
180 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
181 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
182 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
183 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
185 # Omit the objpfx rules when building in the source tree, because
186 # objpfx is empty and so these rules just override the ones above.
188 # Define first rules to find the source files in $(objpfx).
189 # Generated source files will end up there.
190 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
191 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
192 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
193 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
194 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
195 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
196 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
197 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
198 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
199 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
200 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
201 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
202 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
203 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
204 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
207 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
208 # patterns matching sysdep directories whose assembly source files should
210 ifdef inhibit-sysdep-asm
211 define open-check-inhibit-asm
212 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
214 close-check-inhibit-asm = ;; esac ;
217 # Don't include sysd-rules until sysd-Makefile is already there and has been
218 # included. It might define inhibit-sysdep-asm, which would affect the
219 # contents of sysd-rules.
220 ifdef sysd-Makefile-done
221 -include $(+sysdir_pfx)sysd-rules
222 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
223 # The value of $(+sysdep_dirs) the sysd-rules was computed for
224 # differs from the one we are using now. So force a rebuild of sysd-rules.
225 sysd-rules-force = FORCE
229 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
230 $(wildcard $(foreach dir,$(sysdirs),\
234 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
235 for sysdir in $(config-sysdirs); do \
237 /*) dir=$$sysdir ;; \
238 *) dir="\$$(..)$$sysdir" ;; \
240 for o in $(object-suffixes); do \
241 $(open-check-inhibit-asm) \
242 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
243 \$$(compile-command.S)"; \
244 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
245 \$$(compile-command.s)"; \
246 $(close-check-inhibit-asm) \
247 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
248 \$$(compile-command.c)"; \
250 $(open-check-inhibit-asm) \
251 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
252 \$$(make-dummy-dep)"; \
253 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
255 $(close-check-inhibit-asm) \
256 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
259 echo 'sysd-rules-done = t') > $@T
262 ifndef sysd-rules-done
263 # Don't do deps until this exists, because it provides rules to make the deps.
268 ifndef compile-command.S
269 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
271 ifndef compile-command.s
272 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
274 ifndef compile-command.c
275 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
278 # GCC can grok options after the file name, and it looks nicer that way.
279 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
280 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
281 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
282 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
284 # We need this for the output to go in the right place. It will default to
285 # empty if make was configured to work with a cc that can't grok -c and -o
286 # together. You can't compile the C library with such a compiler.
287 OUTPUT_OPTION = -o $@
289 S-CPPFLAGS = $(asm-CPPFLAGS)
291 $(make-target-directory)
293 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
294 sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
295 $(sed-remove-objpfx) > $(@:.d=.T)
299 # Continuation lines here are dangerous because they introduce spaces!
300 define sed-remove-objpfx
301 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
302 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
306 # Shared library building.
308 ifeq (yes,$(build-shared))
310 # Pattern rule to build a shared object from an archive of PIC objects.
311 # This must come after the installation rules so Make doesn't try to
312 # build shared libraries in place from the installed *_pic.a files.
313 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
314 # on other shared objects.
315 lib%.so: lib%_pic.a; $(build-shlib)
317 ifeq ($(have-no-whole-archive),yes)
318 no-whole-archive = -Wl,--no-whole-archive
323 interp-obj = $(common-objpfx)interp.so
324 $(interp-obj): $(common-objpfx)%.so: $(..)%.c
326 common-generated += interp.so
327 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
329 $(common-objpfx)libc.so: $(interp-obj)
330 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
333 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
335 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
336 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
337 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
338 -Wl,--whole-archive $^ $(no-whole-archive) \
339 $(LDLIBS-$(@F:lib%.so=%).so)
342 # Don't try to use -lc when making libc.so itself.
343 # Also omits crti.o and crtn.o, which we do not want
344 # since we define our own `.init' section specially.
345 LDFLAGS-c.so = -nostdlib -nostartfiles
346 # Give libc.so an entry point and make it directly runnable itself.
347 LDFLAGS-c.so += -e __libc_main
348 # Use our own special initializer and finalizer files for libc.so.
349 elfobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)elf)
350 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
351 $(common-objpfx)libc_pic.a \
352 $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
355 ifdef libc.so-version
356 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
358 ln -s $(<F) $@ || ln $< $@
362 # Some files must not be compiled with the exception handler mechanism
363 # enabled (introduced in gcc-2.8). Use $(no-exceptions) in the
364 # appropriate CFLAGS definition.
365 ifeq ($(have-no-exceptions),yes)
366 no-exceptions = -fno-exceptions
371 # Figure out the source filenames in this directory.
373 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
376 sysdep_routines := $(sysdep_routines)
378 headers := $(headers) $(sysdep_headers)
380 # This is the list of all object files, gotten by
381 # replacing every ".c" in `sources' with a ".o".
382 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
385 # This variable is used in ``include $(o-iterator)'' after defining
386 # $(o-iterator-doit) to produce some desired rule using $o for the object
387 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
388 # is produced for each object suffix in use.
389 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
391 # The makefile may define $(extra-libs) with `libfoo libbar'
392 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
394 # extra-lib.mk is included once for each extra lib to define rules
395 # to build it, and to add its objects to the various variables.
396 # During its evaluation, $(lib) is set to the name of the library.
397 extra-libs-left := $(extra-libs)
398 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
401 +depfiles := $(strip $(sources:.c=.d) \
402 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
403 $(addsuffix .d,$(others) $(tests)))
404 +depfiles := $(addprefix $(objpfx),\
405 $(filter-out $(addsuffix .d,$(omit-deps)),\
410 -include $(+depfiles)
414 # Maximize efficiency by minimizing the number of rules.
415 .SUFFIXES: # Clear the suffix list.
416 # Add the suffixes we use.
417 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
419 # Generic rule for making directories.
421 # mkdir isn't smart enough to strip a trailing /.
424 # Make sure that object files are not removed
425 # when they are intermediates between sources and library members.
426 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
428 # Make sure that the parent library archive is never removed.
429 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
431 # Use the verbose option of ar and tar when not running silently.
432 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
438 ARFLAGS := r$(verbose)
440 # This makes all the object files in the parent library archive.
442 .PHONY: lib libobjs lib-noranlib
443 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
445 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
446 lib%.a: lib%.a($(ar-symtab-name)) ;
448 # For object-suffix $o, the list of objects with that suffix.
449 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
450 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
451 $(elide-routines$o)),\
454 libobjs: $(foreach o,$(object-suffixes),\
455 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
456 $(notdir $(o-objects))))
457 lib-noranlib: libobjs
458 others: $(addprefix $(objpfx),$(install-lib))
462 # Create the stamp$o files to keep the parent makefile happy.
463 subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir))
464 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)):
465 $(make-target-directory)
469 # Define a pattern rule that will match many targets libc.a(foo.%), for
470 # each foo.o in $(objects) (% will just happen always to match `o'). This is
471 # the only way to define a rule that updates many targets at once with one
472 # sequence of commands.
473 define o-iterator-doit
474 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
475 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
476 $(objpfx)stamp.%-$(subdir) ;
478 object-suffixes-left := $(object-suffixes)
479 include $(o-iterator)
481 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
482 # the way to update all the foo.% object files in $(objects). Now we
483 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
484 # timestamp file; these rules (one explicit rule is generated for each
485 # object suffix) will update the parent archive with ar. Use a static
486 # pattern rule so $* is set to the object type during the commands.
487 define o-iterator-doit
488 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
490 object-suffixes-left := $(object-suffixes)
491 include $(o-iterator)
493 topdir=`cd $(..).; pwd`; \
494 $(patsubst %/,cd %;,$(objpfx)) \
495 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
496 $(patsubst $(objpfx)%,%,$^)
500 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
504 # Rules to update the $(ar-symtab-name) member with ranlib,
505 # one for each object flavor.
506 define o-iterator-doit
507 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
508 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
509 $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
510 $(SHELL) $$(..)./autolock.sh \
511 $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
512 $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
515 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
516 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
517 $(subdirs-stamps): subdir_lib;
519 object-suffixes-left = $(object-suffixes)
520 include $(o-iterator)
523 # This makes all the object files.
525 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
526 $(addprefix $(objpfx),$(extra-objs))
528 # Canned sequence for building an extra library archive.
529 define build-extra-lib
530 $(patsubst %/,cd %;,$(objpfx)) \
531 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
532 $(patsubst $(objpfx)%,%,$^)
538 # $(install-lib) are installed from the object directory into $(libdir);
539 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
540 # unless they also appear in $(non-lib.a). $(install-data) are installed
541 # as they are into $(datadir). $(headers) are installed as they are in
542 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
543 # object directory into $(bindir) and $(sbindir), respectively.
544 # $(install-others) are absolute path names of files to install; rules to
545 # install them are defined elsewhere.
547 # The simple library name to install libc.a under.
548 # This could be defined by a sysdep Makefile.
554 $(make-target-directory)
555 $(INSTALL_DATA) $< $@
558 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
559 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
560 define make-target-directory
561 $(addprefix $(..)./mkinstalldirs ,\
562 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
565 # Any directory (parent or subdir) that has any object files to build
566 # should install libc.a; this way "make install" in a subdir is guaranteed
567 # to install everything it changes.
569 installed-libcs := $(foreach o,$(object-suffixes),\
570 $(libdir)/$(patsubst %,$(libtype$o),\
571 $(libprefix)$(libc-name)))
572 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
573 install: $(installed-libcs)
574 $(installed-libcs): $(libdir)/lib$(libprefix)%: lib
575 $(make-target-directory)
576 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
577 # Running ranlib after installing makes the __.SYMDEF time stamp up to
578 # date, which avoids messages from some linkers.
582 define do-install-program
583 $(make-target-directory)
584 $(INSTALL_PROGRAM) $< $@.new
588 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
589 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
590 ifeq (yes,$(build-shared))
592 install-lib-nosubdir: $(install-lib.so:%=$(libdir)/%)
594 # Find which .so's have versions.
595 versioned := $(strip $(foreach so,$(install-lib.so),\
596 $(patsubst %,$(so),$($(so)-version))))
598 # Install all the unversioned shared libraries.
599 $(addprefix $(slibdir)/,$(filter-out $(versioned),$(install-lib.so))): \
600 $(slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
605 if test '$(@D)' = '$(<D)'; then \
606 $(LN_S) $(<F) $(@F).new; \
608 $(SHELL) $(common-objpfx)$(..)rellns-sh $< $(@F).new; \
610 mv -f $(@F).new $(@F)
613 ifdef libc.so-version
614 # For a library specified to be version N, install three files:
615 # libc.so -> libc.so.N (e.g. libc.so.6)
616 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
618 $(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so
620 $(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program)
621 install: $(slibdir)/libc.so$(libc.so-version)
624 # What we install as libc.so for programs to link against is in fact a
625 # link script. It contains references for the various libraries we need.
626 # The libc.so object is not complete since some functions are only defined
627 # in libc.a and the dynamic linker is an etra object.
628 install: $(libdir)/libc.so
629 $(libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
630 $(elfobjdir)/$(rtld-installed-name) \
631 $(libdir)/lib$(libc-name).a
632 (echo '/* Use the shared library, but some functions are only in';\
633 echo ' the static library, so try that secondarily.'; \
634 echo ' The dynamic linker defines some functions used by $(<F),';\
635 echo ' but ld uses definitions from libc.a before examining the';\
636 echo ' dependencies of $(<F) to find $(rtld-installed-name). */';\
637 echo 'GROUP ( $(^F) )') > $@.new
643 install: $(slibdir)/libc.so
644 $(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program)
648 ifneq (,$(versioned))
649 # Produce three sets of rules as above for all the smaller versioned libraries.
651 define o-iterator-doit
652 $(libdir)/$o: $(slibdir)/$o$($o-version); $$(make-link)
654 object-suffixes-left := $(versioned)
655 include $(o-iterator)
657 # Make symlinks in the build directory, because the versioned names might
658 # be referenced by a DT_NEEDED in another library.
659 define o-iterator-doit
660 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
662 object-suffixes-left := $(versioned)
663 include $(o-iterator)
666 ifeq (,$($(subdir)-version))
667 define o-iterator-doit
668 $(slibdir)/$o$($o-version): $(slibdir)/$(o:.so=)-$(version).so; $$(make-link)
670 object-suffixes-left := $(versioned)
671 include $(o-iterator)
673 define o-iterator-doit
674 $(slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
676 object-suffixes-left := $(versioned)
677 include $(o-iterator)
679 define o-iterator-doit
680 $(slibdir)/$o$($o-version): $(slibdir)/$(o:.so=)-$($(subdir)-version).so;
683 object-suffixes-left := $(versioned)
684 include $(o-iterator)
686 define o-iterator-doit
687 $(slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
688 $$(do-install-program)
690 object-suffixes-left := $(versioned)
691 include $(o-iterator)
696 $(do-install-program)
697 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
698 $(filter-out %.so,$@))
701 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
702 $(foreach v,$(so-versions),\
703 $(slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
705 $(foreach v,$(so-versions),\
706 $(slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
711 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
712 $(do-install-program)
715 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
716 $(do-install-program)
719 install-lib.a := $(filter lib%.a,$(install-lib))
720 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
721 ifdef install-lib-non.a
722 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
723 $(libdir)/$(libprefix)%: $(objpfx)%
727 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
728 $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
730 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
734 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
736 headers := $(strip $(headers))
738 $(addprefix $(includedir)/,$(headers)): \
739 $(includedir)/%: %;$(do-install)
742 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
743 install-data-nosubdir install-headers-nosubdir
744 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
745 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
746 install-lib-nosubdir: $(addprefix $(libdir)/,\
747 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
748 $(addprefix $(libprefix),$(install-lib-non.a)))
749 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
750 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
751 install-others-nosubdir: $(install-others)
753 # We need all the `-nosubdir' targets so that `install' in the parent
754 # doesn't depend on several things which each iterate over the subdirs.
755 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
756 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
757 install-%:: install-%-nosubdir ;
759 .PHONY: install install-no-libc.a-nosubdir
760 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
761 install-bin-nosubdir install-lib-nosubdir \
762 install-others-nosubdir install-sbin-nosubdir
763 install: install-no-libc.a-nosubdir
765 # Command to compile $< in $(objdir) using the native libraries.
766 define native-compile
767 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
768 $(addprefix $$cwd/,$^) -o $(@F)
771 # Command to compile $< in $(common-objdir) using the native libraries.
772 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
773 define common-objdir-compile
775 $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=$(..)%) -o $(..)$(@F)
778 # We always want to use configuration definitions.
779 BUILD_CFLAGS = -include $(..)config.h
781 # Support the GNU standard name for this target.
786 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
787 $(MAKE) $(addprefix -f ,$^) $@
789 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
790 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
799 # Common cleaning targets.
801 .PHONY: common-mostlyclean common-clean mostlyclean clean
803 mostlyclean: common-mostlyclean
805 # Remove the object files.
807 -rm -f $(addprefix $(objpfx),$(tests) $(others) \
808 $(addsuffix .o,$(tests) $(others)) \
809 $(addsuffix .out,$(tests)))
810 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
811 -rm -f core $(common-objpfx)stub-$(subdir)
814 $(foreach o,$(object-suffixes),
815 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
818 # Also remove the dependencies and generated source files.
819 common-clean: common-mostlyclean
820 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
821 -rm -f $(addprefix $(common-objpfx),$(common-generated))
822 -rm -f $(common-objpfx)distinfo-$(subdir)
824 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
825 # for each function which is a stub. We grovel over all the .d files
826 # looking for references to source files in sysdeps/stub. Then we grovel
827 # over each referenced source file to see what stub function it defines.
829 .PHONY: stubs # The parent Makefile calls this target.
830 stubs: $(common-objpfx)stub-$(subdir)
831 s = $(sysdep_dir)/stub
832 $(common-objpfx)stub-$(subdir): $(+depfiles)
833 # Use /dev/null since `...` might expand to empty.
834 (s=`cd $s; /bin/pwd`; \
835 $(patsubst %/,cd %;,$(objpfx)) \
836 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
837 `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
838 $(patsubst $(objpfx)%,%,$^) /dev/null` \
842 # Make the distribution tar file.
845 dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
846 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
848 # Avoid depending on source files found in sysdeps dirs,
849 # because the references affect implicit rule selection.
850 dist: $(filter-out %.c %.S %.s,$(distribute))
852 # We used to simply export all these variables, but that frequently made the
853 # environment get too large. Instead, we write all the information into
854 # a generated makefile fragment `distinfo', and then include it with -f in
855 # the sub-make that makes the distribution (above).
856 $(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules
859 .PHONY: subdir_distinfo distinfo
860 subdir_distinfo: distinfo
861 distinfo: $(common-objpfx)distinfo-$(subdir)
865 echo > $@.new 'subdir := $(subdir)'
866 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
867 headers sysdep_headers distribute dont_distribute generated \
868 others tests extra-libs $(extra-libs:%=%-routines) \
870 $(addprefix install-,lib lib.so data bin sbin others),
871 echo >> $@.new '$(subdir)-$(var) := $($(var))'
872 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
875 ifneq (,$(strip $(gpl2lgpl)))
876 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
877 # Snarf from the master source and frob the copying notice.
878 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
880 # So I don't edit them by mistake.
883 test ! -d CVS || cvs commit -m'Updated from $^' $@