]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makerules
2003-04-29 Roland McGrath <roland@redhat.com>
[thirdparty/glibc.git] / Makerules
CommitLineData
a7f7b879 1# Copyright (C) 1991-2002, 2003 Free Software Foundation, Inc.
1c68c264
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 Lesser General Public
6# License as published by the Free Software Foundation; either
7# version 2.1 of the 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# Lesser General Public License for more details.
13
14# You should have received a copy of the GNU Lesser General Public
15# License along with the GNU C Library; if not, write to the Free
16# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17# 02111-1307 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
28REQUIRED_MAKE_VERSION = 3.74
29REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
30
31ifneq ($(REQUIRED_MAKE_VERSION), \
32 $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33Wrong GNU Make version. See above for the version needed.
34endif
35
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
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'.
60sysdirs = $(strip $(full_config_sysdirs))
61
62+sysdir_pfx = $(common-objpfx)
63
64export sysdirs := $(sysdirs)
65
66+sysdep_dirs := $(full_config_sysdirs)
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))
74
75# This variable is used in ``include $(o-iterator)'' after defining
76# $(o-iterator-doit) to produce some desired rule using $o for the object
77# suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78# is produced for each object suffix in use.
79o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
80\f
81# Include any system-specific makefiles.
82
83# This is here so things in sysdep Makefiles can easily depend on foo.h as
84# appropriate and not worry about where foo.h comes from, which may be
85# system dependent and not known by that Makefile.
86vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87 $(+sysdep_dirs) $(..)))
88
89# The same is true for RPC source files.
90vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91 $(+sysdep_dirs) $(..)))
92
93# Some sysdep makefiles use this to distinguish being included here from
94# being included individually by a subdir makefile (hurd/Makefile needs this).
95in-Makerules := yes
96
97sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98ifneq (,$(sysdep-makefiles))
99include $(sysdep-makefiles)
100endif
101
102
103# Reorder before-compile so that mach things come first, and hurd things
104# second, before all else. The mach and hurd subdirectories have many
105# generated header files which the much of rest of the library depends on,
106# so it is best to build them first (and mach before hurd, at that).
107before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
108 $(before-compile)) \
109 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
110 $(before-compile))
111
112# Even before that, we need abi-versions.h which is generated right here.
113ifeq ($(versioning),yes)
114ifndef avoid-generated
115before-compile := $(common-objpfx)abi-versions.h $(before-compile)
116$(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
117 $(common-objpfx)Versions.all
118 LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
119 mv -f $@T $@
120
121$(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
122 sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
123 $(common-objpfx)abi-versions.h > $@T
124 mv -f $@T $@
125endif # avoid-generated
126endif # $(versioning) = yes
127
0e56981e
RM
128
129# Generating headers for assembly constants.
130# We need this defined early to get into before-compile before
131# it's used in sysd-rules, below.
132$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
133 %.sym $(before-compile)
134 $(AWK) -f $< $(filter %.sym,$^) \
135 | $(CC) -S -o - $(CFLAGS) $(CPPFLAGS) -x c - \
136 -MD -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)' \
137 | sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' > $(@:.h.d=.h)T
138 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
139 $(@:.h=.h.d)T > $(@:.h=.h.d)T2
140 rm -f $(@:.h=.h.d)T
141 mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
142 mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
143vpath %.sym $(sysdirs)
144before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
145
146
1c68c264
RM
147# When we have no deps pass doing it, then make sure the subdirectory
148# for object files gets created.
149ifdef no_deps
150ifdef objpfx
151before-compile += $(objpfx).
152$(objpfx).:
153 $(make-target-directory)
154endif
155endif
156
157# Remove existing files from `before-compile'. Things are added there when
158# they must exist for dependency generation to work right, but once they
159# exist there is no further need for every single file to depend on them,
160# and those gratuitous dependencies result in many gratuitous
161# recompilations.
162before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
163
164# Don't let any before-compile file be an intermediate and get removed.
165ifdef before-compile
166$(before-compile):
167endif
168
169# If a makefile needs to do something conditional on something that
170# can only be figured out from headers, write a FOO.make.c input
171# file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
172# to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
9ae10332 173$(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(before-compile)
1c68c264
RM
174 rm -f $@T $@.dT
175 (echo '# Generated from $*.make.c by Makerules.'; \
176 SUNPRO_DEPENDENCIES='$@.dT $$(common-objpfx)$*.make' \
177 $(CC) $(CFLAGS) $(CPPFLAGS) -E $< \
178 | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
179 echo 'common-generated += $(@F)'; \
9ae10332
RM
180 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
181 rm -f $@.dT) > $@T
1c68c264 182 mv -f $@T $@
9ae10332 183
0e56981e
RM
184ifdef subdir
185sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g'
186else
187sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g'
188endif
1c68c264
RM
189\f
190# Generate an ordered list of implicit rules which find the source files in
191# each sysdep directory. The old method was to use vpath to search all the
192# sysdep directories. However, that had the problem that a .S file in a
193# later directory would be chosen over a .c file in an earlier directory,
194# which does not preserve the desired sysdeps ordering behavior.
195
196# When making the list of .d files to include, we can't know which ones
197# have source in .s files, and thus do not in fact need a .d file.
198# So we must define rules to make .d files for .s files.
199define make-dummy-dep
200$(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
201endef
202$(common-objpfx)dummy.d:
203 echo '# .s files cannot contain includes, so they need no deps.' > $@
204
205# It matters that this set of rules, for compiling from sources in
206# the current directory (the $srcdir/$subdir) come before the
207# generated sysdep rules in included from sysd-rules below. When
208# compiling in the source tree, generated sources go into the current
209# directory, and those should be chosen before any sources in sysdeps.
210define o-iterator-doit
211$(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
212endef
213object-suffixes-left := $(all-object-suffixes)
214include $(o-iterator)
215$(objpfx)%.d: %.S $(before-compile); $(+make-deps)
216
217define o-iterator-doit
218$(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
219endef
220object-suffixes-left := $(all-object-suffixes)
221include $(o-iterator)
222$(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
223
224define o-iterator-doit
225$(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
226endef
227object-suffixes-left := $(all-object-suffixes)
228include $(o-iterator)
229$(objpfx)%.d: %.c $(before-compile); $(+make-deps)
230
231# Omit the objpfx rules when building in the source tree, because
232# objpfx is empty and so these rules just override the ones above.
233ifdef objpfx
234# Define first rules to find the source files in $(objpfx).
235# Generated source files will end up there.
236define o-iterator-doit
237$(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
238endef
239object-suffixes-left := $(all-object-suffixes)
240include $(o-iterator)
241$(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
242
243define o-iterator-doit
244$(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
245endef
246object-suffixes-left := $(all-object-suffixes)
247include $(o-iterator)
248$(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
249
250define o-iterator-doit
251$(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
252endef
253object-suffixes-left := $(all-object-suffixes)
254include $(o-iterator)
255$(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
256endif
257
258# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
259# patterns matching sysdep directories whose assembly source files should
260# be suppressed.
261ifdef inhibit-sysdep-asm
262define open-check-inhibit-asm
263case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
264endef
265close-check-inhibit-asm = ;; esac ;
266endif
267
268-include $(+sysdir_pfx)sysd-rules
269ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
270# The value of $(+sysdep_dirs) the sysd-rules was computed for
271# differs from the one we are using now. So force a rebuild of sysd-rules.
272sysd-rules-force = FORCE
273FORCE:
274endif
275$(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
276 $(wildcard $(foreach dir,$(sysdirs),\
277 $(dir)/Makefile))\
278 $(sysd-rules-force)
279 -@rm -f $@T
280 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
281 for dir in $(config-sysdirs:%='$$(..)%'); do \
282 for o in $(all-object-suffixes); do \
283 $(open-check-inhibit-asm) \
284 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
285 \$$(compile-command.S)"; \
286 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
287 \$$(compile-command.s)"; \
288 echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
289 \$$(compile-command.S)"; \
290 echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
291 \$$(compile-command.s)"; \
292 echo "\$$(objpfx)ptw-%$$o: $$dir/%.S \$$(before-compile); \
293 \$$(compile-command.S)"; \
294 echo "\$$(objpfx)ptw-%$$o: $$dir/%.s \$$(before-compile); \
295 \$$(compile-command.s)"; \
296 $(close-check-inhibit-asm) \
297 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
298 \$$(compile-command.c)"; \
299 echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
300 \$$(compile-command.c)"; \
301 echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
302 \$$(compile-command.c)"; \
303 done; \
304 $(open-check-inhibit-asm) \
305 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
306 \$$(make-dummy-dep)"; \
307 echo "\$$(objpfx)rtld-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
308 \$$(make-dummy-dep)"; \
309 echo "\$$(objpfx)ptw-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
310 \$$(make-dummy-dep)"; \
311 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
312 \$$(+make-deps)"; \
313 echo "\$$(objpfx)rtld-%.d: $$dir/%.S \$$(before-compile); \
314 \$$(+make-deps)"; \
315 echo "\$$(objpfx)ptw-%.d: $$dir/%.S \$$(before-compile); \
316 \$$(+make-deps)"; \
317 $(close-check-inhibit-asm) \
318 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
319 \$$(+make-deps)"; \
320 echo "\$$(objpfx)rtld-%.d: $$dir/%.c \$$(before-compile); \
321 \$$(+make-deps)"; \
322 echo "\$$(objpfx)ptw-%.d: $$dir/%.c \$$(before-compile); \
323 \$$(+make-deps)"; \
324 echo "\$$(objpfx)m_%.S: $$dir/s_%.S; \$$(+make-include-of-dep)"; \
325 echo "\$$(objpfx)m_%.c: $$dir/s_%.c; \$$(+make-include-of-dep)"; \
326 done; \
327 echo 'sysd-rules-done = t') > $@T
328 mv -f $@T $@
329
330ifndef sysd-rules-done
331# Don't do deps until this exists, because it provides rules to make the deps.
332no_deps=t
333endif
334
335# This is used by the m_%.[Sc] pattern rules in sysd-rules.
336define +make-include-of-dep
337echo '#include <$<>' > $@T
338mv -f $@T $@
339endef
340
341# Generate version maps, but wait until sysdep-subdirs is known
342ifeq ($(sysd-sorted-done),t)
343ifeq ($(versioning),yes)
344-include $(common-objpfx)sysd-versions
345$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
346common-generated += $(version-maps)
347postclean-generated += sysd-versions Versions.all abi-versions.h \
348 Versions.def.v.i Versions.def.v Versions.v.i Versions.v
349
350ifndef avoid-generated
351ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
352sysd-versions-force = FORCE
353FORCE:
354endif
355# See %.v/%.v.i implicit rules in Makeconfig.
356$(common-objpfx)Versions.def.v.i: $(..)Versions.def \
357 $(wildcard $(add-ons:%=$(..)%/Versions.def))
358$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
359 $(common-objpfx)soversions.i \
360 $(common-objpfx)Versions.def.v
361 { while read lib version setname; do \
362 test -z "$$setname" || echo "$$lib : $$setname"; \
363 done < $(word 2,$^); \
364 cat $(word 3,$^); \
365 } | LC_ALL=C $(AWK) -f $< > $@T
366 mv -f $@T $@
367# See %.v/%.v.i implicit rules in Makeconfig.
368$(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
369 $(wildcard $(sysdirs:%=%/Versions)) \
370 $(common-objpfx)abi-versions.h \
371 $(sysd-versions-force)
372$(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
373 $(common-objpfx)Versions.v \
374 $(..)scripts/versions.awk
375 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
376 cat $(word 2,$^) \
377 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
378 -v move_if_change='$(move-if-change)' \
379 -f $(word 3,$^); \
380 ) > $@T
381 mv -f $@T $@
382endif # avoid-generated
383endif # $(versioning) = yes
384endif # sysd-sorted-done
385
386
387ifndef compile-command.S
388compile-command.S = $(compile.S) $(OUTPUT_OPTION)
389endif
390ifndef compile-command.s
391compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
392endif
393ifndef compile-command.c
394compile-command.c = $(compile.c) $(OUTPUT_OPTION)
395endif
396
397# GCC can grok options after the file name, and it looks nicer that way.
398compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
073e82bf
RM
399compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
400 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
401COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
402 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
1c68c264
RM
403COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
404
405# If we want to generate MD5 checksums for the sources do this now.
406ifeq ($(md5),yes)
407generate-md5 = ; rm -f $(@:.d=.md5); \
f4281cc4 408$(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | \
1c68c264
RM
409sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
410else
411generate-md5 =
412endif
413
414# We need this for the output to go in the right place. It will default to
415# empty if make was configured to work with a cc that can't grok -c and -o
416# together. You can't compile the C library with such a compiler.
417OUTPUT_OPTION = -o $@
418
419# We need the $(CFLAGS) to be in there to have the right predefines during
420# the dependency run for C sources. But having it for assembly sources can
421# get the wrong predefines.
f4281cc4 422S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
1c68c264
RM
423define +make-deps
424$(make-target-directory)
425$(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
f4281cc4 426 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed \
1c68c264
RM
427-e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
428$(sed-remove-objpfx) > $(@:.d=.T)
429mv -f $(@:.d=.T) $@ $(generate-md5)
430endef
431ifneq (,$(objpfx))
432# Continuation lines here are dangerous because they introduce spaces!
433define sed-remove-objpfx
434-e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
435-e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
436endef
437endif
438\f
439# Modify the list of routines we build for different targets
440
441ifeq (yesyes,$(build-shared)$(elf))
442ifndef libc.so-version
443# Undefine this because it can't work when we libc.so is unversioned.
444static-only-routines =
445endif
446endif
447
448# Bounded pointer thunks are only built for *.ob
449elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
450
451elide-routines.oS += $(filter-out $(static-only-routines),\
452 $(routines) $(aux) $(sysdep_routines)) \
453 $(elide-bp-thunks)
454elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
455
456# If we have versioned code we don't need the old versions in any of the
457# static libraries.
458elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
459elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
460elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
461elide-routines.ob += $(shared-only-routines)
462\f
463# Shared library building.
464
465ifeq (yes,$(build-shared))
466
467# Reference map file only when versioning is selected and a map file name
468# is given.
469ifeq ($(versioning),yes)
470map-file = $(firstword $($(@F:.so=-map)) \
471 $(addprefix $(common-objpfx), \
472 $(filter $(@F:.so=.map),$(version-maps))))
473load-map-file = $(map-file:%=-Wl,--version-script=%)
474endif
475
476# Pattern rule to build a shared object from an archive of PIC objects.
477# This must come after the installation rules so Make doesn't try to
478# build shared libraries in place from the installed *_pic.a files.
479# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
480# on other shared objects.
481lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
482ifneq (,$(findstring aix,$(config-os)))
483 (echo '#!'; \
484 dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
485endif
486 $(build-shlib)
487
488ifeq ($(elf),yes)
489define build-shlib-helper
a7f7b879 490$(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
73398a44 491 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
1c68c264
RM
492 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
493 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
494 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
495 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
496 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
497endef
498else
499ifneq (,$(findstring aix,$(config-os)))
500define build-shlib-helper
501$(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
502 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
503 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
504 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
505 -L$(subst :, -L,$(rpath-link))
506endef
507else
508endif
509endif
510
511ifeq (yes,$(elf))
512# binutils only position loadable notes into the first page for binaries,
513# not for shared objects
358cad7c
RM
514$(common-objpfx)shlib.lds: $(common-objpfx)config.make
515 $(LINK.o) -shared -Wl,-O1 \
516 $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
517 -Wl,--verbose 2>&1 | \
518 sed > $@T \
519 -e '/^=========/,/^=========/!d;/^=========/d' \
1c68c264 520 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
358cad7c 521 -e 's/^.*\*(\.dynbss).*$$/& \
a7ed068e 522 __start___libc_freeres_ptrs = .; \
358cad7c 523 *(__libc_freeres_ptrs) \
a7ed068e 524 __stop___libc_freeres_ptrs = .;/'
358cad7c
RM
525 mv -f $@T $@
526common-generated += shlib.lds
527
528define build-shlib
529$(build-shlib-helper) -o $@ -T $(common-objpfx)shlib.lds \
1c68c264 530 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
1c68c264
RM
531endef
532else
533ifneq (,$(findstring aix,$(config-os)))
534define build-shlib
535$(build-shlib-helper) \
536 -o $@ \
537 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
538 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
539endef
540define build-shlib
541$(build-shlib-helper) \
542 $(build-shlib-objlist)
543endef
544endif
545endif
546
547ifneq (,$(findstring aix,$(config-os)))
548define build-module-helper
549$(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
550 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
551 $(load-map-file) \
552 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
553 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
554endef
555else
556define build-module-helper
557$(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
558 -B$(csu-objpfx) $(load-map-file) \
559 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
560 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
561endef
562endif
563
564# This macro is similar to build-shlib but it does not define a soname
565# and it does not depend on the destination name to start with `lib'.
566ifeq (yes,$(elf))
567# binutils only position loadable notes into the first page for binaries,
568# not for shared objects
569define build-module
358cad7c 570$(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
1c68c264 571 $(csu-objpfx)abi-note.o $(build-module-objlist)
1c68c264
RM
572endef
573else
574ifneq (,$(findstring aix,$(config-os)))
575define build-module
576$(build-module-helper) \
577 -o $@ \
578 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
579 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
580endef
581else
582define build-module
583define build-module
584$(build-module-helper) \
585 -o $@ \
586 $(build-module-objlist)
587endef
588endif
589endif
590
591build-module-helper-objlist = \
592 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
358cad7c 593 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
1c68c264
RM
594whole-archive := -Wl,--whole-archive
595
596build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
597build-shlib-objlist = $(build-module-helper-objlist) \
598 $(LDLIBS-$(@F:lib%.so=%).so)
599
600# Don't try to use -lc when making libc.so itself.
601# Also omits crti.o and crtn.o, which we do not want
602# since we define our own `.init' section specially.
603LDFLAGS-c.so = -nostdlib -nostartfiles
604# But we still want to link libc.so against $(gnulib).
605LDLIBS-c.so += $(gnulib)
606# Give libc.so an entry point and make it directly runnable itself.
607LDFLAGS-c.so += -e __libc_main
608# Force the backward compatibility EH functions to be linked.
609LDFLAGS-c.so += -u __register_frame
610# Pre-link the objects of libc_pic.a so that we can locally resolve
611# COMMON symbols before we link against ld.so. This is because ld.so
612# contains some of libc_pic.a already, which will prevent the COMMONs
613# from being allocated in libc.so, which introduces evil dependencies
614# between libc.so and ld.so, which can make it impossible to upgrade.
615ifeq ($(elf),yes)
616$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
617 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
618 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
1c68c264
RM
619# Use our own special initializer and finalizer files for libc.so.
620$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
621 $(common-objpfx)libc_pic.os \
622 $(elfobjdir)/sofini.os \
358cad7c
RM
623 $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
624 $(common-objpfx)shlib.lds
1c68c264
RM
625 $(build-shlib)
626ifeq ($(versioning),yes)
627$(common-objpfx)libc.so: $(common-objpfx)libc.map
628endif
629common-generated += libc.so libc_pic.os
630ifdef libc.so-version
631$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
632 $(make-link)
633common-generated += libc.so$(libc.so-version)
634endif
635endif
636else
637ifneq (,$(findstring aix,$(config-os)))
638$(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
639 @rm -f $@
640 (echo '#!'; \
641 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
642 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
643 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
644 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
645 -bE:$(common-objpfx)syscalls.exp \
646 -bI:$(common-objpfx)syscalls.exp \
647 -L$(common-objpfx) -o $@ $^
648# AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
649 cp $@ $(common-objpfx)shr.o
650 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
651endif
652endif
653\f
654# Figure out the source filenames in this directory.
655
656override sources := $(addsuffix .c,\
657 $(filter-out $(elided-routines),\
658 $(routines) $(aux) \
659 $(sysdep_routines)))
660sysdep_routines := $(sysdep_routines)
661
662headers := $(headers) $(sysdep_headers)
663
664# This is the list of all object files, gotten by
665# replacing every ".c" in `sources' with a ".o".
666# We also add bounded-pointer thunks, which are later
667# elided for all suffixes except for `.ob'.
668override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
669 $(patsubst %,$(bppfx)%.o,\
670 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
671
672
673# The makefile may define $(extra-libs) with `libfoo libbar'
674# to build libfoo.a et al from the modules listed in $(libfoo-routines).
675ifdef extra-libs
676# extra-lib.mk is included once for each extra lib to define rules
677# to build it, and to add its objects to the various variables.
678# During its evaluation, $(lib) is set to the name of the library.
679extra-libs-left := $(extra-libs)
680include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
681endif
682\f
683+depfiles := $(sources:.c=.d) \
684 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
685 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
686ifeq ($(build-programs),yes)
687+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
688endif
689+depfiles := $(addprefix $(objpfx),\
690 $(filter-out $(addsuffix .d,$(omit-deps)),\
9ae10332
RM
691 $(+depfiles)))
692
693# Avoid the .h.d files for any .sym files whose .h files don't exist yet.
694# They will be generated when they're needed, and trying too early won't work.
695+gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
696+depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
697 $(+gen-as-const)))
1c68c264
RM
698
699ifdef +depfiles
700ifneq ($(no_deps),t)
701-include $(+depfiles)
702endif
703endif
704\f\f
705# Maximize efficiency by minimizing the number of rules.
706.SUFFIXES: # Clear the suffix list. We don't use suffix rules.
707# Don't define any builtin rules.
708MAKEFLAGS := $(MAKEFLAGS)r
709
710# Generic rule for making directories.
711%/:
712# mkdir isn't smart enough to strip a trailing /.
713 mkdir $(@:%/=%)
714\f
715# Make sure that object files are not removed
716# when they are intermediates between sources and library members.
717.PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
718
719# Make sure that the parent library archive is never removed.
720.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
721\f
722# Use the verbose option of ar and tar when not running silently.
723ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
724verbose := v
725else # -s
726verbose :=
727endif # not -s
728
729ARFLAGS := r$(verbose)
730CREATE_ARFLAGS := cru$(verbose)
731\f
732# This makes all the object files in the parent library archive.
733
734.PHONY: lib lib-noranlib
735lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
736lib-noranlib: libobjs
737
738# For object-suffix $o, the list of objects with that suffix.
739# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
740o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
741 $(elide-routines$o)),\
742 $(objects))) \
743 $(addprefix $(objpfx),$(o-objects$o))
744
745others: $(addprefix $(objpfx),$(install-lib))
746
747ifndef objects
748
749# Create the stamp$o files to keep the parent makefile happy.
750subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
751$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
752 $(make-target-directory)
753 rm -f $@; > $@
754else
755
756# Define explicit rules to update each $(objpfx)stamp.SUFFIX
757# timestamp file; these rules (one explicit rule is generated for each
758# object suffix) write a list of objects to update in the stamp file.
759# The parent will then actually add them all to the archive in the
760# archive rule, below.
761define o-iterator-doit
762$(objpfx)stamp$o: $(o-objects); $$(do-stamp)
763endef
764define do-stamp
765echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
766mv -f $@T $@
767endef
768object-suffixes-left := $(object-suffixes-for-libc)
769include $(o-iterator)
770
771endif
772
773# Now define explicit rules to build the library archives; these depend
774# on the stamp files built above.
775define o-iterator-doit
776$(common-objpfx)$(patsubst %,$(libtype$o),c): \
777 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
778endef
779define do-makelib
780cd $(common-objdir) && \
781$(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
782$(RANLIB) $@
783endef
784subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
785subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
786ifndef subdir
787$(subdirs-stamps): subdir_lib;
788endif
789object-suffixes-left = $(object-suffixes-for-libc)
790include $(o-iterator)
791
792
793# This makes all the object files.
794.PHONY: objects objs libobjs extra-objs
795objects objs: libobjs extra-objs
796libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
797extra-objs: $(addprefix $(objpfx),$(extra-objs))
798
799# Canned sequence for building an extra library archive.
800define build-extra-lib
801$(patsubst %/,cd % &&,$(objpfx)) \
802$(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
803 $(patsubst $(objpfx)%,%,$^)
804$(RANLIB) $@
805endef
806\f
807# Installation.
808
809.PHONY: force-install
810force-install:
811
812# $(install-lib) are installed from the object directory into $(libdir);
813# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
814# unless they also appear in $(non-lib.a). $(install-data) are installed
815# as they are into $(datadir). $(headers) are installed as they are in
816# $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
817# are installed from the object directory into $(bindir), $(bindir) and
818# $(sbindir), respectively. $(install-others) are absolute path names of
819# files to install; rules to install them are defined elsewhere.
820
821# The simple library name to install libc.a under.
822# This could be defined by a sysdep Makefile.
823ifndef libc-name
824libc-name := c
825endif
826
827define do-install
828$(make-target-directory)
829$(INSTALL_DATA) $< $@
830endef
831
832# Make the target directory if it doesn't exist, using the `mkinstalldirs'
833# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
834define make-target-directory
835$(addprefix $(..)./scripts/mkinstalldirs ,\
836 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
837endef
838
839# Any directory (parent or subdir) should install libc.a; this way
840# "make install" in a subdir is guaranteed to install everything it changes.
841installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
842 $(inst_libdir)/$(patsubst %,$(libtype$o),\
843 $(libprefix)$(libc-name)))
844install: $(installed-libcs)
845$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
846 $(make-target-directory)
847 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
848# Running ranlib after installing makes the __.SYMDEF time stamp up to
849# date, which avoids messages from some linkers.
850 $(RANLIB) $@
851
852define do-install-program
853$(make-target-directory)
854$(INSTALL_PROGRAM) $< $@.new
855mv -f $@.new $@
856endef
857
858define do-install-script
859$(make-target-directory)
860$(INSTALL_SCRIPT) $< $@.new
861mv -f $@.new $@
862endef
863
864install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
865install-lib := $(filter-out %.so %_pic.a,$(install-lib))
866
867ifeq (yes,$(build-shared))
868# Find which .so's have versions.
869versioned := $(strip $(foreach so,$(install-lib.so),\
870 $(patsubst %,$(so),$($(so)-version))))
871
872install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
873install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
874
cc8bfce9
RM
875# For versioned libraries, we install three files:
876# $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
877# $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
878# $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
7a0c303e 879V := $(firstword $($(subdir)-version) $(version))
cc8bfce9
RM
880install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
881 $(foreach L,$(install-lib.so-versioned),\
882 $(inst_libdir)/$L \
7a0c303e 883 $(inst_slibdir)/$(L:.so=)-$V.so \
cc8bfce9 884 $(inst_slibdir)/$L$($L-version))
1c68c264
RM
885
886# Install all the unversioned shared libraries.
887$(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
888 $(objpfx)%.so $(+force)
889 $(do-install-program)
890
891ifneq ($(findstring -s,$(LN_S)),)
892define make-link
893rm -f $@.new
894$(SHELL) $(..)scripts/rellns-sh $< $@.new
895mv -f $@.new $@
896endef
897else
898# If we have no symbolic links don't bother with rellns-sh.
899define make-link
900rm -f $@.new
901$(LN_S) $< $@.new
902mv -f $@.new $@
903endef
904endif
905
906ifeq (yes,$(build-shared))
907ifeq (no,$(cross-compiling))
908symbolic-link-prog := $(common-objpfx)elf/sln
909symbolic-link-list := $(common-objpfx)elf/symlink.list
910define make-shlib-link
911echo $(<F) $@ >> $(symbolic-link-list)
912endef
913else # cross-compiling
914# We need a definition that can be used by elf/Makefile's install rules.
915symbolic-link-prog = $(LN_S)
916endif
917endif
918ifndef make-shlib-link
919define make-shlib-link
920rm -f $@
921$(LN_S) $(<F) $@
922endef
923endif
924
925ifdef libc.so-version
926# For a library specified to be version N, install three files:
927# libc.so -> libc.so.N (e.g. libc.so.6)
928# libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
929
930$(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
931 $(+force)
932 $(make-shlib-link)
933$(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
934 $(do-install-program)
935install: $(inst_slibdir)/libc.so$(libc.so-version)
936
937# This fragment of linker script gives the OUTPUT_FORMAT statement
938# for the configuration we are building. We put this statement into
939# the linker scripts we install for -lc et al so that they will not be
940# used by a link for a different format on a multi-architecture system.
941$(common-objpfx)format.lds: $(..)scripts/output-format.sed \
942 $(common-objpfx)config.make \
943 $(common-objpfx)config.h $(..)Makerules
944 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
945 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
946 | sed -n -f $< > $@.new
947 rm -f $@.so
948 mv -f $@.new $@
949common-generated += format.lds
950
951ifndef subdir
952# What we install as libc.so for programs to link against is in fact a
953# link script. It contains references for the various libraries we need.
954# The libc.so object is not complete since some functions are only defined
955# in libc_nonshared.a.
956# We need to use absolute paths since otherwise local copies (if they exist)
957# of the files are taken by the linker.
958install: $(inst_libdir)/libc.so
959$(inst_libdir)/libc.so: $(common-objpfx)format.lds \
960 $(common-objpfx)libc.so$(libc.so-version) \
961 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
962 $(libprefix)$(libc-name)) \
963 $(+force)
964 (echo '/* GNU ld script';\
965 echo ' Use the shared library, but some functions are only in';\
966 echo ' the static library, so try that secondarily. */';\
967 cat $<; \
968 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
969 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
970 ')' \
971 ) > $@.new
972 mv -f $@.new $@
973
974endif
975
976else
977install: $(inst_slibdir)/libc.so
978$(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
979 $(do-install-program)
980endif
981
982ifneq (,$(versioned))
983# Produce three sets of rules as above for all the smaller versioned libraries.
984
985define o-iterator-doit
986$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
987endef
2afbfec4
RM
988object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
989ifneq (,$(object-suffixes-left))
1c68c264 990include $(o-iterator)
2afbfec4 991endif
1c68c264
RM
992
993# Make symlinks in the build directory, because the versioned names might
994# be referenced by a DT_NEEDED in another library.
995define o-iterator-doit
996$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
997endef
998object-suffixes-left := $(versioned)
999include $(o-iterator)
1000
1001generated += $(foreach o,$(versioned),$o$($o-version))
1002
1003ifeq (,$($(subdir)-version))
1004define o-iterator-doit
1005$(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1006 $(+force);
1007 $$(make-shlib-link)
1008endef
1009object-suffixes-left := $(versioned)
1010include $(o-iterator)
1011
1012define o-iterator-doit
1013$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1014 $$(do-install-program)
1015endef
1016object-suffixes-left := $(versioned)
1017include $(o-iterator)
1018else
1019define o-iterator-doit
1020$(inst_slibdir)/$o$($o-version): \
1021 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1022 $$(make-shlib-link)
1023endef
1024object-suffixes-left := $(versioned)
1025include $(o-iterator)
1026
1027define o-iterator-doit
1028$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1029 $$(do-install-program)
1030endef
1031object-suffixes-left := $(versioned)
1032include $(o-iterator)
1033endif
1034endif
1035
1036define do-install-so
1037$(do-install-program)
1038$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1039 $(filter-out %.so,$@))
1040endef
1041
1042so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1043$(foreach v,$(so-versions),\
1044 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1045 $(+force)
1046 $(do-install-so)
1047$(foreach v,$(so-versions),\
1048 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1049 $(do-install-so)
1050endif
1051
1052ifdef install-bin
1053$(addprefix $(inst_bindir)/,$(install-bin)): \
1054 $(inst_bindir)/%: $(objpfx)% $(+force)
1055 $(do-install-program)
1056endif
1057ifdef install-bin-script
1058$(addprefix $(inst_bindir)/,$(install-bin-script)): \
1059 $(inst_bindir)/%: $(objpfx)% $(+force)
1060 $(do-install-script)
1061endif
1062ifdef install-rootsbin
1063$(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1064 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1065 $(do-install-program)
1066endif
1067ifdef install-sbin
1068$(addprefix $(inst_sbindir)/,$(install-sbin)): \
1069 $(inst_sbindir)/%: $(objpfx)% $(+force)
1070 $(do-install-program)
1071endif
1072ifdef install-lib
1073install-lib.a := $(filter lib%.a,$(install-lib))
1074install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1075ifdef install-lib-non.a
1076$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1077 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1078 $(do-install)
1079endif
1080ifdef install-lib.a
1081$(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1082 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1083 $(do-install)
1084 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1085endif
1086endif
1087ifdef install-data
1088$(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1089 $(do-install)
1090endif
1091headers := $(strip $(headers))
1092ifdef headers
1093$(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1094 $(do-install)
1095endif # headers
1096
1097.PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1098 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1099 install-data-nosubdir install-headers-nosubdir
1100install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1101install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1102install-rootsbin-nosubdir: \
1103 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1104install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1105install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1106 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1107 $(addprefix $(libprefix),$(install-lib-non.a)))
1108install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1109install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1110install-others-nosubdir: $(install-others)
1111
1112# We need all the `-nosubdir' targets so that `install' in the parent
1113# doesn't depend on several things which each iterate over the subdirs.
1114# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1115# subroutine. Then in the parent `install-FOO' also causes subdir makes.
1116install-%:: install-%-nosubdir ;
1117
1118.PHONY: install install-no-libc.a-nosubdir
1119ifeq ($(build-programs),yes)
1120install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1121 install-bin-nosubdir install-bin-script-nosubdir \
1122 install-lib-nosubdir install-others-nosubdir \
1123 install-rootsbin-nosubdir install-sbin-nosubdir
1124else
1125install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1126 install-lib-nosubdir install-others-nosubdir
1127endif
1128install: install-no-libc.a-nosubdir
1129\f
1130# Command to compile $< in $(objdir) using the native libraries.
1131define native-compile
1132$(make-target-directory)
1133$(patsubst %/,cd % &&,$(objpfx)) \
1134$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1135 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1136endef
1137
1138# Command to compile $< in $(common-objdir) using the native libraries.
1139# We must cd to $(objdir) anyway so that $(..)config.h is valid.
1140define common-objdir-compile
1141$(patsubst %/,cd % &&,$(objpfx)) \
1142$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1143 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1144endef
1145
1146# We always want to use configuration definitions.
1147# Note that this is only used for commands running in $(objpfx).
1148ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1149
1150# Support the GNU standard name for this target.
1151.PHONY: check
1152check: tests
1153# Special target to run tests which cannot be run unconditionally.
1154# Maintainers should use this target.
1155.PHONY: xcheck
1156xcheck: xtests
1157
1158all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1159ifneq (,$(all-nonlib))
1160cpp-srcs-left = $(all-nonlib:=.c)
1161lib := nonlib
1162include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
1163endif
1164
1165# The include magic above causes those files to use this variable for flags.
1166CPPFLAGS-nonlib = -DNOT_IN_libc=1
1167
1168
1169ifeq ($(versioning),yes)
1170# Generate normalized lists of symbols, versions, and data sizes.
1171# This is handy for checking against existing library binaries.
1172
1173%.symlist: $(..)scripts/abilist.awk %.dynsym
1174 LC_ALL=C $(AWK) -f $^ > $@T
1175 mv -f $@T $@
1176
1177%.dynsym: %.so
1178 $(OBJDUMP) --dynamic-syms $< > $@T
1179 mv -f $@T $@
1180
1c68c264 1181check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
9ae10332
RM
1182 $(..)abilist/%.abilist $(objpfx)%.symlist
1183 $(check-abi)
1184check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1185 $(..)abilist/%.abilist $(common-objpfx)%.symlist
1186 $(check-abi)
1187define check-abi
1c68c264 1188 LC_ALL=C \
9ae10332 1189 $(AWK) -f $< -v 'config=$(check-abi-config)' \
1c68c264 1190 $(filter %.abilist,$^) \
fd54683c 1191 | { diff -pu0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
9ae10332 1192endef
fd54683c
RM
1193ifeq ($(enable-check-abi),warn)
1194check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1195endif
1c68c264 1196
643931fb 1197ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
0e56981e 1198-include $(common-objpfx)tls.make
fd54683c
RM
1199config-tls := notls
1200ifeq ($(use-tls),yes)
1201config-tls := tls
1202endif
1203ifeq ($(use-thread),yes)
1204config-tls := thread
1205endif
9ae10332 1206check-abi-config := \
fd54683c 1207 $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
9ae10332
RM
1208endif
1209
1210update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1211 $(objpfx)%.symlist
1212 $(update-abi)
1213update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1214 $(common-objpfx)%.symlist
1215 $(update-abi)
1c68c264 1216ifndef update-abi-config
9ae10332 1217define update-abi
1c68c264 1218 @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
9ae10332 1219endef
1c68c264 1220else
9ae10332 1221define update-abi
fd54683c 1222LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
9ae10332
RM
1223 > $(..)abilist/$*.abilist.new
1224@if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1225 then rm -f $(..)abilist/$*.abilist.new; \
1226 echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1227 else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1228 echo '*** Now check $*.abilist changes for correctness ***'; \
1229 fi
1230endef
1c68c264
RM
1231endif
1232
1233.PHONY: update-abi check-abi
1234update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1235check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1236ifdef subdir
1237subdir_check-abi: check-abi
1238subdir_update-abi: update-abi
1239else
1240check-abi: subdir_check-abi
1241update-abi: subdir_update-abi
1242endif
1243
1c68c264
RM
1244ifeq ($(subdir),elf)
1245check-abi: check-abi-libc
1246update-abi: update-abi-libc
1247common-generated += libc.symlist
1248endif
1249
fd54683c
RM
1250ifeq ($(build-shared),yes)
1251ifneq ($(enable-check-abi),no)
94659495
RM
1252ifdef subdir
1253tests: check-abi
1254endif
1255endif
fd54683c 1256endif
94659495 1257
1c68c264 1258endif
aad08dba 1259
9ae10332
RM
1260# There's no good place to put this - here will do.
1261# The dependencies are wrong if it's run from the top level.
1262ifeq ($(filter %posix, $(sysdirs)),)
1263L_tmpnam = 1
1264TMP_MAX = 0
1265L_ctermid = 1
1266L_cuserid = 1
1267else
1268L_tmpnam = 20
1269TMP_MAX = 238328
1270L_ctermid = 9
1271L_cuserid = 9
1272endif
1273stdio_lim = $(common-objpfx)bits/stdio_lim.h
1274
1275$(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1276$(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1277 $(common-objpfx)config.make
1278 $(make-target-directory)
1279 echo '#include "$(..)posix/bits/posix1_lim.h"' | \
1280 SUNPRO_DEPENDENCIES='$(@:st=dT) $@' \
1281 $(CC) $(+includes) -E -dM -xc - -o $(@:st=hT)
1282 echo '#include "$(..)misc/sys/uio.h"' | \
1283 SUNPRO_DEPENDENCIES='$(@:st=dT) $@' \
1284 $(CC) -D_LIBC=1 $(+includes) -E -dM -xc - | cat - >> $(@:st=hT)
1285ifdef sed-remove-objpfx
1286 sed $(sed-remove-objpfx) $(@:st=dT) > $(@:st=dt)
1287 cat $(@:st=dt) >> $(@:st=d)
1288else
1289 cat $(@:st=dT) >> $(@:st=d)
1290endif
1291 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1292 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1293 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1294 fopen_max=$${fopen_max:-16}; \
1295 filename_max=$${filename_max:-1024}; \
1296 if [ -z $$iov_max ]; then \
1297 define_iov_max="# undef IOV_MAX"; \
1298 else \
1299 define_iov_max="# define IOV_MAX $$iov_max"; \
1300 fi; \
1301 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1302 -e "s/@FILENAME_MAX@/$$filename_max/" \
1303 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1304 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1305 -e "s/@L_ctermid@/$(L_ctermid)/" \
1306 -e "s/@L_cuserid@/$(L_cuserid)/" \
1307 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1308 $< > $(@:st=h.new)
1309 $(move-if-change) $(@:st=h.new) $(@:st=h)
1310# Remove these last so that they can be examined if something went wrong.
1311 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1312 touch $@
1313# Get dependencies.
1314ifndef no_deps
1315-include $(stdio_lim:h=d)
1316endif
1317common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1c68c264
RM
1318\f
1319.PHONY: TAGS
1320TAGS: $(objpfx)distinfo $(..)MakeTAGS
1321 $(MAKE) $(addprefix -f ,$^) $@
1322
1323$(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1324 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1325FORCE:
1326
1327
1328.PHONY: echo-headers
1329echo-headers:
1330 @echo $(headers)
1331
1332\f
1333# Common cleaning targets.
1334
1335.PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1336clean: common-clean
1337mostlyclean: common-mostlyclean
1338
1339do-tests-clean:
1340 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1341 $(test-srcs)) \
1342 $(addsuffix -bp.out,$(tests) $(xtests) \
1343 $(test-srcs)))
1344
1345# Remove the object files.
1346common-mostlyclean:
1347 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1348 $(others) $(sysdep-others) stubs \
1349 $(addsuffix .o,$(tests) $(xtests) \
1350 $(test-srcs) $(others) \
1351 $(sysdep-others)) \
1352 $(addsuffix -bp,$(tests) $(xtests) \
1353 $(test-srcs)) \
1354 $(addsuffix .out,$(tests) $(xtests) \
1355 $(test-srcs)) \
1356 $(addsuffix -bp.out,$(tests) $(xtests) \
1357 $(test-srcs)))
1358 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1359 $(install-lib.so) \
1360 $(install-lib.so:%.so=%_pic.a))
1361 -rm -f core
1362 -rm -f $(objpfx)rtld-*.os
1363 $(rmobjs)
1364define rmobjs
1365$(foreach o,$(object-suffixes-for-libc),
1366-rm -f $(objpfx)stamp$o $(o-objects))
1367endef
1368
1369# Also remove the dependencies and generated source files.
1370common-clean: common-mostlyclean
1371 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
1372 -rm -f $(objpfx)rtld-*.d
1373 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1374 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1375 -rm -f $(objpfx)distinfo
1376\f
1377# Produce a file `stubs' which contains `#define __stub_FUNCTION'
1378# for each function which is a stub. We grovel over all the .d files
1379# looking for references to <stub-tag.h>. Then we grovel over each
1380# referenced source file to see what stub function it defines.
1381
1382ifdef objpfx
1383.PHONY: stubs # The parent Makefile calls this target.
1384stubs: $(objpfx)stubs
1385endif
1c68c264
RM
1386$(objpfx)stubs: $(+depfiles)
1387# Use /dev/null since `...` might expand to empty.
fd54683c 1388 (s=`cd $(sysdep_dir) && $(PWD_P)`; \
1c68c264
RM
1389 $(patsubst %/,cd % &&,$(objpfx)) \
1390 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
fd54683c
RM
1391 `sed -n -e 's@$(sysdep_dir)/@'"$$s"'/@g' \
1392 -e 's@\$$(common-objpfx)@$(..)@g' -e 's@\$$(objpfx)@@g' \
1393 -e '/: *[^ ]/{s@^.*: *\([^ ]*\) .*$$@\1@; h; }' \
1394 -e '/:$$/d' \
1395 -e '/stub-tag\.h/{; g; p; }' \
1c68c264
RM
1396 $(patsubst $(objpfx)%,%,$^) /dev/null` \
1397 /dev/null) > $@T
1398 mv -f $@T $@
1399\f
1400# Make the distribution tar file.
1401
1402.PHONY: dist
1403dist: $(objpfx)distinfo $(..)Make-dist
1404 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1405
1406# Avoid depending on source files found in sysdeps dirs,
1407# because the references affect implicit rule selection.
1408dist: $(filter-out %.c %.S %.s,$(distribute))
1409
1410# We used to simply export all these variables, but that frequently made the
1411# environment get too large. Instead, we write all the information into
1412# a generated makefile fragment `distinfo', and then include it with -f in
1413# the sub-make that makes the distribution (above).
1414$(objpfx)distinfo: Makefile $(..)Makerules \
1415 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1416 $(make-target-directory)
1417 $(distinfo-vars)
1418 mv -f $@.new $@
1419.PHONY: subdir_distinfo
1420subdir_distinfo: $(objpfx)distinfo
1421
1422define distinfo-vars
1423rm -f $@.new
1424echo > $@.new 'subdir := $(subdir)'
1425$(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1426 headers sysdep_headers distribute dont_distribute generated \
1427 others tests xtests test-srcs extra-libs versioned \
1428 $(extra-libs:%=%-routines) \
1429 $(addprefix install-,lib lib.so data bin bin-script sbin others),
1430echo >> $@.new '$(subdir)-$(var) := $($(var))'
1431echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1432endef
1433\f
1434ifneq (,$(strip $(gpl2lgpl)))
1435ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1436# Snarf from the master source and frob the copying notice.
1437$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1438 sed -f $^ > $@-tmp
1439# So I don't edit them by mistake.
1440 chmod a-w $@-tmp
1441 mv -f $@-tmp $@
1442ifeq ($(with-cvs),yes)
1443 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1444endif
1445endif
1446endif
1447
1448# Local Variables:
1449# mode: makefile
1450# End: