update from main archive 960830
[glibc.git] / Makerules
blob2b751544535735b2e18f4323ee107c8b2cd777c8
1 # Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB.  If
16 # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 # Cambridge, MA 02139, USA.
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
28 REQUIRED_MAKE_VERSION = 3.74
30 ifneq ($(REQUIRED_MAKE_VERSION), \
31        $(firstword $(sort $(MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
32 Wrong GNU Make version.  See above for the version needed.
33 endif
36 ifdef   subdir
37 ..      := ../
38 endif   # subdir
40 # If `sources' was defined by the parent makefile, undefine it so
41 # we will later get it from wildcard search in this directory.
42 ifneq   "$(findstring env,$(origin sources))" ""
43 sources :=
44 endif
46 oPATH := $(PATH)
47 PATH := this definition should take precedence over $(oPATH)
48 ifeq ($(PATH),$(oPATH))
49 You must not use the -e flag when building the GNU C library.
50 else
51 PATH := $(oPATH)
52 endif
54 ifndef +included-Makeconfig
55 include $(..)Makeconfig
56 endif
58 # `configure' writes a definition of `config-sysdirs' in `config.make'.
59 sysdirs = $(config-sysdirs)
61 +sysdir_pfx = $(common-objpfx)
63 export sysdirs := $(sysdirs)
65 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
66 ifdef objdir
67 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
68 endif
70 # Add -I switches to get the right sysdep directories.
71 # `+includes' in Makeconfig references $(+sysdep-includes).
72 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
74 # The name of the symbol table archive member.  The default is suitable for
75 # BSD style archives.  It can be overridden in sysdep Makefiles when SYSV
76 # style archive are used.
77 ifeq (no,$(elf))
78 ar-symtab-name = __.SYMDEF
79 else
80 ar-symtab-name = # The null name is used in ELF archives.
81 endif
83 # Include any system-specific makefiles.
85 # This is here so things in sysdep Makefiles can easily depend on foo.h as
86 # appropriate and not worry about where foo.h comes from, which may be
87 # system dependent and not known by that Makefile.
88 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
89                                       $(addprefix $(sysdep_dir)/,$(sysdirs)) \
90                                       $(..)))
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),$(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 := $(sysdirs)';                          \
106          for dir in $(sysdirs); do                                            \
107            file=sysdeps/$$dir/Makefile;                                       \
108            if [ -f $(..)$$file ]; then                                        \
109              echo include "\$$(..)$$file";                                    \
110            else true; fi;                                                     \
111          done; \
112          echo 'sysd-Makefile-done=t') > $@T
113         mv -f $@T $@
114 endif
116 ifndef sysd-Makefile-done
117 # Don't do deps until this exists, because it might change the sources list.
118 no_deps=t
119 endif
122 # Reorder before-compile so that mach things come first, and hurd things
123 # second, before all else.  The mach and hurd subdirectories have many
124 # generated header files which the much of rest of the library depends on,
125 # so it is best to build them first (and mach before hurd, at that).
126 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
127                            $(before-compile)) \
128                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
129                                $(before-compile))
131 # Remove existing files from `before-compile'.  Things are added there when
132 # they must exist for dependency generation to work right, but once they
133 # exist there is no further need for every single file to depend on them,
134 # and those gratuitous dependencies result in many gratuitous
135 # recompilations.
136 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
138 # Don't let any before-compile file be an intermediate and get removed.
139 ifdef before-compile
140 $(before-compile):
141 endif
143 # Generate an ordered list of implicit rules which find the source files in
144 # each sysdep directory.  The old method was to use vpath to search all the
145 # sysdep directories.  However, that had the problem that a .S file in a
146 # later directory would be chosen over a .c file in an earlier directory,
147 # which does not preserve the desired sysdeps ordering behavior.
149 # When making the list of .d files to include, we can't know which ones
150 # have source in .s files, and thus do not in fact need a .d file.
151 # So we must define rules to make .d files for .s files.
152 define make-dummy-dep
153 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
154 endef
155 $(common-objpfx)dummy.d:
156         echo '# .s files cannot contain includes, so they need no deps.' > $@
158 # It matters that this set of rules, for compiling from sources in
159 # the current directory (the $srcdir/$subdir) come before the
160 # generated sysdep rules in included from sysd-rules below.  When
161 # compiling in the source tree, generated sources go into the current
162 # directory, and those should be chosen before any sources in sysdeps.
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 $(before-compile); $(+make-deps)
168 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
169 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
170 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
171 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
172 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
173 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
174 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
175 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
176 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
177 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
179 # Omit the objpfx rules when building in the source tree, because
180 # objpfx is empty and so these rules just override the ones above.
181 ifdef objpfx
182 # Define first rules to find the source files in $(objpfx).
183 # Generated source files will end up there.
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 $(before-compile); $(+make-deps)
189 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
190 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
191 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
192 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
193 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
194 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
195 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
196 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
197 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
198 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
199 endif
201 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
202 # patterns matching sysdep directories whose assembly source files should
203 # be suppressed.
204 ifdef inhibit-sysdep-asm
205 define open-check-inhibit-asm
206 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
207 endef
208 close-check-inhibit-asm = ;; esac ;
209 endif
211 # Don't include sysd-rules until sysd-Makefile is already there and has been
212 # included.  It might define inhibit-sysdep-asm, which would affect the
213 # contents of sysd-rules.
214 ifdef sysd-Makefile-done
215 -include $(+sysdir_pfx)sysd-rules
216 ifneq ($(sysd-rules-sysdirs),$(sysdirs))
217 # The value of $(sysdirs) the sysd-rules was computed for
218 # differs from the one we are using now.  So force a rebuild of sysd-rules.
219 sysd-rules-force = FORCE
220 FORCE:
221 endif
222 endif
223 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
224                           $(wildcard $(foreach dir,$(sysdirs),\
225                                                $(sysdep_dir)/$(dir)/Makefile))\
226                           $(sysd-rules-force)
227         -@rm -f $@T
228         (echo 'sysd-rules-sysdirs := $(sysdirs)';                             \
229          for sysdir in $(sysdirs); do                                         \
230            dir="\$$(sysdep_dir)/$$sysdir";                                    \
231            for o in $(object-suffixes); do \
232              $(open-check-inhibit-asm) \
233              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
234                   \$$(compile-command.S)";                                    \
235              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
236                   \$$(compile-command.s)";                                    \
237              $(close-check-inhibit-asm) \
238              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
239                   \$$(compile-command.c)";                                    \
240            done; \
241            $(open-check-inhibit-asm) \
242            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
243                 \$$(make-dummy-dep)";                          \
244            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
245                 \$$(+make-deps)";                                             \
246            $(close-check-inhibit-asm)   \
247            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
248                 \$$(+make-deps)";                                             \
249          done;                                                                \
250          echo 'sysd-rules-done = t') > $@T
251         mv -f $@T $@
253 ifndef sysd-rules-done
254 # Don't do deps until this exists, because it provides rules to make the deps.
255 no_deps=t
256 endif
259 ifndef compile-command.S
260 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
261 endif
262 ifndef compile-command.s
263 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
264 endif
265 ifndef compile-command.c
266 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
267 endif
269 # GCC can grok options after the file name, and it looks nicer that way.
270 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
271 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
272 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
273 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
275 # We need this for the output to go in the right place.  It will default to
276 # empty if make was configured to work with a cc that can't grok -c and -o
277 # together.  You can't compile the C library with such a compiler.
278 OUTPUT_OPTION = -o $@
280 S-CPPFLAGS = $(asm-CPPFLAGS)
281 define +make-deps
282 $(make-target-directory)
283 -@rm -f $@
284 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
285 sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
286 $(sed-remove-objpfx) > $(@:.d=.T)
287 mv -f $(@:.d=.T) $@
288 endef
289 ifneq (,$(objpfx))
290 # Continuation lines here are dangerous because they introduce spaces!
291 define sed-remove-objpfx
292 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
293 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
294 endef
295 endif
297 # Shared library building.
299 ifeq (yes,$(build-shared))
301 # Pattern rule to build a shared object from an archive of PIC objects.
302 # This must come after the installation rules so Make doesn't try to
303 # build shared libraries in place from the installed *_pic.a files.
304 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
305 # on other shared objects.
306 lib%.so: lib%_pic.a; $(build-shlib)
308 ifeq ($(have-no-whole-archive),yes)
309 no-whole-archive = -Wl,--no-whole-archive
310 else
311 no-whole-archive =
312 endif
314 define build-shlib
315 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
316           -B$(csu-objpfx) \
317           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
318           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
319           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
320           -Wl,--whole-archive $^ $(no-whole-archive) \
321           $(LDLIBS-$(@F:lib%.so=%).so)
322 endef
324 # Don't try to use -lc when making libc.so itself.
325 # Also omits crti.o and crtn.o, which we do not want
326 # since we define our own `.init' section specially.
327 LDFLAGS-c.so = -nostdlib -nostartfiles
328 # Give libc.so an entry point and make it directly runnable itself.
329 LDFLAGS-c.so += -e __libc_main
330 # Use our own special initializer and finalizer files for libc.so.
331 elfobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)elf)
332 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
333                          $(common-objpfx)libc_pic.a \
334                          $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
335         $(build-shlib)
337 ifdef libc.so-version
338 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
339         rm -f $@
340         ln -s $(<F) $@ || ln $< $@
341 endif
342 endif
344 # Some files must not be compiled with the exception handler mechanism
345 # enabled (introduced in gcc-2.8).  Use $(no-exceptions) in the
346 # appropriate CFLAGS definition.
347 ifeq ($(have-no-exceptions),yes)
348 no-exceptions = -fno-exceptions
349 else
350 no-exceptions =
351 endif
353 # Figure out the source filenames in this directory.
355 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
356                                                        $(routines) $(aux) \
357                                                        $(sysdep_routines)))
358 sysdep_routines := $(sysdep_routines)
360 headers := $(headers) $(sysdep_headers)
362 # This is the list of all object files, gotten by
363 # replacing every ".c" in `sources' with a ".o".
364 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
367 # This variable is used in ``include $(o-iterator)'' after defining
368 # $(o-iterator-doit) to produce some desired rule using $o for the object
369 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
370 # is produced for each object suffix in use.
371 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
373 # The makefile may define $(extra-libs) with `libfoo libbar'
374 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
375 ifdef extra-libs
376 # extra-lib.mk is included once for each extra lib to define rules
377 # to build it, and to add its objects to the various variables.
378 # During its evaluation, $(lib) is set to the name of the library.
379 extra-libs-left := $(extra-libs)
380 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
381 endif
383 +depfiles := $(strip $(sources:.c=.d) \
384                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
385                      $(addsuffix .d,$(others) $(tests)))
386 +depfiles := $(addprefix $(objpfx),\
387                          $(filter-out $(addsuffix .d,$(omit-deps)),\
388                                       $(+depfiles)))
390 ifdef +depfiles
391 ifneq ($(no_deps),t)
392 -include $(+depfiles)
393 endif
394 endif
395 \f\f
396 # Maximize efficiency by minimizing the number of rules.
397 .SUFFIXES:      # Clear the suffix list.
398 # Add the suffixes we use.
399 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
401 # Generic rule for making directories.
403 # mkdir isn't smart enough to strip a trailing /.
404         mkdir $(@:%/=%)
406 # Make sure that object files are not removed
407 # when they are intermediates between sources and library members.
408 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
410 # Make sure that the parent library archive is never removed.
411 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
413 # Use the verbose option of ar and tar when not running silently.
414 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
415 verbose := v
416 else                                            # -s
417 verbose :=
418 endif                                           # not -s
420 ARFLAGS := r$(verbose)
422 # This makes all the object files in the parent library archive.
424 .PHONY: lib libobjs lib-noranlib
425 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
427 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
428 lib%.a: lib%.a($(ar-symtab-name)) ;
430 # For object-suffix $o, the list of objects with that suffix.
431 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
432 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
433                                                        $(elide-routines$o)),\
434                                             $(objects)))
436 libobjs: $(foreach o,$(object-suffixes),\
437                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
438                    $(notdir $(o-objects))))
439 lib-noranlib: libobjs
440 others: $(addprefix $(objpfx),$(install-lib))
442 ifndef objects
444 # Create the stamp$o files to keep the parent makefile happy.
445 subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir))
446 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)):
447         $(make-target-directory)
448         rm -f $@; > $@
449 else
451 # Define a pattern rule that will match many targets libc.a(foo.%), for
452 # each foo.o in $(objects) (% will just happen always to match `o').  This is
453 # the only way to define a rule that updates many targets at once with one
454 # sequence of commands.
455 define o-iterator-doit
456 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
457 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
458   $(objpfx)stamp.%-$(subdir) ;
459 endef
460 object-suffixes-left := $(object-suffixes)
461 include $(o-iterator)
463 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
464 # the way to update all the foo.% object files in $(objects).  Now we
465 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
466 # timestamp file; these rules (one explicit rule is generated for each
467 # object suffix) will update the parent archive with ar.  Use a static
468 # pattern rule so $* is set to the object type during the commands.
469 define o-iterator-doit
470 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
471 endef
472 object-suffixes-left := $(object-suffixes)
473 include $(o-iterator)
474 define do-ar
475 topdir=`cd $(..).; pwd`; \
476 $(patsubst %/,cd %;,$(objpfx)) \
477 $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
478                                          $(patsubst $(objpfx)%,%,$^)
479 rm -f $@
480 touch $@
481 endef
482 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
484 endif
486 # Rules to update the $(ar-symtab-name) member with ranlib,
487 # one for each object flavor.
488 define o-iterator-doit
489 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
490           $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
491             $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
492         $$(..)./autolock.sh \
493           $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
494           $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
495 endef
496 ifndef subdir
497 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
498 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
499 $(subdirs-stamps): subdir_lib;
500 endif
501 object-suffixes-left = $(object-suffixes)
502 include $(o-iterator)
505 # This makes all the object files.
506 .PHONY: objects objs
507 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
508               $(addprefix $(objpfx),$(extra-objs))
510 # Canned sequence for building an extra library archive.
511 define build-extra-lib
512 $(patsubst %/,cd %;,$(objpfx)) \
513 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
514       $(patsubst $(objpfx)%,%,$^)
515 $(RANLIB) $@
516 endef
518 # Installation.
520 # $(install-lib) are installed from the object directory into $(libdir);
521 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
522 # unless they also appear in $(non-lib.a).  $(install-data) are installed
523 # as they are into $(datadir).  $(headers) are installed as they are in
524 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
525 # object directory into $(bindir) and $(sbindir), respectively.
526 # $(install-others) are absolute path names of files to install; rules to
527 # install them are defined elsewhere.
529 # The simple library name to install libc.a under.
530 # This could be defined by a sysdep Makefile.
531 ifndef libc-name
532 libc-name := c
533 endif
535 define do-install
536 $(make-target-directory)
537 $(INSTALL_DATA) $< $@
538 endef
540 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
541 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
542 define make-target-directory
543 $(addprefix $(..)./mkinstalldirs ,\
544             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
545 endef
547 # Any directory (parent or subdir) that has any object files to build
548 # should install libc.a; this way "make install" in a subdir is guaranteed
549 # to install everything it changes.
550 ifdef objects
551 installed-libcs := $(foreach o,$(object-suffixes),\
552                              $(libdir)/$(patsubst %,$(libtype$o),\
553                                                   $(libprefix)$(libc-name)))
554 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
555 install: $(installed-libcs)
556 $(installed-libcs): $(libdir)/lib$(libprefix)%: lib
557         $(make-target-directory)
558         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
559 # Running ranlib after installing makes the __.SYMDEF time stamp up to
560 # date, which avoids messages from some linkers.
561         $(RANLIB) $@
562 endif
564 define do-install-program
565 $(make-target-directory)
566 $(INSTALL_PROGRAM) $< $@.new
567 mv -f $@.new $@
568 endef
570 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
571 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
572 ifeq (yes,$(build-shared))
574 install-lib-nosubdir: $(install-lib.so:%=$(libdir)/%)
576 # Find which .so's have versions.
577 versioned := $(strip $(foreach so,$(install-lib.so),\
578                                $(patsubst %,$(so),$($(so)-version))))
580 # Install all the unversioned shared libraries.
581 $(addprefix $(libdir)/,$(filter-out $(versioned),$(install-lib.so))): \
582 $(libdir)/%.so: $(objpfx)%.so; $(do-install-program)
584 define make-link
585 cd $(@D); rm -f $(@F).new; $(LN_S) $(<F) $(@F).new; mv -f $(@F).new $(@F)
586 endef
588 ifdef libc.so-version
589 # For a library specified to be version N, install three files:
590 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
591 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
593 $(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so
594         $(make-link)
595 $(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program)
596 install: $(slibdir)/libc.so$(libc.so-version)
598 ifndef subdir
599 # What we install as libc.so for programs to link against is in fact an
600 # archive.  It contains the various $(static-only-routines) objects, and
601 # the special object libc-syms.so that contains just the dynamic symbol
602 # table of the shared libc object.
603 install: $(libdir)/libc.so
604 $(libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
605                    $(elfobjdir)/$(rtld-installed-name) \
606                    $(common-objpfx)libc.a
607         (echo '/* Use the shared library, but some functions are only in';\
608          echo '   the static library, so try that secondarily.'; \
609          echo '   The dynamic linker defines some functions used by $(<F),';\
610          echo '   but ld uses definitions from libc.a before examining the';\
611          echo '   dependencies of $(<F) to find $(rtld-installed-name).  */';\
612          echo 'GROUP ( $(^F) )') > $@.new
613         mv -f $@.new $@
615 endif
617 else
618 install: $(slibdir)/libc.so
619 $(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program)
620 endif
623 ifneq (,$(versioned))
624 # Produce three sets of rules as above for all the smaller versioned libraries.
626 define o-iterator-doit
627 $(libdir)/$o: $(libdir)/$o$($o-version); $$(make-link)
628 endef
629 object-suffixes-left := $(versioned)
630 include $(o-iterator)
632 # Make symlinks in the build directory, because the versioned names might
633 # be referenced by a DT_NEEDED in another library.
634 define o-iterator-doit
635 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
636 endef
637 object-suffixes-left := $(versioned)
638 include $(o-iterator)
641 define o-iterator-doit
642 $(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$(version).so; $$(make-link)
643 endef
644 object-suffixes-left := $(versioned)
645 include $(o-iterator)
647 define o-iterator-doit
648 $(libdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
649 endef
650 object-suffixes-left := $(versioned)
651 include $(o-iterator)
652 endif
654 define do-install-so
655 $(do-install-program)
656 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
657            $(filter-out %.so,$@))
658 endef
660 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
661 $(foreach v,$(so-versions),\
662           $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
663         $(do-install-so)
664 $(foreach v,$(so-versions),\
665           $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so
666         $(do-install-so)
667 endif
669 ifdef install-bin
670 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
671         $(do-install-program)
672 endif
673 ifdef install-sbin
674 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
675         $(do-install-program)
676 endif
677 ifdef install-lib
678 install-lib.a := $(filter lib%.a,$(install-lib))
679 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
680 ifdef install-lib-non.a
681 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
682   $(libdir)/$(libprefix)%: $(objpfx)%
683         $(do-install)
684 endif
685 ifdef install-lib.a
686 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
687   $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
688         $(do-install)
689         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
690 endif
691 endif
692 ifdef install-data
693 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
694 endif
695 headers := $(strip $(headers))
696 ifdef headers
697 $(addprefix $(includedir)/,$(headers)): \
698         $(includedir)/%: %;$(do-install)
699 endif   # headers
701 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
702         install-data-nosubdir install-headers-nosubdir
703 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
704 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
705 install-lib-nosubdir: $(addprefix $(libdir)/,\
706                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
707                        $(addprefix $(libprefix),$(install-lib-non.a)))
708 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
709 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
710 install-others-nosubdir: $(install-others)
712 # We need all the `-nosubdir' targets so that `install' in the parent
713 # doesn't depend on several things which each iterate over the subdirs.
714 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
715 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
716 install-%:: install-%-nosubdir ;
718 .PHONY: install install-no-libc.a-nosubdir
719 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
720                             install-bin-nosubdir install-lib-nosubdir   \
721                             install-others-nosubdir install-sbin-nosubdir
722 install: install-no-libc.a-nosubdir
724 # Command to compile $< in $(objdir) using the native libraries.
725 define native-compile
726 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
727            $(addprefix $$cwd/,$^) -o $(@F)
728 endef
730 # Command to compile $< in $(common-objdir) using the native libraries.
731 define common-objdir-compile
732 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
733 endef
735 # We always want to use configuration definitions.
736 BUILD_CFLAGS = -include $(common-objpfx)config.h
738 # Support the GNU standard name for this target.
739 .PHONY: check
740 check: tests
742 .PHONY: TAGS
743 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
744         $(MAKE) $(addprefix -f ,$^) $@
746 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
747         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
748 FORCE:
751 .PHONY: echo-headers
752 echo-headers:
753         @echo $(headers)
756 # Common cleaning targets.
758 .PHONY: common-mostlyclean common-clean mostlyclean clean
759 clean: common-clean
760 mostlyclean: common-mostlyclean
762 # Remove the object files.
763 common-mostlyclean:
764         -rm -f $(addprefix $(objpfx),$(tests) $(others) \
765                                      $(addsuffix .o,$(tests) $(others)) \
766                                      $(addsuffix .out,$(tests)))
767         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
768         -rm -f core $(common-objpfx)stub-$(subdir)
769         $(rmobjs)
770 define rmobjs
771 $(foreach o,$(object-suffixes),
772 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
773 endef
775 # Also remove the dependencies and generated source files.
776 common-clean: common-mostlyclean
777         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
778         -rm -f $(addprefix $(common-objpfx),$(common-generated))
779         -rm -f $(common-objpfx)distinfo-$(subdir)
781 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
782 # for each function which is a stub.  We grovel over all the .d files
783 # looking for references to source files in sysdeps/stub.  Then we grovel
784 # over each referenced source file to see what stub function it defines.
786 .PHONY: stubs # The parent Makefile calls this target.
787 stubs: $(common-objpfx)stub-$(subdir)
788 s = $(sysdep_dir)/stub
789 $(common-objpfx)stub-$(subdir): $(+depfiles)
790 # Use /dev/null since `...` might expand to empty.
791         (s=`cd $s; /bin/pwd`; \
792          $(patsubst %/,cd %;,$(objpfx)) \
793          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
794              `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
795                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
796              /dev/null) > $@T
797         mv -f $@T $@
799 # Make the distribution tar file.
801 .PHONY: dist
802 dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
803         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
805 # Avoid depending on source files found in sysdeps dirs,
806 # because the references affect implicit rule selection.
807 dist: $(filter-out %.c %.S %.s,$(distribute))
809 # We used to simply export all these variables, but that frequently made the
810 # environment get too large.  Instead, we write all the information into
811 # a generated makefile fragment `distinfo', and then include it with -f in
812 # the sub-make that makes the distribution (above).
813 $(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules
814         $(distinfo-vars)
815         mv -f $@.new $@
816 .PHONY: subdir_distinfo distinfo
817 subdir_distinfo: distinfo
818 distinfo: $(common-objpfx)distinfo-$(subdir)
820 define distinfo-vars
821 rm -f $@.new
822 echo > $@.new 'subdir := $(subdir)'
823 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
824               headers sysdep_headers distribute dont_distribute generated \
825               others tests extra-libs $(extra-libs:%=%-routines) \
826               versioned \
827               $(addprefix install-,lib lib.so data bin sbin others),
828 echo >> $@.new '$(subdir)-$(var) := $($(var))'
829 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
830 endef
832 ifneq (,$(strip $(gpl2lgpl)))
833 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
834 # Snarf from the master source and frob the copying notice.
835 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
836         sed -f $^ > $@-tmp
837 # So I don't edit them by mistake.
838         chmod a-w $@-tmp
839         mv -f $@-tmp $@
840         test ! -d CVS || cvs commit -m'Updated from $^' $@
841 endif
842 endif