Update.
[glibc.git] / Makerules
blobe7ef90eae192a7fcb4f19b5360476adf1441cd38
1 # Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version.  See above for the version needed.
34 endif
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq   "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full-config-sysdirs))
62 +sysdir_pfx = $(common-objpfx)
64 export sysdirs := $(sysdirs)
66 +sysdep_dirs := $(full-config-sysdirs)
67 ifdef objdir
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
69 endif
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
75 # The name of the symbol table archive member.  The default is suitable for
76 # BSD style archives.  It can be overridden in sysdep Makefiles when SYSV
77 # style archive are used.
78 ifeq (no,$(elf))
79 ar-symtab-name = __.SYMDEF
80 else
81 ar-symtab-name = # The null name is used in ELF archives.
82 endif
84 # Include any system-specific makefiles.
86 # This is here so things in sysdep Makefiles can easily depend on foo.h as
87 # appropriate and not worry about where foo.h comes from, which may be
88 # system dependent and not known by that Makefile.
89 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
90                                       $(+sysdep_dirs) $(..)))
92 # Some sysdep makefiles use this to distinguish being included here from
93 # being included individually by a subdir makefile (hurd/Makefile needs this).
94 in-Makerules := yes
96 ifndef avoid-generated
97 -include $(+sysdir_pfx)sysd-Makefile
98 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
99 sysd-Makefile-force = FORCE
100 FORCE:
101 endif
102 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
103                              $(sysd-Makefile-force)
104         -@rm -f $@T
105         (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)';                   \
106          for dir in $(config-sysdirs); do                                     \
107            file=$$dir/Makefile;                                               \
108            case $$dir in                                                      \
109              /*) rel= ;;                                                      \
110              *)  rel=$(..) ;;                                                 \
111            esac;                                                              \
112            if [ -f $$rel$$file ]; then                                        \
113              case $$dir in                                                    \
114                /*) echo include "$$file" ;;                                   \
115                *)  echo include "\$$(..)$$file" ;;                            \
116              esac;                                                            \
117            else true; fi;                                                     \
118          done;                                                                \
119          echo 'sysd-Makefile-done=t') > $@T
120         mv -f $@T $@
121 endif
123 ifndef sysd-Makefile-done
124 # Don't do deps until this exists, because it might change the sources list.
125 no_deps=t
126 endif
129 # Reorder before-compile so that mach things come first, and hurd things
130 # second, before all else.  The mach and hurd subdirectories have many
131 # generated header files which the much of rest of the library depends on,
132 # so it is best to build them first (and mach before hurd, at that).
133 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
134                            $(before-compile)) \
135                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
136                                $(before-compile))
138 # Remove existing files from `before-compile'.  Things are added there when
139 # they must exist for dependency generation to work right, but once they
140 # exist there is no further need for every single file to depend on them,
141 # and those gratuitous dependencies result in many gratuitous
142 # recompilations.
143 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
145 # Don't let any before-compile file be an intermediate and get removed.
146 ifdef before-compile
147 $(before-compile):
148 endif
150 # Generate an ordered list of implicit rules which find the source files in
151 # each sysdep directory.  The old method was to use vpath to search all the
152 # sysdep directories.  However, that had the problem that a .S file in a
153 # later directory would be chosen over a .c file in an earlier directory,
154 # which does not preserve the desired sysdeps ordering behavior.
156 # When making the list of .d files to include, we can't know which ones
157 # have source in .s files, and thus do not in fact need a .d file.
158 # So we must define rules to make .d files for .s files.
159 define make-dummy-dep
160 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
161 endef
162 $(common-objpfx)dummy.d:
163         echo '# .s files cannot contain includes, so they need no deps.' > $@
165 # It matters that this set of rules, for compiling from sources in
166 # the current directory (the $srcdir/$subdir) come before the
167 # generated sysdep rules in included from sysd-rules below.  When
168 # compiling in the source tree, generated sources go into the current
169 # directory, and those should be chosen before any sources in sysdeps.
170 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
171 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
172 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
173 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
174 $(objpfx)%.So: %.S $(before-compile); $(compile-command.S)
175 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
176 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
177 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
178 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
179 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
180 $(objpfx)%.So: %.s $(before-compile); $(compile-command.s)
181 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
182 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
183 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
184 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
185 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
186 $(objpfx)%.So: %.c $(before-compile); $(compile-command.c)
187 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
189 # Omit the objpfx rules when building in the source tree, because
190 # objpfx is empty and so these rules just override the ones above.
191 ifdef objpfx
192 # Define first rules to find the source files in $(objpfx).
193 # Generated source files will end up there.
194 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
195 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
196 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
197 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
198 $(objpfx)%.So: $(objpfx)%.S $(before-compile); $(compile-command.S)
199 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
200 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
201 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
202 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
203 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
204 $(objpfx)%.So: $(objpfx)%.s $(before-compile); $(compile-command.s)
205 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
206 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
207 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
208 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
209 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
210 $(objpfx)%.So: $(objpfx)%.c $(before-compile); $(compile-command.c)
211 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
212 endif
214 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
215 # patterns matching sysdep directories whose assembly source files should
216 # be suppressed.
217 ifdef inhibit-sysdep-asm
218 define open-check-inhibit-asm
219 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
220 endef
221 close-check-inhibit-asm = ;; esac ;
222 endif
224 # Don't include sysd-rules until sysd-Makefile is already there and has been
225 # included.  It might define inhibit-sysdep-asm, which would affect the
226 # contents of sysd-rules.
227 ifdef sysd-Makefile-done
228 -include $(+sysdir_pfx)sysd-rules
229 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
230 # The value of $(+sysdep_dirs) the sysd-rules was computed for
231 # differs from the one we are using now.  So force a rebuild of sysd-rules.
232 sysd-rules-force = FORCE
233 FORCE:
234 endif
235 endif
236 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
237                           $(wildcard $(foreach dir,$(sysdirs),\
238                                                $(dir)/Makefile))\
239                           $(sysd-rules-force)
240         -@rm -f $@T
241         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
242          for sysdir in $(config-sysdirs); do                                  \
243            case $$sysdir in \
244              /*) dir=$$sysdir ;; \
245              *)  dir="\$$(..)$$sysdir" ;; \
246            esac; \
247            for o in $(all-object-suffixes); do \
248              $(open-check-inhibit-asm) \
249              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
250                   \$$(compile-command.S)";                                    \
251              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
252                   \$$(compile-command.s)";                                    \
253              $(close-check-inhibit-asm) \
254              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
255                   \$$(compile-command.c)";                                    \
256            done; \
257            $(open-check-inhibit-asm) \
258            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
259                 \$$(make-dummy-dep)";                          \
260            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
261                 \$$(+make-deps)";                                             \
262            $(close-check-inhibit-asm)   \
263            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
264                 \$$(+make-deps)";                                             \
265          done;                                                                \
266          echo 'sysd-rules-done = t') > $@T
267         mv -f $@T $@
269 ifndef sysd-rules-done
270 # Don't do deps until this exists, because it provides rules to make the deps.
271 no_deps=t
272 endif
275 ifndef compile-command.S
276 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
277 endif
278 ifndef compile-command.s
279 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
280 endif
281 ifndef compile-command.c
282 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
283 endif
285 # GCC can grok options after the file name, and it looks nicer that way.
286 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
287 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
288 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
289 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS) $(ASFLAGS-$(suffix $@))
291 # We need this for the output to go in the right place.  It will default to
292 # empty if make was configured to work with a cc that can't grok -c and -o
293 # together.  You can't compile the C library with such a compiler.
294 OUTPUT_OPTION = -o $@
296 S-CPPFLAGS = $(asm-CPPFLAGS)
297 define +make-deps
298 $(make-target-directory)
299 -@rm -f $@
300 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
301 sed \
302 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
303 $(sed-remove-objpfx) > $(@:.d=.T)
304 mv -f $(@:.d=.T) $@
305 endef
306 ifneq (,$(objpfx))
307 # Continuation lines here are dangerous because they introduce spaces!
308 define sed-remove-objpfx
309 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
310 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
311 endef
312 endif
314 # Shared library building.
316 ifeq (yes,$(build-shared))
318 # Pattern rule to build a shared object from an archive of PIC objects.
319 # This must come after the installation rules so Make doesn't try to
320 # build shared libraries in place from the installed *_pic.a files.
321 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
322 # on other shared objects.
323 lib%.so: lib%_pic.a; $(build-shlib)
325 ifeq ($(have-no-whole-archive),yes)
326 no-whole-archive = -Wl,--no-whole-archive
327 else
328 no-whole-archive =
329 endif
331 interp-obj = $(common-objpfx)interp.so
332 $(interp-obj): $(common-objpfx)%.so: $(..)%.c
333         $(compile-command.c)
334 common-generated += interp.so
335 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
337 $(common-objpfx)libc.so: $(interp-obj)
338 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
340 define build-shlib
341 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
342           -B$(csu-objpfx) \
343           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
344           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
345           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
346           -Wl,--whole-archive $^ $(no-whole-archive) \
347           $(LDLIBS-$(@F:lib%.so=%).so)
348           test -z "$($(@F)-version)" || \
349             (rm -f $@$($(@F)-version); $(LN_S) $(@F) $@$($(@F)-version))
350 endef
352 ifndef libc.so-version
353 # Undefine this because it can't work when we libc.so is unversioned.
354 static-only-routines =
355 endif
356 elide-routines.So = $(filter-out $(static-only-routines),\
357                                  $(routines) $(aux) $(sysdep_routines))
359 ifdef static-only-routines
360 # These routines are to be omitted from the shared library object,
361 # so we replace the PIC objects for them with the empty object file.
362 $(static-only-routines:%=$(objpfx)%.so): %.so: $(common-objpfx)empty.o
363         rm -f $@
364         ln $< $@
365 endif
367 # Don't try to use -lc when making libc.so itself.
368 # Also omits crti.o and crtn.o, which we do not want
369 # since we define our own `.init' section specially.
370 LDFLAGS-c.so = -nostdlib -nostartfiles
371 # But we still want to link libc.so against -lgcc.
372 LDLIBS-c.so = -lgcc
373 # Give libc.so an entry point and make it directly runnable itself.
374 LDFLAGS-c.so += -e __libc_main
375 # Use our own special initializer and finalizer files for libc.so.
376 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
377                          $(common-objpfx)libc_pic.a \
378                          $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
379         $(build-shlib)
380 endif
382 # Some files must not be compiled with the exception handler mechanism
383 # enabled (introduced in gcc-2.8).  Use $(no-exceptions) in the
384 # appropriate CFLAGS definition.
385 ifeq ($(have-no-exceptions),yes)
386 no-exceptions = -fno-exceptions
387 else
388 no-exceptions =
389 endif
391 # Figure out the source filenames in this directory.
393 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
394                                                        $(routines) $(aux) \
395                                                        $(sysdep_routines)))
396 sysdep_routines := $(sysdep_routines)
398 headers := $(headers) $(sysdep_headers)
400 # This is the list of all object files, gotten by
401 # replacing every ".c" in `sources' with a ".o".
402 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
405 # This variable is used in ``include $(o-iterator)'' after defining
406 # $(o-iterator-doit) to produce some desired rule using $o for the object
407 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
408 # is produced for each object suffix in use.
409 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
411 # The makefile may define $(extra-libs) with `libfoo libbar'
412 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
413 ifdef extra-libs
414 # extra-lib.mk is included once for each extra lib to define rules
415 # to build it, and to add its objects to the various variables.
416 # During its evaluation, $(lib) is set to the name of the library.
417 extra-libs-left := $(extra-libs)
418 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
419 endif
421 +depfiles := $(strip $(sources:.c=.d) \
422                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
423                      $(addsuffix .d,$(others) $(tests)))
424 +depfiles := $(addprefix $(objpfx),\
425                          $(filter-out $(addsuffix .d,$(omit-deps)),\
426                                       $(+depfiles)))
428 ifdef +depfiles
429 ifneq ($(no_deps),t)
430 -include $(+depfiles)
431 endif
432 endif
433 \f\f
434 # Maximize efficiency by minimizing the number of rules.
435 .SUFFIXES:      # Clear the suffix list.
436 # Add the suffixes we use.
437 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
439 # Generic rule for making directories.
441 # mkdir isn't smart enough to strip a trailing /.
442         mkdir $(@:%/=%)
444 # Make sure that object files are not removed
445 # when they are intermediates between sources and library members.
446 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
448 # Make sure that the parent library archive is never removed.
449 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
451 # Use the verbose option of ar and tar when not running silently.
452 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
453 verbose := v
454 else                                            # -s
455 verbose :=
456 endif                                           # not -s
458 ARFLAGS := r$(verbose)
460 # This makes all the object files in the parent library archive.
462 .PHONY: lib libobjs lib-noranlib
463 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
465 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
466 lib%.a: lib%.a($(ar-symtab-name)) ;
468 # For object-suffix $o, the list of objects with that suffix.
469 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
470 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
471                                                        $(elide-routines$o)),\
472                                             $(objects)))
474 libobjs: $(foreach o,$(object-suffixes-for-libc),\
475                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
476                    $(notdir $(o-objects))))
477 lib-noranlib: libobjs
478 others: $(addprefix $(objpfx),$(install-lib))
480 ifndef objects
482 # Create the stamp$o files to keep the parent makefile happy.
483 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o-$(subdir))
484 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o-$(subdir)):
485         $(make-target-directory)
486         rm -f $@; > $@
487 else
489 # Define a pattern rule that will match many targets libc.a(foo.%), for
490 # each foo.o in $(objects) (% will just happen always to match `o').  This is
491 # the only way to define a rule that updates many targets at once with one
492 # sequence of commands.
493 define o-iterator-doit
494 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
495 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
496   $(objpfx)stamp.%-$(subdir) ;
497 endef
498 object-suffixes-left := $(object-suffixes-for-libc)
499 include $(o-iterator)
501 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
502 # the way to update all the foo.% object files in $(objects).  Now we
503 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
504 # timestamp file; these rules (one explicit rule is generated for each
505 # object suffix) will update the parent archive with ar.  Use a static
506 # pattern rule so $* is set to the object type during the commands.
507 define o-iterator-doit
508 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
509 endef
510 ifdef static-only-routines
511 object-suffixes-left := $(object-suffixes-for-libc)
512 else
513 object-suffixes-left := $(object-suffixes)
514 endif
515 include $(o-iterator)
516 define do-ar
517 topdir=`cd $(..).; pwd`; \
518 $(patsubst %/,cd %;,$(objpfx)) \
519 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
520                                                   $(patsubst $(objpfx)%,%,$^)
521 rm -f $@
522 touch $@
523 endef
524 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
526 endif
528 # Rules to update the $(ar-symtab-name) member with ranlib,
529 # one for each object flavor.
530 define o-iterator-doit
531 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
532         $(filter-out $(common-objpfx)$(patsubst %,$(libtype$o),c)(),\
533           $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
534             $(patsubst $(objpfx)%,%,$(o-objects)))) $(subdirs-stamp-o); \
535         $(SHELL) $$(..)./autolock.sh \
536           $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
537           $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
538 endef
539 ifndef subdir
540 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%-$d)
541 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
542 $(subdirs-stamps): subdir_lib;
543 endif
544 object-suffixes-left = $(object-suffixes-for-libc)
545 include $(o-iterator)
548 # This makes all the object files.
549 .PHONY: objects objs
550 objects objs: $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
551               $(addprefix $(objpfx),$(extra-objs))
553 # Canned sequence for building an extra library archive.
554 define build-extra-lib
555 $(patsubst %/,cd %;,$(objpfx)) \
556 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
557       $(patsubst $(objpfx)%,%,$^)
558 $(RANLIB) $@
559 endef
561 # Installation.
563 # $(install-lib) are installed from the object directory into $(libdir);
564 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
565 # unless they also appear in $(non-lib.a).  $(install-data) are installed
566 # as they are into $(datadir).  $(headers) are installed as they are in
567 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
568 # object directory into $(bindir) and $(sbindir), respectively.
569 # $(install-others) are absolute path names of files to install; rules to
570 # install them are defined elsewhere.
572 # The simple library name to install libc.a under.
573 # This could be defined by a sysdep Makefile.
574 ifndef libc-name
575 libc-name := c
576 endif
578 define do-install
579 $(make-target-directory)
580 $(INSTALL_DATA) $< $@
581 endef
583 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
584 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
585 define make-target-directory
586 $(addprefix $(..)./mkinstalldirs ,\
587             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
588 endef
590 # Any directory (parent or subdir) that has any object files to build
591 # should install libc.a; this way "make install" in a subdir is guaranteed
592 # to install everything it changes.
593 ifdef objects
594 installed-libcs := $(foreach o,$(filter-out .so,$(object-suffixes-for-libc)),\
595                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
596                                                      $(libprefix)$(libc-name)))
597 install: $(installed-libcs)
598 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib
599         $(make-target-directory)
600         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
601 # Running ranlib after installing makes the __.SYMDEF time stamp up to
602 # date, which avoids messages from some linkers.
603         $(RANLIB) $@
604 endif
606 define do-install-program
607 $(make-target-directory)
608 $(INSTALL_PROGRAM) $< $@.new
609 mv -f $@.new $@
610 endef
612 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
613 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
614 ifeq (yes,$(build-shared))
616 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
618 # Find which .so's have versions.
619 versioned := $(strip $(foreach so,$(install-lib.so),\
620                                $(patsubst %,$(so),$($(so)-version))))
622 # Install all the unversioned shared libraries.
623 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
624         $(inst_slibdir)/%.so: $(objpfx)%.so; $(do-install-program)
626 ifneq ($(findstring -s,$(LN_S)),)
627 define make-link
628 rm -f $@.new
629 $(SHELL) $(..)rellns-sh $< $@.new
630 mv -f $@.new $@
631 endef
632 else
633 # If we have no symbolic links don't bother with rellns-sh.
634 define make-link
635 rm -f $@.new
636 $(LN_S) $< $@.new
637 mv -f $@.new $@
638 endef
639 endif
641 # XXX The following will have to be changed when `ldconfig' is available.
642 ifneq (yes,$(cross-compiling))
643 ifeq (yes,$(has-ldconfig))
644 define make-shlib-link
646 endef
647 endif
648 endif
649 ifndef make-shlib-link
650 define make-shlib-link
651 $(make-link)
652 endef
653 endif
655 ifdef libc.so-version
656 # For a library specified to be version N, install three files:
657 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
658 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
660 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so
661         $(make-shlib-link)
662 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so
663         $(do-install-program)
664 install: $(inst_slibdir)/libc.so$(libc.so-version)
666 ifndef subdir
667 # What we install as libc.so for programs to link against is in fact a
668 # link script.  It contains references for the various libraries we need.
669 # The libc.so object is not complete since some functions are only defined
670 # in libc.a and the dynamic linker is an etra object.
671 install: $(inst_libdir)/libc.so
672 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
673                         $(inst_libdir)/$(patsubst %,$(libtype.So),\
674                                                   $(libprefix)$(libc-name))
675         (echo '/* GNU ld script';\
676          echo '   Use the shared library, but some functions are only in';\
677          echo '   the static library, so try that secondarily.  */';\
678          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
679               '$(libdir)/$(patsubst %,$(libtype.So),$(libprefix)$(libc-name))'\
680               ')' \
681         ) > $@.new
682         mv -f $@.new $@
684 endif
686 else
687 install: $(inst_slibdir)/libc.so
688 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so
689         $(do-install-program)
690 endif
693 ifneq (,$(versioned))
694 # Produce three sets of rules as above for all the smaller versioned libraries.
696 define o-iterator-doit
697 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version); $$(make-link)
698 endef
699 object-suffixes-left := $(versioned)
700 include $(o-iterator)
702 # Make symlinks in the build directory, because the versioned names might
703 # be referenced by a DT_NEEDED in another library.
704 define o-iterator-doit
705 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
706 endef
707 object-suffixes-left := $(versioned)
708 include $(o-iterator)
711 ifeq (,$($(subdir)-version))
712 define o-iterator-doit
713 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so;
714         $$(make-shlib-link)
715 endef
716 object-suffixes-left := $(versioned)
717 include $(o-iterator)
719 define o-iterator-doit
720 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
721 endef
722 object-suffixes-left := $(versioned)
723 include $(o-iterator)
724 else
725 define o-iterator-doit
726 $(inst_slibdir)/$o$($o-version): \
727   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so;
728         $$(make-shlib-link)
729 endef
730 object-suffixes-left := $(versioned)
731 include $(o-iterator)
733 define o-iterator-doit
734 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o;
735         $$(do-install-program)
736 endef
737 object-suffixes-left := $(versioned)
738 include $(o-iterator)
739 endif
740 endif
742 define do-install-so
743 $(do-install-program)
744 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
745            $(filter-out %.so,$@))
746 endef
748 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
749 $(foreach v,$(so-versions),\
750           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
751         $(do-install-so)
752 $(foreach v,$(so-versions),\
753           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so
754         $(do-install-so)
755 endif
757 ifdef install-bin
758 $(addprefix $(inst_bindir)/,$(install-bin)): $(inst_bindir)/%: $(objpfx)%
759         $(do-install-program)
760 endif
761 ifdef install-rootsbin
762 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)):
763    $(inst_rootsbindir)/%: $(objpfx)%
764         $(do-install-program)
765 endif
766 ifdef install-sbin
767 $(addprefix $(inst_sbindir)/,$(install-sbin)): $(inst_sbindir)/%: $(objpfx)%
768         $(do-install-program)
769 endif
770 ifdef install-lib
771 install-lib.a := $(filter lib%.a,$(install-lib))
772 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
773 ifdef install-lib-non.a
774 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
775   $(inst_libdir)/$(libprefix)%: $(objpfx)%
776         $(do-install)
777 endif
778 ifdef install-lib.a
779 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
780   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
781         $(do-install)
782         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
783 endif
784 endif
785 ifdef install-data
786 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: %;
787         $(do-install)
788 endif
789 headers := $(strip $(headers))
790 ifdef headers
791 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: %;
792         $(do-install)
793 endif   # headers
795 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
796         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
797 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
798 install-rootsbin-nosubdir: \
799         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
800 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
801 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
802                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
803                        $(addprefix $(libprefix),$(install-lib-non.a)))
804 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
805 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
806 install-others-nosubdir: $(install-others)
808 # We need all the `-nosubdir' targets so that `install' in the parent
809 # doesn't depend on several things which each iterate over the subdirs.
810 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
811 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
812 install-%:: install-%-nosubdir ;
814 .PHONY: install install-no-libc.a-nosubdir
815 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
816                             install-bin-nosubdir install-lib-nosubdir   \
817                             install-others-nosubdir install-rootsbin-nosubdir \
818                             install-sbin-nosubdir
819 install: install-no-libc.a-nosubdir
821 # Command to compile $< in $(objdir) using the native libraries.
822 define native-compile
823 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
824            $(addprefix $$cwd/,$^) -o $(@F)
825 endef
827 # Command to compile $< in $(common-objdir) using the native libraries.
828 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
829 define common-objdir-compile
830 cd $(objpfx).; \
831 $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=$(..)%) -o $(..)$(@F)
832 endef
834 # We always want to use configuration definitions.
835 BUILD_CFLAGS = -include $(..)config.h
837 # Support the GNU standard name for this target.
838 .PHONY: check
839 check: tests
841 .PHONY: TAGS
842 TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
843         $(MAKE) $(addprefix -f ,$^) $@
845 $(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
846         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
847 FORCE:
850 .PHONY: echo-headers
851 echo-headers:
852         @echo $(headers)
855 # Common cleaning targets.
857 .PHONY: common-mostlyclean common-clean mostlyclean clean
858 clean: common-clean
859 mostlyclean: common-mostlyclean
861 # Remove the object files.
862 common-mostlyclean:
863         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
864                                      $(addsuffix .o,$(tests) $(test-srcs) \
865                                                     $(others)) \
866                                      $(addsuffix .out,$(tests) $(test-srcs)))
867         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
868         -rm -f core $(common-objpfx)stub-$(subdir)
869         $(rmobjs)
870 define rmobjs
871 $(foreach o,$(object-suffixes-for-libc),
872 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
873 endef
875 # Also remove the dependencies and generated source files.
876 common-clean: common-mostlyclean
877         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
878         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
879         -rm -f $(addprefix $(common-objpfx),$(common-generated))
880         -rm -f $(common-objpfx)distinfo-$(subdir)
882 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
883 # for each function which is a stub.  We grovel over all the .d files
884 # looking for references to source files in sysdeps/stub.  Then we grovel
885 # over each referenced source file to see what stub function it defines.
887 .PHONY: stubs # The parent Makefile calls this target.
888 stubs: $(common-objpfx)stub-$(subdir)
889 s = $(sysdep_dir)/stub
890 $(common-objpfx)stub-$(subdir): $(+depfiles)
891 # Use /dev/null since `...` might expand to empty.
892         (s=`cd $s; /bin/pwd`; \
893          $(patsubst %/,cd %;,$(objpfx)) \
894          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
895              `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
896                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
897              /dev/null) > $@T
898         mv -f $@T $@
900 # Make the distribution tar file.
902 .PHONY: dist
903 dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
904         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
906 # Avoid depending on source files found in sysdeps dirs,
907 # because the references affect implicit rule selection.
908 dist: $(filter-out %.c %.S %.s,$(distribute))
910 # We used to simply export all these variables, but that frequently made the
911 # environment get too large.  Instead, we write all the information into
912 # a generated makefile fragment `distinfo', and then include it with -f in
913 # the sub-make that makes the distribution (above).
914 $(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules
915         $(distinfo-vars)
916         mv -f $@.new $@
917 .PHONY: subdir_distinfo distinfo
918 subdir_distinfo: distinfo
919 distinfo: $(common-objpfx)distinfo-$(subdir)
921 define distinfo-vars
922 rm -f $@.new
923 echo > $@.new 'subdir := $(subdir)'
924 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
925               headers sysdep_headers distribute dont_distribute generated \
926               others tests extra-libs $(extra-libs:%=%-routines) \
927               versioned \
928               $(addprefix install-,lib lib.so data bin sbin others),
929 echo >> $@.new '$(subdir)-$(var) := $($(var))'
930 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
931 endef
933 ifneq (,$(strip $(gpl2lgpl)))
934 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
935 # Snarf from the master source and frob the copying notice.
936 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
937         sed -f $^ > $@-tmp
938 # So I don't edit them by mistake.
939         chmod a-w $@-tmp
940         mv -f $@-tmp $@
941         test ! -d CVS || cvs commit -m'Updated from $^' $@
942 endif
943 endif