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