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