Update.
[glibc.git] / Makerules
blob4d6a48742c7156a9661e04a074e7c70e223792ed
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)
273 postclean-generated += sysd-versions Versions.all
275 ifndef avoid-generated
276 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
277 sysd-versions-force = FORCE
278 FORCE:
279 endif
280 $(common-objpfx)Versions.all: $(..)Versions.def \
281                               $(wildcard $(add-ons:%=$(..)%/Versions.def))
282         cat $^ > $@T
283         mv -f $@T $@
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           LC_ALL=C $(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 # Force the backward compatibility EH functions to be linked.
409 LDFLAGS-c.so += -u __register_frame
410 # Pre-link the objects of libc_pic.a so that we can locally resolve
411 # COMMON symbols before we link against ld.so.  This is because ld.so
412 # contains some of libc_pic.a already, which will prevent the COMMONs
413 # from being allocated in libc.so, which introduces evil dependencies
414 # between libc.so and ld.so, which can make it impossible to upgrade.
415 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
416         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
417         -Wl,-d -Wl,--whole-archive $^
418 # Use our own special initializer and finalizer files for libc.so.
419 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
420                          $(common-objpfx)libc_pic.os \
421                          $(elfobjdir)/sofini.os \
422                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so
423         $(build-shlib)
424 ifeq ($(versioning),yes)
425 $(common-objpfx)libc.so: $(common-objpfx)libc.map
426 endif
427 common-generated += libc.so libc_pic.os
428 ifdef libc.so-version
429 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
430         $(make-link)
431 common-generated += libc.so$(libc.so-version)
432 endif
433 endif
435 # Figure out the source filenames in this directory.
437 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
438                                                        $(routines) $(aux) \
439                                                        $(sysdep_routines)))
440 sysdep_routines := $(sysdep_routines)
442 headers := $(headers) $(sysdep_headers)
444 # This is the list of all object files, gotten by
445 # replacing every ".c" in `sources' with a ".o".
446 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
449 # The makefile may define $(extra-libs) with `libfoo libbar'
450 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
451 ifdef extra-libs
452 # extra-lib.mk is included once for each extra lib to define rules
453 # to build it, and to add its objects to the various variables.
454 # During its evaluation, $(lib) is set to the name of the library.
455 extra-libs-left := $(extra-libs)
456 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
457 endif
459 +depfiles := $(sources:.c=.d) \
460              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
461              $(addsuffix .d,$(tests) $(test-srcs))
462 ifeq ($(build-programs),yes)
463 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
464 endif
465 +depfiles := $(addprefix $(objpfx),\
466                          $(filter-out $(addsuffix .d,$(omit-deps)),\
467                                       $(+depfiles)))
469 ifdef +depfiles
470 ifneq ($(no_deps),t)
471 -include $(+depfiles)
472 endif
473 endif
474 \f\f
475 # Maximize efficiency by minimizing the number of rules.
476 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
477 # Don't define any builtin rules.
478 MAKEFLAGS := $(MAKEFLAGS)r
480 # Generic rule for making directories.
482 # mkdir isn't smart enough to strip a trailing /.
483         mkdir $(@:%/=%)
485 # Make sure that object files are not removed
486 # when they are intermediates between sources and library members.
487 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
489 # Make sure that the parent library archive is never removed.
490 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
492 # Use the verbose option of ar and tar when not running silently.
493 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
494 verbose := v
495 else                                            # -s
496 verbose :=
497 endif                                           # not -s
499 ARFLAGS := r$(verbose)
500 CREATE_ARFLAGS := cru$(verbose)
502 # This makes all the object files in the parent library archive.
504 .PHONY: lib lib-noranlib
505 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
506 lib-noranlib: libobjs
508 # For object-suffix $o, the list of objects with that suffix.
509 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
510 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
511                                                        $(elide-routines$o)),\
512                                             $(objects)))
513 others: $(addprefix $(objpfx),$(install-lib))
515 ifndef objects
517 # Create the stamp$o files to keep the parent makefile happy.
518 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
519 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
520         $(make-target-directory)
521         rm -f $@; > $@
522 else
524 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
525 # timestamp file; these rules (one explicit rule is generated for each
526 # object suffix) write a list of objects to update in the stamp file.
527 # The parent will then actually add them all to the archive in the
528 # archive rule, below.
529 define o-iterator-doit
530 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
531 endef
532 define do-stamp
533 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
534 mv -f $@T $@
535 endef
536 object-suffixes-left := $(object-suffixes-for-libc)
537 include $(o-iterator)
539 endif
541 # Now define explicit rules to build the library archives; these depend
542 # on the stamp files built above.
543 define o-iterator-doit
544 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
545                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
546 endef
547 define do-makelib
548 cd $(common-objdir) && \
549 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
550 $(RANLIB) $@
551 endef
552 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
553 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
554 ifndef subdir
555 $(subdirs-stamps): subdir_lib;
556 endif
557 object-suffixes-left = $(object-suffixes-for-libc)
558 include $(o-iterator)
561 # This makes all the object files.
562 .PHONY: objects objs libobjs extra-objs
563 objects objs: libobjs extra-objs
564 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
565 extra-objs: $(addprefix $(objpfx),$(extra-objs))
567 # Canned sequence for building an extra library archive.
568 define build-extra-lib
569 $(patsubst %/,cd % &&,$(objpfx)) \
570 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
571       $(patsubst $(objpfx)%,%,$^)
572 $(RANLIB) $@
573 endef
575 # Installation.
577 .PHONY: force-install
578 force-install:
580 # $(install-lib) are installed from the object directory into $(libdir);
581 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
582 # unless they also appear in $(non-lib.a).  $(install-data) are installed
583 # as they are into $(datadir).  $(headers) are installed as they are in
584 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
585 # object directory into $(bindir) and $(sbindir), respectively.
586 # $(install-others) are absolute path names of files to install; rules to
587 # install them are defined elsewhere.
589 # The simple library name to install libc.a under.
590 # This could be defined by a sysdep Makefile.
591 ifndef libc-name
592 libc-name := c
593 endif
595 define do-install
596 $(make-target-directory)
597 $(INSTALL_DATA) $< $@
598 endef
600 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
601 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
602 define make-target-directory
603 $(addprefix $(..)./scripts/mkinstalldirs ,\
604             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
605 endef
607 # Any directory (parent or subdir) should install libc.a; this way
608 # "make install" in a subdir is guaranteed to install everything it changes.
609 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
610                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
611                                                      $(libprefix)$(libc-name)))
612 install: $(installed-libcs)
613 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
614         $(make-target-directory)
615         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
616 # Running ranlib after installing makes the __.SYMDEF time stamp up to
617 # date, which avoids messages from some linkers.
618         $(RANLIB) $@
620 define do-install-program
621 $(make-target-directory)
622 $(INSTALL_PROGRAM) $< $@.new
623 mv -f $@.new $@
624 endef
626 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
627 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
629 ifeq (yes,$(build-shared))
630 # Find which .so's have versions.
631 versioned := $(strip $(foreach so,$(install-lib.so),\
632                                $(patsubst %,$(so),$($(so)-version))))
634 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
635 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
637 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
638                       $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
640 # Install all the unversioned shared libraries.
641 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
642     $(objpfx)%.so $(+force)
643         $(do-install-program)
645 ifneq ($(findstring -s,$(LN_S)),)
646 define make-link
647 rm -f $@.new
648 $(SHELL) $(..)scripts/rellns-sh $< $@.new
649 mv -f $@.new $@
650 endef
651 else
652 # If we have no symbolic links don't bother with rellns-sh.
653 define make-link
654 rm -f $@.new
655 $(LN_S) $< $@.new
656 mv -f $@.new $@
657 endef
658 endif
660 ifeq (no,$(cross-compiling))
661 ifeq (yes,$(build-shared))
662 symbolic-link-prog := $(common-objpfx)elf/sln
663 symbolic-link-list := $(common-objpfx)elf/symlink.list
664 define make-shlib-link
665 echo $(<F) $@ >> $(symbolic-link-list)
666 endef
667 endif
668 endif
669 ifndef make-shlib-link
670 define make-shlib-link
671 rm -f $@
672 $(LN_S) $(<F) $@
673 endef
674 endif
676 ifdef libc.so-version
677 # For a library specified to be version N, install three files:
678 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
679 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
681 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
682                                            $(+force)
683         $(make-shlib-link)
684 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
685         $(do-install-program)
686 install: $(inst_slibdir)/libc.so$(libc.so-version)
688 ifndef subdir
689 # What we install as libc.so for programs to link against is in fact a
690 # link script.  It contains references for the various libraries we need.
691 # The libc.so object is not complete since some functions are only defined
692 # in libc_nonshared.a.
693 # We need to use absolute paths since otherwise local copies (if they exist)
694 # of the files are taken by the linker.
695 install: $(inst_libdir)/libc.so
696 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
697                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
698                                                   $(libprefix)$(libc-name)) \
699                         $(+force)
700         (echo '/* GNU ld script';\
701          echo '   Use the shared library, but some functions are only in';\
702          echo '   the static library, so try that secondarily.  */';\
703          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
704               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
705               ')' \
706         ) > $@.new
707         mv -f $@.new $@
709 endif
711 else
712 install: $(inst_slibdir)/libc.so
713 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
714         $(do-install-program)
715 endif
717 ifneq (,$(versioned))
718 # Produce three sets of rules as above for all the smaller versioned libraries.
720 define o-iterator-doit
721 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
722 endef
723 object-suffixes-left := $(versioned)
724 include $(o-iterator)
726 # Make symlinks in the build directory, because the versioned names might
727 # be referenced by a DT_NEEDED in another library.
728 define o-iterator-doit
729 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
730 endef
731 object-suffixes-left := $(versioned)
732 include $(o-iterator)
734 generated += $(foreach o,$(versioned),$o$($o-version))
736 ifeq (,$($(subdir)-version))
737 define o-iterator-doit
738 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
739                                  $(+force);
740         $$(make-shlib-link)
741 endef
742 object-suffixes-left := $(versioned)
743 include $(o-iterator)
745 define o-iterator-doit
746 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
747         $$(do-install-program)
748 endef
749 object-suffixes-left := $(versioned)
750 include $(o-iterator)
751 else
752 define o-iterator-doit
753 $(inst_slibdir)/$o$($o-version): \
754   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
755         $$(make-shlib-link)
756 endef
757 object-suffixes-left := $(versioned)
758 include $(o-iterator)
760 define o-iterator-doit
761 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
762         $$(do-install-program)
763 endef
764 object-suffixes-left := $(versioned)
765 include $(o-iterator)
766 endif
767 endif
769 define do-install-so
770 $(do-install-program)
771 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
772            $(filter-out %.so,$@))
773 endef
775 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
776 $(foreach v,$(so-versions),\
777           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
778                                                $(+force)
779         $(do-install-so)
780 $(foreach v,$(so-versions),\
781           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
782         $(do-install-so)
783 endif
785 ifdef install-bin
786 $(addprefix $(inst_bindir)/,$(install-bin)): \
787     $(inst_bindir)/%: $(objpfx)% $(+force)
788         $(do-install-program)
789 endif
790 ifdef install-rootsbin
791 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
792    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
793         $(do-install-program)
794 endif
795 ifdef install-sbin
796 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
797     $(inst_sbindir)/%: $(objpfx)% $(+force)
798         $(do-install-program)
799 endif
800 ifdef install-lib
801 install-lib.a := $(filter lib%.a,$(install-lib))
802 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
803 ifdef install-lib-non.a
804 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
805   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
806         $(do-install)
807 endif
808 ifdef install-lib.a
809 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
810   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
811         $(do-install)
812         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
813 endif
814 endif
815 ifdef install-data
816 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
817         $(do-install)
818 endif
819 headers := $(strip $(headers))
820 ifdef headers
821 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
822         $(do-install)
823 endif   # headers
825 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
826         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
827 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
828 install-rootsbin-nosubdir: \
829         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
830 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
831 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
832                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
833                        $(addprefix $(libprefix),$(install-lib-non.a)))
834 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
835 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
836 install-others-nosubdir: $(install-others)
838 # We need all the `-nosubdir' targets so that `install' in the parent
839 # doesn't depend on several things which each iterate over the subdirs.
840 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
841 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
842 install-%:: install-%-nosubdir ;
844 .PHONY: install install-no-libc.a-nosubdir
845 ifeq ($(build-programs),yes)
846 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
847                             install-bin-nosubdir install-lib-nosubdir   \
848                             install-others-nosubdir install-rootsbin-nosubdir \
849                             install-sbin-nosubdir
850 else
851 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
852                             install-lib-nosubdir install-others-nosubdir
853 endif
854 install: install-no-libc.a-nosubdir
856 # Command to compile $< in $(objdir) using the native libraries.
857 define native-compile
858 $(make-target-directory)
859 $(patsubst %/,cd % &&,$(objpfx)) \
860 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
861             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
862 endef
864 # Command to compile $< in $(common-objdir) using the native libraries.
865 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
866 define common-objdir-compile
867 $(patsubst %/,cd % &&,$(objpfx)) \
868 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
869             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
870 endef
872 # We always want to use configuration definitions.
873 # Note that this is only used for commands running in $(objpfx).
874 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
876 # Support the GNU standard name for this target.
877 .PHONY: check
878 check: tests
880 .PHONY: TAGS
881 TAGS: $(objpfx)distinfo $(..)MakeTAGS
882         $(MAKE) $(addprefix -f ,$^) $@
884 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
885         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
886 FORCE:
889 .PHONY: echo-headers
890 echo-headers:
891         @echo $(headers)
894 # Common cleaning targets.
896 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
897 clean: common-clean
898 mostlyclean: common-mostlyclean
900 do-tests-clean:
901         -rm -f $(patsubst %,$(objpfx)%.out,$(tests) $(test-srcs))
903 # Remove the object files.
904 common-mostlyclean:
905         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
906                                      $(sysdep-others) stubs \
907                                      $(addsuffix .o,$(tests) $(test-srcs) \
908                                                     $(others) \
909                                                     $(sysdep-others)) \
910                                      $(addsuffix .out,$(tests) $(test-srcs)))
911         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
912                                      $(install-lib.so) \
913                                      $(install-lib.so:%.so=%_pic.a))
914         -rm -f core
915         $(rmobjs)
916 define rmobjs
917 $(foreach o,$(object-suffixes-for-libc),
918 -rm -f $(objpfx)stamp$o $(o-objects))
919 endef
921 # Also remove the dependencies and generated source files.
922 common-clean: common-mostlyclean
923         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
924         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
925         -rm -f $(addprefix $(common-objpfx),$(common-generated))
926         -rm -f $(objpfx)distinfo
928 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
929 # for each function which is a stub.  We grovel over all the .d files
930 # looking for references to <stub-tag.h>.  Then we grovel over each
931 # referenced source file to see what stub function it defines.
933 ifdef objpfx
934 .PHONY: stubs # The parent Makefile calls this target.
935 stubs: $(objpfx)stubs
936 endif
937 s = $(sysdep_dir)/generic
938 $(objpfx)stubs: $(+depfiles)
939 # Use /dev/null since `...` might expand to empty.
940         (s=`cd $s && /bin/pwd`; \
941          $(patsubst %/,cd % &&,$(objpfx)) \
942          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
943           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
944                 -e '/stub-tag\.h/{; g; p; }' \
945                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
946              /dev/null) > $@T
947         mv -f $@T $@
949 # Make the distribution tar file.
951 .PHONY: dist
952 dist: $(objpfx)distinfo $(..)Make-dist
953         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
955 # Avoid depending on source files found in sysdeps dirs,
956 # because the references affect implicit rule selection.
957 dist: $(filter-out %.c %.S %.s,$(distribute))
959 # We used to simply export all these variables, but that frequently made the
960 # environment get too large.  Instead, we write all the information into
961 # a generated makefile fragment `distinfo', and then include it with -f in
962 # the sub-make that makes the distribution (above).
963 $(objpfx)distinfo: Makefile $(..)Makerules \
964                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
965         $(make-target-directory)
966         $(distinfo-vars)
967         mv -f $@.new $@
968 .PHONY: subdir_distinfo
969 subdir_distinfo: $(objpfx)distinfo
971 define distinfo-vars
972 rm -f $@.new
973 echo > $@.new 'subdir := $(subdir)'
974 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
975               headers sysdep_headers distribute dont_distribute generated \
976               others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
977               versioned \
978               $(addprefix install-,lib lib.so data bin sbin others),
979 echo >> $@.new '$(subdir)-$(var) := $($(var))'
980 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
981 endef
983 ifneq (,$(strip $(gpl2lgpl)))
984 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
985 # Snarf from the master source and frob the copying notice.
986 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
987         sed -f $^ > $@-tmp
988 # So I don't edit them by mistake.
989         chmod a-w $@-tmp
990         mv -f $@-tmp $@
991 ifeq ($(with-cvs),yes)
992         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
993 endif
994 endif
995 endif