Update.
[glibc.git] / Makerules
blob0d04b500840670b6e7b5fcb35582493117b236fe
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 # This variable is used in ``include $(o-iterator)'' after defining
85 # $(o-iterator-doit) to produce some desired rule using $o for the object
86 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
87 # is produced for each object suffix in use.
88 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
90 # Include any system-specific makefiles.
92 # This is here so things in sysdep Makefiles can easily depend on foo.h as
93 # appropriate and not worry about where foo.h comes from, which may be
94 # system dependent and not known by that Makefile.
95 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
96                                       $(+sysdep_dirs) $(..)))
98 # The same is true for RPC source files.
99 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
100                                       $(+sysdep_dirs) $(..)))
102 # Some sysdep makefiles use this to distinguish being included here from
103 # being included individually by a subdir makefile (hurd/Makefile needs this).
104 in-Makerules := yes
106 -include $(+sysdir_pfx)sysd-Makefile
107 ifndef avoid-generated
108 ifneq ($(sysd-Makefile-sysdirs),$(config-sysdirs))
109 sysd-Makefile-force = FORCE
110 FORCE:
111 endif
112 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
113                              $(sysd-Makefile-force)
114         -@rm -f $@T
115         (echo 'sysd-Makefile-sysdirs := $(config-sysdirs)';                   \
116          for dir in $(config-sysdirs); do                                     \
117            file=$$dir/Makefile;                                               \
118            case $$dir in                                                      \
119              /*) rel= ;;                                                      \
120              *)  rel=$(..) ;;                                                 \
121            esac;                                                              \
122            if [ -f $$rel$$file ]; then                                        \
123              case $$dir in                                                    \
124                /*) echo include "$$file" ;;                                   \
125                *)  echo include "\$$(..)$$file" ;;                            \
126              esac;                                                            \
127            else true; fi;                                                     \
128          done;                                                                \
129          echo 'sysd-Makefile-done=t') > $@T
130         mv -f $@T $@
131 endif
133 ifndef sysd-Makefile-done
134 # Don't do deps until this exists, because it might change the sources list.
135 no_deps=t
136 endif
139 # Reorder before-compile so that mach things come first, and hurd things
140 # second, before all else.  The mach and hurd subdirectories have many
141 # generated header files which the much of rest of the library depends on,
142 # so it is best to build them first (and mach before hurd, at that).
143 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
144                            $(before-compile)) \
145                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
146                                $(before-compile))
148 # Remove existing files from `before-compile'.  Things are added there when
149 # they must exist for dependency generation to work right, but once they
150 # exist there is no further need for every single file to depend on them,
151 # and those gratuitous dependencies result in many gratuitous
152 # recompilations.
153 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
155 # Don't let any before-compile file be an intermediate and get removed.
156 ifdef before-compile
157 $(before-compile):
158 endif
160 # Generate an ordered list of implicit rules which find the source files in
161 # each sysdep directory.  The old method was to use vpath to search all the
162 # sysdep directories.  However, that had the problem that a .S file in a
163 # later directory would be chosen over a .c file in an earlier directory,
164 # which does not preserve the desired sysdeps ordering behavior.
166 # When making the list of .d files to include, we can't know which ones
167 # have source in .s files, and thus do not in fact need a .d file.
168 # So we must define rules to make .d files for .s files.
169 define make-dummy-dep
170 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
171 endef
172 $(common-objpfx)dummy.d:
173         echo '# .s files cannot contain includes, so they need no deps.' > $@
175 # It matters that this set of rules, for compiling from sources in
176 # the current directory (the $srcdir/$subdir) come before the
177 # generated sysdep rules in included from sysd-rules below.  When
178 # compiling in the source tree, generated sources go into the current
179 # directory, and those should be chosen before any sources in sysdeps.
180 define o-iterator-doit
181 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
182 endef
183 object-suffixes-left := $(object-suffixes-for-libc)
184 include $(o-iterator)
185 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
187 define o-iterator-doit
188 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
189 endef
190 object-suffixes-left := $(object-suffixes-for-libc)
191 include $(o-iterator)
192 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
194 define o-iterator-doit
195 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
196 endef
197 object-suffixes-left := $(object-suffixes-for-libc)
198 include $(o-iterator)
199 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
201 # Omit the objpfx rules when building in the source tree, because
202 # objpfx is empty and so these rules just override the ones above.
203 ifdef objpfx
204 # Define first rules to find the source files in $(objpfx).
205 # Generated source files will end up there.
206 define o-iterator-doit
207 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
208 endef
209 object-suffixes-left := $(object-suffixes-for-libc)
210 include $(o-iterator)
211 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
213 define o-iterator-doit
214 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
215 endef
216 object-suffixes-left := $(object-suffixes-for-libc)
217 include $(o-iterator)
218 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
220 define o-iterator-doit
221 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
222 endef
223 object-suffixes-left := $(object-suffixes-for-libc)
224 include $(o-iterator)
225 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
226 endif
228 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
229 # patterns matching sysdep directories whose assembly source files should
230 # be suppressed.
231 ifdef inhibit-sysdep-asm
232 define open-check-inhibit-asm
233 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
234 endef
235 close-check-inhibit-asm = ;; esac ;
236 endif
238 # Don't include sysd-rules until sysd-Makefile is already there and has been
239 # included.  It might define inhibit-sysdep-asm, which would affect the
240 # contents of sysd-rules.
241 ifdef sysd-Makefile-done
242 -include $(+sysdir_pfx)sysd-rules
243 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
244 # The value of $(+sysdep_dirs) the sysd-rules was computed for
245 # differs from the one we are using now.  So force a rebuild of sysd-rules.
246 sysd-rules-force = FORCE
247 FORCE:
248 endif
249 endif
250 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
251                           $(wildcard $(foreach dir,$(sysdirs),\
252                                                $(dir)/Makefile))\
253                           $(sysd-rules-force)
254         -@rm -f $@T
255         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
256          for sysdir in $(config-sysdirs); do                                  \
257            case $$sysdir in \
258              /*) dir=$$sysdir ;; \
259              *)  dir="\$$(..)$$sysdir" ;; \
260            esac; \
261            for o in $(all-object-suffixes); do \
262              $(open-check-inhibit-asm) \
263              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
264                   \$$(compile-command.S)";                                    \
265              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
266                   \$$(compile-command.s)";                                    \
267              $(close-check-inhibit-asm) \
268              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
269                   \$$(compile-command.c)";                                    \
270            done; \
271            $(open-check-inhibit-asm) \
272            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
273                 \$$(make-dummy-dep)";                          \
274            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
275                 \$$(+make-deps)";                                             \
276            $(close-check-inhibit-asm)   \
277            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
278                 \$$(+make-deps)";                                             \
279          done;                                                                \
280          echo 'sysd-rules-done = t') > $@T
281         mv -f $@T $@
283 ifndef sysd-rules-done
284 # Don't do deps until this exists, because it provides rules to make the deps.
285 no_deps=t
286 endif
289 ifndef compile-command.S
290 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
291 endif
292 ifndef compile-command.s
293 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
294 endif
295 ifndef compile-command.c
296 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
297 endif
299 # GCC can grok options after the file name, and it looks nicer that way.
300 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
301 compile.S = \
302   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
303 COMPILE.S = \
304   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
305 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
307 # We need this for the output to go in the right place.  It will default to
308 # empty if make was configured to work with a cc that can't grok -c and -o
309 # together.  You can't compile the C library with such a compiler.
310 OUTPUT_OPTION = -o $@
312 S-CPPFLAGS = $(asm-CPPFLAGS)
313 define +make-deps
314 $(make-target-directory)
315 -@rm -f $@
316 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
317 sed \
318 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
319 $(sed-remove-objpfx) > $(@:.d=.T)
320 mv -f $(@:.d=.T) $@
321 endef
322 ifneq (,$(objpfx))
323 # Continuation lines here are dangerous because they introduce spaces!
324 define sed-remove-objpfx
325 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
326 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
327 endef
328 endif
330 # Shared library building.
332 ifeq (yes,$(build-shared))
334 # Reference map file only when versioning is selected and a map file name
335 # is given.
336 ifeq ($(versioning),yes)
337 load-map-file = $($(@F:%.so=%)-map)
338 else
339 load-map-file =
340 endif
342 # Pattern rule to build a shared object from an archive of PIC objects.
343 # This must come after the installation rules so Make doesn't try to
344 # build shared libraries in place from the installed *_pic.a files.
345 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
346 # on other shared objects.
347 lib%.so: lib%_pic.a $(+preinit) $(+postinit)
348         $(build-shlib)
350 ifeq ($(have-no-whole-archive),yes)
351 no-whole-archive = -Wl,--no-whole-archive
352 else
353 no-whole-archive =
354 endif
356 interp-obj = $(common-objpfx)interp.os
357 $(interp-obj): $(common-objpfx)%.os: $(..)%.c
358         $(compile-command.c)
359 common-generated += interp.os
360 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
362 $(common-objpfx)libc.so: $(interp-obj)
363 $(patsubst %,$(objpfx)%.so,$(extra-libs)): $(interp-obj)
365 define build-shlib
366 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
367           -B$(csu-objpfx) $(load-map-file:%=-Wl,--version-script=%) \
368           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
369           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
370           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
371           -Wl,--whole-archive \
372           $(filter-out $($(@F:.so=)-map) $(+preinit) $(+postinit),$^) \
373           $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
374 endef
376 ifndef libc.so-version
377 # Undefine this because it can't work when we libc.so is unversioned.
378 static-only-routines =
379 endif
381 elide-routines.oS = $(filter-out $(static-only-routines),\
382                                  $(routines) $(aux) $(sysdep_routines))
384 ifdef static-only-routines
385 # These routines are to be omitted from the shared library object,
386 # so we replace the PIC objects for them with the empty object file.
387 $(static-only-routines:%=$(objpfx)%.os): %.os: $(common-objpfx)empty.os
388         rm -f $@
389         ln $< $@
390 endif
392 ifdef shared-only-routines
393 # If we have versioned code we don't need the old versions in any of the
394 # static libraries.
395 define o-iterator-doit
396 $(shared-only-routines:%=$(objpfx)%$o): %$o: $(common-objpfx)empty$o;
397         rm -f $$@
398         ln $$< $$@
399 endef
400 object-suffixes-left := $(filter-out .os,$(object-suffixes))
401 include $(o-iterator)
402 endif
404 # Don't try to use -lc when making libc.so itself.
405 # Also omits crti.o and crtn.o, which we do not want
406 # since we define our own `.init' section specially.
407 LDFLAGS-c.so = -nostdlib -nostartfiles
408 # But we still want to link libc.so against $(gnulib).
409 LDLIBS-c.so = $(gnulib)
410 # Give libc.so an entry point and make it directly runnable itself.
411 LDFLAGS-c.so += -e __libc_main
412 # We have a versioning file for libc.so.
413 libc-map = $(..)libc.map
414 # Pre-link the objects of libc_pic.a so that we can locally resolve
415 # COMMON symbols before we link against ld.so.  This is because ld.so
416 # contains some of libc_pic.a already, which will prevent the COMMONs
417 # from being allocated in libc.so, which introduces evil dependencies
418 # between libc.so and ld.so, which can make it impossible to upgrade.
419 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
420         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
421         -Wl,-d -Wl,--whole-archive $^
422 # Use our own special initializer and finalizer files for libc.so.
423 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
424                          $(common-objpfx)libc_pic.os \
425                          $(elfobjdir)/sofini.os $(elfobjdir)/ld.so \
426                          $(libc-map)
427         $(build-shlib)
428 common-generated += libc.so libc_pic.os
429 ifdef libc.so-version
430 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
431         $(make-link)
432 common-generated += libc.so$(libc.so-version)
433 endif
434 endif
436 # Some files must not be compiled with the exception handler mechanism
437 # enabled (introduced in gcc-2.8).  Use $(no-exceptions) in the
438 # appropriate CFLAGS definition.
439 ifeq ($(have-no-exceptions),yes)
440 no-exceptions = -fno-exceptions
441 else
442 no-exceptions =
443 endif
445 # Figure out the source filenames in this directory.
447 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
448                                                        $(routines) $(aux) \
449                                                        $(sysdep_routines)))
450 sysdep_routines := $(sysdep_routines)
452 headers := $(headers) $(sysdep_headers)
454 # This is the list of all object files, gotten by
455 # replacing every ".c" in `sources' with a ".o".
456 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
459 # The makefile may define $(extra-libs) with `libfoo libbar'
460 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
461 ifdef extra-libs
462 # extra-lib.mk is included once for each extra lib to define rules
463 # to build it, and to add its objects to the various variables.
464 # During its evaluation, $(lib) is set to the name of the library.
465 extra-libs-left := $(extra-libs)
466 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
467 endif
469 ifeq ($(build-programs),yes)
470 +depfiles := $(strip $(sources:.c=.d) \
471                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
472                      $(addsuffix .d,$(others) $(tests) $(test-srcs)))
473 else
474 +depfiles := $(strip $(sources:.c=.d) \
475                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
476                      $(addsuffix .d,$(tests) $(test-srcs)))
477 endif
478 +depfiles := $(addprefix $(objpfx),\
479                          $(filter-out $(addsuffix .d,$(omit-deps)),\
480                                       $(+depfiles)))
482 ifdef +depfiles
483 ifneq ($(no_deps),t)
484 -include $(+depfiles)
485 endif
486 endif
487 \f\f
488 # Maximize efficiency by minimizing the number of rules.
489 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
490 # Don't define any builtin rules.
491 MAKEFLAGS := $(MAKEFLAGS)r
493 # Generic rule for making directories.
495 # mkdir isn't smart enough to strip a trailing /.
496         mkdir $(@:%/=%)
498 # Make sure that object files are not removed
499 # when they are intermediates between sources and library members.
500 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
502 # Make sure that the parent library archive is never removed.
503 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
505 # Use the verbose option of ar and tar when not running silently.
506 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
507 verbose := v
508 else                                            # -s
509 verbose :=
510 endif                                           # not -s
512 ARFLAGS := r$(verbose)
513 ifeq ($(have-ar-S),yes)
514 CREATE_ARFLAGS := Scru$(verbose)
515 else
516 CREATE_ARFLAGS := cru$(verbose)
517 endif
519 # This makes all the object files in the parent library archive.
521 .PHONY: lib libobjs lib-noranlib
522 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
524 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
525 lib%.a: lib%.a($(ar-symtab-name)) ;
527 # For object-suffix $o, the list of objects with that suffix.
528 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
529 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
530                                                        $(elide-routines$o)),\
531                                             $(objects)))
533 libobjs: $(foreach o,$(object-suffixes-for-libc),\
534                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
535                    $(notdir $(o-objects))))
536 lib-noranlib: libobjs
537 others: $(addprefix $(objpfx),$(install-lib))
539 ifndef objects
541 # Create the stamp$o files to keep the parent makefile happy.
542 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
543 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
544         $(make-target-directory)
545         rm -f $@; > $@
546 else
548 # Define a pattern rule that will match many targets libc.a(foo.%), for
549 # each foo.o in $(objects) (% will just happen always to match `o').  This is
550 # the only way to define a rule that updates many targets at once with one
551 # sequence of commands.
552 define o-iterator-doit
553 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
554 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
555   $(objpfx)stamp.% ;
556 endef
557 object-suffixes-left := $(object-suffixes-for-libc)
558 include $(o-iterator)
560 # The pattern rule tells Make to remake $(objpfx)stamp.% as
561 # the way to update all the foo.% object files in $(objects).  Now we
562 # define explicit rules to update each $(objpfx)stamp.SUFFIX
563 # timestamp file; these rules (one explicit rule is generated for each
564 # object suffix) will update the parent archive with ar.  Use a static
565 # pattern rule so $* is set to the object type during the commands.
566 define o-iterator-doit
567 $(objpfx)stamp$o: $(objpfx)stamp%: $(o-objects); $$(do-ar)
568 endef
569 ifdef static-only-routines
570 object-suffixes-left := $(object-suffixes-for-libc)
571 else
572 object-suffixes-left := $(object-suffixes)
573 endif
574 include $(o-iterator)
575 define do-ar
576 topdir=`cd $(..).; pwd`; \
577 $(patsubst %/,cd %;,$(objpfx)) \
578 $(SHELL) $$topdir/autolock.sh ${O%-lib}.lck $(AR) $(CREATE_ARFLAGS) ${O%-lib} \
579                                                   $(patsubst $(objpfx)%,%,$?)
580 rm -f $@
581 touch $@
582 endef
583 O%-lib = $(..)$(patsubst %,$(libtype$*),c)
585 ifndef static-only-routines
586 subdir_lib: $(objpfx)stamp.oS
587 $(objpfx)stamp.oS:
588         $(make-target-directory)
589         rm -f $@; > $@
590 endif
592 endif
594 # Rules to update the $(ar-symtab-name) member with ranlib,
595 # one for each object flavor.
596 define o-iterator-doit
597 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
598           $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
599             $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
600         $(SHELL) $$(..)./autolock.sh \
601           $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
602           $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
603 endef
604 ifndef subdir
605 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
606 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
607 $(subdirs-stamps): subdir_lib;
608 endif
609 object-suffixes-left = $(object-suffixes-for-libc)
610 include $(o-iterator)
613 # This makes all the object files.
614 .PHONY: objects objs
615 objects objs: $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
616               $(addprefix $(objpfx),$(extra-objs))
618 # Canned sequence for building an extra library archive.
619 define build-extra-lib
620 $(patsubst %/,cd %;,$(objpfx)) \
621 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
622       $(patsubst $(objpfx)%,%,$^)
623 $(RANLIB) $@
624 endef
626 # Installation.
628 .PHONY: force-install
629 force-install:
631 # $(install-lib) are installed from the object directory into $(libdir);
632 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
633 # unless they also appear in $(non-lib.a).  $(install-data) are installed
634 # as they are into $(datadir).  $(headers) are installed as they are in
635 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
636 # object directory into $(bindir) and $(sbindir), respectively.
637 # $(install-others) are absolute path names of files to install; rules to
638 # install them are defined elsewhere.
640 # The simple library name to install libc.a under.
641 # This could be defined by a sysdep Makefile.
642 ifndef libc-name
643 libc-name := c
644 endif
646 define do-install
647 $(make-target-directory)
648 $(INSTALL_DATA) $< $@
649 endef
651 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
652 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
653 define make-target-directory
654 $(addprefix $(..)./mkinstalldirs ,\
655             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
656 endef
658 # Any directory (parent or subdir) that has any object files to build
659 # should install libc.a; this way "make install" in a subdir is guaranteed
660 # to install everything it changes.
661 ifdef objects
662 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
663                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
664                                                      $(libprefix)$(libc-name)))
665 install: $(installed-libcs)
666 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
667         $(make-target-directory)
668         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
669 # Running ranlib after installing makes the __.SYMDEF time stamp up to
670 # date, which avoids messages from some linkers.
671         $(RANLIB) $@
672 endif
674 define do-install-program
675 $(make-target-directory)
676 $(INSTALL_PROGRAM) $< $@.new
677 mv -f $@.new $@
678 endef
680 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
681 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
682 ifeq (yes,$(build-shared))
684 install-lib-nosubdir: $(install-lib.so:%=$(inst_libdir)/%)
686 # Find which .so's have versions.
687 versioned := $(strip $(foreach so,$(install-lib.so),\
688                                $(patsubst %,$(so),$($(so)-version))))
690 # Install all the unversioned shared libraries.
691 $(addprefix $(inst_slibdir)/, $(filter-out $(versioned),$(install-lib.so))): \
692         $(inst_slibdir)/%.so: $(objpfx)%.so $(+force); $(do-install-program)
694 ifneq ($(findstring -s,$(LN_S)),)
695 define make-link
696 rm -f $@.new
697 $(SHELL) $(..)rellns-sh $< $@.new
698 mv -f $@.new $@
699 endef
700 else
701 # If we have no symbolic links don't bother with rellns-sh.
702 define make-link
703 rm -f $@.new
704 $(LN_S) $< $@.new
705 mv -f $@.new $@
706 endef
707 endif
709 # XXX The following will have to be changed when `ldconfig' is available.
710 ifneq (yes,$(cross-compiling))
711 ifeq (yes,$(has-ldconfig))
712 define make-shlib-link
714 endef
715 endif
716 endif
717 ifndef make-shlib-link
718 define make-shlib-link
719 $(make-link)
720 endef
721 endif
723 ifdef libc.so-version
724 # For a library specified to be version N, install three files:
725 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
726 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
728 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
729                                            $(+force)
730         $(make-shlib-link)
731 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
732         $(do-install-program)
733 install: $(inst_slibdir)/libc.so$(libc.so-version)
735 ifndef subdir
736 # What we install as libc.so for programs to link against is in fact a
737 # link script.  It contains references for the various libraries we need.
738 # The libc.so object is not complete since some functions are only defined
739 # in libc_nonshared.a.
740 install: $(inst_libdir)/libc.so
741 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
742                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
743                                                   $(libprefix)$(libc-name)) \
744                         $(+force)
745         (echo '/* GNU ld script';\
746          echo '   Use the shared library, but some functions are only in';\
747          echo '   the static library, so try that secondarily.  */';\
748          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
749               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
750               ')' \
751         ) > $@.new
752         mv -f $@.new $@
754 endif
756 else
757 install: $(inst_slibdir)/libc.so
758 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
759         $(do-install-program)
760 endif
762 ifneq (,$(versioned))
763 # Produce three sets of rules as above for all the smaller versioned libraries.
765 define o-iterator-doit
766 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
767 endef
768 object-suffixes-left := $(versioned)
769 include $(o-iterator)
771 # Make symlinks in the build directory, because the versioned names might
772 # be referenced by a DT_NEEDED in another library.
773 define o-iterator-doit
774 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
775 endef
776 object-suffixes-left := $(versioned)
777 include $(o-iterator)
779 generated += $(foreach o,$(versioned),$o$($o-version))
781 ifeq (,$($(subdir)-version))
782 define o-iterator-doit
783 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
784                                  $(+force);
785         $$(make-shlib-link)
786 endef
787 object-suffixes-left := $(versioned)
788 include $(o-iterator)
790 define o-iterator-doit
791 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
792         $$(do-install-program)
793 endef
794 object-suffixes-left := $(versioned)
795 include $(o-iterator)
796 else
797 define o-iterator-doit
798 $(inst_slibdir)/$o$($o-version): \
799   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
800         $$(make-shlib-link)
801 endef
802 object-suffixes-left := $(versioned)
803 include $(o-iterator)
805 define o-iterator-doit
806 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
807         $$(do-install-program)
808 endef
809 object-suffixes-left := $(versioned)
810 include $(o-iterator)
811 endif
812 endif
814 define do-install-so
815 $(do-install-program)
816 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
817            $(filter-out %.so,$@))
818 endef
820 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
821 $(foreach v,$(so-versions),\
822           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
823                                                $(+force)
824         $(do-install-so)
825 $(foreach v,$(so-versions),\
826           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
827         $(do-install-so)
828 endif
830 ifdef install-bin
831 $(addprefix $(inst_bindir)/,$(install-bin)): \
832     $(inst_bindir)/%: $(objpfx)% $(+force)
833         $(do-install-program)
834 endif
835 ifdef install-rootsbin
836 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
837    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
838         $(do-install-program)
839 endif
840 ifdef install-sbin
841 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
842     $(inst_sbindir)/%: $(objpfx)% $(+force)
843         $(do-install-program)
844 endif
845 ifdef install-lib
846 install-lib.a := $(filter lib%.a,$(install-lib))
847 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
848 ifdef install-lib-non.a
849 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
850   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
851         $(do-install)
852 endif
853 ifdef install-lib.a
854 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
855   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
856         $(do-install)
857         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
858 endif
859 endif
860 ifdef install-data
861 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
862         $(do-install)
863 endif
864 headers := $(strip $(headers))
865 ifdef headers
866 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
867         $(do-install)
868 endif   # headers
870 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
871         install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
872 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
873 install-rootsbin-nosubdir: \
874         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
875 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
876 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
877                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
878                        $(addprefix $(libprefix),$(install-lib-non.a)))
879 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
880 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
881 install-others-nosubdir: $(install-others)
883 # We need all the `-nosubdir' targets so that `install' in the parent
884 # doesn't depend on several things which each iterate over the subdirs.
885 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
886 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
887 install-%:: install-%-nosubdir ;
889 .PHONY: install install-no-libc.a-nosubdir
890 ifeq ($(build-programs),yes)
891 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
892                             install-bin-nosubdir install-lib-nosubdir   \
893                             install-others-nosubdir install-rootsbin-nosubdir \
894                             install-sbin-nosubdir
895 else
896 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
897                             install-lib-nosubdir install-others-nosubdir
898 endif
899 install: install-no-libc.a-nosubdir
901 # Command to compile $< in $(objdir) using the native libraries.
902 define native-compile
903 $(make-target-directory)
904 $(patsubst %/,cd %;,$(objpfx)) \
905 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
906             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
907 endef
909 # Command to compile $< in $(common-objdir) using the native libraries.
910 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
911 define common-objdir-compile
912 $(patsubst %/,cd %;,$(objpfx)) \
913 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
914             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
915 endef
917 # We always want to use configuration definitions.
918 # Note that this is only used for commands running in $(objpfx).
919 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
921 # Support the GNU standard name for this target.
922 .PHONY: check
923 check: tests
925 .PHONY: TAGS
926 TAGS: $(objpfx)distinfo $(..)MakeTAGS
927         $(MAKE) $(addprefix -f ,$^) $@
929 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
930         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
931 FORCE:
934 .PHONY: echo-headers
935 echo-headers:
936         @echo $(headers)
939 # Common cleaning targets.
941 .PHONY: common-mostlyclean common-clean mostlyclean clean
942 clean: common-clean
943 mostlyclean: common-mostlyclean
945 # Remove the object files.
946 common-mostlyclean:
947         -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
948                                      $(tests-static) \
949                                      $(addsuffix .o,$(tests) $(test-srcs) \
950                                                     $(tests-static) \
951                                                     $(others)) \
952                                      $(addsuffix .out,$(tests) $(test-srcs)) \
953                                      $(addsuffix .sout,$(tests-static)))
954         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
955                                      $(install-lib.so) \
956                                      $(install-lib.so:%.so=%_pic.a))
957         -rm -f core $(common-objpfx)stub-$(subdir)
958         $(rmobjs)
959 define rmobjs
960 $(foreach o,$(object-suffixes-for-libc),
961 -rm -f $(objpfx)stamp$o $(o-objects))
962 endef
964 # Also remove the dependencies and generated source files.
965 common-clean: common-mostlyclean
966         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
967         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
968         -rm -f $(addprefix $(common-objpfx),$(common-generated))
969         -rm -f $(objpfx)distinfo
971 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
972 # for each function which is a stub.  We grovel over all the .d files
973 # looking for references to <stub-tag.h>.  Then we grovel over each
974 # referenced source file to see what stub function it defines.
976 .PHONY: stubs # The parent Makefile calls this target.
977 stubs: $(common-objpfx)stub-$(subdir)
978 s = $(sysdep_dir)/generic
979 $(common-objpfx)stub-$(subdir): $(+depfiles)
980 # Use /dev/null since `...` might expand to empty.
981         (s=`cd $s; /bin/pwd`; \
982          $(patsubst %/,cd %;,$(objpfx)) \
983          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
984           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
985                 -e '/stub-tag\.h/{; g; p; }' \
986                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
987              /dev/null) > $@T
988         mv -f $@T $@
990 # Make the distribution tar file.
992 .PHONY: dist
993 dist: $(objpfx)distinfo $(..)Make-dist
994         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
996 # Avoid depending on source files found in sysdeps dirs,
997 # because the references affect implicit rule selection.
998 dist: $(filter-out %.c %.S %.s,$(distribute))
1000 # We used to simply export all these variables, but that frequently made the
1001 # environment get too large.  Instead, we write all the information into
1002 # a generated makefile fragment `distinfo', and then include it with -f in
1003 # the sub-make that makes the distribution (above).
1004 $(objpfx)distinfo: Makefile $(..)Makerules \
1005                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1006         $(make-target-directory)
1007         $(distinfo-vars)
1008         mv -f $@.new $@
1009 .PHONY: subdir_distinfo
1010 subdir_distinfo: $(objpfx)distinfo
1012 define distinfo-vars
1013 rm -f $@.new
1014 echo > $@.new 'subdir := $(subdir)'
1015 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1016               headers sysdep_headers distribute dont_distribute generated \
1017               others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
1018               $(extra-libs:%=%-map) versioned \
1019               $(addprefix install-,lib lib.so data bin sbin others),
1020 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1021 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1022 endef
1024 ifneq (,$(strip $(gpl2lgpl)))
1025 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1026 # Snarf from the master source and frob the copying notice.
1027 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1028         sed -f $^ > $@-tmp
1029 # So I don't edit them by mistake.
1030         chmod a-w $@-tmp
1031         mv -f $@-tmp $@
1032 ifeq ($(with-cvs),yes)
1033         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1034 endif
1035 endif
1036 endif