1 # Copyright (C) 1991, 92, 93, 94, 95, 96, 97 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 # Some sysdep makefiles use this to distinguish being included here from
99 # being included individually by a subdir makefile (hurd/Makefile needs this).
102 ifndef avoid-generated
103 -include $(+sysdir_pfx)sysd-Makefile
104 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
105 sysd-Makefile-force = FORCE
108 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
109 $(sysd-Makefile-force)
111 (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)'; \
112 for dir in $(config-sysdirs); do \
113 file=$$dir/Makefile; \
118 if [ -f $$rel$$file ]; then \
120 /*) echo include "$$file" ;; \
121 *) echo include "\$$(..)$$file" ;; \
125 echo 'sysd-Makefile-done=t') > $@T
129 ifndef sysd-Makefile-done
130 # Don't do deps until this exists, because it might change the sources list.
135 # Reorder before-compile so that mach things come first, and hurd things
136 # second, before all else. The mach and hurd subdirectories have many
137 # generated header files which the much of rest of the library depends on,
138 # so it is best to build them first (and mach before hurd, at that).
139 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
141 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
144 # Remove existing files from `before-compile'. Things are added there when
145 # they must exist for dependency generation to work right, but once they
146 # exist there is no further need for every single file to depend on them,
147 # and those gratuitous dependencies result in many gratuitous
149 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
151 # Don't let any before-compile file be an intermediate and get removed.
156 # Generate an ordered list of implicit rules which find the source files in
157 # each sysdep directory. The old method was to use vpath to search all the
158 # sysdep directories. However, that had the problem that a .S file in a
159 # later directory would be chosen over a .c file in an earlier directory,
160 # which does not preserve the desired sysdeps ordering behavior.
162 # When making the list of .d files to include, we can't know which ones
163 # have source in .s files, and thus do not in fact need a .d file.
164 # So we must define rules to make .d files for .s files.
165 define make-dummy-dep
166 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
168 $(common-objpfx)dummy.d:
169 echo '# .s files cannot contain includes, so they need no deps.' > $@
171 # It matters that this set of rules, for compiling from sources in
172 # the current directory (the $srcdir/$subdir) come before the
173 # generated sysdep rules in included from sysd-rules below. When
174 # compiling in the source tree, generated sources go into the current
175 # directory, and those should be chosen before any sources in sysdeps.
176 define o-iterator-doit
177 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
179 object-suffixes-left := $(object-suffixes)
180 include $(o-iterator)
181 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
183 define o-iterator-doit
184 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
186 object-suffixes-left := $(object-suffixes)
187 include $(o-iterator)
188 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
190 define o-iterator-doit
191 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
193 object-suffixes-left := $(object-suffixes)
194 include $(o-iterator)
195 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
197 # Omit the objpfx rules when building in the source tree, because
198 # objpfx is empty and so these rules just override the ones above.
200 # Define first rules to find the source files in $(objpfx).
201 # Generated source files will end up there.
202 define o-iterator-doit
203 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
205 object-suffixes-left := $(object-suffixes)
206 include $(o-iterator)
207 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
209 define o-iterator-doit
210 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
212 object-suffixes-left := $(object-suffixes)
213 include $(o-iterator)
214 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
216 define o-iterator-doit
217 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
219 object-suffixes-left := $(object-suffixes)
220 include $(o-iterator)
221 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
224 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
225 # patterns matching sysdep directories whose assembly source files should
227 ifdef inhibit-sysdep-asm
228 define open-check-inhibit-asm
229 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
231 close-check-inhibit-asm = ;; esac ;
234 # Don't include sysd-rules until sysd-Makefile is already there and has been
235 # included. It might define inhibit-sysdep-asm, which would affect the
236 # contents of sysd-rules.
237 ifdef sysd-Makefile-done
238 -include $(+sysdir_pfx)sysd-rules
239 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
240 # The value of $(+sysdep_dirs) the sysd-rules was computed for
241 # differs from the one we are using now. So force a rebuild of sysd-rules.
242 sysd-rules-force = FORCE
246 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
247 $(wildcard $(foreach dir,$(sysdirs),\
251 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
252 for sysdir in $(config-sysdirs); do \
254 /*) dir=$$sysdir ;; \
255 *) dir="\$$(..)$$sysdir" ;; \
257 for o in $(all-object-suffixes); do \
258 $(open-check-inhibit-asm) \
259 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
260 \$$(compile-command.S)"; \
261 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
262 \$$(compile-command.s)"; \
263 $(close-check-inhibit-asm) \
264 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
265 \$$(compile-command.c)"; \
267 $(open-check-inhibit-asm) \
268 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
269 \$$(make-dummy-dep)"; \
270 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
272 $(close-check-inhibit-asm) \
273 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
276 echo 'sysd-rules-done = t') > $@T
279 ifndef sysd-rules-done
280 # Don't do deps until this exists, because it provides rules to make the deps.
285 ifndef compile-command.S
286 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
288 ifndef compile-command.s
289 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
291 ifndef compile-command.c
292 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
295 # GCC can grok options after the file name, and it looks nicer that way.
296 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
297 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
298 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
299 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
301 # We need this for the output to go in the right place. It will default to
302 # empty if make was configured to work with a cc that can't grok -c and -o
303 # together. You can't compile the C library with such a compiler.
304 OUTPUT_OPTION = -o $@
306 S-CPPFLAGS = $(asm-CPPFLAGS)
308 $(make-target-directory)
310 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
312 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
313 $(sed-remove-objpfx) > $(@:.d=.T)
317 # Continuation lines here are dangerous because they introduce spaces!
318 define sed-remove-objpfx
319 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
320 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
324 # Shared library building.
326 ifeq (yes,$(build-shared))
328 # Pattern rule to build a shared object from an archive of PIC objects.
329 # This must come after the installation rules so Make doesn't try to
330 # build shared libraries in place from the installed *_pic.a files.
331 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
332 # on other shared objects.
333 lib%.so: lib%_pic.a; $(build-shlib)
335 ifeq ($(have-no-whole-archive),yes)
336 no-whole-archive = -Wl,--no-whole-archive
341 interp-obj = $(common-objpfx)interp.so
342 $(interp-obj): $(common-objpfx)%.so: $(..)%.c
344 common-generated += interp.so
345 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
347 $(common-objpfx)libc.so: $(interp-obj)
348 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
351 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
353 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
354 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
355 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
356 -Wl,--whole-archive $^ $(no-whole-archive) \
357 $(LDLIBS-$(@F:lib%.so=%).so)
360 # Don't try to use -lc when making libc.so itself.
361 # Also omits crti.o and crtn.o, which we do not want
362 # since we define our own `.init' section specially.
363 LDFLAGS-c.so = -nostdlib -nostartfiles
364 # But we still want to link libc.so against -lgcc.
366 # Give libc.so an entry point and make it directly runnable itself.
367 LDFLAGS-c.so += -e __libc_main
368 # Use our own special initializer and finalizer files for libc.so.
369 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
370 $(common-objpfx)libc_pic.a \
371 $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
374 ifdef libc.so-version
375 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
377 ln -s $(<F) $@ || ln $< $@
381 # Some files must not be compiled with the exception handler mechanism
382 # enabled (introduced in gcc-2.8). Use $(no-exceptions) in the
383 # appropriate CFLAGS definition.
384 ifeq ($(have-no-exceptions),yes)
385 no-exceptions = -fno-exceptions
390 # Figure out the source filenames in this directory.
392 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
395 sysdep_routines := $(sysdep_routines)
397 headers := $(headers) $(sysdep_headers)
399 # This is the list of all object files, gotten by
400 # replacing every ".c" in `sources' with a ".o".
401 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
404 # The makefile may define $(extra-libs) with `libfoo libbar'
405 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
407 # extra-lib.mk is included once for each extra lib to define rules
408 # to build it, and to add its objects to the various variables.
409 # During its evaluation, $(lib) is set to the name of the library.
410 extra-libs-left := $(extra-libs)
411 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
414 +depfiles := $(strip $(sources:.c=.d) \
415 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
416 $(addsuffix .d,$(others) $(tests)))
417 +depfiles := $(addprefix $(objpfx),\
418 $(filter-out $(addsuffix .d,$(omit-deps)),\
423 -include $(+depfiles)
427 # Maximize efficiency by minimizing the number of rules.
428 .SUFFIXES: # Clear the suffix list.
429 # Add the suffixes we use.
430 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
432 # Generic rule for making directories.
434 # mkdir isn't smart enough to strip a trailing /.
437 # Make sure that object files are not removed
438 # when they are intermediates between sources and library members.
439 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
441 # Make sure that the parent library archive is never removed.
442 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
444 # Use the verbose option of ar and tar when not running silently.
445 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
451 ARFLAGS := r$(verbose)
453 # This makes all the object files in the parent library archive.
455 .PHONY: lib libobjs lib-noranlib
456 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
458 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
459 lib%.a: lib%.a($(ar-symtab-name)) ;
461 # For object-suffix $o, the list of objects with that suffix.
462 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
463 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
464 $(elide-routines$o)),\
467 libobjs: $(foreach o,$(object-suffixes),\
468 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
469 $(notdir $(o-objects))))
470 lib-noranlib: libobjs
471 others: $(addprefix $(objpfx),$(install-lib))
475 # Create the stamp$o files to keep the parent makefile happy.
476 subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir))
477 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)):
478 $(make-target-directory)
482 # Define a pattern rule that will match many targets libc.a(foo.%), for
483 # each foo.o in $(objects) (% will just happen always to match `o'). This is
484 # the only way to define a rule that updates many targets at once with one
485 # sequence of commands.
486 define o-iterator-doit
487 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
488 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
489 $(objpfx)stamp.%-$(subdir) ;
491 object-suffixes-left := $(object-suffixes)
492 include $(o-iterator)
494 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
495 # the way to update all the foo.% object files in $(objects). Now we
496 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
497 # timestamp file; these rules (one explicit rule is generated for each
498 # object suffix) will update the parent archive with ar. Use a static
499 # pattern rule so $* is set to the object type during the commands.
500 define o-iterator-doit
501 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
503 object-suffixes-left := $(object-suffixes)
504 include $(o-iterator)
506 topdir=`cd $(..).; pwd`; \
507 $(patsubst %/,cd %;,$(objpfx)) \
508 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
509 $(patsubst $(objpfx)%,%,$^)
513 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
517 # Rules to update the $(ar-symtab-name) member with ranlib,
518 # one for each object flavor.
519 define o-iterator-doit
520 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
521 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
522 $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
523 $(SHELL) $$(..)./autolock.sh \
524 $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
525 $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
528 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
529 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
530 $(subdirs-stamps): subdir_lib;
532 object-suffixes-left = $(object-suffixes)
533 include $(o-iterator)
536 # This makes all the object files.
538 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
539 $(addprefix $(objpfx),$(extra-objs))
541 # Canned sequence for building an extra library archive.
542 define build-extra-lib
543 $(patsubst %/,cd %;,$(objpfx)) \
544 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
545 $(patsubst $(objpfx)%,%,$^)
551 # $(install-lib) are installed from the object directory into $(libdir);
552 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
553 # unless they also appear in $(non-lib.a). $(install-data) are installed
554 # as they are into $(datadir). $(headers) are installed as they are in
555 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
556 # object directory into $(bindir) and $(sbindir), respectively.
557 # $(install-others) are absolute path names of files to install; rules to
558 # install them are defined elsewhere.
560 # The simple library name to install libc.a under.
561 # This could be defined by a sysdep Makefile.
567 $(make-target-directory)
568 $(INSTALL_DATA) $< $@
571 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
572 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
573 define make-target-directory
574 $(addprefix $(..)./mkinstalldirs ,\
575 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
578 # Any directory (parent or subdir) that has any object files to build
579 # should install libc.a; this way "make install" in a subdir is guaranteed
580 # to install everything it changes.
582 installed-libcs := $(foreach o,$(object-suffixes),\
583 $(inst_libdir)/$(patsubst %,$(libtype$o),\
584 $(libprefix)$(libc-name)))
585 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
586 install: $(installed-libcs)
587 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib
588 $(make-target-directory)
589 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
590 # Running ranlib after installing makes the __.SYMDEF time stamp up to
591 # date, which avoids messages from some linkers.
595 define do-install-program
596 $(make-target-directory)
597 $(INSTALL_PROGRAM) $< $@.new
601 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
602 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
603 ifeq (yes,$(build-shared))
605 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
607 # Find which .so's have versions.
608 versioned := $(strip $(foreach so,$(install-lib.so),\
609 $(patsubst %,$(so),$($(so)-version))))
611 # Install all the unversioned shared libraries.
612 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
613 $(inst_slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
615 ifneq ($(findstring -s,$(LN_S)),)
618 $(SHELL) $(..)rellns-sh $< $@.new
622 # If we have no symbolic links don't bother with rellns-sh.
630 # XXX The following will have to be changed when `ldconfig' is available.
631 ifneq (yes,$(cross-compiling))
632 ifeq (yes,$(has-ldconfig))
633 define make-shlib-link
638 ifndef make-shlib-link
639 define make-shlib-link
644 ifdef libc.so-version
645 # For a library specified to be version N, install three files:
646 # libc.so -> libc.so.N (e.g. libc.so.6)
647 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
649 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so
651 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so
652 $(do-install-program)
653 install: $(inst_slibdir)/libc.so$(libc.so-version)
656 # What we install as libc.so for programs to link against is in fact a
657 # link script. It contains references for the various libraries we need.
658 # The libc.so object is not complete since some functions are only defined
659 # in libc.a and the dynamic linker is an etra object.
660 install: $(inst_libdir)/libc.so
661 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
662 $(elfobjdir)/$(rtld-installed-name) \
663 $(inst_libdir)/lib$(libc-name).a
664 (echo '/* GNU ld script';\
665 echo ' Use the shared library, but some functions are only in';\
666 echo ' the static library, so try that secondarily.'; \
667 echo ' The dynamic linker defines some functions used by $(<F),';\
668 echo ' but ld uses definitions from libc.a before examining the';\
669 echo ' dependencies of $(<F) to find $(rtld-installed-name). */';\
670 echo 'GROUP ( $(^F) )') > $@.new
676 install: $(inst_slibdir)/libc.so
677 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so
678 $(do-install-program)
682 ifneq (,$(versioned))
683 # Produce three sets of rules as above for all the smaller versioned libraries.
685 define o-iterator-doit
686 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version); $$(make-link)
688 object-suffixes-left := $(versioned)
689 include $(o-iterator)
691 # Make symlinks in the build directory, because the versioned names might
692 # be referenced by a DT_NEEDED in another library.
693 define o-iterator-doit
694 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
696 object-suffixes-left := $(versioned)
697 include $(o-iterator)
700 ifeq (,$($(subdir)-version))
701 define o-iterator-doit
702 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so;
705 object-suffixes-left := $(versioned)
706 include $(o-iterator)
708 define o-iterator-doit
709 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
711 object-suffixes-left := $(versioned)
712 include $(o-iterator)
714 define o-iterator-doit
715 $(inst_slibdir)/$o$($o-version): \
716 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so;
719 object-suffixes-left := $(versioned)
720 include $(o-iterator)
722 define o-iterator-doit
723 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
724 $$(do-install-program)
726 object-suffixes-left := $(versioned)
727 include $(o-iterator)
732 $(do-install-program)
733 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
734 $(filter-out %.so,$@))
737 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
738 $(foreach v,$(so-versions),\
739 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
741 $(foreach v,$(so-versions),\
742 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
747 $(addprefix $(inst_bindir)/,$(install-bin)): $(inst_bindir)/%: $(objpfx)%
748 $(do-install-program)
750 ifdef install-rootsbin
751 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)):
752 $(inst_rootsbindir)/%: $(objpfx)%
753 $(do-install-program)
756 $(addprefix $(inst_sbindir)/,$(install-sbin)): $(inst_sbindir)/%: $(objpfx)%
757 $(do-install-program)
760 install-lib.a := $(filter lib%.a,$(install-lib))
761 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
762 ifdef install-lib-non.a
763 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
764 $(inst_libdir)/$(libprefix)%: $(objpfx)%
768 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
769 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
771 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
775 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: %;
778 headers := $(strip $(headers))
780 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: %;
784 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
785 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
786 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
787 install-rootsbin-nosubdir: \
788 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
789 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
790 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
791 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
792 $(addprefix $(libprefix),$(install-lib-non.a)))
793 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
794 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
795 install-others-nosubdir: $(install-others)
797 # We need all the `-nosubdir' targets so that `install' in the parent
798 # doesn't depend on several things which each iterate over the subdirs.
799 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
800 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
801 install-%:: install-%-nosubdir ;
803 .PHONY: install install-no-libc.a-nosubdir
804 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
805 install-bin-nosubdir install-lib-nosubdir \
806 install-others-nosubdir install-rootsbin-nosubdir \
807 install-sbin-nosubdir
808 install: install-no-libc.a-nosubdir
810 # Command to compile $< in $(objdir) using the native libraries.
811 define native-compile
812 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
813 $(addprefix $$cwd/,$^) -o $(@F)
816 # Command to compile $< in $(common-objdir) using the native libraries.
817 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
818 define common-objdir-compile
820 $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=$(..)%) -o $(..)$(@F)
823 # We always want to use configuration definitions.
824 BUILD_CFLAGS = -include $(common-objpfx)config.h
826 # Support the GNU standard name for this target.
831 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
832 $(MAKE) $(addprefix -f ,$^) $@
834 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
835 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
844 # Common cleaning targets.
846 .PHONY: common-mostlyclean common-clean mostlyclean clean
848 mostlyclean: common-mostlyclean
850 # Remove the object files.
852 -rm -f $(addprefix $(objpfx),$(tests) $(others) \
853 $(addsuffix .o,$(tests) $(others)) \
854 $(addsuffix .out,$(tests)))
855 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
856 -rm -f core $(common-objpfx)stub-$(subdir)
859 $(foreach o,$(object-suffixes),
860 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
863 # Also remove the dependencies and generated source files.
864 common-clean: common-mostlyclean
865 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
866 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
867 -rm -f $(addprefix $(common-objpfx),$(common-generated))
868 -rm -f $(common-objpfx)distinfo-$(subdir)
870 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
871 # for each function which is a stub. We grovel over all the .d files
872 # looking for references to source files in sysdeps/stub. Then we grovel
873 # over each referenced source file to see what stub function it defines.
875 .PHONY: stubs # The parent Makefile calls this target.
876 stubs: $(common-objpfx)stub-$(subdir)
877 s = $(sysdep_dir)/stub
878 $(common-objpfx)stub-$(subdir): $(+depfiles)
879 # Use /dev/null since `...` might expand to empty.
880 (s=`cd $s; /bin/pwd`; \
881 $(patsubst %/,cd %;,$(objpfx)) \
882 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
883 `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
884 $(patsubst $(objpfx)%,%,$^) /dev/null` \
888 # Make the distribution tar file.
891 dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
892 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
894 # Avoid depending on source files found in sysdeps dirs,
895 # because the references affect implicit rule selection.
896 dist: $(filter-out %.c %.S %.s,$(distribute))
898 # We used to simply export all these variables, but that frequently made the
899 # environment get too large. Instead, we write all the information into
900 # a generated makefile fragment `distinfo', and then include it with -f in
901 # the sub-make that makes the distribution (above).
902 $(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules \
903 $(wildcard $(foreach dir,$(sysdirs),\
907 .PHONY: subdir_distinfo distinfo
908 subdir_distinfo: distinfo
909 distinfo: $(common-objpfx)distinfo-$(subdir)
913 echo > $@.new 'subdir := $(subdir)'
914 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
915 headers sysdep_headers distribute dont_distribute generated \
916 others tests extra-libs $(extra-libs:%=%-routines) \
918 $(addprefix install-,lib lib.so data bin sbin others),
919 echo >> $@.new '$(subdir)-$(var) := $($(var))'
920 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
923 ifneq (,$(strip $(gpl2lgpl)))
924 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
925 # Snarf from the master source and frob the copying notice.
926 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
928 # So I don't edit them by mistake.
931 test ! -d CVS || cvs commit -m'Updated from $^' $@