Update.
[glibc.git] / Makerules
blob4151c2357b492fff3920954f0d34d5b2c2625990
1 # Copyright (C) 1991, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version.  See above for the version needed.
34 endif
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq   "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full-config-sysdirs))
62 +sysdir_pfx = $(common-objpfx)
64 export sysdirs := $(sysdirs)
66 +sysdep_dirs := $(full-config-sysdirs)
67 ifdef objdir
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
69 endif
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
75 # The name of the symbol table archive member.  The default is suitable for
76 # BSD style archives.  It can be overridden in sysdep Makefiles when SYSV
77 # style archive are used.
78 ifeq (no,$(elf))
79 ar-symtab-name = __.SYMDEF
80 else
81 ar-symtab-name = # The null name is used in ELF archives.
82 endif
84 # 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 $(all-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 \
296 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
297 $(sed-remove-objpfx) > $(@:.d=.T)
298 mv -f $(@:.d=.T) $@
299 endef
300 ifneq (,$(objpfx))
301 # Continuation lines here are dangerous because they introduce spaces!
302 define sed-remove-objpfx
303 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
304 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
305 endef
306 endif
308 # Shared library building.
310 ifeq (yes,$(build-shared))
312 # Pattern rule to build a shared object from an archive of PIC objects.
313 # This must come after the installation rules so Make doesn't try to
314 # build shared libraries in place from the installed *_pic.a files.
315 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
316 # on other shared objects.
317 lib%.so: lib%_pic.a; $(build-shlib)
319 ifeq ($(have-no-whole-archive),yes)
320 no-whole-archive = -Wl,--no-whole-archive
321 else
322 no-whole-archive =
323 endif
325 interp-obj = $(common-objpfx)interp.so
326 $(interp-obj): $(common-objpfx)%.so: $(..)%.c
327         $(compile-command.c)
328 common-generated += interp.so
329 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
331 $(common-objpfx)libc.so: $(interp-obj)
332 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
334 define build-shlib
335 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
336           -B$(csu-objpfx) \
337           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
338           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
339           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
340           -Wl,--whole-archive $^ $(no-whole-archive) \
341           $(LDLIBS-$(@F:lib%.so=%).so)
342           test -z "$($(@F)-version)" || \
343             (rm -f $@$($(@F)-version); $(LN_S) $(@F) $@$($(@F)-version))
344 endef
346 # Don't try to use -lc when making libc.so itself.
347 # Also omits crti.o and crtn.o, which we do not want
348 # since we define our own `.init' section specially.
349 LDFLAGS-c.so = -nostdlib -nostartfiles
350 # But we still want to link libc.so against -lgcc.
351 LDLIBS-c.so = -lgcc
352 # Give libc.so an entry point and make it directly runnable itself.
353 LDFLAGS-c.so += -e __libc_main
354 # Use our own special initializer and finalizer files for libc.so.
355 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
356                          $(common-objpfx)libc_pic.a \
357                          $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
358         $(build-shlib)
359 endif
361 # Some files must not be compiled with the exception handler mechanism
362 # enabled (introduced in gcc-2.8).  Use $(no-exceptions) in the
363 # appropriate CFLAGS definition.
364 ifeq ($(have-no-exceptions),yes)
365 no-exceptions = -fno-exceptions
366 else
367 no-exceptions =
368 endif
370 # Figure out the source filenames in this directory.
372 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
373                                                        $(routines) $(aux) \
374                                                        $(sysdep_routines)))
375 sysdep_routines := $(sysdep_routines)
377 headers := $(headers) $(sysdep_headers)
379 # This is the list of all object files, gotten by
380 # replacing every ".c" in `sources' with a ".o".
381 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
384 # This variable is used in ``include $(o-iterator)'' after defining
385 # $(o-iterator-doit) to produce some desired rule using $o for the object
386 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
387 # is produced for each object suffix in use.
388 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
390 # The makefile may define $(extra-libs) with `libfoo libbar'
391 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
392 ifdef extra-libs
393 # extra-lib.mk is included once for each extra lib to define rules
394 # to build it, and to add its objects to the various variables.
395 # During its evaluation, $(lib) is set to the name of the library.
396 extra-libs-left := $(extra-libs)
397 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
398 endif
400 +depfiles := $(strip $(sources:.c=.d) \
401                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
402                      $(addsuffix .d,$(others) $(tests) $(test-srcs)))
403 +depfiles := $(addprefix $(objpfx),\
404                          $(filter-out $(addsuffix .d,$(omit-deps)),\
405                                       $(+depfiles)))
407 ifdef +depfiles
408 ifneq ($(no_deps),t)
409 -include $(+depfiles)
410 endif
411 endif
412 \f\f
413 # Maximize efficiency by minimizing the number of rules.
414 .SUFFIXES:      # Clear the suffix list.
415 # Add the suffixes we use.
416 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
418 # Generic rule for making directories.
420 # mkdir isn't smart enough to strip a trailing /.
421         mkdir $(@:%/=%)
423 # Make sure that object files are not removed
424 # when they are intermediates between sources and library members.
425 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
427 # Make sure that the parent library archive is never removed.
428 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
430 # Use the verbose option of ar and tar when not running silently.
431 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
432 verbose := v
433 else                                            # -s
434 verbose :=
435 endif                                           # not -s
437 ARFLAGS := r$(verbose)
439 # This makes all the object files in the parent library archive.
441 .PHONY: lib libobjs lib-noranlib
442 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
444 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
445 lib%.a: lib%.a($(ar-symtab-name)) ;
447 # For object-suffix $o, the list of objects with that suffix.
448 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
449 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
450                                                        $(elide-routines$o)),\
451                                             $(objects)))
453 libobjs: $(foreach o,$(object-suffixes),\
454                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
455                    $(notdir $(o-objects))))
456 lib-noranlib: libobjs
457 others: $(addprefix $(objpfx),$(install-lib))
459 ifndef objects
461 # Create the stamp$o files to keep the parent makefile happy.
462 subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir))
463 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)):
464         $(make-target-directory)
465         rm -f $@; > $@
466 else
468 # Define a pattern rule that will match many targets libc.a(foo.%), for
469 # each foo.o in $(objects) (% will just happen always to match `o').  This is
470 # the only way to define a rule that updates many targets at once with one
471 # sequence of commands.
472 define o-iterator-doit
473 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
474 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
475   $(objpfx)stamp.%-$(subdir) ;
476 endef
477 object-suffixes-left := $(object-suffixes)
478 include $(o-iterator)
480 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
481 # the way to update all the foo.% object files in $(objects).  Now we
482 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
483 # timestamp file; these rules (one explicit rule is generated for each
484 # object suffix) will update the parent archive with ar.  Use a static
485 # pattern rule so $* is set to the object type during the commands.
486 define o-iterator-doit
487 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
488 endef
489 object-suffixes-left := $(object-suffixes)
490 include $(o-iterator)
491 define do-ar
492 topdir=`cd $(..).; pwd`; \
493 $(patsubst %/,cd %;,$(objpfx)) \
494 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
495                                                   $(patsubst $(objpfx)%,%,$^)
496 rm -f $@
497 touch $@
498 endef
499 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
501 endif
503 # Rules to update the $(ar-symtab-name) member with ranlib,
504 # one for each object flavor.
505 define o-iterator-doit
506 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
507           $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
508             $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
509         $(SHELL) $$(..)./autolock.sh \
510           $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
511           $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
512 endef
513 ifndef subdir
514 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
515 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
516 $(subdirs-stamps): subdir_lib;
517 endif
518 object-suffixes-left = $(object-suffixes)
519 include $(o-iterator)
522 # This makes all the object files.
523 .PHONY: objects objs
524 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
525               $(addprefix $(objpfx),$(extra-objs))
527 # Canned sequence for building an extra library archive.
528 define build-extra-lib
529 $(patsubst %/,cd %;,$(objpfx)) \
530 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
531       $(patsubst $(objpfx)%,%,$^)
532 $(RANLIB) $@
533 endef
535 # Installation.
537 # $(install-lib) are installed from the object directory into $(libdir);
538 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
539 # unless they also appear in $(non-lib.a).  $(install-data) are installed
540 # as they are into $(datadir).  $(headers) are installed as they are in
541 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
542 # object directory into $(bindir) and $(sbindir), respectively.
543 # $(install-others) are absolute path names of files to install; rules to
544 # install them are defined elsewhere.
546 # The simple library name to install libc.a under.
547 # This could be defined by a sysdep Makefile.
548 ifndef libc-name
549 libc-name := c
550 endif
552 define do-install
553 $(make-target-directory)
554 $(INSTALL_DATA) $< $@
555 endef
557 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
558 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
559 define make-target-directory
560 $(addprefix $(..)./mkinstalldirs ,\
561             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
562 endef
564 # Any directory (parent or subdir) that has any object files to build
565 # should install libc.a; this way "make install" in a subdir is guaranteed
566 # to install everything it changes.
567 ifdef objects
568 installed-libcs := $(foreach o,$(object-suffixes),\
569                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
570                                                      $(libprefix)$(libc-name)))
571 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
572 install: $(installed-libcs)
573 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib
574         $(make-target-directory)
575         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
576 # Running ranlib after installing makes the __.SYMDEF time stamp up to
577 # date, which avoids messages from some linkers.
578         $(RANLIB) $@
579 endif
581 define do-install-program
582 $(make-target-directory)
583 $(INSTALL_PROGRAM) $< $@.new
584 mv -f $@.new $@
585 endef
587 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
588 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
589 ifeq (yes,$(build-shared))
591 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
593 # Find which .so's have versions.
594 versioned := $(strip $(foreach so,$(install-lib.so),\
595                                $(patsubst %,$(so),$($(so)-version))))
597 # Install all the unversioned shared libraries.
598 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
599         $(inst_slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
601 ifneq ($(findstring -s,$(LN_S)),)
602 define make-link
603 rm -f $@.new
604 $(SHELL) $(..)rellns-sh $< $@.new
605 mv -f $@.new $@
606 endef
607 else
608 # If we have no symbolic links don't bother with rellns-sh.
609 define make-link
610 rm -f $@.new
611 $(LN_S) $< $@.new
612 mv -f $@.new $@
613 endef
614 endif
616 # XXX The following will have to be changed when `ldconfig' is available.
617 ifneq (yes,$(cross-compiling))
618 ifeq (yes,$(has-ldconfig))
619 define make-shlib-link
621 endef
622 endif
623 endif
624 ifndef make-shlib-link
625 define make-shlib-link
626 $(make-link)
627 endef
628 endif
630 ifdef libc.so-version
631 # For a library specified to be version N, install three files:
632 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
633 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
635 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so
636         $(make-shlib-link)
637 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so
638         $(do-install-program)
639 install: $(inst_slibdir)/libc.so$(libc.so-version)
641 ifndef subdir
642 # What we install as libc.so for programs to link against is in fact a
643 # link script.  It contains references for the various libraries we need.
644 # The libc.so object is not complete since some functions are only defined
645 # in libc.a and the dynamic linker is an etra object.
646 install: $(inst_libdir)/libc.so
647 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
648                         $(elfobjdir)/$(rtld-installed-name) \
649                         $(inst_libdir)/lib$(libc-name).a
650         (echo '/* GNU ld script';\
651          echo '   Use the shared library, but some functions are only in';\
652          echo '   the static library, so try that secondarily.'; \
653          echo '   The dynamic linker defines some functions used by $(<F),';\
654          echo '   but ld uses definitions from libc.a before examining the';\
655          echo '   dependencies of $(<F) to find $(rtld-installed-name).  */';\
656          echo 'GROUP ( $(^F) )') > $@.new
657         mv -f $@.new $@
659 endif
661 else
662 install: $(inst_slibdir)/libc.so
663 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so
664         $(do-install-program)
665 endif
668 ifneq (,$(versioned))
669 # Produce three sets of rules as above for all the smaller versioned libraries.
671 define o-iterator-doit
672 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version); $$(make-link)
673 endef
674 object-suffixes-left := $(versioned)
675 include $(o-iterator)
677 # Make symlinks in the build directory, because the versioned names might
678 # be referenced by a DT_NEEDED in another library.
679 define o-iterator-doit
680 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
681 endef
682 object-suffixes-left := $(versioned)
683 include $(o-iterator)
686 ifeq (,$($(subdir)-version))
687 define o-iterator-doit
688 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so;
689         $$(make-shlib-link)
690 endef
691 object-suffixes-left := $(versioned)
692 include $(o-iterator)
694 define o-iterator-doit
695 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
696 endef
697 object-suffixes-left := $(versioned)
698 include $(o-iterator)
699 else
700 define o-iterator-doit
701 $(inst_slibdir)/$o$($o-version): \
702   $(inst_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 $(inst_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           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
726         $(do-install-so)
727 $(foreach v,$(so-versions),\
728           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
729         $(do-install-so)
730 endif
732 ifdef install-bin
733 $(addprefix $(inst_bindir)/,$(install-bin)): $(inst_bindir)/%: $(objpfx)%
734         $(do-install-program)
735 endif
736 ifdef install-rootsbin
737 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)):
738    $(inst_rootsbindir)/%: $(objpfx)%
739         $(do-install-program)
740 endif
741 ifdef install-sbin
742 $(addprefix $(inst_sbindir)/,$(install-sbin)): $(inst_sbindir)/%: $(objpfx)%
743         $(do-install-program)
744 endif
745 ifdef install-lib
746 install-lib.a := $(filter lib%.a,$(install-lib))
747 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
748 ifdef install-lib-non.a
749 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
750   $(inst_libdir)/$(libprefix)%: $(objpfx)%
751         $(do-install)
752 endif
753 ifdef install-lib.a
754 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
755   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
756         $(do-install)
757         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
758 endif
759 endif
760 ifdef install-data
761 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: %;
762         $(do-install)
763 endif
764 headers := $(strip $(headers))
765 ifdef headers
766 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: %;
767         $(do-install)
768 endif   # headers
770 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
771         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
772 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
773 install-rootsbin-nosubdir: \
774         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
775 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
776 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
777                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
778                        $(addprefix $(libprefix),$(install-lib-non.a)))
779 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
780 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
781 install-others-nosubdir: $(install-others)
783 # We need all the `-nosubdir' targets so that `install' in the parent
784 # doesn't depend on several things which each iterate over the subdirs.
785 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
786 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
787 install-%:: install-%-nosubdir ;
789 .PHONY: install install-no-libc.a-nosubdir
790 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
791                             install-bin-nosubdir install-lib-nosubdir   \
792                             install-others-nosubdir install-rootsbin-nosubdir \
793                             install-sbin-nosubdir
794 install: install-no-libc.a-nosubdir
796 # Command to compile $< in $(objdir) using the native libraries.
797 define native-compile
798 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
799            $(addprefix $$cwd/,$^) -o $(@F)
800 endef
802 # Command to compile $< in $(common-objdir) using the native libraries.
803 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
804 define common-objdir-compile
805 cd $(objpfx).; \
806 $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=$(..)%) -o $(..)$(@F)
807 endef
809 # We always want to use configuration definitions.
810 BUILD_CFLAGS = -include $(common-objpfx)config.h
812 # Support the GNU standard name for this target.
813 .PHONY: check
814 check: tests
816 .PHONY: TAGS
817 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
818         $(MAKE) $(addprefix -f ,$^) $@
820 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
821         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
822 FORCE:
825 .PHONY: echo-headers
826 echo-headers:
827         @echo $(headers)
830 # Common cleaning targets.
832 .PHONY: common-mostlyclean common-clean mostlyclean clean
833 clean: common-clean
834 mostlyclean: common-mostlyclean
836 # Remove the object files.
837 common-mostlyclean:
838         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
839                                      $(addsuffix .o,$(tests) $(test-srcs) \
840                                                     $(others)) \
841                                      $(addsuffix .out,$(tests) $(test-srcs)))
842         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
843         -rm -f core $(common-objpfx)stub-$(subdir)
844         $(rmobjs)
845 define rmobjs
846 $(foreach o,$(object-suffixes),
847 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
848 endef
850 # Also remove the dependencies and generated source files.
851 common-clean: common-mostlyclean
852         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
853         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
854         -rm -f $(addprefix $(common-objpfx),$(common-generated))
855         -rm -f $(common-objpfx)distinfo-$(subdir)
857 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
858 # for each function which is a stub.  We grovel over all the .d files
859 # looking for references to source files in sysdeps/stub.  Then we grovel
860 # over each referenced source file to see what stub function it defines.
862 .PHONY: stubs # The parent Makefile calls this target.
863 stubs: $(common-objpfx)stub-$(subdir)
864 s = $(sysdep_dir)/stub
865 $(common-objpfx)stub-$(subdir): $(+depfiles)
866 # Use /dev/null since `...` might expand to empty.
867         (s=`cd $s; /bin/pwd`; \
868          $(patsubst %/,cd %;,$(objpfx)) \
869          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
870              `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
871                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
872              /dev/null) > $@T
873         mv -f $@T $@
875 # Make the distribution tar file.
877 .PHONY: dist
878 dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
879         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
881 # Avoid depending on source files found in sysdeps dirs,
882 # because the references affect implicit rule selection.
883 dist: $(filter-out %.c %.S %.s,$(distribute))
885 # We used to simply export all these variables, but that frequently made the
886 # environment get too large.  Instead, we write all the information into
887 # a generated makefile fragment `distinfo', and then include it with -f in
888 # the sub-make that makes the distribution (above).
889 $(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules
890         $(distinfo-vars)
891         mv -f $@.new $@
892 .PHONY: subdir_distinfo distinfo
893 subdir_distinfo: distinfo
894 distinfo: $(common-objpfx)distinfo-$(subdir)
896 define distinfo-vars
897 rm -f $@.new
898 echo > $@.new 'subdir := $(subdir)'
899 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
900               headers sysdep_headers distribute dont_distribute generated \
901               others tests extra-libs $(extra-libs:%=%-routines) \
902               versioned \
903               $(addprefix install-,lib lib.so data bin sbin others),
904 echo >> $@.new '$(subdir)-$(var) := $($(var))'
905 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
906 endef
908 ifneq (,$(strip $(gpl2lgpl)))
909 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
910 # Snarf from the master source and frob the copying notice.
911 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
912         sed -f $^ > $@-tmp
913 # So I don't edit them by mistake.
914         chmod a-w $@-tmp
915         mv -f $@-tmp $@
916         test ! -d CVS || cvs commit -m'Updated from $^' $@
917 endif
918 endif