Update.
[glibc.git] / Makerules
blob7a99001c8ef4444a79f2af4b25690a3a1b2381bb
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
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
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.
34 endif
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
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))" ""
44 sources :=
45 endif
47 oPATH := $(PATH)
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.
51 else
52 PATH := $(oPATH)
53 endif
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
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)
67 ifdef objdir
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
69 endif
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.
78 ifeq (no,$(elf))
79 ar-symtab-name = __.SYMDEF
80 else
81 ar-symtab-name = # The null name is used in ELF archives.
82 endif
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).
100 in-Makerules := yes
102 ifndef avoid-generated
103 -include $(+sysdir_pfx)sysd-Makefile
104 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
105 sysd-Makefile-force = FORCE
106 FORCE:
107 endif
108 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
109                              $(sysd-Makefile-force)
110         -@rm -f $@T
111         (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)';                   \
112          for dir in $(config-sysdirs); do                                     \
113            file=$$dir/Makefile;                                               \
114            case $$dir in                                                      \
115              /*) rel= ;;                                                      \
116              *)  rel=$(..) ;;                                                 \
117            esac;                                                              \
118            if [ -f $$rel$$file ]; then                                        \
119              case $$dir in                                                    \
120                /*) echo include "$$file" ;;                                   \
121                *)  echo include "\$$(..)$$file" ;;                            \
122              esac;                                                            \
123            else true; fi;                                                     \
124          done;                                                                \
125          echo 'sysd-Makefile-done=t') > $@T
126         mv -f $@T $@
127 endif
129 ifndef sysd-Makefile-done
130 # Don't do deps until this exists, because it might change the sources list.
131 no_deps=t
132 endif
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%,\
140                            $(before-compile)) \
141                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
142                                $(before-compile))
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
148 # recompilations.
149 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
151 # Don't let any before-compile file be an intermediate and get removed.
152 ifdef before-compile
153 $(before-compile):
154 endif
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 $@),$@))
167 endef
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)
178 endef
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)
185 endef
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)
192 endef
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.
199 ifdef objpfx
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)
204 endef
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)
211 endef
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)
218 endef
219 object-suffixes-left := $(object-suffixes)
220 include $(o-iterator)
221 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
222 endif
224 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
225 # patterns matching sysdep directories whose assembly source files should
226 # be suppressed.
227 ifdef inhibit-sysdep-asm
228 define open-check-inhibit-asm
229 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
230 endef
231 close-check-inhibit-asm = ;; esac ;
232 endif
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
243 FORCE:
244 endif
245 endif
246 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
247                           $(wildcard $(foreach dir,$(sysdirs),\
248                                                $(dir)/Makefile))\
249                           $(sysd-rules-force)
250         -@rm -f $@T
251         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
252          for sysdir in $(config-sysdirs); do                                  \
253            case $$sysdir in \
254              /*) dir=$$sysdir ;; \
255              *)  dir="\$$(..)$$sysdir" ;; \
256            esac; \
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)";                                    \
266            done; \
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); \
271                 \$$(+make-deps)";                                             \
272            $(close-check-inhibit-asm)   \
273            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
274                 \$$(+make-deps)";                                             \
275          done;                                                                \
276          echo 'sysd-rules-done = t') > $@T
277         mv -f $@T $@
279 ifndef sysd-rules-done
280 # Don't do deps until this exists, because it provides rules to make the deps.
281 no_deps=t
282 endif
285 ifndef compile-command.S
286 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
287 endif
288 ifndef compile-command.s
289 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
290 endif
291 ifndef compile-command.c
292 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
293 endif
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 = \
298   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
299 COMPILE.S = \
300   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
301 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
303 # We need this for the output to go in the right place.  It will default to
304 # empty if make was configured to work with a cc that can't grok -c and -o
305 # together.  You can't compile the C library with such a compiler.
306 OUTPUT_OPTION = -o $@
308 S-CPPFLAGS = $(asm-CPPFLAGS)
309 define +make-deps
310 $(make-target-directory)
311 -@rm -f $@
312 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
313 sed \
314 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
315 $(sed-remove-objpfx) > $(@:.d=.T)
316 mv -f $(@:.d=.T) $@
317 endef
318 ifneq (,$(objpfx))
319 # Continuation lines here are dangerous because they introduce spaces!
320 define sed-remove-objpfx
321 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
322 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
323 endef
324 endif
326 # Shared library building.
328 ifeq (yes,$(build-shared))
330 # Pattern rule to build a shared object from an archive of PIC objects.
331 # This must come after the installation rules so Make doesn't try to
332 # build shared libraries in place from the installed *_pic.a files.
333 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
334 # on other shared objects.
335 lib%.so: lib%_pic.a; $(build-shlib)
337 ifeq ($(have-no-whole-archive),yes)
338 no-whole-archive = -Wl,--no-whole-archive
339 else
340 no-whole-archive =
341 endif
343 ifeq ($(versioning),yes)
344 load-map-file = $($(@F:%.so=%)-map:%=-Wl,--version-script=%)
345 else
346 load-map-file =
347 endif
349 interp-obj = $(common-objpfx)interp.so
350 $(interp-obj): $(common-objpfx)%.so: $(..)%.c
351         $(compile-command.c)
352 common-generated += interp.so
353 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
355 $(common-objpfx)libc.so: $(interp-obj)
356 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
358 define build-shlib
359 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
360           -B$(csu-objpfx) $(load-map-file) \
361           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
362           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
363           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
364           -Wl,--whole-archive $^ $(no-whole-archive) \
365           $(LDLIBS-$(@F:lib%.so=%).so)
366 endef
368 # Don't try to use -lc when making libc.so itself.
369 # Also omits crti.o and crtn.o, which we do not want
370 # since we define our own `.init' section specially.
371 LDFLAGS-c.so = -nostdlib -nostartfiles
372 # But we still want to link libc.so against -lgcc.
373 LDLIBS-c.so = -lgcc
374 # Give libc.so an entry point and make it directly runnable itself.
375 LDFLAGS-c.so += -e __libc_main
376 # Use our own special initializer and finalizer files for libc.so.
377 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
378                          $(common-objpfx)libc_pic.a \
379                          $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
380         $(build-shlib)
382 ifdef libc.so-version
383 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
384         rm -f $@
385         ln -s $(<F) $@ || ln $< $@
386 endif
387 endif
389 # Some files must not be compiled with the exception handler mechanism
390 # enabled (introduced in gcc-2.8).  Use $(no-exceptions) in the
391 # appropriate CFLAGS definition.
392 ifeq ($(have-no-exceptions),yes)
393 no-exceptions = -fno-exceptions
394 else
395 no-exceptions =
396 endif
398 # Figure out the source filenames in this directory.
400 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
401                                                        $(routines) $(aux) \
402                                                        $(sysdep_routines)))
403 sysdep_routines := $(sysdep_routines)
405 headers := $(headers) $(sysdep_headers)
407 # This is the list of all object files, gotten by
408 # replacing every ".c" in `sources' with a ".o".
409 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
412 # The makefile may define $(extra-libs) with `libfoo libbar'
413 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
414 ifdef extra-libs
415 # extra-lib.mk is included once for each extra lib to define rules
416 # to build it, and to add its objects to the various variables.
417 # During its evaluation, $(lib) is set to the name of the library.
418 extra-libs-left := $(extra-libs)
419 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
420 endif
422 +depfiles := $(strip $(sources:.c=.d) \
423                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
424                      $(addsuffix .d,$(others) $(tests)))
425 +depfiles := $(addprefix $(objpfx),\
426                          $(filter-out $(addsuffix .d,$(omit-deps)),\
427                                       $(+depfiles)))
429 ifdef +depfiles
430 ifneq ($(no_deps),t)
431 -include $(+depfiles)
432 endif
433 endif
434 \f\f
435 # Maximize efficiency by minimizing the number of rules.
436 .SUFFIXES:      # Clear the suffix list.
437 # Add the suffixes we use.
438 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
440 # Generic rule for making directories.
442 # mkdir isn't smart enough to strip a trailing /.
443         mkdir $(@:%/=%)
445 # Make sure that object files are not removed
446 # when they are intermediates between sources and library members.
447 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
449 # Make sure that the parent library archive is never removed.
450 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
452 # Use the verbose option of ar and tar when not running silently.
453 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
454 verbose := v
455 else                                            # -s
456 verbose :=
457 endif                                           # not -s
459 ARFLAGS := r$(verbose)
461 # This makes all the object files in the parent library archive.
463 .PHONY: lib libobjs lib-noranlib
464 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
466 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
467 lib%.a: lib%.a($(ar-symtab-name)) ;
469 # For object-suffix $o, the list of objects with that suffix.
470 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
471 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
472                                                        $(elide-routines$o)),\
473                                             $(objects)))
475 libobjs: $(foreach o,$(object-suffixes),\
476                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
477                    $(notdir $(o-objects))))
478 lib-noranlib: libobjs
479 others: $(addprefix $(objpfx),$(install-lib))
481 ifndef objects
483 # Create the stamp$o files to keep the parent makefile happy.
484 subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir))
485 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)):
486         $(make-target-directory)
487         rm -f $@; > $@
488 else
490 # Define a pattern rule that will match many targets libc.a(foo.%), for
491 # each foo.o in $(objects) (% will just happen always to match `o').  This is
492 # the only way to define a rule that updates many targets at once with one
493 # sequence of commands.
494 define o-iterator-doit
495 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
496 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
497   $(objpfx)stamp.%-$(subdir) ;
498 endef
499 object-suffixes-left := $(object-suffixes)
500 include $(o-iterator)
502 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
503 # the way to update all the foo.% object files in $(objects).  Now we
504 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
505 # timestamp file; these rules (one explicit rule is generated for each
506 # object suffix) will update the parent archive with ar.  Use a static
507 # pattern rule so $* is set to the object type during the commands.
508 define o-iterator-doit
509 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
510 endef
511 object-suffixes-left := $(object-suffixes)
512 include $(o-iterator)
513 define do-ar
514 topdir=`cd $(..).; pwd`; \
515 $(patsubst %/,cd %;,$(objpfx)) \
516 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
517                                                   $(patsubst $(objpfx)%,%,$^)
518 rm -f $@
519 touch $@
520 endef
521 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
523 endif
525 # Rules to update the $(ar-symtab-name) member with ranlib,
526 # one for each object flavor.
527 define o-iterator-doit
528 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
529           $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
530             $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
531         $(SHELL) $$(..)./autolock.sh \
532           $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
533           $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
534 endef
535 ifndef subdir
536 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
537 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
538 $(subdirs-stamps): subdir_lib;
539 endif
540 object-suffixes-left = $(object-suffixes)
541 include $(o-iterator)
544 # This makes all the object files.
545 .PHONY: objects objs
546 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
547               $(addprefix $(objpfx),$(extra-objs))
549 # Canned sequence for building an extra library archive.
550 define build-extra-lib
551 $(patsubst %/,cd %;,$(objpfx)) \
552 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
553       $(patsubst $(objpfx)%,%,$^)
554 $(RANLIB) $@
555 endef
557 # Installation.
559 # $(install-lib) are installed from the object directory into $(libdir);
560 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
561 # unless they also appear in $(non-lib.a).  $(install-data) are installed
562 # as they are into $(datadir).  $(headers) are installed as they are in
563 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
564 # object directory into $(bindir) and $(sbindir), respectively.
565 # $(install-others) are absolute path names of files to install; rules to
566 # install them are defined elsewhere.
568 # The simple library name to install libc.a under.
569 # This could be defined by a sysdep Makefile.
570 ifndef libc-name
571 libc-name := c
572 endif
574 define do-install
575 $(make-target-directory)
576 $(INSTALL_DATA) $< $@
577 endef
579 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
580 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
581 define make-target-directory
582 $(addprefix $(..)./mkinstalldirs ,\
583             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
584 endef
586 # Any directory (parent or subdir) that has any object files to build
587 # should install libc.a; this way "make install" in a subdir is guaranteed
588 # to install everything it changes.
589 ifdef objects
590 installed-libcs := $(foreach o,$(object-suffixes),\
591                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
592                                                      $(libprefix)$(libc-name)))
593 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
594 install: $(installed-libcs)
595 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib
596         $(make-target-directory)
597         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
598 # Running ranlib after installing makes the __.SYMDEF time stamp up to
599 # date, which avoids messages from some linkers.
600         $(RANLIB) $@
601 endif
603 define do-install-program
604 $(make-target-directory)
605 $(INSTALL_PROGRAM) $< $@.new
606 mv -f $@.new $@
607 endef
609 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
610 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
611 ifeq (yes,$(build-shared))
613 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
615 # Find which .so's have versions.
616 versioned := $(strip $(foreach so,$(install-lib.so),\
617                                $(patsubst %,$(so),$($(so)-version))))
619 # Install all the unversioned shared libraries.
620 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
621         $(inst_slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
623 ifneq ($(findstring -s,$(LN_S)),)
624 define make-link
625 rm -f $@.new
626 $(SHELL) $(..)rellns-sh $< $@.new
627 mv -f $@.new $@
628 endef
629 else
630 # If we have no symbolic links don't bother with rellns-sh.
631 define make-link
632 rm -f $@.new
633 $(LN_S) $< $@.new
634 mv -f $@.new $@
635 endef
636 endif
638 # XXX The following will have to be changed when `ldconfig' is available.
639 ifneq (yes,$(cross-compiling))
640 ifeq (yes,$(has-ldconfig))
641 define make-shlib-link
643 endef
644 endif
645 endif
646 ifndef make-shlib-link
647 define make-shlib-link
648 $(make-link)
649 endef
650 endif
652 ifdef libc.so-version
653 # For a library specified to be version N, install three files:
654 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
655 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
657 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so
658         $(make-shlib-link)
659 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so
660         $(do-install-program)
661 install: $(inst_slibdir)/libc.so$(libc.so-version)
663 ifndef subdir
664 # What we install as libc.so for programs to link against is in fact a
665 # link script.  It contains references for the various libraries we need.
666 # The libc.so object is not complete since some functions are only defined
667 # in libc.a and the dynamic linker is an etra object.
668 install: $(inst_libdir)/libc.so
669 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
670                         $(elfobjdir)/$(rtld-installed-name) \
671                         $(inst_libdir)/lib$(libc-name).a
672         (echo '/* GNU ld script';\
673          echo '   Use the shared library, but some functions are only in';\
674          echo '   the static library, so try that secondarily.'; \
675          echo '   The dynamic linker defines some functions used by $(<F),';\
676          echo '   but ld uses definitions from libc.a before examining the';\
677          echo '   dependencies of $(<F) to find $(rtld-installed-name).  */';\
678          echo 'GROUP ( $(^F) )') > $@.new
679         mv -f $@.new $@
681 endif
683 else
684 install: $(inst_slibdir)/libc.so
685 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so
686         $(do-install-program)
687 endif
690 ifneq (,$(versioned))
691 # Produce three sets of rules as above for all the smaller versioned libraries.
693 define o-iterator-doit
694 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version); $$(make-link)
695 endef
696 object-suffixes-left := $(versioned)
697 include $(o-iterator)
699 # Make symlinks in the build directory, because the versioned names might
700 # be referenced by a DT_NEEDED in another library.
701 define o-iterator-doit
702 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
703 endef
704 object-suffixes-left := $(versioned)
705 include $(o-iterator)
708 ifeq (,$($(subdir)-version))
709 define o-iterator-doit
710 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so;
711         $$(make-shlib-link)
712 endef
713 object-suffixes-left := $(versioned)
714 include $(o-iterator)
716 define o-iterator-doit
717 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
718 endef
719 object-suffixes-left := $(versioned)
720 include $(o-iterator)
721 else
722 define o-iterator-doit
723 $(inst_slibdir)/$o$($o-version): \
724   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so;
725         $$(make-shlib-link)
726 endef
727 object-suffixes-left := $(versioned)
728 include $(o-iterator)
730 define o-iterator-doit
731 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
732         $$(do-install-program)
733 endef
734 object-suffixes-left := $(versioned)
735 include $(o-iterator)
736 endif
737 endif
739 define do-install-so
740 $(do-install-program)
741 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
742            $(filter-out %.so,$@))
743 endef
745 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
746 $(foreach v,$(so-versions),\
747           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
748         $(do-install-so)
749 $(foreach v,$(so-versions),\
750           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
751         $(do-install-so)
752 endif
754 ifdef install-bin
755 $(addprefix $(inst_bindir)/,$(install-bin)): $(inst_bindir)/%: $(objpfx)%
756         $(do-install-program)
757 endif
758 ifdef install-rootsbin
759 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)):
760    $(inst_rootsbindir)/%: $(objpfx)%
761         $(do-install-program)
762 endif
763 ifdef install-sbin
764 $(addprefix $(inst_sbindir)/,$(install-sbin)): $(inst_sbindir)/%: $(objpfx)%
765         $(do-install-program)
766 endif
767 ifdef install-lib
768 install-lib.a := $(filter lib%.a,$(install-lib))
769 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
770 ifdef install-lib-non.a
771 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
772   $(inst_libdir)/$(libprefix)%: $(objpfx)%
773         $(do-install)
774 endif
775 ifdef install-lib.a
776 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
777   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
778         $(do-install)
779         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
780 endif
781 endif
782 ifdef install-data
783 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: %;
784         $(do-install)
785 endif
786 headers := $(strip $(headers))
787 ifdef headers
788 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: %;
789         $(do-install)
790 endif   # headers
792 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
793         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
794 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
795 install-rootsbin-nosubdir: \
796         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
797 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
798 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
799                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
800                        $(addprefix $(libprefix),$(install-lib-non.a)))
801 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
802 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
803 install-others-nosubdir: $(install-others)
805 # We need all the `-nosubdir' targets so that `install' in the parent
806 # doesn't depend on several things which each iterate over the subdirs.
807 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
808 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
809 install-%:: install-%-nosubdir ;
811 .PHONY: install install-no-libc.a-nosubdir
812 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
813                             install-bin-nosubdir install-lib-nosubdir   \
814                             install-others-nosubdir install-rootsbin-nosubdir \
815                             install-sbin-nosubdir
816 install: install-no-libc.a-nosubdir
818 # Command to compile $< in $(objdir) using the native libraries.
819 define native-compile
820 $(make-target-directory)
821 $(patsubst %/,cd %;,$(objpfx)) \
822 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
823             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
824 endef
826 # Command to compile $< in $(common-objdir) using the native libraries.
827 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
828 define common-objdir-compile
829 $(patsubst %/,cd %;,$(objpfx)) \
830 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
831             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
832 endef
834 # We always want to use configuration definitions.
835 # Note that this is only used for commands running in $(objpfx).
836 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
838 # Support the GNU standard name for this target.
839 .PHONY: check
840 check: tests
842 .PHONY: TAGS
843 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
844         $(MAKE) $(addprefix -f ,$^) $@
846 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
847         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
848 FORCE:
851 .PHONY: echo-headers
852 echo-headers:
853         @echo $(headers)
856 # Common cleaning targets.
858 .PHONY: common-mostlyclean common-clean mostlyclean clean
859 clean: common-clean
860 mostlyclean: common-mostlyclean
862 # Remove the object files.
863 common-mostlyclean:
864         -rm -f $(addprefix $(objpfx),$(tests) $(others) \
865                                      $(addsuffix .o,$(tests) $(others)) \
866                                      $(addsuffix .out,$(tests)))
867         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
868         -rm -f core $(common-objpfx)stub-$(subdir)
869         $(rmobjs)
870 define rmobjs
871 $(foreach o,$(object-suffixes),
872 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
873 endef
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` \
897              /dev/null) > $@T
898         mv -f $@T $@
900 # Make the distribution tar file.
902 .PHONY: dist
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 \
915                                     $(wildcard $(foreach dir,$(sysdirs),\
916                                                          $(dir)/Makefile))
917         $(distinfo-vars)
918         mv -f $@.new $@
919 .PHONY: subdir_distinfo distinfo
920 subdir_distinfo: distinfo
921 distinfo: $(common-objpfx)distinfo-$(subdir)
923 define distinfo-vars
924 rm -f $@.new
925 echo > $@.new 'subdir := $(subdir)'
926 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
927               headers sysdep_headers distribute dont_distribute generated \
928               others tests extra-libs $(extra-libs:%=%-routines) \
929               versioned \
930               $(addprefix install-,lib lib.so data bin sbin others),
931 echo >> $@.new '$(subdir)-$(var) := $($(var))'
932 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
933 endef
935 ifneq (,$(strip $(gpl2lgpl)))
936 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
937 # Snarf from the master source and frob the copying notice.
938 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
939         sed -f $^ > $@-tmp
940 # So I don't edit them by mistake.
941         chmod a-w $@-tmp
942         mv -f $@-tmp $@
943         test ! -d CVS || cvs commit -m'Updated from $^' $@
944 endif
945 endif