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