Update.
[glibc.git] / Makerules
blob01be04b57d06d929cd2d7bf485f9bc703996343e
1 # Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98 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 # This variable is used in ``include $(o-iterator)'' after defining
76 # $(o-iterator-doit) to produce some desired rule using $o for the object
77 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78 # is produced for each object suffix in use.
79 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
81 # Include any system-specific makefiles.
83 # This is here so things in sysdep Makefiles can easily depend on foo.h as
84 # appropriate and not worry about where foo.h comes from, which may be
85 # system dependent and not known by that Makefile.
86 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87                                       $(+sysdep_dirs) $(..)))
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91                                       $(+sysdep_dirs) $(..)))
93 # Some sysdep makefiles use this to distinguish being included here from
94 # being included individually by a subdir makefile (hurd/Makefile needs this).
95 in-Makerules := yes
97 -include $(+sysdir_pfx)sysd-Makefile
98 ifndef avoid-generated
99 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
100 sysd-Makefile-force = FORCE
101 FORCE:
102 endif
103 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
104                              $(sysd-Makefile-force)
105         -@rm -f $@T
106         (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)';                   \
107          for dir in $(config-sysdirs); do                                     \
108            file=$$dir/Makefile;                                               \
109            case $$dir in                                                      \
110              /*) rel= ;;                                                      \
111              *)  rel=$(..) ;;                                                 \
112            esac;                                                              \
113            if [ -f $$rel$$file ]; then                                        \
114              case $$dir in                                                    \
115                /*) echo include "$$file" ;;                                   \
116                *)  echo include "\$$(..)$$file" ;;                            \
117              esac;                                                            \
118            else true; fi;                                                     \
119          done;                                                                \
120          echo 'sysd-Makefile-done=t') > $@T
121         mv -f $@T $@
122 endif
124 ifndef sysd-Makefile-done
125 # Don't do deps until this exists, because it might change the sources list.
126 no_deps=t
127 endif
130 # Reorder before-compile so that mach things come first, and hurd things
131 # second, before all else.  The mach and hurd subdirectories have many
132 # generated header files which the much of rest of the library depends on,
133 # so it is best to build them first (and mach before hurd, at that).
134 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
135                            $(before-compile)) \
136                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
137                                $(before-compile))
139 # Remove existing files from `before-compile'.  Things are added there when
140 # they must exist for dependency generation to work right, but once they
141 # exist there is no further need for every single file to depend on them,
142 # and those gratuitous dependencies result in many gratuitous
143 # recompilations.
144 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
146 # Don't let any before-compile file be an intermediate and get removed.
147 ifdef before-compile
148 $(before-compile):
149 endif
151 # Generate an ordered list of implicit rules which find the source files in
152 # each sysdep directory.  The old method was to use vpath to search all the
153 # sysdep directories.  However, that had the problem that a .S file in a
154 # later directory would be chosen over a .c file in an earlier directory,
155 # which does not preserve the desired sysdeps ordering behavior.
157 # When making the list of .d files to include, we can't know which ones
158 # have source in .s files, and thus do not in fact need a .d file.
159 # So we must define rules to make .d files for .s files.
160 define make-dummy-dep
161 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
162 endef
163 $(common-objpfx)dummy.d:
164         echo '# .s files cannot contain includes, so they need no deps.' > $@
166 # It matters that this set of rules, for compiling from sources in
167 # the current directory (the $srcdir/$subdir) come before the
168 # generated sysdep rules in included from sysd-rules below.  When
169 # compiling in the source tree, generated sources go into the current
170 # directory, and those should be chosen before any sources in sysdeps.
171 define o-iterator-doit
172 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
173 endef
174 object-suffixes-left := $(object-suffixes-for-libc)
175 include $(o-iterator)
176 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
178 define o-iterator-doit
179 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
180 endef
181 object-suffixes-left := $(object-suffixes-for-libc)
182 include $(o-iterator)
183 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
185 define o-iterator-doit
186 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
187 endef
188 object-suffixes-left := $(object-suffixes-for-libc)
189 include $(o-iterator)
190 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
192 # Omit the objpfx rules when building in the source tree, because
193 # objpfx is empty and so these rules just override the ones above.
194 ifdef objpfx
195 # Define first rules to find the source files in $(objpfx).
196 # Generated source files will end up there.
197 define o-iterator-doit
198 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
199 endef
200 object-suffixes-left := $(object-suffixes-for-libc)
201 include $(o-iterator)
202 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
204 define o-iterator-doit
205 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
206 endef
207 object-suffixes-left := $(object-suffixes-for-libc)
208 include $(o-iterator)
209 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
211 define o-iterator-doit
212 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
213 endef
214 object-suffixes-left := $(object-suffixes-for-libc)
215 include $(o-iterator)
216 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
217 endif
219 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
220 # patterns matching sysdep directories whose assembly source files should
221 # be suppressed.
222 ifdef inhibit-sysdep-asm
223 define open-check-inhibit-asm
224 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
225 endef
226 close-check-inhibit-asm = ;; esac ;
227 endif
229 # Don't include sysd-rules until sysd-Makefile is already there and has been
230 # included.  It might define inhibit-sysdep-asm, which would affect the
231 # contents of sysd-rules.
232 ifdef sysd-Makefile-done
233 -include $(+sysdir_pfx)sysd-rules
234 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
235 # The value of $(+sysdep_dirs) the sysd-rules was computed for
236 # differs from the one we are using now.  So force a rebuild of sysd-rules.
237 sysd-rules-force = FORCE
238 FORCE:
239 endif
240 endif
241 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
242                           $(wildcard $(foreach dir,$(sysdirs),\
243                                                $(dir)/Makefile))\
244                           $(sysd-rules-force)
245         -@rm -f $@T
246         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
247          for sysdir in $(config-sysdirs); do                                  \
248            case $$sysdir in \
249              /*) dir=$$sysdir ;; \
250              *)  dir="\$$(..)$$sysdir" ;; \
251            esac; \
252            for o in $(all-object-suffixes); do \
253              $(open-check-inhibit-asm) \
254              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
255                   \$$(compile-command.S)";                                    \
256              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
257                   \$$(compile-command.s)";                                    \
258              $(close-check-inhibit-asm) \
259              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
260                   \$$(compile-command.c)";                                    \
261            done; \
262            $(open-check-inhibit-asm) \
263            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
264                 \$$(make-dummy-dep)";                          \
265            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
266                 \$$(+make-deps)";                                             \
267            $(close-check-inhibit-asm)   \
268            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
269                 \$$(+make-deps)";                                             \
270          done;                                                                \
271          echo 'sysd-rules-done = t') > $@T
272         mv -f $@T $@
274 ifndef sysd-rules-done
275 # Don't do deps until this exists, because it provides rules to make the deps.
276 no_deps=t
277 endif
279 # Generate version maps.
280 ifeq ($(versioning),yes)
281 -include $(common-objpfx)sysd-versions
282 $(common-objpfx)sysd-versions: $(..)Versions.def $(..)versions.awk \
283                                $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
284                                $(wildcard $(+sysdep_dirs:%=%/Versions))
285         $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
286                -f $(filter-out $<,$^) > $@T
287         mv -f $@T $@
288 $(all-version-maps): $(common-objpfx)sysd-versions
289 endif
291 ifndef compile-command.S
292 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
293 endif
294 ifndef compile-command.s
295 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
296 endif
297 ifndef compile-command.c
298 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
299 endif
301 # GCC can grok options after the file name, and it looks nicer that way.
302 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
303 compile.S = \
304   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
305 COMPILE.S = \
306   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
307 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
309 # We need this for the output to go in the right place.  It will default to
310 # empty if make was configured to work with a cc that can't grok -c and -o
311 # together.  You can't compile the C library with such a compiler.
312 OUTPUT_OPTION = -o $@
314 S-CPPFLAGS = $(asm-CPPFLAGS)
315 define +make-deps
316 $(make-target-directory)
317 -@rm -f $@
318 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
319 sed \
320 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
321 $(sed-remove-objpfx) > $(@:.d=.T)
322 mv -f $(@:.d=.T) $@
323 endef
324 ifneq (,$(objpfx))
325 # Continuation lines here are dangerous because they introduce spaces!
326 define sed-remove-objpfx
327 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
328 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
329 endef
330 endif
332 # Shared library building.
334 ifeq (yes,$(build-shared))
336 # Reference map file only when versioning is selected and a map file name
337 # is given.
338 ifeq ($(versioning),yes)
339 map-file = $(firstword $(wildcard $($(@F:.so=-map)) \
340                                   $(common-objpfx)$(@F:.so=.map)))
341 load-map-file = $(map-file:%=-Wl,--version-script=%)
342 endif
344 # Pattern rule to build a shared object from an archive of PIC objects.
345 # This must come after the installation rules so Make doesn't try to
346 # build shared libraries in place from the installed *_pic.a files.
347 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
348 # on other shared objects.
349 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
350         $(build-shlib)
352 define build-shlib
353 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
354           -B$(csu-objpfx) $(load-map-file) \
355           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
356           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
357           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
358           -Wl,--whole-archive \
359           $(filter-out $(map-file) $(common-objpfx)$(@F:.so=.map) \
360                        $(+preinit) $(+postinit),$^) \
361           $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
362 endef
364 ifndef libc.so-version
365 # Undefine this because it can't work when we libc.so is unversioned.
366 static-only-routines =
367 endif
369 elide-routines.oS += $(filter-out $(static-only-routines),\
370                                   $(routines) $(aux) $(sysdep_routines))
371 elide-routines.os += $(static-only-routines)
373 # If we have versioned code we don't need the old versions in any of the
374 # static libraries.
375 elide-routines.o  += $(shared-only-routines)
376 elide-routines.op += $(shared-only-routines)
377 elide-routines.og += $(shared-only-routines)
378 elide-routines.ob += $(shared-only-routines)
380 # Don't try to use -lc when making libc.so itself.
381 # Also omits crti.o and crtn.o, which we do not want
382 # since we define our own `.init' section specially.
383 LDFLAGS-c.so = -nostdlib -nostartfiles
384 # But we still want to link libc.so against $(gnulib).
385 LDLIBS-c.so = $(gnulib)
386 # Give libc.so an entry point and make it directly runnable itself.
387 LDFLAGS-c.so += -e __libc_main
388 # Pre-link the objects of libc_pic.a so that we can locally resolve
389 # COMMON symbols before we link against ld.so.  This is because ld.so
390 # contains some of libc_pic.a already, which will prevent the COMMONs
391 # from being allocated in libc.so, which introduces evil dependencies
392 # between libc.so and ld.so, which can make it impossible to upgrade.
393 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
394         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
395         -Wl,-d -Wl,--whole-archive $^
396 # Use our own special initializer and finalizer files for libc.so.
397 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
398                          $(common-objpfx)libc_pic.os \
399                          $(elfobjdir)/sofini.os \
400                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
401                          $(common-objpfx)libc.map
402         $(build-shlib)
403 common-generated += libc.so libc_pic.os
404 ifdef libc.so-version
405 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
406         $(make-link)
407 common-generated += libc.so$(libc.so-version)
408 endif
409 endif
411 # Figure out the source filenames in this directory.
413 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
414                                                        $(routines) $(aux) \
415                                                        $(sysdep_routines)))
416 sysdep_routines := $(sysdep_routines)
418 headers := $(headers) $(sysdep_headers)
420 # This is the list of all object files, gotten by
421 # replacing every ".c" in `sources' with a ".o".
422 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
425 # The makefile may define $(extra-libs) with `libfoo libbar'
426 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
427 ifdef extra-libs
428 # extra-lib.mk is included once for each extra lib to define rules
429 # to build it, and to add its objects to the various variables.
430 # During its evaluation, $(lib) is set to the name of the library.
431 extra-libs-left := $(extra-libs)
432 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
433 endif
435 +depfiles := $(sources:.c=.d) \
436              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
437              $(addsuffix .d,$(tests) $(test-srcs) $(tests-static))
438 ifeq ($(build-programs),yes)
439 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
440 endif
441 +depfiles := $(addprefix $(objpfx),\
442                          $(filter-out $(addsuffix .d,$(omit-deps)),\
443                                       $(+depfiles)))
445 ifdef +depfiles
446 ifneq ($(no_deps),t)
447 -include $(+depfiles)
448 endif
449 endif
450 \f\f
451 # Maximize efficiency by minimizing the number of rules.
452 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
453 # Don't define any builtin rules.
454 MAKEFLAGS := $(MAKEFLAGS)r
456 # Generic rule for making directories.
458 # mkdir isn't smart enough to strip a trailing /.
459         mkdir $(@:%/=%)
461 # Make sure that object files are not removed
462 # when they are intermediates between sources and library members.
463 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
465 # Make sure that the parent library archive is never removed.
466 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
468 # Use the verbose option of ar and tar when not running silently.
469 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
470 verbose := v
471 else                                            # -s
472 verbose :=
473 endif                                           # not -s
475 ARFLAGS := r$(verbose)
476 CREATE_ARFLAGS := cru$(verbose)
478 # This makes all the object files in the parent library archive.
480 .PHONY: lib lib-noranlib
481 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
482 lib-noranlib: libobjs
484 # For object-suffix $o, the list of objects with that suffix.
485 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
486 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
487                                                        $(elide-routines$o)),\
488                                             $(objects)))
489 others: $(addprefix $(objpfx),$(install-lib))
491 ifndef objects
493 # Create the stamp$o files to keep the parent makefile happy.
494 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
495 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
496         $(make-target-directory)
497         rm -f $@; > $@
498 else
500 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
501 # timestamp file; these rules (one explicit rule is generated for each
502 # object suffix) write a list of objects to update in the stamp file.
503 # The parent will then actually add them all to the archive in the
504 # archive rule, below.
505 define o-iterator-doit
506 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
507 endef
508 define do-stamp
509 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
510 mv -f $@T $@
511 endef
512 object-suffixes-left := $(object-suffixes-for-libc)
513 include $(o-iterator)
515 endif
517 # Now define explicit rules to build the library archives; these depend
518 # on the stamp files built above.
519 define o-iterator-doit
520 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
521                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
522 endef
523 define do-makelib
524 cd $(common-objdir) && \
525 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
526 $(RANLIB) $@
527 endef
528 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
529 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
530 ifndef subdir
531 $(subdirs-stamps): subdir_lib;
532 endif
533 object-suffixes-left = $(object-suffixes-for-libc)
534 include $(o-iterator)
537 # This makes all the object files.
538 .PHONY: objects objs libobjs extra-objs
539 objects objs: libobjs extra-objs
540 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
541 extra-objs: $(addprefix $(objpfx),$(extra-objs))
543 # Canned sequence for building an extra library archive.
544 define build-extra-lib
545 $(patsubst %/,cd % &&,$(objpfx)) \
546 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
547       $(patsubst $(objpfx)%,%,$^)
548 $(RANLIB) $@
549 endef
551 # Installation.
553 .PHONY: force-install
554 force-install:
556 # $(install-lib) are installed from the object directory into $(libdir);
557 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
558 # unless they also appear in $(non-lib.a).  $(install-data) are installed
559 # as they are into $(datadir).  $(headers) are installed as they are in
560 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
561 # object directory into $(bindir) and $(sbindir), respectively.
562 # $(install-others) are absolute path names of files to install; rules to
563 # install them are defined elsewhere.
565 # The simple library name to install libc.a under.
566 # This could be defined by a sysdep Makefile.
567 ifndef libc-name
568 libc-name := c
569 endif
571 define do-install
572 $(make-target-directory)
573 $(INSTALL_DATA) $< $@
574 endef
576 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
577 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
578 define make-target-directory
579 $(addprefix $(..)./scripts/mkinstalldirs ,\
580             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
581 endef
583 # Any directory (parent or subdir) should install libc.a; this way
584 # "make install" in a subdir is guaranteed to install everything it changes.
585 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
586                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
587                                                      $(libprefix)$(libc-name)))
588 install: $(installed-libcs)
589 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
590         $(make-target-directory)
591         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
592 # Running ranlib after installing makes the __.SYMDEF time stamp up to
593 # date, which avoids messages from some linkers.
594         $(RANLIB) $@
596 define do-install-program
597 $(make-target-directory)
598 $(INSTALL_PROGRAM) $< $@.new
599 mv -f $@.new $@
600 endef
602 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
603 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
604 ifeq (yes,$(build-shared))
606 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
608 # Find which .so's have versions.
609 versioned := $(strip $(foreach so,$(install-lib.so),\
610                                $(patsubst %,$(so),$($(so)-version))))
612 # Install all the unversioned shared libraries.
613 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
614         $(inst_slibdir)/%.so: $(objpfx)%.so $(+force); $(do-install-program)
616 ifneq ($(findstring -s,$(LN_S)),)
617 define make-link
618 rm -f $@.new
619 $(SHELL) $(..)scripts/rellns-sh $< $@.new
620 mv -f $@.new $@
621 endef
622 else
623 # If we have no symbolic links don't bother with rellns-sh.
624 define make-link
625 rm -f $@.new
626 $(LN_S) $< $@.new
627 mv -f $@.new $@
628 endef
629 endif
631 # XXX The following will have to be changed when `ldconfig' is available.
632 ifneq (yes,$(cross-compiling))
633 ifeq (yes,$(has-ldconfig))
634 define make-shlib-link
636 endef
637 endif
638 endif
639 ifndef make-shlib-link
640 define make-shlib-link
641 $(make-link)
642 endef
643 endif
645 ifdef libc.so-version
646 # For a library specified to be version N, install three files:
647 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
648 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
650 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
651                                            $(+force)
652         $(make-shlib-link)
653 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
654         $(do-install-program)
655 install: $(inst_slibdir)/libc.so$(libc.so-version)
657 ifndef subdir
658 # What we install as libc.so for programs to link against is in fact a
659 # link script.  It contains references for the various libraries we need.
660 # The libc.so object is not complete since some functions are only defined
661 # in libc_nonshared.a.
662 install: $(inst_libdir)/libc.so
663 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
664                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
665                                                   $(libprefix)$(libc-name)) \
666                         $(+force)
667         (echo '/* GNU ld script';\
668          echo '   Use the shared library, but some functions are only in';\
669          echo '   the static library, so try that secondarily.  */';\
670          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
671               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
672               ')' \
673         ) > $@.new
674         mv -f $@.new $@
676 endif
678 else
679 install: $(inst_slibdir)/libc.so
680 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
681         $(do-install-program)
682 endif
684 ifneq (,$(versioned))
685 # Produce three sets of rules as above for all the smaller versioned libraries.
687 define o-iterator-doit
688 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
689 endef
690 object-suffixes-left := $(versioned)
691 include $(o-iterator)
693 # Make symlinks in the build directory, because the versioned names might
694 # be referenced by a DT_NEEDED in another library.
695 define o-iterator-doit
696 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
697 endef
698 object-suffixes-left := $(versioned)
699 include $(o-iterator)
701 generated += $(foreach o,$(versioned),$o$($o-version))
703 ifeq (,$($(subdir)-version))
704 define o-iterator-doit
705 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
706                                  $(+force);
707         $$(make-shlib-link)
708 endef
709 object-suffixes-left := $(versioned)
710 include $(o-iterator)
712 define o-iterator-doit
713 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
714         $$(do-install-program)
715 endef
716 object-suffixes-left := $(versioned)
717 include $(o-iterator)
718 else
719 define o-iterator-doit
720 $(inst_slibdir)/$o$($o-version): \
721   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
722         $$(make-shlib-link)
723 endef
724 object-suffixes-left := $(versioned)
725 include $(o-iterator)
727 define o-iterator-doit
728 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
729         $$(do-install-program)
730 endef
731 object-suffixes-left := $(versioned)
732 include $(o-iterator)
733 endif
734 endif
736 define do-install-so
737 $(do-install-program)
738 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
739            $(filter-out %.so,$@))
740 endef
742 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
743 $(foreach v,$(so-versions),\
744           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
745                                                $(+force)
746         $(do-install-so)
747 $(foreach v,$(so-versions),\
748           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
749         $(do-install-so)
750 endif
752 ifdef install-bin
753 $(addprefix $(inst_bindir)/,$(install-bin)): \
754     $(inst_bindir)/%: $(objpfx)% $(+force)
755         $(do-install-program)
756 endif
757 ifdef install-rootsbin
758 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
759    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
760         $(do-install-program)
761 endif
762 ifdef install-sbin
763 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
764     $(inst_sbindir)/%: $(objpfx)% $(+force)
765         $(do-install-program)
766 endif
767 ifdef install-lib
768 install-lib.a := $(filter lib%.a,$(install-lib))
769 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
770 ifdef install-lib-non.a
771 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
772   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
773         $(do-install)
774 endif
775 ifdef install-lib.a
776 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
777   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
778         $(do-install)
779         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
780 endif
781 endif
782 ifdef install-data
783 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
784         $(do-install)
785 endif
786 headers := $(strip $(headers))
787 ifdef headers
788 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
789         $(do-install)
790 endif   # headers
792 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
793         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
794 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
795 install-rootsbin-nosubdir: \
796         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
797 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
798 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
799                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
800                        $(addprefix $(libprefix),$(install-lib-non.a)))
801 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
802 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
803 install-others-nosubdir: $(install-others)
805 # We need all the `-nosubdir' targets so that `install' in the parent
806 # doesn't depend on several things which each iterate over the subdirs.
807 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
808 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
809 install-%:: install-%-nosubdir ;
811 .PHONY: install install-no-libc.a-nosubdir
812 ifeq ($(build-programs),yes)
813 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
814                             install-bin-nosubdir install-lib-nosubdir   \
815                             install-others-nosubdir install-rootsbin-nosubdir \
816                             install-sbin-nosubdir
817 else
818 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
819                             install-lib-nosubdir install-others-nosubdir
820 endif
821 install: install-no-libc.a-nosubdir
823 # Command to compile $< in $(objdir) using the native libraries.
824 define native-compile
825 $(make-target-directory)
826 $(patsubst %/,cd % &&,$(objpfx)) \
827 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
828             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
829 endef
831 # Command to compile $< in $(common-objdir) using the native libraries.
832 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
833 define common-objdir-compile
834 $(patsubst %/,cd % &&,$(objpfx)) \
835 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
836             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
837 endef
839 # We always want to use configuration definitions.
840 # Note that this is only used for commands running in $(objpfx).
841 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
843 # Support the GNU standard name for this target.
844 .PHONY: check
845 check: tests
847 .PHONY: TAGS
848 TAGS: $(objpfx)distinfo $(..)MakeTAGS
849         $(MAKE) $(addprefix -f ,$^) $@
851 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
852         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
853 FORCE:
856 .PHONY: echo-headers
857 echo-headers:
858         @echo $(headers)
861 # Common cleaning targets.
863 .PHONY: common-mostlyclean common-clean mostlyclean clean
864 clean: common-clean
865 mostlyclean: common-mostlyclean
867 # Remove the object files.
868 common-mostlyclean:
869         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
870                                      $(sysdep-others) $(tests-static) stubs \
871                                      $(addsuffix .o,$(tests) $(test-srcs) \
872                                                     $(tests-static) \
873                                                     $(others) \
874                                                     $(sysdep-others)) \
875                                      $(addsuffix .out,$(tests) $(test-srcs)) \
876                                      $(addsuffix .sout,$(tests-static)))
877         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
878                                      $(install-lib.so) \
879                                      $(install-lib.so:%.so=%_pic.a))
880         -rm -f core
881         $(rmobjs)
882 define rmobjs
883 $(foreach o,$(object-suffixes-for-libc),
884 -rm -f $(objpfx)stamp$o $(o-objects))
885 endef
887 # Also remove the dependencies and generated source files.
888 common-clean: common-mostlyclean
889         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
890         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
891         -rm -f $(addprefix $(common-objpfx),$(common-generated))
892         -rm -f $(objpfx)distinfo
894 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
895 # for each function which is a stub.  We grovel over all the .d files
896 # looking for references to <stub-tag.h>.  Then we grovel over each
897 # referenced source file to see what stub function it defines.
899 ifdef objpfx
900 .PHONY: stubs # The parent Makefile calls this target.
901 stubs: $(objpfx)stubs
902 endif
903 s = $(sysdep_dir)/generic
904 $(objpfx)stubs: $(+depfiles)
905 # Use /dev/null since `...` might expand to empty.
906         (s=`cd $s && /bin/pwd`; \
907          $(patsubst %/,cd % &&,$(objpfx)) \
908          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
909           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
910                 -e '/stub-tag\.h/{; g; p; }' \
911                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
912              /dev/null) > $@T
913         mv -f $@T $@
915 # Make the distribution tar file.
917 .PHONY: dist
918 dist: $(objpfx)distinfo $(..)Make-dist
919         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
921 # Avoid depending on source files found in sysdeps dirs,
922 # because the references affect implicit rule selection.
923 dist: $(filter-out %.c %.S %.s,$(distribute))
925 # We used to simply export all these variables, but that frequently made the
926 # environment get too large.  Instead, we write all the information into
927 # a generated makefile fragment `distinfo', and then include it with -f in
928 # the sub-make that makes the distribution (above).
929 $(objpfx)distinfo: Makefile $(..)Makerules \
930                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
931         $(make-target-directory)
932         $(distinfo-vars)
933         mv -f $@.new $@
934 .PHONY: subdir_distinfo
935 subdir_distinfo: $(objpfx)distinfo
937 define distinfo-vars
938 rm -f $@.new
939 echo > $@.new 'subdir := $(subdir)'
940 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
941               headers sysdep_headers distribute dont_distribute generated \
942               others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
943               tests-static $(extra-libs:%=%-map) versioned \
944               $(addprefix install-,lib lib.so data bin sbin others),
945 echo >> $@.new '$(subdir)-$(var) := $($(var))'
946 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
947 endef
949 ifneq (,$(strip $(gpl2lgpl)))
950 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
951 # Snarf from the master source and frob the copying notice.
952 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
953         sed -f $^ > $@-tmp
954 # So I don't edit them by mistake.
955         chmod a-w $@-tmp
956         mv -f $@-tmp $@
957 ifeq ($(with-cvs),yes)
958         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
959 endif
960 endif
961 endif