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