Update.
[glibc.git] / Makerules
bloba339caa71412907df6ec7503d38a24d60f16353a
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 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
283 generated += $(version-maps)
285 ifndef avoid-generated
286 $(common-objpfx)sysd-versions: $(..)Versions.def $(..)scripts/versions.awk \
287                                $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
288                                $(wildcard $(+sysdep_dirs:%=%/Versions))
289         $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
290                -v move_if_change='$(move-if-change)' \
291                -f $(filter-out $<,$^) > $@T
292         mv -f $@T $@
293 endif
294 endif
296 ifndef compile-command.S
297 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
298 endif
299 ifndef compile-command.s
300 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
301 endif
302 ifndef compile-command.c
303 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
304 endif
306 # GCC can grok options after the file name, and it looks nicer that way.
307 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
308 compile.S = \
309   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
310 COMPILE.S = \
311   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
312 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
314 # We need this for the output to go in the right place.  It will default to
315 # empty if make was configured to work with a cc that can't grok -c and -o
316 # together.  You can't compile the C library with such a compiler.
317 OUTPUT_OPTION = -o $@
319 S-CPPFLAGS = $(asm-CPPFLAGS)
320 define +make-deps
321 $(make-target-directory)
322 -@rm -f $@
323 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
324 sed \
325 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
326 $(sed-remove-objpfx) > $(@:.d=.T)
327 mv -f $(@:.d=.T) $@
328 endef
329 ifneq (,$(objpfx))
330 # Continuation lines here are dangerous because they introduce spaces!
331 define sed-remove-objpfx
332 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
333 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
334 endef
335 endif
337 # Shared library building.
339 ifeq (yes,$(build-shared))
341 # Reference map file only when versioning is selected and a map file name
342 # is given.
343 ifeq ($(versioning),yes)
344 map-file = $(firstword $(wildcard $($(@F:.so=-map)) \
345                                   $(common-objpfx)$(@F:.so=.map)))
346 load-map-file = $(map-file:%=-Wl,--version-script=%)
347 endif
349 # Pattern rule to build a shared object from an archive of PIC objects.
350 # This must come after the installation rules so Make doesn't try to
351 # build shared libraries in place from the installed *_pic.a files.
352 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
353 # on other shared objects.
354 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
355         $(build-shlib)
357 define build-shlib
358 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
359           -B$(csu-objpfx) $(load-map-file) \
360           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
361           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
362           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
363           -Wl,--whole-archive \
364           $(filter-out $(map-file) $(common-objpfx)$(@F:.so=.map) \
365                        $(+preinit) $(+postinit),$^) \
366           $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
367 endef
369 ifndef libc.so-version
370 # Undefine this because it can't work when we libc.so is unversioned.
371 static-only-routines =
372 endif
374 elide-routines.oS += $(filter-out $(static-only-routines),\
375                                   $(routines) $(aux) $(sysdep_routines))
376 elide-routines.os += $(static-only-routines)
378 # If we have versioned code we don't need the old versions in any of the
379 # static libraries.
380 elide-routines.o  += $(shared-only-routines)
381 elide-routines.op += $(shared-only-routines)
382 elide-routines.og += $(shared-only-routines)
383 elide-routines.ob += $(shared-only-routines)
385 # Don't try to use -lc when making libc.so itself.
386 # Also omits crti.o and crtn.o, which we do not want
387 # since we define our own `.init' section specially.
388 LDFLAGS-c.so = -nostdlib -nostartfiles
389 # But we still want to link libc.so against $(gnulib).
390 LDLIBS-c.so = $(gnulib)
391 # Give libc.so an entry point and make it directly runnable itself.
392 LDFLAGS-c.so += -e __libc_main
393 # Pre-link the objects of libc_pic.a so that we can locally resolve
394 # COMMON symbols before we link against ld.so.  This is because ld.so
395 # contains some of libc_pic.a already, which will prevent the COMMONs
396 # from being allocated in libc.so, which introduces evil dependencies
397 # between libc.so and ld.so, which can make it impossible to upgrade.
398 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
399         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
400         -Wl,-d -Wl,--whole-archive $^
401 # Use our own special initializer and finalizer files for libc.so.
402 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
403                          $(common-objpfx)libc_pic.os \
404                          $(elfobjdir)/sofini.os \
405                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
406                          $(common-objpfx)libc.map
407         $(build-shlib)
408 common-generated += libc.so libc_pic.os
409 ifdef libc.so-version
410 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
411         $(make-link)
412 common-generated += libc.so$(libc.so-version)
413 endif
414 endif
416 # Figure out the source filenames in this directory.
418 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
419                                                        $(routines) $(aux) \
420                                                        $(sysdep_routines)))
421 sysdep_routines := $(sysdep_routines)
423 headers := $(headers) $(sysdep_headers)
425 # This is the list of all object files, gotten by
426 # replacing every ".c" in `sources' with a ".o".
427 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
430 # The makefile may define $(extra-libs) with `libfoo libbar'
431 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
432 ifdef extra-libs
433 # extra-lib.mk is included once for each extra lib to define rules
434 # to build it, and to add its objects to the various variables.
435 # During its evaluation, $(lib) is set to the name of the library.
436 extra-libs-left := $(extra-libs)
437 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
438 endif
440 +depfiles := $(sources:.c=.d) \
441              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
442              $(addsuffix .d,$(tests) $(test-srcs) $(tests-static))
443 ifeq ($(build-programs),yes)
444 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
445 endif
446 +depfiles := $(addprefix $(objpfx),\
447                          $(filter-out $(addsuffix .d,$(omit-deps)),\
448                                       $(+depfiles)))
450 ifdef +depfiles
451 ifneq ($(no_deps),t)
452 -include $(+depfiles)
453 endif
454 endif
455 \f\f
456 # Maximize efficiency by minimizing the number of rules.
457 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
458 # Don't define any builtin rules.
459 MAKEFLAGS := $(MAKEFLAGS)r
461 # Generic rule for making directories.
463 # mkdir isn't smart enough to strip a trailing /.
464         mkdir $(@:%/=%)
466 # Make sure that object files are not removed
467 # when they are intermediates between sources and library members.
468 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
470 # Make sure that the parent library archive is never removed.
471 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
473 # Use the verbose option of ar and tar when not running silently.
474 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
475 verbose := v
476 else                                            # -s
477 verbose :=
478 endif                                           # not -s
480 ARFLAGS := r$(verbose)
481 CREATE_ARFLAGS := cru$(verbose)
483 # This makes all the object files in the parent library archive.
485 .PHONY: lib lib-noranlib
486 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
487 lib-noranlib: libobjs
489 # For object-suffix $o, the list of objects with that suffix.
490 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
491 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
492                                                        $(elide-routines$o)),\
493                                             $(objects)))
494 others: $(addprefix $(objpfx),$(install-lib))
496 ifndef objects
498 # Create the stamp$o files to keep the parent makefile happy.
499 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
500 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
501         $(make-target-directory)
502         rm -f $@; > $@
503 else
505 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
506 # timestamp file; these rules (one explicit rule is generated for each
507 # object suffix) write a list of objects to update in the stamp file.
508 # The parent will then actually add them all to the archive in the
509 # archive rule, below.
510 define o-iterator-doit
511 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
512 endef
513 define do-stamp
514 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
515 mv -f $@T $@
516 endef
517 object-suffixes-left := $(object-suffixes-for-libc)
518 include $(o-iterator)
520 endif
522 # Now define explicit rules to build the library archives; these depend
523 # on the stamp files built above.
524 define o-iterator-doit
525 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
526                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
527 endef
528 define do-makelib
529 cd $(common-objdir) && \
530 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
531 $(RANLIB) $@
532 endef
533 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
534 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
535 ifndef subdir
536 $(subdirs-stamps): subdir_lib;
537 endif
538 object-suffixes-left = $(object-suffixes-for-libc)
539 include $(o-iterator)
542 # This makes all the object files.
543 .PHONY: objects objs libobjs extra-objs
544 objects objs: libobjs extra-objs
545 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
546 extra-objs: $(addprefix $(objpfx),$(extra-objs))
548 # Canned sequence for building an extra library archive.
549 define build-extra-lib
550 $(patsubst %/,cd % &&,$(objpfx)) \
551 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
552       $(patsubst $(objpfx)%,%,$^)
553 $(RANLIB) $@
554 endef
556 # Installation.
558 .PHONY: force-install
559 force-install:
561 # $(install-lib) are installed from the object directory into $(libdir);
562 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
563 # unless they also appear in $(non-lib.a).  $(install-data) are installed
564 # as they are into $(datadir).  $(headers) are installed as they are in
565 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
566 # object directory into $(bindir) and $(sbindir), respectively.
567 # $(install-others) are absolute path names of files to install; rules to
568 # install them are defined elsewhere.
570 # The simple library name to install libc.a under.
571 # This could be defined by a sysdep Makefile.
572 ifndef libc-name
573 libc-name := c
574 endif
576 define do-install
577 $(make-target-directory)
578 $(INSTALL_DATA) $< $@
579 endef
581 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
582 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
583 define make-target-directory
584 $(addprefix $(..)./scripts/mkinstalldirs ,\
585             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
586 endef
588 # Any directory (parent or subdir) should install libc.a; this way
589 # "make install" in a subdir is guaranteed to install everything it changes.
590 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
591                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
592                                                      $(libprefix)$(libc-name)))
593 install: $(installed-libcs)
594 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
595         $(make-target-directory)
596         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
597 # Running ranlib after installing makes the __.SYMDEF time stamp up to
598 # date, which avoids messages from some linkers.
599         $(RANLIB) $@
601 define do-install-program
602 $(make-target-directory)
603 $(INSTALL_PROGRAM) $< $@.new
604 mv -f $@.new $@
605 endef
607 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
608 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
609 ifeq (yes,$(build-shared))
611 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
613 # Find which .so's have versions.
614 versioned := $(strip $(foreach so,$(install-lib.so),\
615                                $(patsubst %,$(so),$($(so)-version))))
617 # Install all the unversioned shared libraries.
618 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
619         $(inst_slibdir)/%.so: $(objpfx)%.so $(+force); $(do-install-program)
621 ifneq ($(findstring -s,$(LN_S)),)
622 define make-link
623 rm -f $@.new
624 $(SHELL) $(..)scripts/rellns-sh $< $@.new
625 mv -f $@.new $@
626 endef
627 else
628 # If we have no symbolic links don't bother with rellns-sh.
629 define make-link
630 rm -f $@.new
631 $(LN_S) $< $@.new
632 mv -f $@.new $@
633 endef
634 endif
636 # XXX The following will have to be changed when `ldconfig' is available.
637 ifneq (yes,$(cross-compiling))
638 ifeq (yes,$(has-ldconfig))
639 define make-shlib-link
641 endef
642 endif
643 endif
644 ifndef make-shlib-link
645 define make-shlib-link
646 $(make-link)
647 endef
648 endif
650 ifdef libc.so-version
651 # For a library specified to be version N, install three files:
652 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
653 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
655 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
656                                            $(+force)
657         $(make-shlib-link)
658 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
659         $(do-install-program)
660 install: $(inst_slibdir)/libc.so$(libc.so-version)
662 ifndef subdir
663 # What we install as libc.so for programs to link against is in fact a
664 # link script.  It contains references for the various libraries we need.
665 # The libc.so object is not complete since some functions are only defined
666 # in libc_nonshared.a.
667 install: $(inst_libdir)/libc.so
668 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
669                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
670                                                   $(libprefix)$(libc-name)) \
671                         $(+force)
672         (echo '/* GNU ld script';\
673          echo '   Use the shared library, but some functions are only in';\
674          echo '   the static library, so try that secondarily.  */';\
675          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
676               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
677               ')' \
678         ) > $@.new
679         mv -f $@.new $@
681 endif
683 else
684 install: $(inst_slibdir)/libc.so
685 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
686         $(do-install-program)
687 endif
689 ifneq (,$(versioned))
690 # Produce three sets of rules as above for all the smaller versioned libraries.
692 define o-iterator-doit
693 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
694 endef
695 object-suffixes-left := $(versioned)
696 include $(o-iterator)
698 # Make symlinks in the build directory, because the versioned names might
699 # be referenced by a DT_NEEDED in another library.
700 define o-iterator-doit
701 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
702 endef
703 object-suffixes-left := $(versioned)
704 include $(o-iterator)
706 generated += $(foreach o,$(versioned),$o$($o-version))
708 ifeq (,$($(subdir)-version))
709 define o-iterator-doit
710 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
711                                  $(+force);
712         $$(make-shlib-link)
713 endef
714 object-suffixes-left := $(versioned)
715 include $(o-iterator)
717 define o-iterator-doit
718 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
719         $$(do-install-program)
720 endef
721 object-suffixes-left := $(versioned)
722 include $(o-iterator)
723 else
724 define o-iterator-doit
725 $(inst_slibdir)/$o$($o-version): \
726   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
727         $$(make-shlib-link)
728 endef
729 object-suffixes-left := $(versioned)
730 include $(o-iterator)
732 define o-iterator-doit
733 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
734         $$(do-install-program)
735 endef
736 object-suffixes-left := $(versioned)
737 include $(o-iterator)
738 endif
739 endif
741 define do-install-so
742 $(do-install-program)
743 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
744            $(filter-out %.so,$@))
745 endef
747 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
748 $(foreach v,$(so-versions),\
749           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
750                                                $(+force)
751         $(do-install-so)
752 $(foreach v,$(so-versions),\
753           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
754         $(do-install-so)
755 endif
757 ifdef install-bin
758 $(addprefix $(inst_bindir)/,$(install-bin)): \
759     $(inst_bindir)/%: $(objpfx)% $(+force)
760         $(do-install-program)
761 endif
762 ifdef install-rootsbin
763 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
764    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
765         $(do-install-program)
766 endif
767 ifdef install-sbin
768 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
769     $(inst_sbindir)/%: $(objpfx)% $(+force)
770         $(do-install-program)
771 endif
772 ifdef install-lib
773 install-lib.a := $(filter lib%.a,$(install-lib))
774 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
775 ifdef install-lib-non.a
776 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
777   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
778         $(do-install)
779 endif
780 ifdef install-lib.a
781 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
782   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
783         $(do-install)
784         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
785 endif
786 endif
787 ifdef install-data
788 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
789         $(do-install)
790 endif
791 headers := $(strip $(headers))
792 ifdef headers
793 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
794         $(do-install)
795 endif   # headers
797 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
798         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
799 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
800 install-rootsbin-nosubdir: \
801         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
802 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
803 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
804                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
805                        $(addprefix $(libprefix),$(install-lib-non.a)))
806 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
807 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
808 install-others-nosubdir: $(install-others)
810 # We need all the `-nosubdir' targets so that `install' in the parent
811 # doesn't depend on several things which each iterate over the subdirs.
812 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
813 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
814 install-%:: install-%-nosubdir ;
816 .PHONY: install install-no-libc.a-nosubdir
817 ifeq ($(build-programs),yes)
818 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
819                             install-bin-nosubdir install-lib-nosubdir   \
820                             install-others-nosubdir install-rootsbin-nosubdir \
821                             install-sbin-nosubdir
822 else
823 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
824                             install-lib-nosubdir install-others-nosubdir
825 endif
826 install: install-no-libc.a-nosubdir
828 # Command to compile $< in $(objdir) using the native libraries.
829 define native-compile
830 $(make-target-directory)
831 $(patsubst %/,cd % &&,$(objpfx)) \
832 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
833             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
834 endef
836 # Command to compile $< in $(common-objdir) using the native libraries.
837 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
838 define common-objdir-compile
839 $(patsubst %/,cd % &&,$(objpfx)) \
840 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
841             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
842 endef
844 # We always want to use configuration definitions.
845 # Note that this is only used for commands running in $(objpfx).
846 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
848 # Support the GNU standard name for this target.
849 .PHONY: check
850 check: tests
852 .PHONY: TAGS
853 TAGS: $(objpfx)distinfo $(..)MakeTAGS
854         $(MAKE) $(addprefix -f ,$^) $@
856 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
857         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
858 FORCE:
861 .PHONY: echo-headers
862 echo-headers:
863         @echo $(headers)
866 # Common cleaning targets.
868 .PHONY: common-mostlyclean common-clean mostlyclean clean
869 clean: common-clean
870 mostlyclean: common-mostlyclean
872 # Remove the object files.
873 common-mostlyclean:
874         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
875                                      $(sysdep-others) $(tests-static) stubs \
876                                      $(addsuffix .o,$(tests) $(test-srcs) \
877                                                     $(tests-static) \
878                                                     $(others) \
879                                                     $(sysdep-others)) \
880                                      $(addsuffix .out,$(tests) $(test-srcs)) \
881                                      $(addsuffix .sout,$(tests-static)))
882         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
883                                      $(install-lib.so) \
884                                      $(install-lib.so:%.so=%_pic.a))
885         -rm -f core
886         $(rmobjs)
887 define rmobjs
888 $(foreach o,$(object-suffixes-for-libc),
889 -rm -f $(objpfx)stamp$o $(o-objects))
890 endef
892 # Also remove the dependencies and generated source files.
893 common-clean: common-mostlyclean
894         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
895         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
896         -rm -f $(addprefix $(common-objpfx),$(common-generated))
897         -rm -f $(objpfx)distinfo
899 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
900 # for each function which is a stub.  We grovel over all the .d files
901 # looking for references to <stub-tag.h>.  Then we grovel over each
902 # referenced source file to see what stub function it defines.
904 ifdef objpfx
905 .PHONY: stubs # The parent Makefile calls this target.
906 stubs: $(objpfx)stubs
907 endif
908 s = $(sysdep_dir)/generic
909 $(objpfx)stubs: $(+depfiles)
910 # Use /dev/null since `...` might expand to empty.
911         (s=`cd $s && /bin/pwd`; \
912          $(patsubst %/,cd % &&,$(objpfx)) \
913          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
914           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
915                 -e '/stub-tag\.h/{; g; p; }' \
916                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
917              /dev/null) > $@T
918         mv -f $@T $@
920 # Make the distribution tar file.
922 .PHONY: dist
923 dist: $(objpfx)distinfo $(..)Make-dist
924         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
926 # Avoid depending on source files found in sysdeps dirs,
927 # because the references affect implicit rule selection.
928 dist: $(filter-out %.c %.S %.s,$(distribute))
930 # We used to simply export all these variables, but that frequently made the
931 # environment get too large.  Instead, we write all the information into
932 # a generated makefile fragment `distinfo', and then include it with -f in
933 # the sub-make that makes the distribution (above).
934 $(objpfx)distinfo: Makefile $(..)Makerules \
935                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
936         $(make-target-directory)
937         $(distinfo-vars)
938         mv -f $@.new $@
939 .PHONY: subdir_distinfo
940 subdir_distinfo: $(objpfx)distinfo
942 define distinfo-vars
943 rm -f $@.new
944 echo > $@.new 'subdir := $(subdir)'
945 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
946               headers sysdep_headers distribute dont_distribute generated \
947               others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
948               tests-static $(extra-libs:%=%-map) versioned \
949               $(addprefix install-,lib lib.so data bin sbin others),
950 echo >> $@.new '$(subdir)-$(var) := $($(var))'
951 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
952 endef
954 ifneq (,$(strip $(gpl2lgpl)))
955 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
956 # Snarf from the master source and frob the copying notice.
957 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
958         sed -f $^ > $@-tmp
959 # So I don't edit them by mistake.
960         chmod a-w $@-tmp
961         mv -f $@-tmp $@
962 ifeq ($(with-cvs),yes)
963         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
964 endif
965 endif
966 endif