Update.
[glibc.git] / Makerules
blobcf0a6a5bfc45c8b93ec2a9f1bc4f4c7ba954eee4
1 # Copyright (C) 1991,92,93,94,95,96,97,98,99 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 file in $(config-sysdirs:=/Makefile); do                         \
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 define o-iterator-doit
164 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
165 endef
166 object-suffixes-left := $(all-object-suffixes)
167 include $(o-iterator)
168 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
170 define o-iterator-doit
171 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
172 endef
173 object-suffixes-left := $(all-object-suffixes)
174 include $(o-iterator)
175 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
177 define o-iterator-doit
178 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
179 endef
180 object-suffixes-left := $(all-object-suffixes)
181 include $(o-iterator)
182 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
184 # Omit the objpfx rules when building in the source tree, because
185 # objpfx is empty and so these rules just override the ones above.
186 ifdef objpfx
187 # Define first rules to find the source files in $(objpfx).
188 # Generated source files will end up there.
189 define o-iterator-doit
190 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
191 endef
192 object-suffixes-left := $(all-object-suffixes)
193 include $(o-iterator)
194 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
196 define o-iterator-doit
197 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
198 endef
199 object-suffixes-left := $(all-object-suffixes)
200 include $(o-iterator)
201 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
203 define o-iterator-doit
204 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
205 endef
206 object-suffixes-left := $(all-object-suffixes)
207 include $(o-iterator)
208 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
209 endif
211 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
212 # patterns matching sysdep directories whose assembly source files should
213 # be suppressed.
214 ifdef inhibit-sysdep-asm
215 define open-check-inhibit-asm
216 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
217 endef
218 close-check-inhibit-asm = ;; esac ;
219 endif
221 # Don't include sysd-rules until sysd-Makefile is already there and has been
222 # included.  It might define inhibit-sysdep-asm, which would affect the
223 # contents of sysd-rules.
224 ifdef sysd-Makefile-done
225 -include $(+sysdir_pfx)sysd-rules
226 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
227 # The value of $(+sysdep_dirs) the sysd-rules was computed for
228 # differs from the one we are using now.  So force a rebuild of sysd-rules.
229 sysd-rules-force = FORCE
230 FORCE:
231 endif
232 endif
233 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
234                           $(wildcard $(foreach dir,$(sysdirs),\
235                                                $(dir)/Makefile))\
236                           $(sysd-rules-force)
237         -@rm -f $@T
238         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
239          for dir in $(config-sysdirs:%='$$(..)%'); do                         \
240            for o in $(all-object-suffixes); do \
241              $(open-check-inhibit-asm) \
242              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
243                   \$$(compile-command.S)";                                    \
244              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
245                   \$$(compile-command.s)";                                    \
246              $(close-check-inhibit-asm) \
247              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
248                   \$$(compile-command.c)";                                    \
249            done; \
250            $(open-check-inhibit-asm) \
251            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
252                 \$$(make-dummy-dep)";                          \
253            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
254                 \$$(+make-deps)";                                             \
255            $(close-check-inhibit-asm)   \
256            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
257                 \$$(+make-deps)";                                             \
258          done;                                                                \
259          echo 'sysd-rules-done = t') > $@T
260         mv -f $@T $@
262 ifndef sysd-rules-done
263 # Don't do deps until this exists, because it provides rules to make the deps.
264 no_deps=t
265 endif
267 # Generate version maps, but wait until sysdep-subdirs is known
268 ifdef sysd-dirs-done
269 ifeq ($(versioning),yes)
270 -include $(common-objpfx)sysd-versions
271 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
272 common-generated += $(version-maps) sysd-versions
274 ifndef avoid-generated
275 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
276 sysd-versions-force = FORCE
277 FORCE:
278 endif
279 $(common-objpfx)Versions.all: $(..)Versions.def \
280                               $(wildcard $(add-ons:%=$(..)%/Versions.def))
281         cat $^ > $@T
282         mv -f $@T $@
283 common-generated += $(common-objpfx)Versions.all
284 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
285                                $(..)scripts/versions.awk \
286                                $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
287                                $(wildcard $(sysdirs:%=%/Versions)) \
288                                $(sysd-versions-force)
289         { echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
290           $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
291                  -v move_if_change='$(move-if-change)' \
292                  -f $(filter-out $< $(sysd-versions-force),$^); \
293         } > $@T
294         mv -f $@T $@
295 endif # avoid-generated
296 endif # $(versioning) = yes
297 endif # sysd-dirs-done
299 ifndef compile-command.S
300 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
301 endif
302 ifndef compile-command.s
303 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
304 endif
305 ifndef compile-command.c
306 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
307 endif
309 # GCC can grok options after the file name, and it looks nicer that way.
310 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
311 compile.S = \
312   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
313 COMPILE.S = \
314   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
315 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
317 # We need this for the output to go in the right place.  It will default to
318 # empty if make was configured to work with a cc that can't grok -c and -o
319 # together.  You can't compile the C library with such a compiler.
320 OUTPUT_OPTION = -o $@
322 S-CPPFLAGS = $(asm-CPPFLAGS)
323 define +make-deps
324 $(make-target-directory)
325 -@rm -f $@
326 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
327 sed \
328 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
329 $(sed-remove-objpfx) > $(@:.d=.T)
330 mv -f $(@:.d=.T) $@
331 endef
332 ifneq (,$(objpfx))
333 # Continuation lines here are dangerous because they introduce spaces!
334 define sed-remove-objpfx
335 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
336 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
337 endef
338 endif
340 # Shared library building.
342 ifeq (yes,$(build-shared))
344 # Reference map file only when versioning is selected and a map file name
345 # is given.
346 ifeq ($(versioning),yes)
347 map-file = $(firstword $($(@F:.so=-map)) \
348                        $(addprefix $(common-objpfx), \
349                                    $(filter $(@F:.so=.map),$(version-maps))))
350 load-map-file = $(map-file:%=-Wl,--version-script=%)
351 endif
353 # Pattern rule to build a shared object from an archive of PIC objects.
354 # This must come after the installation rules so Make doesn't try to
355 # build shared libraries in place from the installed *_pic.a files.
356 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
357 # on other shared objects.
358 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
359         $(build-shlib)
361 define build-shlib
362 $(LINK.o) -shared -Wl,-O1 -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
363           -B$(csu-objpfx) $(load-map-file) \
364           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
365           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
366           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
367           -Wl,--whole-archive \
368           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
369           $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
370 endef
372 # This macro is similar to build-shlib but it does not define a soname
373 # and it does not depend on the destination name to start with `lib'.
374 define build-module
375 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
376           -B$(csu-objpfx) $(load-map-file) \
377           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
378           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
379           -Wl,--whole-archive \
380           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
381           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
382 endef
384 ifndef libc.so-version
385 # Undefine this because it can't work when we libc.so is unversioned.
386 static-only-routines =
387 endif
389 elide-routines.oS += $(filter-out $(static-only-routines),\
390                                   $(routines) $(aux) $(sysdep_routines))
391 elide-routines.os += $(static-only-routines)
393 # If we have versioned code we don't need the old versions in any of the
394 # static libraries.
395 elide-routines.o  += $(shared-only-routines)
396 elide-routines.op += $(shared-only-routines)
397 elide-routines.og += $(shared-only-routines)
398 elide-routines.ob += $(shared-only-routines)
400 # Don't try to use -lc when making libc.so itself.
401 # Also omits crti.o and crtn.o, which we do not want
402 # since we define our own `.init' section specially.
403 LDFLAGS-c.so = -nostdlib -nostartfiles
404 # But we still want to link libc.so against $(gnulib).
405 LDLIBS-c.so += $(gnulib)
406 # Give libc.so an entry point and make it directly runnable itself.
407 LDFLAGS-c.so += -e __libc_main
408 # Pre-link the objects of libc_pic.a so that we can locally resolve
409 # COMMON symbols before we link against ld.so.  This is because ld.so
410 # contains some of libc_pic.a already, which will prevent the COMMONs
411 # from being allocated in libc.so, which introduces evil dependencies
412 # between libc.so and ld.so, which can make it impossible to upgrade.
413 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
414         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
415         -Wl,-d -Wl,--whole-archive $^
416 # Use our own special initializer and finalizer files for libc.so.
417 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
418                          $(common-objpfx)libc_pic.os \
419                          $(elfobjdir)/sofini.os \
420                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so
421         $(build-shlib)
422 ifeq ($(versioning),yes)
423 $(common-objpfx)libc.so: $(common-objpfx)libc.map
424 endif
425 common-generated += libc.so libc_pic.os
426 ifdef libc.so-version
427 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
428         $(make-link)
429 common-generated += libc.so$(libc.so-version)
430 endif
431 endif
433 # Figure out the source filenames in this directory.
435 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
436                                                        $(routines) $(aux) \
437                                                        $(sysdep_routines)))
438 sysdep_routines := $(sysdep_routines)
440 headers := $(headers) $(sysdep_headers)
442 # This is the list of all object files, gotten by
443 # replacing every ".c" in `sources' with a ".o".
444 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
447 # The makefile may define $(extra-libs) with `libfoo libbar'
448 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
449 ifdef extra-libs
450 # extra-lib.mk is included once for each extra lib to define rules
451 # to build it, and to add its objects to the various variables.
452 # During its evaluation, $(lib) is set to the name of the library.
453 extra-libs-left := $(extra-libs)
454 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
455 endif
457 +depfiles := $(sources:.c=.d) \
458              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
459              $(addsuffix .d,$(tests) $(test-srcs))
460 ifeq ($(build-programs),yes)
461 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
462 endif
463 +depfiles := $(addprefix $(objpfx),\
464                          $(filter-out $(addsuffix .d,$(omit-deps)),\
465                                       $(+depfiles)))
467 ifdef +depfiles
468 ifneq ($(no_deps),t)
469 -include $(+depfiles)
470 endif
471 endif
472 \f\f
473 # Maximize efficiency by minimizing the number of rules.
474 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
475 # Don't define any builtin rules.
476 MAKEFLAGS := $(MAKEFLAGS)r
478 # Generic rule for making directories.
480 # mkdir isn't smart enough to strip a trailing /.
481         mkdir $(@:%/=%)
483 # Make sure that object files are not removed
484 # when they are intermediates between sources and library members.
485 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
487 # Make sure that the parent library archive is never removed.
488 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
490 # Use the verbose option of ar and tar when not running silently.
491 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
492 verbose := v
493 else                                            # -s
494 verbose :=
495 endif                                           # not -s
497 ARFLAGS := r$(verbose)
498 CREATE_ARFLAGS := cru$(verbose)
500 # This makes all the object files in the parent library archive.
502 .PHONY: lib lib-noranlib
503 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
504 lib-noranlib: libobjs
506 # For object-suffix $o, the list of objects with that suffix.
507 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
508 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
509                                                        $(elide-routines$o)),\
510                                             $(objects)))
511 others: $(addprefix $(objpfx),$(install-lib))
513 ifndef objects
515 # Create the stamp$o files to keep the parent makefile happy.
516 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
517 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
518         $(make-target-directory)
519         rm -f $@; > $@
520 else
522 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
523 # timestamp file; these rules (one explicit rule is generated for each
524 # object suffix) write a list of objects to update in the stamp file.
525 # The parent will then actually add them all to the archive in the
526 # archive rule, below.
527 define o-iterator-doit
528 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
529 endef
530 define do-stamp
531 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
532 mv -f $@T $@
533 endef
534 object-suffixes-left := $(object-suffixes-for-libc)
535 include $(o-iterator)
537 endif
539 # Now define explicit rules to build the library archives; these depend
540 # on the stamp files built above.
541 define o-iterator-doit
542 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
543                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
544 endef
545 define do-makelib
546 cd $(common-objdir) && \
547 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
548 $(RANLIB) $@
549 endef
550 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
551 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
552 ifndef subdir
553 $(subdirs-stamps): subdir_lib;
554 endif
555 object-suffixes-left = $(object-suffixes-for-libc)
556 include $(o-iterator)
559 # This makes all the object files.
560 .PHONY: objects objs libobjs extra-objs
561 objects objs: libobjs extra-objs
562 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
563 extra-objs: $(addprefix $(objpfx),$(extra-objs))
565 # Canned sequence for building an extra library archive.
566 define build-extra-lib
567 $(patsubst %/,cd % &&,$(objpfx)) \
568 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
569       $(patsubst $(objpfx)%,%,$^)
570 $(RANLIB) $@
571 endef
573 # Installation.
575 .PHONY: force-install
576 force-install:
578 # $(install-lib) are installed from the object directory into $(libdir);
579 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
580 # unless they also appear in $(non-lib.a).  $(install-data) are installed
581 # as they are into $(datadir).  $(headers) are installed as they are in
582 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
583 # object directory into $(bindir) and $(sbindir), respectively.
584 # $(install-others) are absolute path names of files to install; rules to
585 # install them are defined elsewhere.
587 # The simple library name to install libc.a under.
588 # This could be defined by a sysdep Makefile.
589 ifndef libc-name
590 libc-name := c
591 endif
593 define do-install
594 $(make-target-directory)
595 $(INSTALL_DATA) $< $@
596 endef
598 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
599 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
600 define make-target-directory
601 $(addprefix $(..)./scripts/mkinstalldirs ,\
602             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
603 endef
605 # Any directory (parent or subdir) should install libc.a; this way
606 # "make install" in a subdir is guaranteed to install everything it changes.
607 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
608                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
609                                                      $(libprefix)$(libc-name)))
610 install: $(installed-libcs)
611 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
612         $(make-target-directory)
613         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
614 # Running ranlib after installing makes the __.SYMDEF time stamp up to
615 # date, which avoids messages from some linkers.
616         $(RANLIB) $@
618 define do-install-program
619 $(make-target-directory)
620 $(INSTALL_PROGRAM) $< $@.new
621 mv -f $@.new $@
622 endef
624 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
625 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
627 ifeq (yes,$(build-shared))
628 # Find which .so's have versions.
629 versioned := $(strip $(foreach so,$(install-lib.so),\
630                                $(patsubst %,$(so),$($(so)-version))))
632 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
633 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
635 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
636                       $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
638 # Install all the unversioned shared libraries.
639 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
640     $(objpfx)%.so $(+force)
641         $(do-install-program)
643 ifneq ($(findstring -s,$(LN_S)),)
644 define make-link
645 rm -f $@.new
646 $(SHELL) $(..)scripts/rellns-sh $< $@.new
647 mv -f $@.new $@
648 endef
649 else
650 # If we have no symbolic links don't bother with rellns-sh.
651 define make-link
652 rm -f $@.new
653 $(LN_S) $< $@.new
654 mv -f $@.new $@
655 endef
656 endif
658 ifeq (no,$(cross-compiling))
659 ifeq (yes,$(build-shared))
660 symbolic-link-prog := $(common-objpfx)elf/sln
661 symbolic-link-list := $(common-objpfx)elf/symlink.list
662 define make-shlib-link
663 echo $(<F) $@ >> $(symbolic-link-list)
664 endef
665 endif
666 endif
667 ifndef make-shlib-link
668 define make-shlib-link
669 rm -f $@
670 $(LN_S) $(<F) $@
671 endef
672 endif
674 ifdef libc.so-version
675 # For a library specified to be version N, install three files:
676 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
677 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
679 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
680                                            $(+force)
681         $(make-shlib-link)
682 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
683         $(do-install-program)
684 install: $(inst_slibdir)/libc.so$(libc.so-version)
686 ifndef subdir
687 # What we install as libc.so for programs to link against is in fact a
688 # link script.  It contains references for the various libraries we need.
689 # The libc.so object is not complete since some functions are only defined
690 # in libc_nonshared.a.
691 # We need to use absolute paths since otherwise local copies (if they exist)
692 # of the files are taken by the linker.
693 install: $(inst_libdir)/libc.so
694 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
695                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
696                                                   $(libprefix)$(libc-name)) \
697                         $(+force)
698         (echo '/* GNU ld script';\
699          echo '   Use the shared library, but some functions are only in';\
700          echo '   the static library, so try that secondarily.  */';\
701          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
702               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
703               ')' \
704         ) > $@.new
705         mv -f $@.new $@
707 endif
709 else
710 install: $(inst_slibdir)/libc.so
711 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
712         $(do-install-program)
713 endif
715 ifneq (,$(versioned))
716 # Produce three sets of rules as above for all the smaller versioned libraries.
718 define o-iterator-doit
719 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
720 endef
721 object-suffixes-left := $(versioned)
722 include $(o-iterator)
724 # Make symlinks in the build directory, because the versioned names might
725 # be referenced by a DT_NEEDED in another library.
726 define o-iterator-doit
727 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
728 endef
729 object-suffixes-left := $(versioned)
730 include $(o-iterator)
732 generated += $(foreach o,$(versioned),$o$($o-version))
734 ifeq (,$($(subdir)-version))
735 define o-iterator-doit
736 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
737                                  $(+force);
738         $$(make-shlib-link)
739 endef
740 object-suffixes-left := $(versioned)
741 include $(o-iterator)
743 define o-iterator-doit
744 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
745         $$(do-install-program)
746 endef
747 object-suffixes-left := $(versioned)
748 include $(o-iterator)
749 else
750 define o-iterator-doit
751 $(inst_slibdir)/$o$($o-version): \
752   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
753         $$(make-shlib-link)
754 endef
755 object-suffixes-left := $(versioned)
756 include $(o-iterator)
758 define o-iterator-doit
759 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
760         $$(do-install-program)
761 endef
762 object-suffixes-left := $(versioned)
763 include $(o-iterator)
764 endif
765 endif
767 define do-install-so
768 $(do-install-program)
769 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
770            $(filter-out %.so,$@))
771 endef
773 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
774 $(foreach v,$(so-versions),\
775           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
776                                                $(+force)
777         $(do-install-so)
778 $(foreach v,$(so-versions),\
779           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
780         $(do-install-so)
781 endif
783 ifdef install-bin
784 $(addprefix $(inst_bindir)/,$(install-bin)): \
785     $(inst_bindir)/%: $(objpfx)% $(+force)
786         $(do-install-program)
787 endif
788 ifdef install-rootsbin
789 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
790    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
791         $(do-install-program)
792 endif
793 ifdef install-sbin
794 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
795     $(inst_sbindir)/%: $(objpfx)% $(+force)
796         $(do-install-program)
797 endif
798 ifdef install-lib
799 install-lib.a := $(filter lib%.a,$(install-lib))
800 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
801 ifdef install-lib-non.a
802 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
803   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
804         $(do-install)
805 endif
806 ifdef install-lib.a
807 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
808   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
809         $(do-install)
810         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
811 endif
812 endif
813 ifdef install-data
814 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
815         $(do-install)
816 endif
817 headers := $(strip $(headers))
818 ifdef headers
819 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
820         $(do-install)
821 endif   # headers
823 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
824         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
825 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
826 install-rootsbin-nosubdir: \
827         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
828 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
829 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
830                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
831                        $(addprefix $(libprefix),$(install-lib-non.a)))
832 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
833 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
834 install-others-nosubdir: $(install-others)
836 # We need all the `-nosubdir' targets so that `install' in the parent
837 # doesn't depend on several things which each iterate over the subdirs.
838 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
839 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
840 install-%:: install-%-nosubdir ;
842 .PHONY: install install-no-libc.a-nosubdir
843 ifeq ($(build-programs),yes)
844 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
845                             install-bin-nosubdir install-lib-nosubdir   \
846                             install-others-nosubdir install-rootsbin-nosubdir \
847                             install-sbin-nosubdir
848 else
849 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
850                             install-lib-nosubdir install-others-nosubdir
851 endif
852 install: install-no-libc.a-nosubdir
854 # Command to compile $< in $(objdir) using the native libraries.
855 define native-compile
856 $(make-target-directory)
857 $(patsubst %/,cd % &&,$(objpfx)) \
858 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
859             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
860 endef
862 # Command to compile $< in $(common-objdir) using the native libraries.
863 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
864 define common-objdir-compile
865 $(patsubst %/,cd % &&,$(objpfx)) \
866 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
867             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
868 endef
870 # We always want to use configuration definitions.
871 # Note that this is only used for commands running in $(objpfx).
872 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
874 # Support the GNU standard name for this target.
875 .PHONY: check
876 check: tests
878 .PHONY: TAGS
879 TAGS: $(objpfx)distinfo $(..)MakeTAGS
880         $(MAKE) $(addprefix -f ,$^) $@
882 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
883         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
884 FORCE:
887 .PHONY: echo-headers
888 echo-headers:
889         @echo $(headers)
892 # Common cleaning targets.
894 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
895 clean: common-clean
896 mostlyclean: common-mostlyclean
898 do-tests-clean:
899         -rm -f $(patsubst %,$(objpfx)%.out,$(tests) $(test-srcs))
901 # Remove the object files.
902 common-mostlyclean:
903         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
904                                      $(sysdep-others) stubs \
905                                      $(addsuffix .o,$(tests) $(test-srcs) \
906                                                     $(others) \
907                                                     $(sysdep-others)) \
908                                      $(addsuffix .out,$(tests) $(test-srcs)))
909         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
910                                      $(install-lib.so) \
911                                      $(install-lib.so:%.so=%_pic.a))
912         -rm -f core
913         $(rmobjs)
914 define rmobjs
915 $(foreach o,$(object-suffixes-for-libc),
916 -rm -f $(objpfx)stamp$o $(o-objects))
917 endef
919 # Also remove the dependencies and generated source files.
920 common-clean: common-mostlyclean
921         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
922         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
923         -rm -f $(addprefix $(common-objpfx),$(common-generated))
924         -rm -f $(objpfx)distinfo
926 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
927 # for each function which is a stub.  We grovel over all the .d files
928 # looking for references to <stub-tag.h>.  Then we grovel over each
929 # referenced source file to see what stub function it defines.
931 ifdef objpfx
932 .PHONY: stubs # The parent Makefile calls this target.
933 stubs: $(objpfx)stubs
934 endif
935 s = $(sysdep_dir)/generic
936 $(objpfx)stubs: $(+depfiles)
937 # Use /dev/null since `...` might expand to empty.
938         (s=`cd $s && /bin/pwd`; \
939          $(patsubst %/,cd % &&,$(objpfx)) \
940          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
941           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
942                 -e '/stub-tag\.h/{; g; p; }' \
943                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
944              /dev/null) > $@T
945         mv -f $@T $@
947 # Make the distribution tar file.
949 .PHONY: dist
950 dist: $(objpfx)distinfo $(..)Make-dist
951         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
953 # Avoid depending on source files found in sysdeps dirs,
954 # because the references affect implicit rule selection.
955 dist: $(filter-out %.c %.S %.s,$(distribute))
957 # We used to simply export all these variables, but that frequently made the
958 # environment get too large.  Instead, we write all the information into
959 # a generated makefile fragment `distinfo', and then include it with -f in
960 # the sub-make that makes the distribution (above).
961 $(objpfx)distinfo: Makefile $(..)Makerules \
962                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
963         $(make-target-directory)
964         $(distinfo-vars)
965         mv -f $@.new $@
966 .PHONY: subdir_distinfo
967 subdir_distinfo: $(objpfx)distinfo
969 define distinfo-vars
970 rm -f $@.new
971 echo > $@.new 'subdir := $(subdir)'
972 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
973               headers sysdep_headers distribute dont_distribute generated \
974               others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
975               versioned \
976               $(addprefix install-,lib lib.so data bin sbin others),
977 echo >> $@.new '$(subdir)-$(var) := $($(var))'
978 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
979 endef
981 ifneq (,$(strip $(gpl2lgpl)))
982 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
983 # Snarf from the master source and frob the copying notice.
984 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
985         sed -f $^ > $@-tmp
986 # So I don't edit them by mistake.
987         chmod a-w $@-tmp
988         mv -f $@-tmp $@
989 ifeq ($(with-cvs),yes)
990         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
991 endif
992 endif
993 endif