update from main archive 961005
[glibc.git] / Makerules
blob132165bb3884bcf314e95f658f8be670fda6bbe7
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
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
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.
33 endif
36 ifdef   subdir
37 ..      := ../
38 endif   # subdir
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))" ""
43 sources :=
44 endif
46 oPATH := $(PATH)
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.
50 else
51 PATH := $(oPATH)
52 endif
54 ifndef +included-Makeconfig
55 include $(..)Makeconfig
56 endif
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)
66 ifdef objdir
67 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
68 endif
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.
77 ifeq (no,$(elf))
78 ar-symtab-name = __.SYMDEF
79 else
80 ar-symtab-name = # The null name is used in ELF archives.
81 endif
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).
93 in-Makerules := yes
95 ifndef avoid-generated
96 -include $(+sysdir_pfx)sysd-Makefile
97 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
98 sysd-Makefile-force = FORCE
99 FORCE:
100 endif
101 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
102                              $(sysd-Makefile-force)
103         -@rm -f $@T
104         (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)';                   \
105          for dir in $(config-sysdirs); do                                     \
106            file=$$dir/Makefile;                                               \
107            if [ -f $$file ]; then                                             \
108              case $$dir in                                                    \
109                /*) echo include "$$file" ;;                                   \
110                *)  echo include "\$$(..)$$file" ;;                            \
111              esac;                                                            \
112            else true; fi;                                                     \
113          done; \
114          echo 'sysd-Makefile-done=t') > $@T
115         mv -f $@T $@
116 endif
118 ifndef sysd-Makefile-done
119 # Don't do deps until this exists, because it might change the sources list.
120 no_deps=t
121 endif
124 # Reorder before-compile so that mach things come first, and hurd things
125 # second, before all else.  The mach and hurd subdirectories have many
126 # generated header files which the much of rest of the library depends on,
127 # so it is best to build them first (and mach before hurd, at that).
128 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
129                            $(before-compile)) \
130                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
131                                $(before-compile))
133 # Remove existing files from `before-compile'.  Things are added there when
134 # they must exist for dependency generation to work right, but once they
135 # exist there is no further need for every single file to depend on them,
136 # and those gratuitous dependencies result in many gratuitous
137 # recompilations.
138 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
140 # Don't let any before-compile file be an intermediate and get removed.
141 ifdef before-compile
142 $(before-compile):
143 endif
145 # Generate an ordered list of implicit rules which find the source files in
146 # each sysdep directory.  The old method was to use vpath to search all the
147 # sysdep directories.  However, that had the problem that a .S file in a
148 # later directory would be chosen over a .c file in an earlier directory,
149 # which does not preserve the desired sysdeps ordering behavior.
151 # When making the list of .d files to include, we can't know which ones
152 # have source in .s files, and thus do not in fact need a .d file.
153 # So we must define rules to make .d files for .s files.
154 define make-dummy-dep
155 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
156 endef
157 $(common-objpfx)dummy.d:
158         echo '# .s files cannot contain includes, so they need no deps.' > $@
160 # It matters that this set of rules, for compiling from sources in
161 # the current directory (the $srcdir/$subdir) come before the
162 # generated sysdep rules in included from sysd-rules below.  When
163 # compiling in the source tree, generated sources go into the current
164 # directory, and those should be chosen before any sources in sysdeps.
165 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
166 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
167 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
168 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
169 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
170 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
171 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
172 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
173 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
174 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
175 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
176 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
177 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
178 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
179 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
181 # Omit the objpfx rules when building in the source tree, because
182 # objpfx is empty and so these rules just override the ones above.
183 ifdef objpfx
184 # Define first rules to find the source files in $(objpfx).
185 # Generated source files will end up there.
186 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
187 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
188 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
189 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
190 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
191 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
192 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
193 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
194 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
195 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
196 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
197 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
198 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
199 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
200 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
201 endif
203 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
204 # patterns matching sysdep directories whose assembly source files should
205 # be suppressed.
206 ifdef inhibit-sysdep-asm
207 define open-check-inhibit-asm
208 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
209 endef
210 close-check-inhibit-asm = ;; esac ;
211 endif
213 # Don't include sysd-rules until sysd-Makefile is already there and has been
214 # included.  It might define inhibit-sysdep-asm, which would affect the
215 # contents of sysd-rules.
216 ifdef sysd-Makefile-done
217 -include $(+sysdir_pfx)sysd-rules
218 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
219 # The value of $(+sysdep_dirs) the sysd-rules was computed for
220 # differs from the one we are using now.  So force a rebuild of sysd-rules.
221 sysd-rules-force = FORCE
222 FORCE:
223 endif
224 endif
225 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
226                           $(wildcard $(foreach dir,$(sysdirs),\
227                                                $(dir)/Makefile))\
228                           $(sysd-rules-force)
229         -@rm -f $@T
230         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
231          for sysdir in $(config-sysdirs); do                                  \
232            case $$sysdir in \
233              /*) dir=$$sysdir ;; \
234              *)  dir="\$$(..)$$sysdir" ;; \
235            esac; \
236            for o in $(object-suffixes); do \
237              $(open-check-inhibit-asm) \
238              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
239                   \$$(compile-command.S)";                                    \
240              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
241                   \$$(compile-command.s)";                                    \
242              $(close-check-inhibit-asm) \
243              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
244                   \$$(compile-command.c)";                                    \
245            done; \
246            $(open-check-inhibit-asm) \
247            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
248                 \$$(make-dummy-dep)";                          \
249            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
250                 \$$(+make-deps)";                                             \
251            $(close-check-inhibit-asm)   \
252            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
253                 \$$(+make-deps)";                                             \
254          done;                                                                \
255          echo 'sysd-rules-done = t') > $@T
256         mv -f $@T $@
258 ifndef sysd-rules-done
259 # Don't do deps until this exists, because it provides rules to make the deps.
260 no_deps=t
261 endif
264 ifndef compile-command.S
265 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
266 endif
267 ifndef compile-command.s
268 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
269 endif
270 ifndef compile-command.c
271 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
272 endif
274 # GCC can grok options after the file name, and it looks nicer that way.
275 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
276 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
277 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
278 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
280 # We need this for the output to go in the right place.  It will default to
281 # empty if make was configured to work with a cc that can't grok -c and -o
282 # together.  You can't compile the C library with such a compiler.
283 OUTPUT_OPTION = -o $@
285 S-CPPFLAGS = $(asm-CPPFLAGS)
286 define +make-deps
287 $(make-target-directory)
288 -@rm -f $@
289 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
290 sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
291 $(sed-remove-objpfx) > $(@:.d=.T)
292 mv -f $(@:.d=.T) $@
293 endef
294 ifneq (,$(objpfx))
295 # Continuation lines here are dangerous because they introduce spaces!
296 define sed-remove-objpfx
297 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
298 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
299 endef
300 endif
302 # Shared library building.
304 ifeq (yes,$(build-shared))
306 # Pattern rule to build a shared object from an archive of PIC objects.
307 # This must come after the installation rules so Make doesn't try to
308 # build shared libraries in place from the installed *_pic.a files.
309 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
310 # on other shared objects.
311 lib%.so: lib%_pic.a; $(build-shlib)
313 ifeq ($(have-no-whole-archive),yes)
314 no-whole-archive = -Wl,--no-whole-archive
315 else
316 no-whole-archive =
317 endif
319 interp-obj = $(common-objpfx)interp.so
320 $(interp-obj): $(common-objpfx)%.so: $(..)%.c
321         $(compile-command.c)
322 common-generated += interp.so
323 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
325 $(common-objpfx)libc.so: $(interp-obj)
326 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
328 define build-shlib
329 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
330           -B$(csu-objpfx) \
331           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
332           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
333           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
334           -Wl,--whole-archive $^ $(no-whole-archive) \
335           $(LDLIBS-$(@F:lib%.so=%).so)
336 endef
338 # Don't try to use -lc when making libc.so itself.
339 # Also omits crti.o and crtn.o, which we do not want
340 # since we define our own `.init' section specially.
341 LDFLAGS-c.so = -nostdlib -nostartfiles
342 # Give libc.so an entry point and make it directly runnable itself.
343 LDFLAGS-c.so += -e __libc_main
344 # Use our own special initializer and finalizer files for libc.so.
345 elfobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)elf)
346 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
347                          $(common-objpfx)libc_pic.a \
348                          $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
349         $(build-shlib)
351 ifdef libc.so-version
352 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
353         rm -f $@
354         ln -s $(<F) $@ || ln $< $@
355 endif
356 endif
358 # Some files must not be compiled with the exception handler mechanism
359 # enabled (introduced in gcc-2.8).  Use $(no-exceptions) in the
360 # appropriate CFLAGS definition.
361 ifeq ($(have-no-exceptions),yes)
362 no-exceptions = -fno-exceptions
363 else
364 no-exceptions =
365 endif
367 # Figure out the source filenames in this directory.
369 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
370                                                        $(routines) $(aux) \
371                                                        $(sysdep_routines)))
372 sysdep_routines := $(sysdep_routines)
374 headers := $(headers) $(sysdep_headers)
376 # This is the list of all object files, gotten by
377 # replacing every ".c" in `sources' with a ".o".
378 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
381 # This variable is used in ``include $(o-iterator)'' after defining
382 # $(o-iterator-doit) to produce some desired rule using $o for the object
383 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
384 # is produced for each object suffix in use.
385 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
387 # The makefile may define $(extra-libs) with `libfoo libbar'
388 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
389 ifdef extra-libs
390 # extra-lib.mk is included once for each extra lib to define rules
391 # to build it, and to add its objects to the various variables.
392 # During its evaluation, $(lib) is set to the name of the library.
393 extra-libs-left := $(extra-libs)
394 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
395 endif
397 +depfiles := $(strip $(sources:.c=.d) \
398                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
399                      $(addsuffix .d,$(others) $(tests)))
400 +depfiles := $(addprefix $(objpfx),\
401                          $(filter-out $(addsuffix .d,$(omit-deps)),\
402                                       $(+depfiles)))
404 ifdef +depfiles
405 ifneq ($(no_deps),t)
406 -include $(+depfiles)
407 endif
408 endif
409 \f\f
410 # Maximize efficiency by minimizing the number of rules.
411 .SUFFIXES:      # Clear the suffix list.
412 # Add the suffixes we use.
413 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
415 # Generic rule for making directories.
417 # mkdir isn't smart enough to strip a trailing /.
418         mkdir $(@:%/=%)
420 # Make sure that object files are not removed
421 # when they are intermediates between sources and library members.
422 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
424 # Make sure that the parent library archive is never removed.
425 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
427 # Use the verbose option of ar and tar when not running silently.
428 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
429 verbose := v
430 else                                            # -s
431 verbose :=
432 endif                                           # not -s
434 ARFLAGS := r$(verbose)
436 # This makes all the object files in the parent library archive.
438 .PHONY: lib libobjs lib-noranlib
439 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
441 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
442 lib%.a: lib%.a($(ar-symtab-name)) ;
444 # For object-suffix $o, the list of objects with that suffix.
445 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
446 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
447                                                        $(elide-routines$o)),\
448                                             $(objects)))
450 libobjs: $(foreach o,$(object-suffixes),\
451                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
452                    $(notdir $(o-objects))))
453 lib-noranlib: libobjs
454 others: $(addprefix $(objpfx),$(install-lib))
456 ifndef objects
458 # Create the stamp$o files to keep the parent makefile happy.
459 subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir))
460 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)):
461         $(make-target-directory)
462         rm -f $@; > $@
463 else
465 # Define a pattern rule that will match many targets libc.a(foo.%), for
466 # each foo.o in $(objects) (% will just happen always to match `o').  This is
467 # the only way to define a rule that updates many targets at once with one
468 # sequence of commands.
469 define o-iterator-doit
470 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
471 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
472   $(objpfx)stamp.%-$(subdir) ;
473 endef
474 object-suffixes-left := $(object-suffixes)
475 include $(o-iterator)
477 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
478 # the way to update all the foo.% object files in $(objects).  Now we
479 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
480 # timestamp file; these rules (one explicit rule is generated for each
481 # object suffix) will update the parent archive with ar.  Use a static
482 # pattern rule so $* is set to the object type during the commands.
483 define o-iterator-doit
484 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
485 endef
486 object-suffixes-left := $(object-suffixes)
487 include $(o-iterator)
488 define do-ar
489 topdir=`cd $(..).; pwd`; \
490 $(patsubst %/,cd %;,$(objpfx)) \
491 $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
492                                          $(patsubst $(objpfx)%,%,$^)
493 rm -f $@
494 touch $@
495 endef
496 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
498 endif
500 # Rules to update the $(ar-symtab-name) member with ranlib,
501 # one for each object flavor.
502 define o-iterator-doit
503 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
504           $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
505             $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
506         $$(..)./autolock.sh \
507           $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
508           $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
509 endef
510 ifndef subdir
511 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
512 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
513 $(subdirs-stamps): subdir_lib;
514 endif
515 object-suffixes-left = $(object-suffixes)
516 include $(o-iterator)
519 # This makes all the object files.
520 .PHONY: objects objs
521 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
522               $(addprefix $(objpfx),$(extra-objs))
524 # Canned sequence for building an extra library archive.
525 define build-extra-lib
526 $(patsubst %/,cd %;,$(objpfx)) \
527 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
528       $(patsubst $(objpfx)%,%,$^)
529 $(RANLIB) $@
530 endef
532 # Installation.
534 # $(install-lib) are installed from the object directory into $(libdir);
535 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
536 # unless they also appear in $(non-lib.a).  $(install-data) are installed
537 # as they are into $(datadir).  $(headers) are installed as they are in
538 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
539 # object directory into $(bindir) and $(sbindir), respectively.
540 # $(install-others) are absolute path names of files to install; rules to
541 # install them are defined elsewhere.
543 # The simple library name to install libc.a under.
544 # This could be defined by a sysdep Makefile.
545 ifndef libc-name
546 libc-name := c
547 endif
549 define do-install
550 $(make-target-directory)
551 $(INSTALL_DATA) $< $@
552 endef
554 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
555 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
556 define make-target-directory
557 $(addprefix $(..)./mkinstalldirs ,\
558             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
559 endef
561 # Any directory (parent or subdir) that has any object files to build
562 # should install libc.a; this way "make install" in a subdir is guaranteed
563 # to install everything it changes.
564 ifdef objects
565 installed-libcs := $(foreach o,$(object-suffixes),\
566                              $(libdir)/$(patsubst %,$(libtype$o),\
567                                                   $(libprefix)$(libc-name)))
568 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
569 install: $(installed-libcs)
570 $(installed-libcs): $(libdir)/lib$(libprefix)%: lib
571         $(make-target-directory)
572         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
573 # Running ranlib after installing makes the __.SYMDEF time stamp up to
574 # date, which avoids messages from some linkers.
575         $(RANLIB) $@
576 endif
578 define do-install-program
579 $(make-target-directory)
580 $(INSTALL_PROGRAM) $< $@.new
581 mv -f $@.new $@
582 endef
584 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
585 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
586 ifeq (yes,$(build-shared))
588 install-lib-nosubdir: $(install-lib.so:%=$(libdir)/%)
590 # Find which .so's have versions.
591 versioned := $(strip $(foreach so,$(install-lib.so),\
592                                $(patsubst %,$(so),$($(so)-version))))
594 # Install all the unversioned shared libraries.
595 $(addprefix $(libdir)/,$(filter-out $(versioned),$(install-lib.so))): \
596 $(libdir)/%.so: $(objpfx)%.so; $(do-install-program)
598 define make-link
599 cd $(@D); rm -f $(@F).new; $(LN_S) $(<F) $(@F).new; mv -f $(@F).new $(@F)
600 endef
602 ifdef libc.so-version
603 # For a library specified to be version N, install three files:
604 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
605 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
607 $(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so
608         $(make-link)
609 $(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program)
610 install: $(slibdir)/libc.so$(libc.so-version)
612 ifndef subdir
613 # What we install as libc.so for programs to link against is in fact a
614 # link script.  It contains references for the various libraries we need.
615 # The libc.so object is not complete since some functions are only defined
616 # in libc.a and the dynamic linker is an etra object.
617 install: $(libdir)/libc.so
618 $(libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
619                    $(elfobjdir)/$(rtld-installed-name) \
620                    $(common-objpfx)libc.a
621         (echo '/* Use the shared library, but some functions are only in';\
622          echo '   the static library, so try that secondarily.'; \
623          echo '   The dynamic linker defines some functions used by $(<F),';\
624          echo '   but ld uses definitions from libc.a before examining the';\
625          echo '   dependencies of $(<F) to find $(rtld-installed-name).  */';\
626          echo 'GROUP ( $(^F) )') > $@.new
627         mv -f $@.new $@
629 endif
631 else
632 install: $(slibdir)/libc.so
633 $(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program)
634 endif
637 ifneq (,$(versioned))
638 # Produce three sets of rules as above for all the smaller versioned libraries.
640 define o-iterator-doit
641 $(libdir)/$o: $(libdir)/$o$($o-version); $$(make-link)
642 endef
643 object-suffixes-left := $(versioned)
644 include $(o-iterator)
646 # Make symlinks in the build directory, because the versioned names might
647 # be referenced by a DT_NEEDED in another library.
648 define o-iterator-doit
649 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
650 endef
651 object-suffixes-left := $(versioned)
652 include $(o-iterator)
655 ifeq (,$($(subdir)-version))
656 define o-iterator-doit
657 $(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$(version).so; $$(make-link)
658 endef
659 object-suffixes-left := $(versioned)
660 include $(o-iterator)
662 define o-iterator-doit
663 $(libdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
664 endef
665 object-suffixes-left := $(versioned)
666 include $(o-iterator)
667 else
668 define o-iterator-doit
669 $(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$($(subdir)-version).so;
670         $$(make-link)
671 endef
672 object-suffixes-left := $(versioned)
673 include $(o-iterator)
675 define o-iterator-doit
676 $(libdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
677         $$(do-install-program)
678 endef
679 object-suffixes-left := $(versioned)
680 include $(o-iterator)
681 endif
682 endif
684 define do-install-so
685 $(do-install-program)
686 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
687            $(filter-out %.so,$@))
688 endef
690 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
691 $(foreach v,$(so-versions),\
692           $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
693         $(do-install-so)
694 $(foreach v,$(so-versions),\
695           $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so
696         $(do-install-so)
697 endif
699 ifdef install-bin
700 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
701         $(do-install-program)
702 endif
703 ifdef install-sbin
704 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
705         $(do-install-program)
706 endif
707 ifdef install-lib
708 install-lib.a := $(filter lib%.a,$(install-lib))
709 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
710 ifdef install-lib-non.a
711 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
712   $(libdir)/$(libprefix)%: $(objpfx)%
713         $(do-install)
714 endif
715 ifdef install-lib.a
716 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
717   $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
718         $(do-install)
719         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
720 endif
721 endif
722 ifdef install-data
723 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
724 endif
725 headers := $(strip $(headers))
726 ifdef headers
727 $(addprefix $(includedir)/,$(headers)): \
728         $(includedir)/%: %;$(do-install)
729 endif   # headers
731 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
732         install-data-nosubdir install-headers-nosubdir
733 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
734 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
735 install-lib-nosubdir: $(addprefix $(libdir)/,\
736                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
737                        $(addprefix $(libprefix),$(install-lib-non.a)))
738 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
739 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
740 install-others-nosubdir: $(install-others)
742 # We need all the `-nosubdir' targets so that `install' in the parent
743 # doesn't depend on several things which each iterate over the subdirs.
744 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
745 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
746 install-%:: install-%-nosubdir ;
748 .PHONY: install install-no-libc.a-nosubdir
749 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
750                             install-bin-nosubdir install-lib-nosubdir   \
751                             install-others-nosubdir install-sbin-nosubdir
752 install: install-no-libc.a-nosubdir
754 # Command to compile $< in $(objdir) using the native libraries.
755 define native-compile
756 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
757            $(addprefix $$cwd/,$^) -o $(@F)
758 endef
760 # Command to compile $< in $(common-objdir) using the native libraries.
761 define common-objdir-compile
762 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
763 endef
765 # We always want to use configuration definitions.
766 BUILD_CFLAGS = -include $(common-objpfx)config.h
768 # Support the GNU standard name for this target.
769 .PHONY: check
770 check: tests
772 .PHONY: TAGS
773 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
774         $(MAKE) $(addprefix -f ,$^) $@
776 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
777         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
778 FORCE:
781 .PHONY: echo-headers
782 echo-headers:
783         @echo $(headers)
786 # Common cleaning targets.
788 .PHONY: common-mostlyclean common-clean mostlyclean clean
789 clean: common-clean
790 mostlyclean: common-mostlyclean
792 # Remove the object files.
793 common-mostlyclean:
794         -rm -f $(addprefix $(objpfx),$(tests) $(others) \
795                                      $(addsuffix .o,$(tests) $(others)) \
796                                      $(addsuffix .out,$(tests)))
797         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
798         -rm -f core $(common-objpfx)stub-$(subdir)
799         $(rmobjs)
800 define rmobjs
801 $(foreach o,$(object-suffixes),
802 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
803 endef
805 # Also remove the dependencies and generated source files.
806 common-clean: common-mostlyclean
807         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
808         -rm -f $(addprefix $(common-objpfx),$(common-generated))
809         -rm -f $(common-objpfx)distinfo-$(subdir)
811 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
812 # for each function which is a stub.  We grovel over all the .d files
813 # looking for references to source files in sysdeps/stub.  Then we grovel
814 # over each referenced source file to see what stub function it defines.
816 .PHONY: stubs # The parent Makefile calls this target.
817 stubs: $(common-objpfx)stub-$(subdir)
818 s = $(sysdep_dir)/stub
819 $(common-objpfx)stub-$(subdir): $(+depfiles)
820 # Use /dev/null since `...` might expand to empty.
821         (s=`cd $s; /bin/pwd`; \
822          $(patsubst %/,cd %;,$(objpfx)) \
823          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
824              `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
825                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
826              /dev/null) > $@T
827         mv -f $@T $@
829 # Make the distribution tar file.
831 .PHONY: dist
832 dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
833         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
835 # Avoid depending on source files found in sysdeps dirs,
836 # because the references affect implicit rule selection.
837 dist: $(filter-out %.c %.S %.s,$(distribute))
839 # We used to simply export all these variables, but that frequently made the
840 # environment get too large.  Instead, we write all the information into
841 # a generated makefile fragment `distinfo', and then include it with -f in
842 # the sub-make that makes the distribution (above).
843 $(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules
844         $(distinfo-vars)
845         mv -f $@.new $@
846 .PHONY: subdir_distinfo distinfo
847 subdir_distinfo: distinfo
848 distinfo: $(common-objpfx)distinfo-$(subdir)
850 define distinfo-vars
851 rm -f $@.new
852 echo > $@.new 'subdir := $(subdir)'
853 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
854               headers sysdep_headers distribute dont_distribute generated \
855               others tests extra-libs $(extra-libs:%=%-routines) \
856               versioned \
857               $(addprefix install-,lib lib.so data bin sbin others),
858 echo >> $@.new '$(subdir)-$(var) := $($(var))'
859 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
860 endef
862 ifneq (,$(strip $(gpl2lgpl)))
863 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
864 # Snarf from the master source and frob the copying notice.
865 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
866         sed -f $^ > $@-tmp
867 # So I don't edit them by mistake.
868         chmod a-w $@-tmp
869         mv -f $@-tmp $@
870         test ! -d CVS || cvs commit -m'Updated from $^' $@
871 endif
872 endif