Fixed entry.
[glibc.git] / Makerules
blob5c9b757ea957d86a4a98f56ad92fa938c32275c8
1 # Copyright (C) 1991-1999, 2000,2001 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 # Even before that, we need abi-versions.h which is generated right here.
132 ifeq ($(versioning),yes)
133 ifndef avoid-generated
134 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
135 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
136                                 $(common-objpfx)Versions.all
137         LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
138         mv -f $@T $@
139 endif # avoid-generated
140 endif # $(versioning) = yes
143 # Remove existing files from `before-compile'.  Things are added there when
144 # they must exist for dependency generation to work right, but once they
145 # exist there is no further need for every single file to depend on them,
146 # and those gratuitous dependencies result in many gratuitous
147 # recompilations.
148 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
150 # Don't let any before-compile file be an intermediate and get removed.
151 ifdef before-compile
152 $(before-compile):
153 endif
155 # Generate an ordered list of implicit rules which find the source files in
156 # each sysdep directory.  The old method was to use vpath to search all the
157 # sysdep directories.  However, that had the problem that a .S file in a
158 # later directory would be chosen over a .c file in an earlier directory,
159 # which does not preserve the desired sysdeps ordering behavior.
161 # When making the list of .d files to include, we can't know which ones
162 # have source in .s files, and thus do not in fact need a .d file.
163 # So we must define rules to make .d files for .s files.
164 define make-dummy-dep
165 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
166 endef
167 $(common-objpfx)dummy.d:
168         echo '# .s files cannot contain includes, so they need no deps.' > $@
170 # It matters that this set of rules, for compiling from sources in
171 # the current directory (the $srcdir/$subdir) come before the
172 # generated sysdep rules in included from sysd-rules below.  When
173 # compiling in the source tree, generated sources go into the current
174 # directory, and those should be chosen before any sources in sysdeps.
175 define o-iterator-doit
176 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
177 endef
178 object-suffixes-left := $(all-object-suffixes)
179 include $(o-iterator)
180 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
182 define o-iterator-doit
183 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
184 endef
185 object-suffixes-left := $(all-object-suffixes)
186 include $(o-iterator)
187 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
189 define o-iterator-doit
190 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
191 endef
192 object-suffixes-left := $(all-object-suffixes)
193 include $(o-iterator)
194 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
196 # Omit the objpfx rules when building in the source tree, because
197 # objpfx is empty and so these rules just override the ones above.
198 ifdef objpfx
199 # Define first rules to find the source files in $(objpfx).
200 # Generated source files will end up there.
201 define o-iterator-doit
202 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
203 endef
204 object-suffixes-left := $(all-object-suffixes)
205 include $(o-iterator)
206 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
208 define o-iterator-doit
209 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
210 endef
211 object-suffixes-left := $(all-object-suffixes)
212 include $(o-iterator)
213 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
215 define o-iterator-doit
216 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
217 endef
218 object-suffixes-left := $(all-object-suffixes)
219 include $(o-iterator)
220 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
221 endif
223 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
224 # patterns matching sysdep directories whose assembly source files should
225 # be suppressed.
226 ifdef inhibit-sysdep-asm
227 define open-check-inhibit-asm
228 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
229 endef
230 close-check-inhibit-asm = ;; esac ;
231 endif
233 # Don't include sysd-rules until sysd-Makefile is already there and has been
234 # included.  It might define inhibit-sysdep-asm, which would affect the
235 # contents of sysd-rules.
236 ifdef sysd-Makefile-done
237 -include $(+sysdir_pfx)sysd-rules
238 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
239 # The value of $(+sysdep_dirs) the sysd-rules was computed for
240 # differs from the one we are using now.  So force a rebuild of sysd-rules.
241 sysd-rules-force = FORCE
242 FORCE:
243 endif
244 endif
245 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
246                           $(wildcard $(foreach dir,$(sysdirs),\
247                                                $(dir)/Makefile))\
248                           $(sysd-rules-force)
249         -@rm -f $@T
250         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
251          for dir in $(config-sysdirs:%='$$(..)%'); do                         \
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, but wait until sysdep-subdirs is known
280 ifeq ($(sysd-sorted-done),t)
281 ifeq ($(versioning),yes)
282 -include $(common-objpfx)sysd-versions
283 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
284 common-generated += $(version-maps)
285 postclean-generated += sysd-versions Versions.all abi-versions.h
287 ifndef avoid-generated
288 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
289 sysd-versions-force = FORCE
290 FORCE:
291 endif
292 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
293                               $(common-objpfx)soversions.i \
294                               $(..)Versions.def \
295                               $(wildcard $(add-ons:%=$(..)%/Versions.def))
296         { while read lib version setname; do \
297             test -z "$$setname" || echo "$$lib : $$setname"; \
298           done < $(word 2,$^); \
299           cat $(filter-out $< $(word 2,$^),$^) \
300           | $(preprocess-versions); \
301         } | LC_ALL=C $(AWK) -f $< > $@T
302         mv -f $@T $@
303 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
304                                $(..)scripts/versions.awk \
305                                $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
306                                $(wildcard $(sysdirs:%=%/Versions)) \
307                                $(sysd-versions-force)
308         ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
309           cat $(filter-out $< $(word 2,$^) $(sysd-versions-force),$^) \
310           | $(preprocess-versions) \
311           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
312                             -v move_if_change='$(move-if-change)' \
313                             -f $(word 2,$^); \
314         ) > $@T
315         mv -f $@T $@
316 endif # avoid-generated
317 endif # $(versioning) = yes
318 endif # sysd-sorted-done
321 ifndef compile-command.S
322 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
323 endif
324 ifndef compile-command.s
325 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
326 endif
327 ifndef compile-command.c
328 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
329 endif
331 # GCC can grok options after the file name, and it looks nicer that way.
332 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
333 compile.S = \
334   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
335 COMPILE.S = \
336   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
337 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
339 # If we want to generate MD% checksums for the sources do this now.
340 ifeq ($(md5),yes)
341 generate-md5 = ; rm -f $(@:.d=.md5); \
342 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
343 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
344 else
345 generate-md5 =
346 endif
348 # We need this for the output to go in the right place.  It will default to
349 # empty if make was configured to work with a cc that can't grok -c and -o
350 # together.  You can't compile the C library with such a compiler.
351 OUTPUT_OPTION = -o $@
353 S-CPPFLAGS = $(asm-CPPFLAGS)
354 define +make-deps
355 $(make-target-directory)
356 -@rm -f $@
357 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
358 sed \
359 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
360 $(sed-remove-objpfx) > $(@:.d=.T)
361 mv -f $(@:.d=.T) $@ $(generate-md5)
362 endef
363 ifneq (,$(objpfx))
364 # Continuation lines here are dangerous because they introduce spaces!
365 define sed-remove-objpfx
366 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
367 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
368 endef
369 endif
371 # Modify the list of routines we build for different targets
373 ifeq (yes,$(build-shared))
374 ifndef libc.so-version
375 # Undefine this because it can't work when we libc.so is unversioned.
376 static-only-routines =
377 endif
378 endif
380 # Bounded pointer thunks are only built for *.ob
381 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
383 elide-routines.oS += $(filter-out $(static-only-routines),\
384                                   $(routines) $(aux) $(sysdep_routines)) \
385                      $(elide-bp-thunks)
386 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
388 # If we have versioned code we don't need the old versions in any of the
389 # static libraries.
390 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
391 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
392 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
393 elide-routines.ob += $(shared-only-routines)
395 # Shared library building.
397 ifeq (yes,$(build-shared))
399 # Reference map file only when versioning is selected and a map file name
400 # is given.
401 ifeq ($(versioning),yes)
402 map-file = $(firstword $($(@F:.so=-map)) \
403                        $(addprefix $(common-objpfx), \
404                                    $(filter $(@F:.so=.map),$(version-maps))))
405 load-map-file = $(map-file:%=-Wl,--version-script=%)
406 endif
408 # Pattern rule to build a shared object from an archive of PIC objects.
409 # This must come after the installation rules so Make doesn't try to
410 # build shared libraries in place from the installed *_pic.a files.
411 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
412 # on other shared objects.
413 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
414         $(build-shlib)
416 define build-shlib
417 $(LINK.o) -shared -Wl,-O1 -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
418           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) $(load-map-file) \
419           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
420           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
421           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
422           -Wl,--whole-archive \
423           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
424           $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
425 endef
427 # This macro is similar to build-shlib but it does not define a soname
428 # and it does not depend on the destination name to start with `lib'.
429 define build-module
430 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
431           -B$(csu-objpfx) $(load-map-file) \
432           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
433           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
434           -Wl,--whole-archive \
435           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
436           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
437 endef
439 # Don't try to use -lc when making libc.so itself.
440 # Also omits crti.o and crtn.o, which we do not want
441 # since we define our own `.init' section specially.
442 LDFLAGS-c.so = -nostdlib -nostartfiles
443 # But we still want to link libc.so against $(gnulib).
444 LDLIBS-c.so += $(gnulib)
445 # Give libc.so an entry point and make it directly runnable itself.
446 LDFLAGS-c.so += -e __libc_main
447 # Force the backward compatibility EH functions to be linked.
448 LDFLAGS-c.so += -u __register_frame
449 # Pre-link the objects of libc_pic.a so that we can locally resolve
450 # COMMON symbols before we link against ld.so.  This is because ld.so
451 # contains some of libc_pic.a already, which will prevent the COMMONs
452 # from being allocated in libc.so, which introduces evil dependencies
453 # between libc.so and ld.so, which can make it impossible to upgrade.
454 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
455         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
456         -Wl,-d -Wl,--whole-archive $^
457 # Use our own special initializer and finalizer files for libc.so.
458 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
459                          $(common-objpfx)libc_pic.os \
460                          $(elfobjdir)/sofini.os \
461                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so
462         $(build-shlib)
463 ifeq ($(versioning),yes)
464 $(common-objpfx)libc.so: $(common-objpfx)libc.map
465 endif
466 common-generated += libc.so libc_pic.os
467 ifdef libc.so-version
468 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
469         $(make-link)
470 common-generated += libc.so$(libc.so-version)
471 endif
472 endif
474 # Figure out the source filenames in this directory.
476 override sources := $(addsuffix .c,\
477                         $(filter-out $(elided-routines),\
478                             $(routines) $(aux) \
479                             $(sysdep_routines)))
480 sysdep_routines := $(sysdep_routines)
482 headers := $(headers) $(sysdep_headers)
484 # This is the list of all object files, gotten by
485 # replacing every ".c" in `sources' with a ".o".
486 # We also add bounded-pointer thunks, which are later
487 # elided for all suffixes except for `.ob'.
488 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
489                       $(patsubst %,$(bppfx)%.o,\
490                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
493 # The makefile may define $(extra-libs) with `libfoo libbar'
494 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
495 ifdef extra-libs
496 # extra-lib.mk is included once for each extra lib to define rules
497 # to build it, and to add its objects to the various variables.
498 # During its evaluation, $(lib) is set to the name of the library.
499 extra-libs-left := $(extra-libs)
500 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
501 endif
503 +depfiles := $(sources:.c=.d) \
504              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
505              $(addsuffix .d,$(tests) $(test-srcs))
506 ifeq ($(build-programs),yes)
507 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
508 endif
509 +depfiles := $(addprefix $(objpfx),\
510                          $(filter-out $(addsuffix .d,$(omit-deps)),\
511                                       $(+depfiles)))
513 ifdef +depfiles
514 ifneq ($(no_deps),t)
515 -include $(+depfiles)
516 endif
517 endif
518 \f\f
519 # Maximize efficiency by minimizing the number of rules.
520 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
521 # Don't define any builtin rules.
522 MAKEFLAGS := $(MAKEFLAGS)r
524 # Generic rule for making directories.
526 # mkdir isn't smart enough to strip a trailing /.
527         mkdir $(@:%/=%)
529 # Make sure that object files are not removed
530 # when they are intermediates between sources and library members.
531 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
533 # Make sure that the parent library archive is never removed.
534 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
536 # Use the verbose option of ar and tar when not running silently.
537 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
538 verbose := v
539 else                                            # -s
540 verbose :=
541 endif                                           # not -s
543 ARFLAGS := r$(verbose)
544 CREATE_ARFLAGS := cru$(verbose)
546 # This makes all the object files in the parent library archive.
548 .PHONY: lib lib-noranlib
549 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
550 lib-noranlib: libobjs
552 # For object-suffix $o, the list of objects with that suffix.
553 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
554 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
555                                                        $(elide-routines$o)),\
556                                             $(objects))) \
557             $(addprefix $(objpfx),$(o-objects$o))
559 others: $(addprefix $(objpfx),$(install-lib))
561 ifndef objects
563 # Create the stamp$o files to keep the parent makefile happy.
564 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
565 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
566         $(make-target-directory)
567         rm -f $@; > $@
568 else
570 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
571 # timestamp file; these rules (one explicit rule is generated for each
572 # object suffix) write a list of objects to update in the stamp file.
573 # The parent will then actually add them all to the archive in the
574 # archive rule, below.
575 define o-iterator-doit
576 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
577 endef
578 define do-stamp
579 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
580 mv -f $@T $@
581 endef
582 object-suffixes-left := $(object-suffixes-for-libc)
583 include $(o-iterator)
585 endif
587 # Now define explicit rules to build the library archives; these depend
588 # on the stamp files built above.
589 define o-iterator-doit
590 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
591                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
592 endef
593 define do-makelib
594 cd $(common-objdir) && \
595 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
596 $(RANLIB) $@
597 endef
598 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
599 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
600 ifndef subdir
601 $(subdirs-stamps): subdir_lib;
602 endif
603 object-suffixes-left = $(object-suffixes-for-libc)
604 include $(o-iterator)
607 # This makes all the object files.
608 .PHONY: objects objs libobjs extra-objs
609 objects objs: libobjs extra-objs
610 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
611 extra-objs: $(addprefix $(objpfx),$(extra-objs))
613 # Canned sequence for building an extra library archive.
614 define build-extra-lib
615 $(patsubst %/,cd % &&,$(objpfx)) \
616 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
617       $(patsubst $(objpfx)%,%,$^)
618 $(RANLIB) $@
619 endef
621 # Installation.
623 .PHONY: force-install
624 force-install:
626 # $(install-lib) are installed from the object directory into $(libdir);
627 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
628 # unless they also appear in $(non-lib.a).  $(install-data) are installed
629 # as they are into $(datadir).  $(headers) are installed as they are in
630 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
631 # object directory into $(bindir) and $(sbindir), respectively.
632 # $(install-others) are absolute path names of files to install; rules to
633 # install them are defined elsewhere.
635 # The simple library name to install libc.a under.
636 # This could be defined by a sysdep Makefile.
637 ifndef libc-name
638 libc-name := c
639 endif
641 define do-install
642 $(make-target-directory)
643 $(INSTALL_DATA) $< $@
644 endef
646 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
647 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
648 define make-target-directory
649 $(addprefix $(..)./scripts/mkinstalldirs ,\
650             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
651 endef
653 # Any directory (parent or subdir) should install libc.a; this way
654 # "make install" in a subdir is guaranteed to install everything it changes.
655 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
656                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
657                                                      $(libprefix)$(libc-name)))
658 install: $(installed-libcs)
659 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
660         $(make-target-directory)
661         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
662 # Running ranlib after installing makes the __.SYMDEF time stamp up to
663 # date, which avoids messages from some linkers.
664         $(RANLIB) $@
666 define do-install-program
667 $(make-target-directory)
668 $(INSTALL_PROGRAM) $< $@.new
669 mv -f $@.new $@
670 endef
672 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
673 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
675 ifeq (yes,$(build-shared))
676 # Find which .so's have versions.
677 versioned := $(strip $(foreach so,$(install-lib.so),\
678                                $(patsubst %,$(so),$($(so)-version))))
680 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
681 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
683 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
684                       $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
686 # Install all the unversioned shared libraries.
687 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
688     $(objpfx)%.so $(+force)
689         $(do-install-program)
691 ifneq ($(findstring -s,$(LN_S)),)
692 define make-link
693 rm -f $@.new
694 $(SHELL) $(..)scripts/rellns-sh $< $@.new
695 mv -f $@.new $@
696 endef
697 else
698 # If we have no symbolic links don't bother with rellns-sh.
699 define make-link
700 rm -f $@.new
701 $(LN_S) $< $@.new
702 mv -f $@.new $@
703 endef
704 endif
706 ifeq (yes,$(build-shared))
707 ifeq (no,$(cross-compiling))
708 symbolic-link-prog := $(common-objpfx)elf/sln
709 symbolic-link-list := $(common-objpfx)elf/symlink.list
710 define make-shlib-link
711 echo $(<F) $@ >> $(symbolic-link-list)
712 endef
713 else # cross-compiling
714 # We need a definition that can be used by elf/Makefile's install rules.
715 symbolic-link-prog = $(LN_S)
716 endif
717 endif
718 ifndef make-shlib-link
719 define make-shlib-link
720 rm -f $@
721 $(LN_S) $(<F) $@
722 endef
723 endif
725 ifdef libc.so-version
726 # For a library specified to be version N, install three files:
727 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
728 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
730 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
731                                            $(+force)
732         $(make-shlib-link)
733 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
734         $(do-install-program)
735 install: $(inst_slibdir)/libc.so$(libc.so-version)
737 ifndef subdir
738 # What we install as libc.so for programs to link against is in fact a
739 # link script.  It contains references for the various libraries we need.
740 # The libc.so object is not complete since some functions are only defined
741 # in libc_nonshared.a.
742 # We need to use absolute paths since otherwise local copies (if they exist)
743 # of the files are taken by the linker.
744 install: $(inst_libdir)/libc.so
745 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
746                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
747                                                   $(libprefix)$(libc-name)) \
748                         $(+force)
749         (echo '/* GNU ld script';\
750          echo '   Use the shared library, but some functions are only in';\
751          echo '   the static library, so try that secondarily.  */';\
752          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
753               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
754               ')' \
755         ) > $@.new
756         mv -f $@.new $@
758 endif
760 else
761 install: $(inst_slibdir)/libc.so
762 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
763         $(do-install-program)
764 endif
766 ifneq (,$(versioned))
767 # Produce three sets of rules as above for all the smaller versioned libraries.
769 define o-iterator-doit
770 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
771 endef
772 object-suffixes-left := $(versioned)
773 include $(o-iterator)
775 # Make symlinks in the build directory, because the versioned names might
776 # be referenced by a DT_NEEDED in another library.
777 define o-iterator-doit
778 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
779 endef
780 object-suffixes-left := $(versioned)
781 include $(o-iterator)
783 generated += $(foreach o,$(versioned),$o$($o-version))
785 ifeq (,$($(subdir)-version))
786 define o-iterator-doit
787 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
788                                  $(+force);
789         $$(make-shlib-link)
790 endef
791 object-suffixes-left := $(versioned)
792 include $(o-iterator)
794 define o-iterator-doit
795 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
796         $$(do-install-program)
797 endef
798 object-suffixes-left := $(versioned)
799 include $(o-iterator)
800 else
801 define o-iterator-doit
802 $(inst_slibdir)/$o$($o-version): \
803   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
804         $$(make-shlib-link)
805 endef
806 object-suffixes-left := $(versioned)
807 include $(o-iterator)
809 define o-iterator-doit
810 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
811         $$(do-install-program)
812 endef
813 object-suffixes-left := $(versioned)
814 include $(o-iterator)
815 endif
816 endif
818 define do-install-so
819 $(do-install-program)
820 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
821            $(filter-out %.so,$@))
822 endef
824 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
825 $(foreach v,$(so-versions),\
826           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
827                                                $(+force)
828         $(do-install-so)
829 $(foreach v,$(so-versions),\
830           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
831         $(do-install-so)
832 endif
834 ifdef install-bin
835 $(addprefix $(inst_bindir)/,$(install-bin)): \
836     $(inst_bindir)/%: $(objpfx)% $(+force)
837         $(do-install-program)
838 endif
839 ifdef install-rootsbin
840 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
841    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
842         $(do-install-program)
843 endif
844 ifdef install-sbin
845 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
846     $(inst_sbindir)/%: $(objpfx)% $(+force)
847         $(do-install-program)
848 endif
849 ifdef install-lib
850 install-lib.a := $(filter lib%.a,$(install-lib))
851 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
852 ifdef install-lib-non.a
853 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
854   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
855         $(do-install)
856 endif
857 ifdef install-lib.a
858 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
859   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
860         $(do-install)
861         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
862 endif
863 endif
864 ifdef install-data
865 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
866         $(do-install)
867 endif
868 headers := $(strip $(headers))
869 ifdef headers
870 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
871         $(do-install)
872 endif   # headers
874 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
875         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
876 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
877 install-rootsbin-nosubdir: \
878         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
879 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
880 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
881                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
882                        $(addprefix $(libprefix),$(install-lib-non.a)))
883 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
884 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
885 install-others-nosubdir: $(install-others)
887 # We need all the `-nosubdir' targets so that `install' in the parent
888 # doesn't depend on several things which each iterate over the subdirs.
889 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
890 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
891 install-%:: install-%-nosubdir ;
893 .PHONY: install install-no-libc.a-nosubdir
894 ifeq ($(build-programs),yes)
895 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
896                             install-bin-nosubdir install-lib-nosubdir   \
897                             install-others-nosubdir install-rootsbin-nosubdir \
898                             install-sbin-nosubdir
899 else
900 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
901                             install-lib-nosubdir install-others-nosubdir
902 endif
903 install: install-no-libc.a-nosubdir
905 # Command to compile $< in $(objdir) using the native libraries.
906 define native-compile
907 $(make-target-directory)
908 $(patsubst %/,cd % &&,$(objpfx)) \
909 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
910             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
911 endef
913 # Command to compile $< in $(common-objdir) using the native libraries.
914 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
915 define common-objdir-compile
916 $(patsubst %/,cd % &&,$(objpfx)) \
917 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
918             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
919 endef
921 # We always want to use configuration definitions.
922 # Note that this is only used for commands running in $(objpfx).
923 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
925 # Support the GNU standard name for this target.
926 .PHONY: check
927 check: tests
929 .PHONY: TAGS
930 TAGS: $(objpfx)distinfo $(..)MakeTAGS
931         $(MAKE) $(addprefix -f ,$^) $@
933 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
934         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
935 FORCE:
938 .PHONY: echo-headers
939 echo-headers:
940         @echo $(headers)
943 # Common cleaning targets.
945 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
946 clean: common-clean
947 mostlyclean: common-mostlyclean
949 do-tests-clean:
950         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(test-srcs)) \
951                                      $(addsuffix -bp.out,$(tests) $(test-srcs)))
953 # Remove the object files.
954 common-mostlyclean:
955         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
956                                      $(sysdep-others) stubs \
957                                      $(addsuffix .o,$(tests) $(test-srcs) \
958                                                     $(others) \
959                                                     $(sysdep-others)) \
960                                      $(addsuffix -bp,$(tests) $(test-srcs)) \
961                                      $(addsuffix .out,$(tests) $(test-srcs)) \
962                                      $(addsuffix -bp.out,$(tests) $(test-srcs)))
963         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
964                                      $(install-lib.so) \
965                                      $(install-lib.so:%.so=%_pic.a))
966         -rm -f core
967         $(rmobjs)
968 define rmobjs
969 $(foreach o,$(object-suffixes-for-libc),
970 -rm -f $(objpfx)stamp$o $(o-objects))
971 endef
973 # Also remove the dependencies and generated source files.
974 common-clean: common-mostlyclean
975         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
976         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
977         -rm -f $(addprefix $(common-objpfx),$(common-generated))
978         -rm -f $(objpfx)distinfo
980 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
981 # for each function which is a stub.  We grovel over all the .d files
982 # looking for references to <stub-tag.h>.  Then we grovel over each
983 # referenced source file to see what stub function it defines.
985 ifdef objpfx
986 .PHONY: stubs # The parent Makefile calls this target.
987 stubs: $(objpfx)stubs
988 endif
989 s = $(sysdep_dir)/generic
990 $(objpfx)stubs: $(+depfiles)
991 # Use /dev/null since `...` might expand to empty.
992         (s=`cd $s && $(PWD_P)`; \
993          $(patsubst %/,cd % &&,$(objpfx)) \
994          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
995           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
996                 -e '/stub-tag\.h/{; g; p; }' \
997                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
998              /dev/null) > $@T
999         mv -f $@T $@
1001 # Make the distribution tar file.
1003 .PHONY: dist
1004 dist: $(objpfx)distinfo $(..)Make-dist
1005         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1007 # Avoid depending on source files found in sysdeps dirs,
1008 # because the references affect implicit rule selection.
1009 dist: $(filter-out %.c %.S %.s,$(distribute))
1011 # We used to simply export all these variables, but that frequently made the
1012 # environment get too large.  Instead, we write all the information into
1013 # a generated makefile fragment `distinfo', and then include it with -f in
1014 # the sub-make that makes the distribution (above).
1015 $(objpfx)distinfo: Makefile $(..)Makerules \
1016                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1017         $(make-target-directory)
1018         $(distinfo-vars)
1019         mv -f $@.new $@
1020 .PHONY: subdir_distinfo
1021 subdir_distinfo: $(objpfx)distinfo
1023 define distinfo-vars
1024 rm -f $@.new
1025 echo > $@.new 'subdir := $(subdir)'
1026 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1027               headers sysdep_headers distribute dont_distribute generated \
1028               others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
1029               versioned \
1030               $(addprefix install-,lib lib.so data bin sbin others),
1031 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1032 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1033 endef
1035 ifneq (,$(strip $(gpl2lgpl)))
1036 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1037 # Snarf from the master source and frob the copying notice.
1038 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1039         sed -f $^ > $@-tmp
1040 # So I don't edit them by mistake.
1041         chmod a-w $@-tmp
1042         mv -f $@-tmp $@
1043 ifeq ($(with-cvs),yes)
1044         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1045 endif
1046 endif
1047 endif