* time/tzfile.h, time/private.h, time/zdump.c, time/zic.c,
[glibc.git] / Makerules
blobd770957bf2144ef57f8fd67d38087cedafde47ab
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
29 ifdef   subdir
30 ..      := ../
31 endif   # subdir
33 # If `sources' was defined by the parent makefile, undefine it so
34 # we will later get it from wildcard search in this directory.
35 ifneq   "$(findstring env,$(origin sources))" ""
36 sources :=
37 endif
39 headers := $(headers) $(sysdep_headers)
41 oPATH := $(PATH)
42 PATH := this definition should take precedence over $(oPATH)
43 ifeq ($(PATH),$(oPATH))
44 You must not use the -e flag when building the GNU C library.
45 else
46 PATH := $(oPATH)
47 endif
49 ifndef +included-Makeconfig
50 include $(..)Makeconfig
51 endif
53 # `configure' writes a definition of `config-sysdirs' in `config.make'.
54 sysdirs = $(config-sysdirs)
56 +sysdir_pfx = $(common-objpfx)
58 export sysdirs := $(sysdirs)
60 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
61 ifdef objdir
62 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
63 endif
65 # Add -I switches to get the right sysdep directories.
66 # `+includes' in Makeconfig references $(+sysdep-includes).
67 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
69 # The name of the symbol table archive member.  The default is suitable for
70 # BSD style archives.  It can be overridden in sysdep Makefiles when SYSV
71 # style archive are used.
72 ifeq (no,$(elf))
73 ar-symtab-name = __.SYMDEF
74 else
75 ar-symtab-name = # The null name is used in ELF archives.
76 endif
78 # Include any system-specific makefiles.
80 # This is here so things in sysdep Makefiles can easily depend on foo.h as
81 # appropriate and not worry about where foo.h comes from, which may be
82 # system dependent and not known by that Makefile.
83 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \
84                                       $(addprefix $(sysdep_dir)/,$(sysdirs)) \
85                                       $(..)))
87 # Some sysdep makefiles use this to distinguish being included here from
88 # being included individually by a subdir makefile (hurd/Makefile needs this).
89 in-Makerules := yes
91 ifndef avoid-generated
92 -include $(+sysdir_pfx)sysd-Makefile
93 ifneq ($(sysd-Makefile-sysdirs),$(sysdirs))
94 sysd-Makefile-force = FORCE
95 FORCE:
96 endif
97 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
98                              $(sysd-Makefile-force)
99         -@rm -f $@T
100         (echo 'sysd-Makefile-sysdirs := $(sysdirs)';                          \
101          for dir in $(sysdirs); do                                            \
102            file=sysdeps/$$dir/Makefile;                                       \
103            if [ -f $(..)$$file ]; then                                        \
104              echo include "\$$(..)$$file";                                    \
105            else true; fi;                                                     \
106          done; \
107          echo 'sysd-Makefile-done=t') > $@T
108         mv -f $@T $@
109 endif
111 ifndef sysd-Makefile-done
112 # Don't do deps until this exists, because it might change the sources list.
113 no_deps=t
114 endif
117 # Reorder before-compile so that mach things come first, and hurd things
118 # second, before all else.  The mach and hurd subdirectories have many
119 # generated header files which the much of rest of the library depends on,
120 # so it is best to build them first (and mach before hurd, at that).
121 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
122                            $(before-compile)) \
123                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
124                                $(before-compile))
126 # Remove existing files from `before-compile'.  Things are added there when
127 # they must exist for dependency generation to work right, but once they
128 # exist there is no further need for every single file to depend on them,
129 # and those gratuitous dependencies result in many gratuitous
130 # recompilations.
131 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
133 # Don't let any before-compile file be an intermediate and get removed.
134 ifdef before-compile
135 $(before-compile):
136 endif
138 # Generate an ordered list of implicit rules which find the source files in
139 # each sysdep directory.  The old method was to use vpath to search all the
140 # sysdep directories.  However, that had the problem that a .S file in a
141 # later directory would be chosen over a .c file in an earlier directory,
142 # which does not preserve the desired sysdeps ordering behavior.
144 # When making the list of .d files to include, we can't know which ones
145 # have source in .s files, and thus do not in fact need a .d file.
146 # So we must define rules to make .d files for .s files.
147 define make-dummy-dep
148 $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
149 endef
150 $(objpfx)dummy.d:
151         echo '# .s files cannot contain includes, so they need no deps.' > $@
153 # It matters that this set of rules, for compiling from sources in
154 # the current directory (the $srcdir/$subdir) come before the
155 # generated sysdep rules in included from sysd-rules below.  When
156 # compiling in the source tree, generated sources go into the current
157 # directory, and those should be chosen before any sources in sysdeps.
158 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
159 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
160 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
161 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
162 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
163 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
164 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
165 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
166 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
167 $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep)
168 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
169 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
170 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
171 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
172 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
174 # Omit the objpfx rules when building in the source tree, because
175 # objpfx is empty and so these rules just override the ones above.
176 ifdef objpfx
177 # Define first rules to find the source files in $(objpfx).
178 # Generated source files will end up there.
179 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
180 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
181 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
182 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
183 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
184 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
185 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
186 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
187 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
188 $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep)
189 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
190 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
191 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
192 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
193 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
194 endif
196 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
197 # patterns matching sysdep directories whose assembly source files should
198 # be suppressed.
199 ifdef inhibit-sysdep-asm
200 define open-check-inhibit-asm
201 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
202 endef
203 close-check-inhibit-asm = ;; esac ;
204 endif
206 # Don't include sysd-rules until sysd-Makefile is already there and has been
207 # included.  It might define inhibit-sysdep-asm, which would affect the
208 # contents of sysd-rules.
209 ifdef sysd-Makefile-done
210 -include $(+sysdir_pfx)sysd-rules
211 ifneq ($(sysd-rules-sysdirs),$(sysdirs))
212 # The value of $(sysdirs) the sysd-rules was computed for
213 # differs from the one we are using now.  So force a rebuild of sysd-rules.
214 sysd-rules-force = FORCE
215 FORCE:
216 endif
217 endif
218 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
219                           $(wildcard $(foreach dir,$(sysdirs),\
220                                                $(sysdep_dir)/$(dir)/Makefile))\
221                           $(sysd-rules-force)
222         -@rm -f $@T
223         (echo 'sysd-rules-sysdirs := $(sysdirs)';                             \
224          for sysdir in $(sysdirs); do                                         \
225            dir="\$$(sysdep_dir)/$$sysdir";                                    \
226            for o in $(object-suffixes); do \
227              $(open-check-inhibit-asm) \
228              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
229                   \$$(compile-command.S)";                                    \
230              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
231                   \$$(compile-command.s)";                                    \
232              $(close-check-inhibit-asm) \
233              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
234                   \$$(compile-command.c)";                                    \
235            done; \
236            $(open-check-inhibit-asm) \
237            echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \
238                 \$$(make-dummy-dep)";                          \
239            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
240                 \$$(+make-deps)";                                             \
241            $(close-check-inhibit-asm)   \
242            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
243                 \$$(+make-deps)";                                             \
244          done;                                                                \
245          echo 'sysd-rules-done = t') > $@T
246         mv -f $@T $@
248 ifndef sysd-rules-done
249 # Don't do deps until this exists, because it provides rules to make the deps.
250 no_deps=t
251 endif
254 ifndef compile-command.S
255 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
256 endif
257 ifndef compile-command.s
258 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
259 endif
260 ifndef compile-command.c
261 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
262 endif
264 # GCC can grok options after the file name, and it looks nicer that way.
265 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
266 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
267 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
268 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
270 # We need this for the output to go in the right place.  It will default to
271 # empty if make was configured to work with a cc that can't grok -c and -o
272 # together.  You can't compile the C library with such a compiler.
273 OUTPUT_OPTION = -o $@
275 S-CPPFLAGS = $(asm-CPPFLAGS)
276 define +make-deps
277 -@rm -f $@
278 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
279 sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
280 $(sed-remove-objpfx) > $(@:.d=.T)
281 mv -f $(@:.d=.T) $@
282 endef
283 ifneq (,$(objpfx))
284 # Continuation lines here are dangerous because they introduce spaces!
285 define sed-remove-objpfx
286 -e 's@ $(subst .,\.,$(subst @,\@,$(objpfx)))@ $$(objpfx)@g' \
287 -e 's@^$(subst .,\.,$(subst @,\@,$(objpfx)))@$$(objpfx)@g'
288 endef
289 endif
291 # Figure out the source filenames in this directory.
293 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
294                                                        $(routines) $(aux) \
295                                                        $(sysdep_routines)))
296 sysdep_routines := $(sysdep_routines)
298 # This is the list of all object files, gotten by
299 # replacing every ".c" in `sources' with a ".o".
300 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
303 # This variable is used in ``include $(o-iterator)'' after defining
304 # $(o-iterator-doit) to produce some desired rule using $o for the object
305 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
306 # is produced for each object suffix in use.
307 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
309 # The makefile may define $(extra-libs) with `libfoo libbar'
310 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
311 ifdef extra-libs
312 # extra-lib.mk is included once for each extra lib to define rules
313 # to build it, and to add its objects to the various variables.
314 # During its evaluation, $(lib) is set to the name of the library.
315 extra-libs-left := $(extra-libs)
316 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
317 endif
319 +depfiles := $(strip $(sources:.c=.d) \
320                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
321                      $(addsuffix .d,$(others) $(tests)))
322 +depfiles := $(addprefix $(objpfx),\
323                          $(filter-out $(addsuffix .d,$(omit-deps)),\
324                                       $(+depfiles)))
326 ifdef +depfiles
327 ifneq ($(no_deps),t)
328 -include $(+depfiles)
329 endif
330 endif
331 \f\f
332 # Maximize efficiency by minimizing the number of rules.
333 .SUFFIXES:      # Clear the suffix list.
334 # Add the suffixes we use.
335 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
337 # Generic rule for making directories.
339 # mkdir isn't smart enough to strip a trailing /.
340         mkdir $(@:%/=%)
342 # Make sure that object files are not removed
343 # when they are intermediates between sources and library members.
344 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
346 # Make sure that the parent library archive is never removed.
347 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
349 # Use the verbose option of ar and tar when not running silently.
350 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
351 verbose := v
352 else                                            # -s
353 verbose :=
354 endif                                           # not -s
356 ARFLAGS := r$(verbose)
358 # This makes all the object files in the parent library archive.
360 .PHONY: lib libobjs lib-noranlib
361 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
363 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
364 lib%.a: lib%.a($(ar-symtab-name)) ;
366 libobjs: $(foreach o,$(object-suffixes),\
367                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
368                    $(notdir $(objects:.o=$o))))
369 lib-noranlib: libobjs
370 others: $(addprefix $(objpfx),$(install-lib))
372 ifdef objects
374 # Define a pattern rule that will match many targets libc.a(foo.%), for
375 # each foo.o in $(objects) (% will just happen always to match `o').  This is
376 # the only way to define a rule that updates many targets at once with one
377 # sequence of commands.  We in fact define the pattern rule to match
378 # targets libc.a(foo.%), libc_pic.a(foo.%), etc, to avoid repeating the rule.
379 # Each match will only ever be called upon to make member objects of
380 # the appropriate type in each library (i.e. libc_pic.a(foo.so)).
381 $(foreach l,$(libtypes),\
382           $(common-objpfx)$(patsubst %,$l,c)($(notdir $(objects:.o=.%)))): \
383   $(objpfx)stamp.%-$(subdir) ;
385 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
386 # the way to update all the foo.% object files in $(objects).
387 # Now we define a static pattern rule to update each
388 # $(objpfx)stamp.SUFFIX-$(subdir) timestamp file;
389 # these rules (one explicit rule is generated for each object suffix)
390 # will update the parent archive with
391 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)): \
392   $(objpfx)stamp%-$(subdir): $(objects:.o=%)
393         $(patsubst %,cd %;,$(objdir)) \
394         $(AR) cru$(verbose) ${O%-lib} \
395               $(patsubst $(objpfx)%,%,$^)
396 # `touch' won't let me touch a world-writable file I don't own.  Sigh.
397         rm -f $@
398         touch $@
399 ifdef subdir
400 O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c)
401 else
402 O%-lib = $(patsubst %,$(libtype$*),c)
403 endif
405 endif
407 # Rules to update the $(ar-symtab-name) member with ranlib,
408 # one for each object flavor.
409 define o-iterator-doit
410 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
411           $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
412           $(patsubst $(objpfx)%.o,%$o,$(objects))) \
413           $(filter subdir_lib,$(firstword $(subdir) subdir_lib)); \
414         $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
415 endef
416 object-suffixes-left = $(object-suffixes)
417 include $(o-iterator)
420 # This makes all the object files.
421 .PHONY: objects objs
422 objects objs: $(foreach o,$(object-suffixes),$(objects:.o=$o)) \
423               $(addprefix $(objpfx),$(extra-objs))
425 # Canned sequence for building an extra library archive.
426 define build-extra-lib
427 $(patsubst %,cd %;,$(objdir)) \
428 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
429       $(patsubst $(objpfx)%,%,$^)
430 $(RANLIB) $@
431 endef
433 # Shared library building.
435 ifeq (yes,$(build-shared))
437 # Process the shlib-versions file, which tells us what shared library
438 # version numbers to use when we install shared objects on this system.
439 -include $(common-objpfx)soversions.mk
440 $(common-objpfx)soversions.mk: $(..)shlib-versions $(..)Makerules \
441                                $(common-objpfx)config.make
442         sed 's/#.*$$//' $< | while read conf versions; do \
443           test -n "$$versions" || continue; \
444           case '$(config-machine)-$(config-vendor)-$(config-os)' in $$conf)\
445             for v in $$versions; do \
446               lib="$${v%%=*}"; if eval "test -z \"\$$vers_lib$$lib\""; then \
447                 eval vers_lib$${lib}=yes; \
448                 echo $$lib.so-version=.$${v##$$lib=}; fi; \
449           done ;; esac; done > $@T
450         mv -f $@T $@
452 # Get $(version) defined with the release version number.
453 -include $(common-objpfx)version.mk
456 # Pattern rule to build a shared object from an archive of PIC objects.
457 # This must come after the installation rules so Make doesn't try to
458 # build shared libraries in place from the installed *_pic.a files.
459 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
460 # on other shared objects.
461 lib%.so: lib%_pic.a; $(build-shlib)
463 ifeq ($(have-no-whole-archive),yes)
464 no-whole-archive = -Wl,--no-whole-archive
465 else
466 no-whole-archive =
467 endif
469 define build-shlib
470 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
471           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
472           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
473           -Wl,-rpath-link=$(common-objdir) \
474           -Wl,--whole-archive $^ $(no-whole-archive) \
475           $(LDLIBS-$(@F:lib%.so=%).so)
476 endef
478 # Don't try to use -lc when making libc.so itself.
479 # Also omits crti.o and crtn.o, which we do not want
480 # since we define our own `.init' section specially.
481 LDFLAGS-c.so = -nostdlib -nostartfiles
482 # Give libc.so an entry point and make it directly runnable itself.
483 LDFLAGS-c.so += -e __libc_print_version
484 # Use our own special initializer and finalizer files for libc.so.
485 elfobjdir := $(firstword $(objdir) $(..)elf)
486 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
487                          $(common-objpfx)libc_pic.a \
488                          $(elfobjdir)/sofini.so
489         $(build-shlib)
491 ifdef libc.so-version
492 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
493         rm -f $@
494         ln -s $(<F) $@ || ln $< $@
495 endif
496 endif
498 # Installation.
500 # $(install-lib) are installed from the object directory into $(libdir);
501 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
502 # unless they also appear in $(non-lib.a).  $(install-data) are installed
503 # as they are into $(datadir).  $(headers) are installed as they are in
504 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
505 # object directory into $(bindir) and $(sbindir), respectively.
506 # $(install-others) are absolute path names of files to install; rules to
507 # install them are defined elsewhere.
509 # The simple library name to install libc.a under.
510 # This could be defined by a sysdep Makefile.
511 ifndef libc-name
512 libc-name := c
513 endif
515 define do-install
516 $(make-target-directory)
517 $(INSTALL_DATA) $< $@
518 endef
520 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
521 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
522 define make-target-directory
523 $(addprefix $(..)mkinstalldirs ,\
524             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
525 endef
527 # Any directory (parent or subdir) that has any object files to build
528 # should install libc.a; this way "make install" in a subdir is guaranteed
529 # to install everything it changes.
530 ifdef objects
531 installed-libcs := $(foreach o,$(object-suffixes),\
532                              $(libdir)/$(patsubst %,$(libtype$o),\
533                                                   $(libprefix)$(libc-name)))
534 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
535 install: $(installed-libcs)
536 $(installed-libcs): $(libdir)/lib$(libprefix)%: lib
537         $(make-target-directory)
538         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
539 # Running ranlib after installing makes the __.SYMDEF time stamp up to
540 # date, which avoids messages from some linkers.
541         $(RANLIB) $@
542 endif
544 define do-install-program
545 $(make-target-directory)
546 $(INSTALL_PROGRAM) $< $@.new
547 mv -f $@.new $@
548 endef
550 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
551 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
552 ifeq (yes,$(build-shared))
554 install-lib-nosubdir: $(install-lib.so:%=$(libdir)/%)
556 # Find which .so's have versions.
557 versioned := $(strip $(foreach so,$(install-lib.so),\
558                                $(patsubst %,$(so),$($(so)-version))))
560 # Install all the unversioned shared libraries.
561 $(addprefix $(libdir)/,$(filter-out $(versioned),$(install-lib.so))): \
562 $(libdir)/%.so: $(objpfx)%.so; $(do-install-program)
564 make-link = cd $(@D); rm -f $(@F); $(LN_S) $(<F) $(@F)
566 ifdef libc.so-version
567 # For a library specified to be version N, install three files:
568 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
569 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
571 $(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so
572         $(make-link)
573 $(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program)
574 install: $(slibdir)/libc.so$(libc.so-version)
576 ifndef subdir
577 # What we install as libc.so for programs to link against is in fact an
578 # archive.  It contains the various $(static-only-routines) objects, and
579 # the special object libc-syms.so that contains just the dynamic symbol
580 # table of the shared libc object.
581 install: $(libdir)/libc.so
582 $(libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
583                    $(common-objpfx)libc.a
584         (echo '/* Use the shared library, but some functions are only in';\
585          echo '   the static library, so try that secondarily.  */';\
586          echo 'GROUP ( $(^F) )') > $@.new
587         mv -f $@.new $@
589 endif
591 else
592 install: $(slibdir)/libc.so
593 $(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program)
594 endif
597 ifneq (,$(versioned))
598 # Produce three sets of rules as above for all the smaller versioned libraries.
600 define o-iterator-doit
601 $(libdir)/$o: $(libdir)/$o$($o-version); $$(make-link)
602 endef
603 object-suffixes-left := $(versioned)
604 include $(o-iterator)
606 # Make symlinks in the build directory, because the versioned names might
607 # be referenced by a DT_NEEDED in another library.
608 define o-iterator-doit
609 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
610 endef
611 object-suffixes-left := $(versioned)
612 include $(o-iterator)
615 define o-iterator-doit
616 $(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$(version).so; $$(make-link)
617 endef
618 object-suffixes-left := $(versioned)
619 include $(o-iterator)
621 define o-iterator-doit
622 $(libdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
623 endef
624 object-suffixes-left := $(versioned)
625 include $(o-iterator)
626 endif
628 define do-install-so
629 $(do-install-program)
630 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
631            $(filter-out %.so,$@))
632 endef
634 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
635 $(foreach v,$(so-versions),\
636           $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
637         $(do-install-so)
638 $(foreach v,$(so-versions),\
639           $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so
640         $(do-install-so)
641 endif
643 ifdef install-bin
644 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
645         $(do-install-program)
646 endif
647 ifdef install-sbin
648 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
649         $(do-install-program)
650 endif
651 ifdef install-lib
652 install-lib.a := $(filter lib%.a,$(install-lib))
653 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
654 ifdef install-lib-non.a
655 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
656   $(libdir)/$(libprefix)%: $(objpfx)%
657         $(do-install)
658 endif
659 ifdef install-lib.a
660 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
661   $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
662         $(do-install)
663         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
664 endif
665 endif
666 ifdef install-data
667 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
668 endif
669 headers := $(strip $(headers))
670 ifdef headers
671 $(addprefix $(includedir)/,$(headers)): \
672         $(includedir)/%: %;$(do-install)
673 endif   # headers
675 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
676         install-data-nosubdir install-headers-nosubdir
677 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
678 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
679 install-lib-nosubdir: $(addprefix $(libdir)/,\
680                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
681                        $(addprefix $(libprefix),$(install-lib-non.a)))
682 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
683 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
684 install-others-nosubdir: $(install-others)
686 # We need all the `-nosubdir' targets so that `install' in the parent
687 # doesn't depend on several things which each iterate over the subdirs.
688 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
689 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
690 install-%:: install-%-nosubdir ;
692 .PHONY: install install-no-libc.a-nosubdir
693 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
694                             install-bin-nosubdir install-lib-nosubdir   \
695                             install-others-nosubdir install-sbin-nosubdir
696 install: install-no-libc.a-nosubdir
698 # Command to compile $< in $(objdir) using the native libraries.
699 define native-compile
700 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
701            $(addprefix $$cwd/,$^) -o $(@F)
702 endef
704 # Command to compile $< in $(common-objdir) using the native libraries.
705 define common-objdir-compile
706 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
707 endef
709 # We always want to use configuration definitions.
710 ifdef objdir
711 # This is always used in $(common-objdir), so we use no directory name.
712 BUILD_CFLAGS = -include config.h
713 else
714 BUILD_CFLAGS = -include $(..)config.h
715 endif
717 # Support the GNU standard name for this target.
718 .PHONY: check
719 check: tests
721 .PHONY: TAGS
722 TAGS: distinfo $(..)MakeTAGS
723         $(MAKE) $(addprefix -f ,$^) $@
725 $(..)po/%.pot: distinfo $(..)MakeTAGS FORCE
726         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
727 FORCE:
730 .PHONY: echo-headers
731 echo-headers:
732         @echo $(headers)
735 # Common cleaning targets.
737 .PHONY: common-mostlyclean common-clean mostlyclean clean
738 clean: common-clean
739 mostlyclean: common-mostlyclean
741 # Remove the object files.
742 common-mostlyclean:
743         -rm -f $(addprefix $(objpfx),$(tests) $(others) \
744                                      $(addsuffix .o,$(tests) $(others)) \
745                                      $(addsuffix .out,$(tests)))
746         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
747         -rm -f core $(objpfx)stub-$(subdir)
748         $(rmobjs)
749 define rmobjs
750 $(foreach o,$(object-suffixes),
751 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(objects:.o=$o))
752 endef
754 # Also remove the dependencies and generated source files.
755 common-clean: common-mostlyclean
756         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
758 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
759 # for each function which is a stub.  We grovel over all the .d files
760 # looking for references to source files in sysdeps/stub.  Then we grovel
761 # over each referenced source file to see what stub function it defines.
763 .PHONY: stubs # The parent Makefile calls this target.
764 stubs: $(common-objpfx)stub-$(subdir)
765 s = $(sysdep_dir)/stub
766 $(common-objpfx)stub-$(subdir): $(+depfiles)
767 # Use /dev/null since `...` might expand to empty.
768         (s=`cd $s; /bin/pwd`; \
769          $(patsubst %,cd %;,$(objdir)) \
770          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
771              `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
772                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
773              /dev/null) > $@T
774         mv -f $@T $@
776 # Make the distribution tar file.
778 .PHONY: dist
779 dist: distinfo $(..)Make-dist
780         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
782 # Avoid depending on source files found in sysdeps dirs,
783 # because the references affect implicit rule selection.
784 dist: $(filter-out %.c %.S %.s,$(distribute))
786 # We used to simply export all these variables, but that frequently made the
787 # environment get too large.  Instead, we write all the information into
788 # a generated makefile fragment `distinfo', and then include it with -f in
789 # the sub-make that makes the distribution (above).
790 distinfo: Makefile $(..)Makerules
791         $(distinfo-vars)
792         mv -f $@.new $@
794 define distinfo-vars
795 rm -f $@.new
796 $(foreach var,subdir subdir-dirs sources elided-routines sysdep_routines \
797               headers sysdep_headers distribute dont_distribute generated \
798               others tests extra-libs $(extra-libs:%=%-routines),
799 echo >> $@.new '$(var)  := $($(var))')
800 echo >> $@.new 'sources += $$(addsuffix .c,$$(elided-routines))'
801 endef
803 ifneq (,$(strip $(gpl2lgpl)))
804 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
805 # Snarf from the master source and frob the copying notice.
806 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
807         sed -f $^ > $@-tmp
808 # So I don't edit them by mistake.
809         chmod a-w $@-tmp
810         mv -f $@-tmp $@
811         test ! -d CVS || cvs commit -m'Updated from $^' $@
812 endif
813 endif