]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makerules
update from main archive 960814
[thirdparty/glibc.git] / Makerules
CommitLineData
aeb72b16 1# Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
28f540f4
RM
2# This file is part of the GNU C Library.
3
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.
8
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.
13
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
16# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17# Cambridge, MA 02139, USA.
18
19#
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).
23#
24ifneq (,)
25This makefile requires GNU Make.
26endif
27
28
29ifdef subdir
30.. := ../
31endif # subdir
32
33# If `sources' was defined by the parent makefile, undefine it so
34# we will later get it from wildcard search in this directory.
35ifneq "$(findstring env,$(origin sources))" ""
36sources :=
37endif
38
28f540f4
RM
39oPATH := $(PATH)
40PATH := this definition should take precedence over $(oPATH)
41ifeq ($(PATH),$(oPATH))
42You must not use the -e flag when building the GNU C library.
43else
44PATH := $(oPATH)
45endif
46\f
47ifndef +included-Makeconfig
48include $(..)Makeconfig
49endif
50
51# `configure' writes a definition of `config-sysdirs' in `config.make'.
52sysdirs = $(config-sysdirs)
53
54+sysdir_pfx = $(common-objpfx)
55
56export sysdirs := $(sysdirs)
57
58+sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
59ifdef objdir
60+sysdep_dirs := $(objdir) $(+sysdep_dirs)
61endif
62
63# Add -I switches to get the right sysdep directories.
64# `+includes' in Makeconfig references $(+sysdep-includes).
65+sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
dbdb6189
RM
66
67# The name of the symbol table archive member. The default is suitable for
68# BSD style archives. It can be overridden in sysdep Makefiles when SYSV
69# style archive are used.
01f3e03b 70ifeq (no,$(elf))
dbdb6189 71ar-symtab-name = __.SYMDEF
01f3e03b
RM
72else
73ar-symtab-name = # The null name is used in ELF archives.
74endif
28f540f4
RM
75\f
76# Include any system-specific makefiles.
77
78# This is here so things in sysdep Makefiles can easily depend on foo.h as
79# appropriate and not worry about where foo.h comes from, which may be
80# system dependent and not known by that Makefile.
81vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \
82 $(addprefix $(sysdep_dir)/,$(sysdirs)) \
83 $(..)))
84
28f540f4
RM
85# Some sysdep makefiles use this to distinguish being included here from
86# being included individually by a subdir makefile (hurd/Makefile needs this).
87in-Makerules := yes
88
89ifndef avoid-generated
555f3a39 90-include $(+sysdir_pfx)sysd-Makefile
273d56ce
RM
91ifneq ($(sysd-Makefile-sysdirs),$(sysdirs))
92sysd-Makefile-force = FORCE
93FORCE:
94endif
95$(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
96 $(sysd-Makefile-force)
28f540f4 97 -@rm -f $@T
273d56ce
RM
98 (echo 'sysd-Makefile-sysdirs := $(sysdirs)'; \
99 for dir in $(sysdirs); do \
28f540f4
RM
100 file=sysdeps/$$dir/Makefile; \
101 if [ -f $(..)$$file ]; then \
102 echo include "\$$(..)$$file"; \
103 else true; fi; \
104 done; \
105 echo 'sysd-Makefile-done=t') > $@T
106 mv -f $@T $@
107endif
108
3bbceb12
RM
109ifndef sysd-Makefile-done
110# Don't do deps until this exists, because it might change the sources list.
111no_deps=t
112endif
113
114
28f540f4
RM
115# Reorder before-compile so that mach things come first, and hurd things
116# second, before all else. The mach and hurd subdirectories have many
117# generated header files which the much of rest of the library depends on,
118# so it is best to build them first (and mach before hurd, at that).
119before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
120 $(before-compile)) \
121 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
122 $(before-compile))
123
124# Remove existing files from `before-compile'. Things are added there when
125# they must exist for dependency generation to work right, but once they
126# exist there is no further need for every single file to depend on them,
127# and those gratuitous dependencies result in many gratuitous
128# recompilations.
129before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
130
131# Don't let any before-compile file be an intermediate and get removed.
132ifdef before-compile
133$(before-compile):
134endif
135\f
136# Generate an ordered list of implicit rules which find the source files in
137# each sysdep directory. The old method was to use vpath to search all the
138# sysdep directories. However, that had the problem that a .S file in a
139# later directory would be chosen over a .c file in an earlier directory,
140# which does not preserve the desired sysdeps ordering behavior.
141
142# When making the list of .d files to include, we can't know which ones
143# have source in .s files, and thus do not in fact need a .d file.
144# So we must define rules to make .d files for .s files.
145define make-dummy-dep
146$(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
147endef
148$(objpfx)dummy.d:
149 echo '# .s files cannot contain includes, so they need no deps.' > $@
150
151# It matters that this set of rules, for compiling from sources in
152# the current directory (the $srcdir/$subdir) come before the
153# generated sysdep rules in included from sysd-rules below. When
154# compiling in the source tree, generated sources go into the current
155# directory, and those should be chosen before any sources in sysdeps.
156$(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
51f75302
RM
157$(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
158$(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
159$(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
28f540f4
RM
160$(objpfx)%.d: %.S $(before-compile); $(+make-deps)
161$(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
51f75302
RM
162$(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
163$(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
164$(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
28f540f4
RM
165$(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep)
166$(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
51f75302
RM
167$(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
168$(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
169$(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
28f540f4
RM
170$(objpfx)%.d: %.c $(before-compile); $(+make-deps)
171
172# Omit the objpfx rules when building in the source tree, because
173# objpfx is empty and so these rules just override the ones above.
174ifdef objpfx
175# Define first rules to find the source files in $(objpfx).
176# Generated source files will end up there.
177$(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
51f75302
RM
178$(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
179$(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
180$(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
28f540f4
RM
181$(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
182$(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
51f75302
RM
183$(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
184$(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
185$(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
28f540f4
RM
186$(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep)
187$(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
51f75302
RM
188$(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
189$(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
190$(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
28f540f4
RM
191$(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
192endif
193
194# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
195# patterns matching sysdep directories whose assembly source files should
196# be suppressed.
197ifdef inhibit-sysdep-asm
198define open-check-inhibit-asm
199case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
200endef
51f75302 201close-check-inhibit-asm = ;; esac ;
28f540f4
RM
202endif
203
204# Don't include sysd-rules until sysd-Makefile is already there and has been
205# included. It might define inhibit-sysdep-asm, which would affect the
206# contents of sysd-rules.
207ifdef sysd-Makefile-done
555f3a39 208-include $(+sysdir_pfx)sysd-rules
273d56ce
RM
209ifneq ($(sysd-rules-sysdirs),$(sysdirs))
210# The value of $(sysdirs) the sysd-rules was computed for
211# differs from the one we are using now. So force a rebuild of sysd-rules.
212sysd-rules-force = FORCE
213FORCE:
214endif
28f540f4
RM
215endif
216$(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
217 $(wildcard $(foreach dir,$(sysdirs),\
273d56ce
RM
218 $(sysdep_dir)/$(dir)/Makefile))\
219 $(sysd-rules-force)
28f540f4 220 -@rm -f $@T
273d56ce
RM
221 (echo 'sysd-rules-sysdirs := $(sysdirs)'; \
222 for sysdir in $(sysdirs); do \
28f540f4 223 dir="\$$(sysdep_dir)/$$sysdir"; \
51f75302
RM
224 for o in $(object-suffixes); do \
225 $(open-check-inhibit-asm) \
226 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
227 \$$(compile-command.S)"; \
228 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
229 \$$(compile-command.s)"; \
230 $(close-check-inhibit-asm) \
231 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
232 \$$(compile-command.c)"; \
233 done; \
28f540f4 234 $(open-check-inhibit-asm) \
51f75302
RM
235 echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \
236 \$$(make-dummy-dep)"; \
28f540f4
RM
237 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
238 \$$(+make-deps)"; \
51f75302 239 $(close-check-inhibit-asm) \
28f540f4
RM
240 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
241 \$$(+make-deps)"; \
3bbceb12
RM
242 done; \
243 echo 'sysd-rules-done = t') > $@T
28f540f4
RM
244 mv -f $@T $@
245
3bbceb12
RM
246ifndef sysd-rules-done
247# Don't do deps until this exists, because it provides rules to make the deps.
248no_deps=t
249endif
250
251
28f540f4
RM
252ifndef compile-command.S
253compile-command.S = $(compile.S) $(OUTPUT_OPTION)
254endif
255ifndef compile-command.s
256compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
257endif
258ifndef compile-command.c
259compile-command.c = $(compile.c) $(OUTPUT_OPTION)
260endif
261
28f540f4 262# GCC can grok options after the file name, and it looks nicer that way.
28f540f4 263compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
aeb72b16
RM
264compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
265COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
266COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
28f540f4 267
28f540f4
RM
268# We need this for the output to go in the right place. It will default to
269# empty if make was configured to work with a cc that can't grok -c and -o
270# together. You can't compile the C library with such a compiler.
271OUTPUT_OPTION = -o $@
28f540f4
RM
272
273S-CPPFLAGS = $(asm-CPPFLAGS)
274define +make-deps
275-@rm -f $@
276$(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
1177c8ba 277sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
51f75302 278$(sed-remove-objpfx) > $(@:.d=.T)
28f540f4
RM
279mv -f $(@:.d=.T) $@
280endef
281ifneq (,$(objpfx))
215dbbb1
RM
282# Continuation lines here are dangerous because they introduce spaces!
283define sed-remove-objpfx
284-e 's@ $(subst .,\.,$(subst @,\@,$(objpfx)))@ $$(objpfx)@g' \
285-e 's@^$(subst .,\.,$(subst @,\@,$(objpfx)))@$$(objpfx)@g'
286endef
28f540f4
RM
287endif
288\f
5f0e6fc7
RM
289# Shared library building.
290
291ifeq (yes,$(build-shared))
292
5f0e6fc7
RM
293# Pattern rule to build a shared object from an archive of PIC objects.
294# This must come after the installation rules so Make doesn't try to
295# build shared libraries in place from the installed *_pic.a files.
296# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
297# on other shared objects.
298lib%.so: lib%_pic.a; $(build-shlib)
299
300ifeq ($(have-no-whole-archive),yes)
301no-whole-archive = -Wl,--no-whole-archive
302else
303no-whole-archive =
304endif
305
306define build-shlib
307$(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
e75154a6 308 -B$(csu-objpfx) \
5f0e6fc7
RM
309 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
310 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
311 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
312 -Wl,--whole-archive $^ $(no-whole-archive) \
313 $(LDLIBS-$(@F:lib%.so=%).so)
314endef
315
316# Don't try to use -lc when making libc.so itself.
317# Also omits crti.o and crtn.o, which we do not want
318# since we define our own `.init' section specially.
319LDFLAGS-c.so = -nostdlib -nostartfiles
320# Give libc.so an entry point and make it directly runnable itself.
321LDFLAGS-c.so += -e __libc_main
322# Use our own special initializer and finalizer files for libc.so.
323elfobjdir := $(firstword $(objdir) $(patsubst ../$(subdir),.,$(..)elf))
324$(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
325 $(common-objpfx)libc_pic.a \
326 $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
327 $(build-shlib)
328
329ifdef libc.so-version
330$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
331 rm -f $@
332 ln -s $(<F) $@ || ln $< $@
333endif
334endif
335\f
28f540f4
RM
336# Figure out the source filenames in this directory.
337
338override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
339 $(routines) $(aux) \
340 $(sysdep_routines)))
341sysdep_routines := $(sysdep_routines)
342
e60062b7
RM
343headers := $(headers) $(sysdep_headers)
344
28f540f4
RM
345# This is the list of all object files, gotten by
346# replacing every ".c" in `sources' with a ".o".
347override objects := $(addprefix $(objpfx),$(sources:.c=.o))
693e7b96
RM
348
349
350# This variable is used in ``include $(o-iterator)'' after defining
351# $(o-iterator-doit) to produce some desired rule using $o for the object
352# suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
353# is produced for each object suffix in use.
dc997231 354o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
693e7b96
RM
355
356# The makefile may define $(extra-libs) with `libfoo libbar'
357# to build libfoo.a et al from the modules listed in $(libfoo-routines).
358ifdef extra-libs
359# extra-lib.mk is included once for each extra lib to define rules
360# to build it, and to add its objects to the various variables.
361# During its evaluation, $(lib) is set to the name of the library.
362extra-libs-left := $(extra-libs)
363include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
364endif
28f540f4
RM
365\f
366+depfiles := $(strip $(sources:.c=.d) \
8c0dc19c 367 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
28f540f4
RM
368 $(addsuffix .d,$(others) $(tests)))
369+depfiles := $(addprefix $(objpfx),\
370 $(filter-out $(addsuffix .d,$(omit-deps)),\
371 $(+depfiles)))
372
28f540f4 373ifdef +depfiles
28f540f4 374ifneq ($(no_deps),t)
555f3a39 375-include $(+depfiles)
deab9dea 376endif
28f540f4
RM
377endif
378\f\f
379# Maximize efficiency by minimizing the number of rules.
380.SUFFIXES: # Clear the suffix list.
381# Add the suffixes we use.
51f75302 382.SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
28f540f4
RM
383
384# Generic rule for making directories.
385%/:
386# mkdir isn't smart enough to strip a trailing /.
387 mkdir $(@:%/=%)
388\f
389# Make sure that object files are not removed
390# when they are intermediates between sources and library members.
51f75302 391.PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
28f540f4
RM
392
393# Make sure that the parent library archive is never removed.
51f75302 394.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
28f540f4
RM
395\f
396# Use the verbose option of ar and tar when not running silently.
397ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
398verbose := v
399else # -s
400verbose :=
401endif # not -s
402
403ARFLAGS := r$(verbose)
404\f
405# This makes all the object files in the parent library archive.
406
407.PHONY: lib libobjs lib-noranlib
4788ab46 408lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
51f75302
RM
409
410# Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
dbdb6189 411lib%.a: lib%.a($(ar-symtab-name)) ;
51f75302 412
564210fe
RM
413# For object-suffix $o, the list of objects with that suffix.
414# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
415o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
416 $(elide-routines$o)),\
417 $(objects)))
418
51f75302
RM
419libobjs: $(foreach o,$(object-suffixes),\
420 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
564210fe 421 $(notdir $(o-objects))))
3bbceb12
RM
422lib-noranlib: libobjs
423others: $(addprefix $(objpfx),$(install-lib))
28f540f4 424
072ebcef
RM
425ifndef objects
426
427# Create the stamp$o files to keep the parent makefile happy.
428subdir_lib: $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir))
429$(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)):
430 rm -f $@; > $@
431else
51f75302
RM
432
433# Define a pattern rule that will match many targets libc.a(foo.%), for
434# each foo.o in $(objects) (% will just happen always to match `o'). This is
435# the only way to define a rule that updates many targets at once with one
564210fe
RM
436# sequence of commands.
437define o-iterator-doit
438$(common-objpfx)$(patsubst %,$(libtype$o),c)(\
439$(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
51f75302 440 $(objpfx)stamp.%-$(subdir) ;
564210fe
RM
441endef
442object-suffixes-left := $(object-suffixes)
443include $(o-iterator)
51f75302
RM
444
445# The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
564210fe
RM
446# the way to update all the foo.% object files in $(objects). Now we
447# define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
448# timestamp file; these rules (one explicit rule is generated for each
449# object suffix) will update the parent archive with ar. Use a static
450# pattern rule so $* is set to the object type during the commands.
451define o-iterator-doit
452$(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
453endef
454object-suffixes-left := $(object-suffixes)
455include $(o-iterator)
456define do-ar
706074a5 457topdir=`cd $(..).; pwd`; \
564210fe 458$(patsubst %,cd %;,$(objdir)) \
706074a5
UD
459$$topdir/autolock.sh ${O%-lib}.lck $(AR) cru$(verbose) ${O%-lib} \
460 $(patsubst $(objpfx)%,%,$^)
564210fe
RM
461rm -f $@
462touch $@
463endef
e215c478 464ifdef subdir
51f75302 465O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c)
e215c478
RM
466else
467O%-lib = $(patsubst %,$(libtype$*),c)
468endif
28f540f4 469
51f75302 470endif
28f540f4 471
dbdb6189
RM
472# Rules to update the $(ar-symtab-name) member with ranlib,
473# one for each object flavor.
474define o-iterator-doit
475$(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
476 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
4d6acc61 477 $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
706074a5
UD
478 topdir=`cd $(..).; pwd`; \
479 $$$$topdir/autolock.sh \
480 $$(common-objpfx)$$(patsubst %,$$(libtype$o),c).lck \
df21c858 481 $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
dbdb6189 482endef
4d6acc61
RM
483ifndef subdir
484subdirs-stamps := $(foreach d,$(subdirs),\
485 $(firstword $(objdir) $(subdir))/stamp%-$d)
486subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
487$(subdirs-stamps): subdir_lib;
488endif
dbdb6189
RM
489object-suffixes-left = $(object-suffixes)
490include $(o-iterator)
491
28f540f4
RM
492
493# This makes all the object files.
494.PHONY: objects objs
564210fe 495objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
51f75302 496 $(addprefix $(objpfx),$(extra-objs))
f0bf9cb9
RM
497
498# Canned sequence for building an extra library archive.
499define build-extra-lib
500$(patsubst %,cd %;,$(objdir)) \
501$(AR) cru$(verbose) $(@:$(objpfx)%=%) \
502 $(patsubst $(objpfx)%,%,$^)
503$(RANLIB) $@
504endef
28f540f4
RM
505\f
506# Installation.
507
508# $(install-lib) are installed from the object directory into $(libdir);
509# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
510# unless they also appear in $(non-lib.a). $(install-data) are installed
511# as they are into $(datadir). $(headers) are installed as they are in
512# $(includedir). $(install-bin) and $(install-sbin) are installed from the
513# object directory into $(bindir) and $(sbindir), respectively.
514# $(install-others) are absolute path names of files to install; rules to
515# install them are defined elsewhere.
516
517# The simple library name to install libc.a under.
518# This could be defined by a sysdep Makefile.
519ifndef libc-name
520libc-name := c
521endif
522
523define do-install
524$(make-target-directory)
525$(INSTALL_DATA) $< $@
526endef
527
a182affd
RM
528# Make the target directory if it doesn't exist, using the `mkinstalldirs'
529# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
28f540f4 530define make-target-directory
dcfb26a7 531$(addprefix $(..)./mkinstalldirs ,\
a182affd 532 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
28f540f4
RM
533endef
534
535# Any directory (parent or subdir) that has any object files to build
536# should install libc.a; this way "make install" in a subdir is guaranteed
537# to install everything it changes.
538ifdef objects
51f75302
RM
539installed-libcs := $(foreach o,$(object-suffixes),\
540 $(libdir)/$(patsubst %,$(libtype$o),\
541 $(libprefix)$(libc-name)))
75914335 542installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
51f75302 543install: $(installed-libcs)
9f2233e8 544$(installed-libcs): $(libdir)/lib$(libprefix)%: lib
28f540f4 545 $(make-target-directory)
c316b486 546 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
9f2233e8
RM
547# Running ranlib after installing makes the __.SYMDEF time stamp up to
548# date, which avoids messages from some linkers.
28f540f4
RM
549 $(RANLIB) $@
550endif
551
273d56ce
RM
552define do-install-program
553$(make-target-directory)
554$(INSTALL_PROGRAM) $< $@.new
555mv -f $@.new $@
556endef
557
5bf62f2d 558install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
0700dfa1 559install-lib := $(filter-out %.so %_pic.a,$(install-lib))
51f75302 560ifeq (yes,$(build-shared))
5bf62f2d 561
0e3426bb 562install-lib-nosubdir: $(install-lib.so:%=$(libdir)/%)
0e3426bb
RM
563
564# Find which .so's have versions.
05d4c982
RM
565versioned := $(strip $(foreach so,$(install-lib.so),\
566 $(patsubst %,$(so),$($(so)-version))))
0e3426bb
RM
567
568# Install all the unversioned shared libraries.
569$(addprefix $(libdir)/,$(filter-out $(versioned),$(install-lib.so))): \
f0523145 570$(libdir)/%.so: $(objpfx)%.so; $(do-install-program)
0e3426bb 571
f36f8dcf
RM
572define make-link
573cd $(@D); rm -f $(@F).new; $(LN_S) $(<F) $(@F).new; mv -f $(@F).new $(@F)
574endef
0e3426bb
RM
575
576ifdef libc.so-version
577# For a library specified to be version N, install three files:
578# libc.so -> libc.so.N (e.g. libc.so.6)
579# libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
580
0e3426bb
RM
581$(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so
582 $(make-link)
583$(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program)
aa1075ea 584install: $(slibdir)/libc.so$(libc.so-version)
7c713e28 585
aa1075ea 586ifndef subdir
7c713e28
RM
587# What we install as libc.so for programs to link against is in fact an
588# archive. It contains the various $(static-only-routines) objects, and
589# the special object libc-syms.so that contains just the dynamic symbol
590# table of the shared libc object.
591install: $(libdir)/libc.so
0f90ef96 592$(libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
d8c7ef98 593 $(elfobjdir)/$(rtld-installed-name) \
22f87e0f 594 $(common-objpfx)libc.a
0f90ef96 595 (echo '/* Use the shared library, but some functions are only in';\
d8c7ef98
RM
596 echo ' the static library, so try that secondarily.'; \
597 echo ' The dynamic linker defines some functions used by $(<F),';\
4311b2a6
RM
598 echo ' but ld uses definitions from libc.a before examining the';\
599 echo ' dependencies of $(<F) to find $(rtld-installed-name). */';\
0f90ef96
RM
600 echo 'GROUP ( $(^F) )') > $@.new
601 mv -f $@.new $@
602
aa1075ea 603endif
7c713e28 604
0e3426bb 605else
7c713e28 606install: $(slibdir)/libc.so
0e3426bb
RM
607$(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program)
608endif
609
610
611ifneq (,$(versioned))
612# Produce three sets of rules as above for all the smaller versioned libraries.
613
614define o-iterator-doit
f0523145 615$(libdir)/$o: $(libdir)/$o$($o-version); $$(make-link)
0e3426bb
RM
616endef
617object-suffixes-left := $(versioned)
dc997231 618include $(o-iterator)
0e3426bb 619
20c81189
RM
620# Make symlinks in the build directory, because the versioned names might
621# be referenced by a DT_NEEDED in another library.
622define o-iterator-doit
623$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
624endef
625object-suffixes-left := $(versioned)
dc997231 626include $(o-iterator)
20c81189
RM
627
628
0e3426bb 629define o-iterator-doit
f0523145 630$(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$(version).so; $$(make-link)
0e3426bb
RM
631endef
632object-suffixes-left := $(versioned)
dc997231 633include $(o-iterator)
0e3426bb
RM
634
635define o-iterator-doit
f0523145 636$(libdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
0e3426bb
RM
637endef
638object-suffixes-left := $(versioned)
dc997231 639include $(o-iterator)
0e3426bb 640endif
102800e0
RM
641
642define do-install-so
643$(do-install-program)
644$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
645 $(filter-out %.so,$@))
646endef
094bacdb 647
102800e0
RM
648so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
649$(foreach v,$(so-versions),\
273d56ce 650 $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
102800e0
RM
651 $(do-install-so)
652$(foreach v,$(so-versions),\
273d56ce 653 $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so
102800e0 654 $(do-install-so)
51f75302
RM
655endif
656
28f540f4
RM
657ifdef install-bin
658$(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
273d56ce 659 $(do-install-program)
28f540f4
RM
660endif
661ifdef install-sbin
662$(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
273d56ce 663 $(do-install-program)
28f540f4
RM
664endif
665ifdef install-lib
666install-lib.a := $(filter lib%.a,$(install-lib))
667install-lib-non.a := $(filter-out lib%.a,$(install-lib))
668ifdef install-lib-non.a
669$(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
d929664a 670 $(libdir)/$(libprefix)%: $(objpfx)%
28f540f4
RM
671 $(do-install)
672endif
673ifdef install-lib.a
674$(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
64166d98 675 $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
28f540f4
RM
676 $(do-install)
677 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
678endif
679endif
680ifdef install-data
681$(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
682endif
683headers := $(strip $(headers))
684ifdef headers
685$(addprefix $(includedir)/,$(headers)): \
686 $(includedir)/%: %;$(do-install)
687endif # headers
688
689.PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
690 install-data-nosubdir install-headers-nosubdir
691install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
692install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
693install-lib-nosubdir: $(addprefix $(libdir)/,\
694 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
695 $(addprefix $(libprefix),$(install-lib-non.a)))
696install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
697install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
698install-others-nosubdir: $(install-others)
699
700# We need all the `-nosubdir' targets so that `install' in the parent
701# doesn't depend on several things which each iterate over the subdirs.
702# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
703# subroutine. Then in the parent `install-FOO' also causes subdir makes.
704install-%:: install-%-nosubdir ;
705
706.PHONY: install install-no-libc.a-nosubdir
707install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
708 install-bin-nosubdir install-lib-nosubdir \
709 install-others-nosubdir install-sbin-nosubdir
710install: install-no-libc.a-nosubdir
711\f
712# Command to compile $< in $(objdir) using the native libraries.
713define native-compile
714cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
715 $(addprefix $$cwd/,$^) -o $(@F)
716endef
717
718# Command to compile $< in $(common-objdir) using the native libraries.
719define common-objdir-compile
720cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
721endef
722
723# We always want to use configuration definitions.
299a95b9 724ifdef objdir
ffcf9634
RM
725# This is always used in $(common-objdir), so we use no directory name.
726BUILD_CFLAGS = -include config.h
299a95b9
RM
727else
728BUILD_CFLAGS = -include $(..)config.h
729endif
28f540f4
RM
730
731# Support the GNU standard name for this target.
732.PHONY: check
733check: tests
734\f
735.PHONY: TAGS
36dbcbc9 736TAGS: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS
dbdb6189 737 $(MAKE) $(addprefix -f ,$^) $@
28f540f4 738
36dbcbc9 739$(..)po/%.pot: $(common-objpfx)distinfo-$(subdir) $(..)MakeTAGS FORCE
ce563359
RM
740 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
741FORCE:
a182affd
RM
742
743
28f540f4
RM
744.PHONY: echo-headers
745echo-headers:
746 @echo $(headers)
747
748\f
749# Common cleaning targets.
750
751.PHONY: common-mostlyclean common-clean mostlyclean clean
752clean: common-clean
753mostlyclean: common-mostlyclean
754
755# Remove the object files.
756common-mostlyclean:
757 -rm -f $(addprefix $(objpfx),$(tests) $(others) \
758 $(addsuffix .o,$(tests) $(others)) \
759 $(addsuffix .out,$(tests)))
4788ab46
RM
760 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
761 -rm -f core $(objpfx)stub-$(subdir)
51f75302
RM
762 $(rmobjs)
763define rmobjs
764$(foreach o,$(object-suffixes),
564210fe 765-rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
51f75302 766endef
28f540f4
RM
767
768# Also remove the dependencies and generated source files.
769common-clean: common-mostlyclean
deab9dea 770 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
36dbcbc9 771 -rm -f $(common-objpfx)distinfo-$(subdir)
28f540f4
RM
772\f
773# Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
774# for each function which is a stub. We grovel over all the .d files
775# looking for references to source files in sysdeps/stub. Then we grovel
776# over each referenced source file to see what stub function it defines.
777
778.PHONY: stubs # The parent Makefile calls this target.
779stubs: $(common-objpfx)stub-$(subdir)
780s = $(sysdep_dir)/stub
781$(common-objpfx)stub-$(subdir): $(+depfiles)
782# Use /dev/null since `...` might expand to empty.
c4cc693d
RM
783 (s=`cd $s; /bin/pwd`; \
784 $(patsubst %,cd %;,$(objdir)) \
785 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
786 `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
787 $(patsubst $(objpfx)%,%,$^) /dev/null` \
788 /dev/null) > $@T
28f540f4
RM
789 mv -f $@T $@
790\f
791# Make the distribution tar file.
792
793.PHONY: dist
36dbcbc9 794dist: $(common-objpfx)distinfo-$(subdir) $(..)Make-dist
28f540f4
RM
795 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
796
10ceac89
RM
797# Avoid depending on source files found in sysdeps dirs,
798# because the references affect implicit rule selection.
799dist: $(filter-out %.c %.S %.s,$(distribute))
28f540f4
RM
800
801# We used to simply export all these variables, but that frequently made the
802# environment get too large. Instead, we write all the information into
803# a generated makefile fragment `distinfo', and then include it with -f in
804# the sub-make that makes the distribution (above).
36dbcbc9 805$(common-objpfx)distinfo-$(subdir): Makefile $(..)Makerules
28f540f4
RM
806 $(distinfo-vars)
807 mv -f $@.new $@
36dbcbc9 808.PHONY: subdir_distinfo distinfo
6a441471 809subdir_distinfo: distinfo
36dbcbc9 810distinfo: $(common-objpfx)distinfo-$(subdir)
28f540f4
RM
811
812define distinfo-vars
813rm -f $@.new
a4242e25
RM
814echo > $@.new 'subdir := $(subdir)'
815$(foreach var,subdir-dirs sources elided-routines sysdep_routines \
dfe1754a 816 headers sysdep_headers distribute dont_distribute generated \
4d6acc61 817 others tests extra-libs $(extra-libs:%=%-routines) \
6a441471
RM
818 versioned \
819 $(addprefix install-,lib lib.so data bin sbin others),
4d6acc61
RM
820echo >> $@.new '$(subdir)-$(var) := $($(var))'
821echo >> $@.new '$(var) = $$($(subdir)-$(var))')
28f540f4
RM
822endef
823\f
824ifneq (,$(strip $(gpl2lgpl)))
825ifneq (,$(wildcard $(..)gpl2lgpl.sed))
826# Snarf from the master source and frob the copying notice.
827$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
828 sed -f $^ > $@-tmp
829# So I don't edit them by mistake.
830 chmod a-w $@-tmp
831 mv -f $@-tmp $@
a2fe9c76 832 test ! -d CVS || cvs commit -m'Updated from $^' $@
28f540f4
RM
833endif
834endif