Update.
[glibc.git] / Makerules
blob7ea9783d0d73ff7728da34b45047f67c212e2199
1 # Copyright (C) 1991,92,93,94,95,96,97,98,99,2000
2 #       Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Library General Public License as
7 # published by the Free Software Foundation; either version 2 of the
8 # License, or (at your option) any later version.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Library General Public License for more details.
15 # You should have received a copy of the GNU Library General Public
16 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
17 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 # Boston, MA 02111-1307, USA.
21 #       Common rules for making the GNU C library.  This file is included
22 #       by the top-level Makefile and by all subdirectory makefiles
23 #       (through Rules).
25 ifneq (,)
26 This makefile requires GNU Make.
27 endif
29 REQUIRED_MAKE_VERSION = 3.74
30 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
32 ifneq ($(REQUIRED_MAKE_VERSION), \
33        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
34 Wrong GNU Make version.  See above for the version needed.
35 endif
38 ifdef   subdir
39 ..      := ../
40 endif   # subdir
42 # If `sources' was defined by the parent makefile, undefine it so
43 # we will later get it from wildcard search in this directory.
44 ifneq   "$(findstring env,$(origin sources))" ""
45 sources :=
46 endif
48 oPATH := $(PATH)
49 PATH := this definition should take precedence over $(oPATH)
50 ifeq ($(PATH),$(oPATH))
51 You must not use the -e flag when building the GNU C library.
52 else
53 PATH := $(oPATH)
54 endif
56 ifndef +included-Makeconfig
57 include $(..)Makeconfig
58 endif
60 # `configure' writes a definition of `config-sysdirs' in `config.make'.
61 sysdirs = $(strip $(full_config_sysdirs))
63 +sysdir_pfx = $(common-objpfx)
65 export sysdirs := $(sysdirs)
67 +sysdep_dirs := $(full_config_sysdirs)
68 ifdef objdir
69 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
70 endif
72 # Add -I switches to get the right sysdep directories.
73 # `+includes' in Makeconfig references $(+sysdep-includes).
74 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
76 # This variable is used in ``include $(o-iterator)'' after defining
77 # $(o-iterator-doit) to produce some desired rule using $o for the object
78 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
79 # is produced for each object suffix in use.
80 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
82 # Include any system-specific makefiles.
84 # This is here so things in sysdep Makefiles can easily depend on foo.h as
85 # appropriate and not worry about where foo.h comes from, which may be
86 # system dependent and not known by that Makefile.
87 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
88                                       $(+sysdep_dirs) $(..)))
90 # The same is true for RPC source files.
91 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
92                                       $(+sysdep_dirs) $(..)))
94 # Some sysdep makefiles use this to distinguish being included here from
95 # being included individually by a subdir makefile (hurd/Makefile needs this).
96 in-Makerules := yes
98 -include $(+sysdir_pfx)sysd-Makefile
99 ifndef avoid-generated
100 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
101 sysd-Makefile-force = FORCE
102 FORCE:
103 endif
104 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
105                              $(sysd-Makefile-force)
106         -@rm -f $@T
107         (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)';                   \
108          for file in $(config-sysdirs:=/Makefile); do                         \
109            if [ -f $(..)$$file ]; then                                        \
110              echo include "\$$(..)$$file";                                    \
111            else true; fi;                                                     \
112          done;                                                                \
113          echo 'sysd-Makefile-done=t') > $@T
114         mv -f $@T $@
115 endif
117 ifndef sysd-Makefile-done
118 # Don't do deps until this exists, because it might change the sources list.
119 no_deps=t
120 endif
123 # Reorder before-compile so that mach things come first, and hurd things
124 # second, before all else.  The mach and hurd subdirectories have many
125 # generated header files which the much of rest of the library depends on,
126 # so it is best to build them first (and mach before hurd, at that).
127 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
128                            $(before-compile)) \
129                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
130                                $(before-compile))
132 # Even before that, we need abi-versions.h which is generated right here.
133 ifeq ($(versioning),yes)
134 ifndef avoid-generated
135 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
136 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
137                                 $(common-objpfx)Versions.all
138         LC_ALL=C $(AWK) -f $^ > $@T
139         mv -f $@T $@
140 endif # avoid-generated
141 endif # $(versioning) = yes
144 # Remove existing files from `before-compile'.  Things are added there when
145 # they must exist for dependency generation to work right, but once they
146 # exist there is no further need for every single file to depend on them,
147 # and those gratuitous dependencies result in many gratuitous
148 # recompilations.
149 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
151 # Don't let any before-compile file be an intermediate and get removed.
152 ifdef before-compile
153 $(before-compile):
154 endif
156 # Generate an ordered list of implicit rules which find the source files in
157 # each sysdep directory.  The old method was to use vpath to search all the
158 # sysdep directories.  However, that had the problem that a .S file in a
159 # later directory would be chosen over a .c file in an earlier directory,
160 # which does not preserve the desired sysdeps ordering behavior.
162 # When making the list of .d files to include, we can't know which ones
163 # have source in .s files, and thus do not in fact need a .d file.
164 # So we must define rules to make .d files for .s files.
165 define make-dummy-dep
166 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
167 endef
168 $(common-objpfx)dummy.d:
169         echo '# .s files cannot contain includes, so they need no deps.' > $@
171 # It matters that this set of rules, for compiling from sources in
172 # the current directory (the $srcdir/$subdir) come before the
173 # generated sysdep rules in included from sysd-rules below.  When
174 # compiling in the source tree, generated sources go into the current
175 # directory, and those should be chosen before any sources in sysdeps.
176 define o-iterator-doit
177 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
178 endef
179 object-suffixes-left := $(all-object-suffixes)
180 include $(o-iterator)
181 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
183 define o-iterator-doit
184 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
185 endef
186 object-suffixes-left := $(all-object-suffixes)
187 include $(o-iterator)
188 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
190 define o-iterator-doit
191 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
192 endef
193 object-suffixes-left := $(all-object-suffixes)
194 include $(o-iterator)
195 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
197 # Omit the objpfx rules when building in the source tree, because
198 # objpfx is empty and so these rules just override the ones above.
199 ifdef objpfx
200 # Define first rules to find the source files in $(objpfx).
201 # Generated source files will end up there.
202 define o-iterator-doit
203 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
204 endef
205 object-suffixes-left := $(all-object-suffixes)
206 include $(o-iterator)
207 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
209 define o-iterator-doit
210 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
211 endef
212 object-suffixes-left := $(all-object-suffixes)
213 include $(o-iterator)
214 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
216 define o-iterator-doit
217 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
218 endef
219 object-suffixes-left := $(all-object-suffixes)
220 include $(o-iterator)
221 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
222 endif
224 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
225 # patterns matching sysdep directories whose assembly source files should
226 # be suppressed.
227 ifdef inhibit-sysdep-asm
228 define open-check-inhibit-asm
229 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
230 endef
231 close-check-inhibit-asm = ;; esac ;
232 endif
234 # Don't include sysd-rules until sysd-Makefile is already there and has been
235 # included.  It might define inhibit-sysdep-asm, which would affect the
236 # contents of sysd-rules.
237 ifdef sysd-Makefile-done
238 -include $(+sysdir_pfx)sysd-rules
239 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
240 # The value of $(+sysdep_dirs) the sysd-rules was computed for
241 # differs from the one we are using now.  So force a rebuild of sysd-rules.
242 sysd-rules-force = FORCE
243 FORCE:
244 endif
245 endif
246 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
247                           $(wildcard $(foreach dir,$(sysdirs),\
248                                                $(dir)/Makefile))\
249                           $(sysd-rules-force)
250         -@rm -f $@T
251         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
252          for dir in $(config-sysdirs:%='$$(..)%'); do                         \
253            for o in $(all-object-suffixes); do \
254              $(open-check-inhibit-asm) \
255              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
256                   \$$(compile-command.S)";                                    \
257              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
258                   \$$(compile-command.s)";                                    \
259              $(close-check-inhibit-asm) \
260              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
261                   \$$(compile-command.c)";                                    \
262            done; \
263            $(open-check-inhibit-asm) \
264            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
265                 \$$(make-dummy-dep)";                          \
266            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
267                 \$$(+make-deps)";                                             \
268            $(close-check-inhibit-asm)   \
269            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
270                 \$$(+make-deps)";                                             \
271          done;                                                                \
272          echo 'sysd-rules-done = t') > $@T
273         mv -f $@T $@
275 ifndef sysd-rules-done
276 # Don't do deps until this exists, because it provides rules to make the deps.
277 no_deps=t
278 endif
280 # Generate version maps, but wait until sysdep-subdirs is known
281 ifeq ($(sysd-sorted-done),t)
282 ifeq ($(versioning),yes)
283 -include $(common-objpfx)sysd-versions
284 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
285 common-generated += $(version-maps)
286 postclean-generated += sysd-versions Versions.all abi-versions.h
288 ifndef avoid-generated
289 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
290 sysd-versions-force = FORCE
291 FORCE:
292 endif
293 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
294                               $(common-objpfx)soversions.i \
295                               $(..)Versions.def \
296                               $(wildcard $(add-ons:%=$(..)%/Versions.def))
297         { while read lib version setname; do \
298             test -z "$$setname" || echo "$$lib : $$setname"; \
299           done < $(word 2,$^); \
300           cat $(filter-out $< $(word 2,$^),$^) \
301           | $(preprocess-versions); \
302         } | LC_ALL=C $(AWK) -f $< > $@T
303         mv -f $@T $@
304 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
305                                $(..)scripts/versions.awk \
306                                $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
307                                $(wildcard $(sysdirs:%=%/Versions)) \
308                                $(sysd-versions-force)
309         ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
310           cat $(filter-out $< $(word 2,$^) $(sysd-versions-force),$^) \
311           | $(preprocess-versions) \
312           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
313                             -v move_if_change='$(move-if-change)' \
314                             -f $(word 2,$^); \
315         ) > $@T
316         mv -f $@T $@
317 endif # avoid-generated
318 endif # $(versioning) = yes
319 endif # sysd-sorted-done
322 ifndef compile-command.S
323 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
324 endif
325 ifndef compile-command.s
326 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
327 endif
328 ifndef compile-command.c
329 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
330 endif
332 # GCC can grok options after the file name, and it looks nicer that way.
333 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
334 compile.S = \
335   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
336 COMPILE.S = \
337   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
338 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
340 # If we want to generate MD% checksums for the sources do this now.
341 ifeq ($(md5),yes)
342 generate-md5 = ; rm -f $(@:.d=.md5); \
343 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
344 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
345 else
346 generate-md5 =
347 endif
349 # We need this for the output to go in the right place.  It will default to
350 # empty if make was configured to work with a cc that can't grok -c and -o
351 # together.  You can't compile the C library with such a compiler.
352 OUTPUT_OPTION = -o $@
354 S-CPPFLAGS = $(asm-CPPFLAGS)
355 define +make-deps
356 $(make-target-directory)
357 -@rm -f $@
358 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
359 sed \
360 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
361 $(sed-remove-objpfx) > $(@:.d=.T)
362 mv -f $(@:.d=.T) $@ $(generate-md5)
363 endef
364 ifneq (,$(objpfx))
365 # Continuation lines here are dangerous because they introduce spaces!
366 define sed-remove-objpfx
367 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
368 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
369 endef
370 endif
372 # Shared library building.
374 ifeq (yes,$(build-shared))
376 # Reference map file only when versioning is selected and a map file name
377 # is given.
378 ifeq ($(versioning),yes)
379 map-file = $(firstword $($(@F:.so=-map)) \
380                        $(addprefix $(common-objpfx), \
381                                    $(filter $(@F:.so=.map),$(version-maps))))
382 load-map-file = $(map-file:%=-Wl,--version-script=%)
383 endif
385 # Pattern rule to build a shared object from an archive of PIC objects.
386 # This must come after the installation rules so Make doesn't try to
387 # build shared libraries in place from the installed *_pic.a files.
388 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
389 # on other shared objects.
390 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
391         $(build-shlib)
393 define build-shlib
394 $(LINK.o) -shared -Wl,-O1 -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
395           -B$(csu-objpfx) $(load-map-file) \
396           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
397           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
398           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
399           -Wl,--whole-archive \
400           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
401           $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
402 endef
404 # This macro is similar to build-shlib but it does not define a soname
405 # and it does not depend on the destination name to start with `lib'.
406 define build-module
407 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
408           -B$(csu-objpfx) $(load-map-file) \
409           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
410           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
411           -Wl,--whole-archive \
412           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
413           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
414 endef
416 ifndef libc.so-version
417 # Undefine this because it can't work when we libc.so is unversioned.
418 static-only-routines =
419 endif
421 # Bounded pointer thunks are only built for *.ob
422 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
424 elide-routines.oS += $(filter-out $(static-only-routines),\
425                                   $(routines) $(aux) $(sysdep_routines)) \
426                      $(elide-bp-thunks)
427 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
429 # If we have versioned code we don't need the old versions in any of the
430 # static libraries.
431 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
432 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
433 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
434 elide-routines.ob += $(shared-only-routines)
436 # Don't try to use -lc when making libc.so itself.
437 # Also omits crti.o and crtn.o, which we do not want
438 # since we define our own `.init' section specially.
439 LDFLAGS-c.so = -nostdlib -nostartfiles
440 # But we still want to link libc.so against $(gnulib).
441 LDLIBS-c.so += $(gnulib)
442 # Give libc.so an entry point and make it directly runnable itself.
443 LDFLAGS-c.so += -e __libc_main
444 # Force the backward compatibility EH functions to be linked.
445 LDFLAGS-c.so += -u __register_frame
446 # Pre-link the objects of libc_pic.a so that we can locally resolve
447 # COMMON symbols before we link against ld.so.  This is because ld.so
448 # contains some of libc_pic.a already, which will prevent the COMMONs
449 # from being allocated in libc.so, which introduces evil dependencies
450 # between libc.so and ld.so, which can make it impossible to upgrade.
451 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
452         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
453         -Wl,-d -Wl,--whole-archive $^
454 # Use our own special initializer and finalizer files for libc.so.
455 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
456                          $(common-objpfx)libc_pic.os \
457                          $(elfobjdir)/sofini.os \
458                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so
459         $(build-shlib)
460 ifeq ($(versioning),yes)
461 $(common-objpfx)libc.so: $(common-objpfx)libc.map
462 endif
463 common-generated += libc.so libc_pic.os
464 ifdef libc.so-version
465 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
466         $(make-link)
467 common-generated += libc.so$(libc.so-version)
468 endif
469 endif
471 # Figure out the source filenames in this directory.
473 override sources := $(addsuffix .c,\
474                         $(filter-out $(elided-routines),\
475                             $(routines) $(aux) \
476                             $(sysdep_routines)))
477 # XXX The following was introduced here in the BP patches but it belongs
478 # XXX somewhere else since adding it here breaks `make dist'.
479 #                           $(addprefix $(bppfx),\
480 #                               $(filter $(routines) $(sysdep_routines),\
481 #                                   $(bp-thunks))))
482 sysdep_routines := $(sysdep_routines)
484 headers := $(headers) $(sysdep_headers)
486 # This is the list of all object files, gotten by
487 # replacing every ".c" in `sources' with a ".o".
488 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
491 # The makefile may define $(extra-libs) with `libfoo libbar'
492 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
493 ifdef extra-libs
494 # extra-lib.mk is included once for each extra lib to define rules
495 # to build it, and to add its objects to the various variables.
496 # During its evaluation, $(lib) is set to the name of the library.
497 extra-libs-left := $(extra-libs)
498 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
499 endif
501 +depfiles := $(sources:.c=.d) \
502              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
503              $(addsuffix .d,$(tests) $(test-srcs))
504 ifeq ($(build-programs),yes)
505 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
506 endif
507 +depfiles := $(addprefix $(objpfx),\
508                          $(filter-out $(addsuffix .d,$(omit-deps)),\
509                                       $(+depfiles)))
511 ifdef +depfiles
512 ifneq ($(no_deps),t)
513 -include $(+depfiles)
514 endif
515 endif
516 \f\f
517 # Maximize efficiency by minimizing the number of rules.
518 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
519 # Don't define any builtin rules.
520 MAKEFLAGS := $(MAKEFLAGS)r
522 # Generic rule for making directories.
524 # mkdir isn't smart enough to strip a trailing /.
525         mkdir $(@:%/=%)
527 # Make sure that object files are not removed
528 # when they are intermediates between sources and library members.
529 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
531 # Make sure that the parent library archive is never removed.
532 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
534 # Use the verbose option of ar and tar when not running silently.
535 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
536 verbose := v
537 else                                            # -s
538 verbose :=
539 endif                                           # not -s
541 ARFLAGS := r$(verbose)
542 CREATE_ARFLAGS := cru$(verbose)
544 # This makes all the object files in the parent library archive.
546 .PHONY: lib lib-noranlib
547 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
548 lib-noranlib: libobjs
550 # For object-suffix $o, the list of objects with that suffix.
551 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
552 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
553                                                        $(elide-routines$o)),\
554                                             $(objects)))
555 others: $(addprefix $(objpfx),$(install-lib))
557 ifndef objects
559 # Create the stamp$o files to keep the parent makefile happy.
560 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
561 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
562         $(make-target-directory)
563         rm -f $@; > $@
564 else
566 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
567 # timestamp file; these rules (one explicit rule is generated for each
568 # object suffix) write a list of objects to update in the stamp file.
569 # The parent will then actually add them all to the archive in the
570 # archive rule, below.
571 define o-iterator-doit
572 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
573 endef
574 define do-stamp
575 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
576 mv -f $@T $@
577 endef
578 object-suffixes-left := $(object-suffixes-for-libc)
579 include $(o-iterator)
581 endif
583 # Now define explicit rules to build the library archives; these depend
584 # on the stamp files built above.
585 define o-iterator-doit
586 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
587                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
588 endef
589 define do-makelib
590 cd $(common-objdir) && \
591 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
592 $(RANLIB) $@
593 endef
594 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
595 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
596 ifndef subdir
597 $(subdirs-stamps): subdir_lib;
598 endif
599 object-suffixes-left = $(object-suffixes-for-libc)
600 include $(o-iterator)
603 # This makes all the object files.
604 .PHONY: objects objs libobjs extra-objs
605 objects objs: libobjs extra-objs
606 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
607 extra-objs: $(addprefix $(objpfx),$(extra-objs))
609 # Canned sequence for building an extra library archive.
610 define build-extra-lib
611 $(patsubst %/,cd % &&,$(objpfx)) \
612 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
613       $(patsubst $(objpfx)%,%,$^)
614 $(RANLIB) $@
615 endef
617 # Installation.
619 .PHONY: force-install
620 force-install:
622 # $(install-lib) are installed from the object directory into $(libdir);
623 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
624 # unless they also appear in $(non-lib.a).  $(install-data) are installed
625 # as they are into $(datadir).  $(headers) are installed as they are in
626 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
627 # object directory into $(bindir) and $(sbindir), respectively.
628 # $(install-others) are absolute path names of files to install; rules to
629 # install them are defined elsewhere.
631 # The simple library name to install libc.a under.
632 # This could be defined by a sysdep Makefile.
633 ifndef libc-name
634 libc-name := c
635 endif
637 define do-install
638 $(make-target-directory)
639 $(INSTALL_DATA) $< $@
640 endef
642 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
643 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
644 define make-target-directory
645 $(addprefix $(..)./scripts/mkinstalldirs ,\
646             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
647 endef
649 # Any directory (parent or subdir) should install libc.a; this way
650 # "make install" in a subdir is guaranteed to install everything it changes.
651 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
652                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
653                                                      $(libprefix)$(libc-name)))
654 install: $(installed-libcs)
655 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
656         $(make-target-directory)
657         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
658 # Running ranlib after installing makes the __.SYMDEF time stamp up to
659 # date, which avoids messages from some linkers.
660         $(RANLIB) $@
662 define do-install-program
663 $(make-target-directory)
664 $(INSTALL_PROGRAM) $< $@.new
665 mv -f $@.new $@
666 endef
668 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
669 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
671 ifeq (yes,$(build-shared))
672 # Find which .so's have versions.
673 versioned := $(strip $(foreach so,$(install-lib.so),\
674                                $(patsubst %,$(so),$($(so)-version))))
676 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
677 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
679 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
680                       $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
682 # Install all the unversioned shared libraries.
683 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
684     $(objpfx)%.so $(+force)
685         $(do-install-program)
687 ifneq ($(findstring -s,$(LN_S)),)
688 define make-link
689 rm -f $@.new
690 $(SHELL) $(..)scripts/rellns-sh $< $@.new
691 mv -f $@.new $@
692 endef
693 else
694 # If we have no symbolic links don't bother with rellns-sh.
695 define make-link
696 rm -f $@.new
697 $(LN_S) $< $@.new
698 mv -f $@.new $@
699 endef
700 endif
702 ifeq (yes,$(build-shared))
703 ifeq (no,$(cross-compiling))
704 symbolic-link-prog := $(common-objpfx)elf/sln
705 symbolic-link-list := $(common-objpfx)elf/symlink.list
706 define make-shlib-link
707 echo $(<F) $@ >> $(symbolic-link-list)
708 endef
709 else # cross-compiling
710 # We need a definition that can be used by elf/Makefile's install rules.
711 symbolic-link-prog = $(LN_S)
712 endif
713 endif
714 ifndef make-shlib-link
715 define make-shlib-link
716 rm -f $@
717 $(LN_S) $(<F) $@
718 endef
719 endif
721 ifdef libc.so-version
722 # For a library specified to be version N, install three files:
723 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
724 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
726 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
727                                            $(+force)
728         $(make-shlib-link)
729 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
730         $(do-install-program)
731 install: $(inst_slibdir)/libc.so$(libc.so-version)
733 ifndef subdir
734 # What we install as libc.so for programs to link against is in fact a
735 # link script.  It contains references for the various libraries we need.
736 # The libc.so object is not complete since some functions are only defined
737 # in libc_nonshared.a.
738 # We need to use absolute paths since otherwise local copies (if they exist)
739 # of the files are taken by the linker.
740 install: $(inst_libdir)/libc.so
741 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
742                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
743                                                   $(libprefix)$(libc-name)) \
744                         $(+force)
745         (echo '/* GNU ld script';\
746          echo '   Use the shared library, but some functions are only in';\
747          echo '   the static library, so try that secondarily.  */';\
748          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
749               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
750               ')' \
751         ) > $@.new
752         mv -f $@.new $@
754 endif
756 else
757 install: $(inst_slibdir)/libc.so
758 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
759         $(do-install-program)
760 endif
762 ifneq (,$(versioned))
763 # Produce three sets of rules as above for all the smaller versioned libraries.
765 define o-iterator-doit
766 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
767 endef
768 object-suffixes-left := $(versioned)
769 include $(o-iterator)
771 # Make symlinks in the build directory, because the versioned names might
772 # be referenced by a DT_NEEDED in another library.
773 define o-iterator-doit
774 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
775 endef
776 object-suffixes-left := $(versioned)
777 include $(o-iterator)
779 generated += $(foreach o,$(versioned),$o$($o-version))
781 ifeq (,$($(subdir)-version))
782 define o-iterator-doit
783 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
784                                  $(+force);
785         $$(make-shlib-link)
786 endef
787 object-suffixes-left := $(versioned)
788 include $(o-iterator)
790 define o-iterator-doit
791 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
792         $$(do-install-program)
793 endef
794 object-suffixes-left := $(versioned)
795 include $(o-iterator)
796 else
797 define o-iterator-doit
798 $(inst_slibdir)/$o$($o-version): \
799   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
800         $$(make-shlib-link)
801 endef
802 object-suffixes-left := $(versioned)
803 include $(o-iterator)
805 define o-iterator-doit
806 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
807         $$(do-install-program)
808 endef
809 object-suffixes-left := $(versioned)
810 include $(o-iterator)
811 endif
812 endif
814 define do-install-so
815 $(do-install-program)
816 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
817            $(filter-out %.so,$@))
818 endef
820 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
821 $(foreach v,$(so-versions),\
822           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
823                                                $(+force)
824         $(do-install-so)
825 $(foreach v,$(so-versions),\
826           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
827         $(do-install-so)
828 endif
830 ifdef install-bin
831 $(addprefix $(inst_bindir)/,$(install-bin)): \
832     $(inst_bindir)/%: $(objpfx)% $(+force)
833         $(do-install-program)
834 endif
835 ifdef install-rootsbin
836 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
837    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
838         $(do-install-program)
839 endif
840 ifdef install-sbin
841 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
842     $(inst_sbindir)/%: $(objpfx)% $(+force)
843         $(do-install-program)
844 endif
845 ifdef install-lib
846 install-lib.a := $(filter lib%.a,$(install-lib))
847 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
848 ifdef install-lib-non.a
849 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
850   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
851         $(do-install)
852 endif
853 ifdef install-lib.a
854 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
855   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
856         $(do-install)
857         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
858 endif
859 endif
860 ifdef install-data
861 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
862         $(do-install)
863 endif
864 headers := $(strip $(headers))
865 ifdef headers
866 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
867         $(do-install)
868 endif   # headers
870 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
871         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
872 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
873 install-rootsbin-nosubdir: \
874         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
875 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
876 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
877                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
878                        $(addprefix $(libprefix),$(install-lib-non.a)))
879 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
880 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
881 install-others-nosubdir: $(install-others)
883 # We need all the `-nosubdir' targets so that `install' in the parent
884 # doesn't depend on several things which each iterate over the subdirs.
885 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
886 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
887 install-%:: install-%-nosubdir ;
889 .PHONY: install install-no-libc.a-nosubdir
890 ifeq ($(build-programs),yes)
891 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
892                             install-bin-nosubdir install-lib-nosubdir   \
893                             install-others-nosubdir install-rootsbin-nosubdir \
894                             install-sbin-nosubdir
895 else
896 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
897                             install-lib-nosubdir install-others-nosubdir
898 endif
899 install: install-no-libc.a-nosubdir
901 # Command to compile $< in $(objdir) using the native libraries.
902 define native-compile
903 $(make-target-directory)
904 $(patsubst %/,cd % &&,$(objpfx)) \
905 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
906             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
907 endef
909 # Command to compile $< in $(common-objdir) using the native libraries.
910 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
911 define common-objdir-compile
912 $(patsubst %/,cd % &&,$(objpfx)) \
913 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
914             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
915 endef
917 # We always want to use configuration definitions.
918 # Note that this is only used for commands running in $(objpfx).
919 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
921 # Support the GNU standard name for this target.
922 .PHONY: check
923 check: tests
925 .PHONY: TAGS
926 TAGS: $(objpfx)distinfo $(..)MakeTAGS
927         $(MAKE) $(addprefix -f ,$^) $@
929 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
930         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
931 FORCE:
934 .PHONY: echo-headers
935 echo-headers:
936         @echo $(headers)
939 # Common cleaning targets.
941 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
942 clean: common-clean
943 mostlyclean: common-mostlyclean
945 do-tests-clean:
946         -rm -f $(patsubst %,$(objpfx)%.out,$(tests) $(test-srcs))
948 # Remove the object files.
949 common-mostlyclean:
950         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
951                                      $(sysdep-others) stubs \
952                                      $(addsuffix .o,$(tests) $(test-srcs) \
953                                                     $(others) \
954                                                     $(sysdep-others)) \
955                                      $(addsuffix .out,$(tests) $(test-srcs)))
956         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
957                                      $(install-lib.so) \
958                                      $(install-lib.so:%.so=%_pic.a))
959         -rm -f core
960         $(rmobjs)
961 define rmobjs
962 $(foreach o,$(object-suffixes-for-libc),
963 -rm -f $(objpfx)stamp$o $(o-objects))
964 endef
966 # Also remove the dependencies and generated source files.
967 common-clean: common-mostlyclean
968         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
969         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
970         -rm -f $(addprefix $(common-objpfx),$(common-generated))
971         -rm -f $(objpfx)distinfo
973 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
974 # for each function which is a stub.  We grovel over all the .d files
975 # looking for references to <stub-tag.h>.  Then we grovel over each
976 # referenced source file to see what stub function it defines.
978 ifdef objpfx
979 .PHONY: stubs # The parent Makefile calls this target.
980 stubs: $(objpfx)stubs
981 endif
982 s = $(sysdep_dir)/generic
983 $(objpfx)stubs: $(+depfiles)
984 # Use /dev/null since `...` might expand to empty.
985         (s=`cd $s && /bin/pwd`; \
986          $(patsubst %/,cd % &&,$(objpfx)) \
987          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
988           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
989                 -e '/stub-tag\.h/{; g; p; }' \
990                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
991              /dev/null) > $@T
992         mv -f $@T $@
994 # Make the distribution tar file.
996 .PHONY: dist
997 dist: $(objpfx)distinfo $(..)Make-dist
998         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1000 # Avoid depending on source files found in sysdeps dirs,
1001 # because the references affect implicit rule selection.
1002 dist: $(filter-out %.c %.S %.s,$(distribute))
1004 # We used to simply export all these variables, but that frequently made the
1005 # environment get too large.  Instead, we write all the information into
1006 # a generated makefile fragment `distinfo', and then include it with -f in
1007 # the sub-make that makes the distribution (above).
1008 $(objpfx)distinfo: Makefile $(..)Makerules \
1009                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1010         $(make-target-directory)
1011         $(distinfo-vars)
1012         mv -f $@.new $@
1013 .PHONY: subdir_distinfo
1014 subdir_distinfo: $(objpfx)distinfo
1016 define distinfo-vars
1017 rm -f $@.new
1018 echo > $@.new 'subdir := $(subdir)'
1019 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1020               headers sysdep_headers distribute dont_distribute generated \
1021               others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
1022               versioned \
1023               $(addprefix install-,lib lib.so data bin sbin others),
1024 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1025 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1026 endef
1028 ifneq (,$(strip $(gpl2lgpl)))
1029 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1030 # Snarf from the master source and frob the copying notice.
1031 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1032         sed -f $^ > $@-tmp
1033 # So I don't edit them by mistake.
1034         chmod a-w $@-tmp
1035         mv -f $@-tmp $@
1036 ifeq ($(with-cvs),yes)
1037         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1038 endif
1039 endif
1040 endif