]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makerules
* Versions (libpthread: GLIBC_2.2): Remove
[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
514define build-shlib
515$(build-shlib-helper) \
516 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
517 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
518 sed -e '/^=========/,/^=========/!d;/^=========/d' \
519 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
520 $(LDSEDCMD-$(@F:lib%.so=%).so) > $@.lds
521rm -f $@.new
522$(build-shlib-helper) -o $@ -T $@.lds \
523 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
524rm -f $@.lds
525endef
526else
527ifneq (,$(findstring aix,$(config-os)))
528define build-shlib
529$(build-shlib-helper) \
530 -o $@ \
531 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
532 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
533endef
534define build-shlib
535$(build-shlib-helper) \
536 $(build-shlib-objlist)
537endef
538endif
539endif
540
541ifneq (,$(findstring aix,$(config-os)))
542define build-module-helper
543$(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
544 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
545 $(load-map-file) \
546 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
547 -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
548endef
549else
550define build-module-helper
551$(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
552 -B$(csu-objpfx) $(load-map-file) \
553 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
554 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
555endef
556endif
557
558# This macro is similar to build-shlib but it does not define a soname
559# and it does not depend on the destination name to start with `lib'.
560ifeq (yes,$(elf))
561# binutils only position loadable notes into the first page for binaries,
562# not for shared objects
563define build-module
564$(build-module-helper) \
565 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
566 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
567 sed -e '/^=========/,/^=========/!d;/^=========/d' \
568 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
569 > $@.lds
570rm -f $@.new
571$(build-module-helper) -o $@ -T $@.lds \
572 $(csu-objpfx)abi-note.o $(build-module-objlist)
573rm -f $@.lds
574endef
575else
576ifneq (,$(findstring aix,$(config-os)))
577define build-module
578$(build-module-helper) \
579 -o $@ \
580 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
581 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
582endef
583else
584define build-module
585define build-module
586$(build-module-helper) \
587 -o $@ \
588 $(build-module-objlist)
589endef
590endif
591endif
592
593build-module-helper-objlist = \
594 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
595 $(filter-out $(map-file) $(+preinit) $(+postinit),$^))
596whole-archive := -Wl,--whole-archive
597
598build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
599build-shlib-objlist = $(build-module-helper-objlist) \
600 $(LDLIBS-$(@F:lib%.so=%).so)
601
602# Don't try to use -lc when making libc.so itself.
603# Also omits crti.o and crtn.o, which we do not want
604# since we define our own `.init' section specially.
605LDFLAGS-c.so = -nostdlib -nostartfiles
606# But we still want to link libc.so against $(gnulib).
607LDLIBS-c.so += $(gnulib)
608# Give libc.so an entry point and make it directly runnable itself.
609LDFLAGS-c.so += -e __libc_main
610# Force the backward compatibility EH functions to be linked.
611LDFLAGS-c.so += -u __register_frame
612# Pre-link the objects of libc_pic.a so that we can locally resolve
613# COMMON symbols before we link against ld.so. This is because ld.so
614# contains some of libc_pic.a already, which will prevent the COMMONs
615# from being allocated in libc.so, which introduces evil dependencies
616# between libc.so and ld.so, which can make it impossible to upgrade.
617ifeq ($(elf),yes)
618$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
619 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
620 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
621LDSEDCMD-c.so = -e 's/^.*\*(\.dynbss).*$$/& __start___libc_freeres_ptrs = .; *(__libc_freeres_ptrs) __stop___libc_freeres_ptrs = .;/'
622# Use our own special initializer and finalizer files for libc.so.
623$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
624 $(common-objpfx)libc_pic.os \
625 $(elfobjdir)/sofini.os \
626 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
627 $(build-shlib)
628ifeq ($(versioning),yes)
629$(common-objpfx)libc.so: $(common-objpfx)libc.map
630endif
631common-generated += libc.so libc_pic.os
632ifdef libc.so-version
633$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
634 $(make-link)
635common-generated += libc.so$(libc.so-version)
636endif
637endif
638else
639ifneq (,$(findstring aix,$(config-os)))
640$(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
641 @rm -f $@
642 (echo '#!'; \
643 dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
644 sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
645 /lib/syscalls.exp > $(common-objpfx)syscalls.exp
646 $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
647 -bE:$(common-objpfx)syscalls.exp \
648 -bI:$(common-objpfx)syscalls.exp \
649 -L$(common-objpfx) -o $@ $^
650# AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
651 cp $@ $(common-objpfx)shr.o
652 $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
653endif
654endif
655\f
656# Figure out the source filenames in this directory.
657
658override sources := $(addsuffix .c,\
659 $(filter-out $(elided-routines),\
660 $(routines) $(aux) \
661 $(sysdep_routines)))
662sysdep_routines := $(sysdep_routines)
663
664headers := $(headers) $(sysdep_headers)
665
666# This is the list of all object files, gotten by
667# replacing every ".c" in `sources' with a ".o".
668# We also add bounded-pointer thunks, which are later
669# elided for all suffixes except for `.ob'.
670override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
671 $(patsubst %,$(bppfx)%.o,\
672 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
673
674
675# The makefile may define $(extra-libs) with `libfoo libbar'
676# to build libfoo.a et al from the modules listed in $(libfoo-routines).
677ifdef extra-libs
678# extra-lib.mk is included once for each extra lib to define rules
679# to build it, and to add its objects to the various variables.
680# During its evaluation, $(lib) is set to the name of the library.
681extra-libs-left := $(extra-libs)
682include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
683endif
684\f
685+depfiles := $(sources:.c=.d) \
686 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
687 $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
688ifeq ($(build-programs),yes)
689+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
690endif
691+depfiles := $(addprefix $(objpfx),\
692 $(filter-out $(addsuffix .d,$(omit-deps)),\
9ae10332
RM
693 $(+depfiles)))
694
695# Avoid the .h.d files for any .sym files whose .h files don't exist yet.
696# They will be generated when they're needed, and trying too early won't work.
697+gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
698+depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
699 $(+gen-as-const)))
1c68c264
RM
700
701ifdef +depfiles
702ifneq ($(no_deps),t)
703-include $(+depfiles)
704endif
705endif
706\f\f
707# Maximize efficiency by minimizing the number of rules.
708.SUFFIXES: # Clear the suffix list. We don't use suffix rules.
709# Don't define any builtin rules.
710MAKEFLAGS := $(MAKEFLAGS)r
711
712# Generic rule for making directories.
713%/:
714# mkdir isn't smart enough to strip a trailing /.
715 mkdir $(@:%/=%)
716\f
717# Make sure that object files are not removed
718# when they are intermediates between sources and library members.
719.PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
720
721# Make sure that the parent library archive is never removed.
722.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
723\f
724# Use the verbose option of ar and tar when not running silently.
725ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
726verbose := v
727else # -s
728verbose :=
729endif # not -s
730
731ARFLAGS := r$(verbose)
732CREATE_ARFLAGS := cru$(verbose)
733\f
734# This makes all the object files in the parent library archive.
735
736.PHONY: lib lib-noranlib
737lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
738lib-noranlib: libobjs
739
740# For object-suffix $o, the list of objects with that suffix.
741# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
742o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
743 $(elide-routines$o)),\
744 $(objects))) \
745 $(addprefix $(objpfx),$(o-objects$o))
746
747others: $(addprefix $(objpfx),$(install-lib))
748
749ifndef objects
750
751# Create the stamp$o files to keep the parent makefile happy.
752subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
753$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
754 $(make-target-directory)
755 rm -f $@; > $@
756else
757
758# Define explicit rules to update each $(objpfx)stamp.SUFFIX
759# timestamp file; these rules (one explicit rule is generated for each
760# object suffix) write a list of objects to update in the stamp file.
761# The parent will then actually add them all to the archive in the
762# archive rule, below.
763define o-iterator-doit
764$(objpfx)stamp$o: $(o-objects); $$(do-stamp)
765endef
766define do-stamp
767echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
768mv -f $@T $@
769endef
770object-suffixes-left := $(object-suffixes-for-libc)
771include $(o-iterator)
772
773endif
774
775# Now define explicit rules to build the library archives; these depend
776# on the stamp files built above.
777define o-iterator-doit
778$(common-objpfx)$(patsubst %,$(libtype$o),c): \
779 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
780endef
781define do-makelib
782cd $(common-objdir) && \
783$(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
784$(RANLIB) $@
785endef
786subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
787subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
788ifndef subdir
789$(subdirs-stamps): subdir_lib;
790endif
791object-suffixes-left = $(object-suffixes-for-libc)
792include $(o-iterator)
793
794
795# This makes all the object files.
796.PHONY: objects objs libobjs extra-objs
797objects objs: libobjs extra-objs
798libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
799extra-objs: $(addprefix $(objpfx),$(extra-objs))
800
801# Canned sequence for building an extra library archive.
802define build-extra-lib
803$(patsubst %/,cd % &&,$(objpfx)) \
804$(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
805 $(patsubst $(objpfx)%,%,$^)
806$(RANLIB) $@
807endef
808\f
809# Installation.
810
811.PHONY: force-install
812force-install:
813
814# $(install-lib) are installed from the object directory into $(libdir);
815# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
816# unless they also appear in $(non-lib.a). $(install-data) are installed
817# as they are into $(datadir). $(headers) are installed as they are in
818# $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
819# are installed from the object directory into $(bindir), $(bindir) and
820# $(sbindir), respectively. $(install-others) are absolute path names of
821# files to install; rules to install them are defined elsewhere.
822
823# The simple library name to install libc.a under.
824# This could be defined by a sysdep Makefile.
825ifndef libc-name
826libc-name := c
827endif
828
829define do-install
830$(make-target-directory)
831$(INSTALL_DATA) $< $@
832endef
833
834# Make the target directory if it doesn't exist, using the `mkinstalldirs'
835# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
836define make-target-directory
837$(addprefix $(..)./scripts/mkinstalldirs ,\
838 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
839endef
840
841# Any directory (parent or subdir) should install libc.a; this way
842# "make install" in a subdir is guaranteed to install everything it changes.
843installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
844 $(inst_libdir)/$(patsubst %,$(libtype$o),\
845 $(libprefix)$(libc-name)))
846install: $(installed-libcs)
847$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
848 $(make-target-directory)
849 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
850# Running ranlib after installing makes the __.SYMDEF time stamp up to
851# date, which avoids messages from some linkers.
852 $(RANLIB) $@
853
854define do-install-program
855$(make-target-directory)
856$(INSTALL_PROGRAM) $< $@.new
857mv -f $@.new $@
858endef
859
860define do-install-script
861$(make-target-directory)
862$(INSTALL_SCRIPT) $< $@.new
863mv -f $@.new $@
864endef
865
866install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
867install-lib := $(filter-out %.so %_pic.a,$(install-lib))
868
869ifeq (yes,$(build-shared))
870# Find which .so's have versions.
871versioned := $(strip $(foreach so,$(install-lib.so),\
872 $(patsubst %,$(so),$($(so)-version))))
873
874install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
875install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
876
cc8bfce9
RM
877# For versioned libraries, we install three files:
878# $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
879# $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
880# $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
7a0c303e 881V := $(firstword $($(subdir)-version) $(version))
cc8bfce9
RM
882install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
883 $(foreach L,$(install-lib.so-versioned),\
884 $(inst_libdir)/$L \
7a0c303e 885 $(inst_slibdir)/$(L:.so=)-$V.so \
cc8bfce9 886 $(inst_slibdir)/$L$($L-version))
1c68c264
RM
887
888# Install all the unversioned shared libraries.
889$(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
890 $(objpfx)%.so $(+force)
891 $(do-install-program)
892
893ifneq ($(findstring -s,$(LN_S)),)
894define make-link
895rm -f $@.new
896$(SHELL) $(..)scripts/rellns-sh $< $@.new
897mv -f $@.new $@
898endef
899else
900# If we have no symbolic links don't bother with rellns-sh.
901define make-link
902rm -f $@.new
903$(LN_S) $< $@.new
904mv -f $@.new $@
905endef
906endif
907
908ifeq (yes,$(build-shared))
909ifeq (no,$(cross-compiling))
910symbolic-link-prog := $(common-objpfx)elf/sln
911symbolic-link-list := $(common-objpfx)elf/symlink.list
912define make-shlib-link
913echo $(<F) $@ >> $(symbolic-link-list)
914endef
915else # cross-compiling
916# We need a definition that can be used by elf/Makefile's install rules.
917symbolic-link-prog = $(LN_S)
918endif
919endif
920ifndef make-shlib-link
921define make-shlib-link
922rm -f $@
923$(LN_S) $(<F) $@
924endef
925endif
926
927ifdef libc.so-version
928# For a library specified to be version N, install three files:
929# libc.so -> libc.so.N (e.g. libc.so.6)
930# libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
931
932$(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
933 $(+force)
934 $(make-shlib-link)
935$(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
936 $(do-install-program)
937install: $(inst_slibdir)/libc.so$(libc.so-version)
938
939# This fragment of linker script gives the OUTPUT_FORMAT statement
940# for the configuration we are building. We put this statement into
941# the linker scripts we install for -lc et al so that they will not be
942# used by a link for a different format on a multi-architecture system.
943$(common-objpfx)format.lds: $(..)scripts/output-format.sed \
944 $(common-objpfx)config.make \
945 $(common-objpfx)config.h $(..)Makerules
946 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
947 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
948 | sed -n -f $< > $@.new
949 rm -f $@.so
950 mv -f $@.new $@
951common-generated += format.lds
952
953ifndef subdir
954# What we install as libc.so for programs to link against is in fact a
955# link script. It contains references for the various libraries we need.
956# The libc.so object is not complete since some functions are only defined
957# in libc_nonshared.a.
958# We need to use absolute paths since otherwise local copies (if they exist)
959# of the files are taken by the linker.
960install: $(inst_libdir)/libc.so
961$(inst_libdir)/libc.so: $(common-objpfx)format.lds \
962 $(common-objpfx)libc.so$(libc.so-version) \
963 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
964 $(libprefix)$(libc-name)) \
965 $(+force)
966 (echo '/* GNU ld script';\
967 echo ' Use the shared library, but some functions are only in';\
968 echo ' the static library, so try that secondarily. */';\
969 cat $<; \
970 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
971 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
972 ')' \
973 ) > $@.new
974 mv -f $@.new $@
975
976endif
977
978else
979install: $(inst_slibdir)/libc.so
980$(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
981 $(do-install-program)
982endif
983
984ifneq (,$(versioned))
985# Produce three sets of rules as above for all the smaller versioned libraries.
986
987define o-iterator-doit
988$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
989endef
2afbfec4
RM
990object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
991ifneq (,$(object-suffixes-left))
1c68c264 992include $(o-iterator)
2afbfec4 993endif
1c68c264
RM
994
995# Make symlinks in the build directory, because the versioned names might
996# be referenced by a DT_NEEDED in another library.
997define o-iterator-doit
998$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
999endef
1000object-suffixes-left := $(versioned)
1001include $(o-iterator)
1002
1003generated += $(foreach o,$(versioned),$o$($o-version))
1004
1005ifeq (,$($(subdir)-version))
1006define o-iterator-doit
1007$(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1008 $(+force);
1009 $$(make-shlib-link)
1010endef
1011object-suffixes-left := $(versioned)
1012include $(o-iterator)
1013
1014define o-iterator-doit
1015$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1016 $$(do-install-program)
1017endef
1018object-suffixes-left := $(versioned)
1019include $(o-iterator)
1020else
1021define o-iterator-doit
1022$(inst_slibdir)/$o$($o-version): \
1023 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1024 $$(make-shlib-link)
1025endef
1026object-suffixes-left := $(versioned)
1027include $(o-iterator)
1028
1029define o-iterator-doit
1030$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1031 $$(do-install-program)
1032endef
1033object-suffixes-left := $(versioned)
1034include $(o-iterator)
1035endif
1036endif
1037
1038define do-install-so
1039$(do-install-program)
1040$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1041 $(filter-out %.so,$@))
1042endef
1043
1044so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1045$(foreach v,$(so-versions),\
1046 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1047 $(+force)
1048 $(do-install-so)
1049$(foreach v,$(so-versions),\
1050 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1051 $(do-install-so)
1052endif
1053
1054ifdef install-bin
1055$(addprefix $(inst_bindir)/,$(install-bin)): \
1056 $(inst_bindir)/%: $(objpfx)% $(+force)
1057 $(do-install-program)
1058endif
1059ifdef install-bin-script
1060$(addprefix $(inst_bindir)/,$(install-bin-script)): \
1061 $(inst_bindir)/%: $(objpfx)% $(+force)
1062 $(do-install-script)
1063endif
1064ifdef install-rootsbin
1065$(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1066 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1067 $(do-install-program)
1068endif
1069ifdef install-sbin
1070$(addprefix $(inst_sbindir)/,$(install-sbin)): \
1071 $(inst_sbindir)/%: $(objpfx)% $(+force)
1072 $(do-install-program)
1073endif
1074ifdef install-lib
1075install-lib.a := $(filter lib%.a,$(install-lib))
1076install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1077ifdef install-lib-non.a
1078$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1079 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1080 $(do-install)
1081endif
1082ifdef install-lib.a
1083$(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1084 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1085 $(do-install)
1086 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1087endif
1088endif
1089ifdef install-data
1090$(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1091 $(do-install)
1092endif
1093headers := $(strip $(headers))
1094ifdef headers
1095$(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1096 $(do-install)
1097endif # headers
1098
1099.PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1100 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1101 install-data-nosubdir install-headers-nosubdir
1102install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1103install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1104install-rootsbin-nosubdir: \
1105 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1106install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1107install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1108 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1109 $(addprefix $(libprefix),$(install-lib-non.a)))
1110install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1111install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1112install-others-nosubdir: $(install-others)
1113
1114# We need all the `-nosubdir' targets so that `install' in the parent
1115# doesn't depend on several things which each iterate over the subdirs.
1116# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1117# subroutine. Then in the parent `install-FOO' also causes subdir makes.
1118install-%:: install-%-nosubdir ;
1119
1120.PHONY: install install-no-libc.a-nosubdir
1121ifeq ($(build-programs),yes)
1122install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1123 install-bin-nosubdir install-bin-script-nosubdir \
1124 install-lib-nosubdir install-others-nosubdir \
1125 install-rootsbin-nosubdir install-sbin-nosubdir
1126else
1127install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1128 install-lib-nosubdir install-others-nosubdir
1129endif
1130install: install-no-libc.a-nosubdir
1131\f
1132# Command to compile $< in $(objdir) using the native libraries.
1133define native-compile
1134$(make-target-directory)
1135$(patsubst %/,cd % &&,$(objpfx)) \
1136$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1137 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1138endef
1139
1140# Command to compile $< in $(common-objdir) using the native libraries.
1141# We must cd to $(objdir) anyway so that $(..)config.h is valid.
1142define common-objdir-compile
1143$(patsubst %/,cd % &&,$(objpfx)) \
1144$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1145 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1146endef
1147
1148# We always want to use configuration definitions.
1149# Note that this is only used for commands running in $(objpfx).
1150ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1151
1152# Support the GNU standard name for this target.
1153.PHONY: check
1154check: tests
1155# Special target to run tests which cannot be run unconditionally.
1156# Maintainers should use this target.
1157.PHONY: xcheck
1158xcheck: xtests
1159
1160all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1161ifneq (,$(all-nonlib))
1162cpp-srcs-left = $(all-nonlib:=.c)
1163lib := nonlib
1164include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
1165endif
1166
1167# The include magic above causes those files to use this variable for flags.
1168CPPFLAGS-nonlib = -DNOT_IN_libc=1
1169
1170
1171ifeq ($(versioning),yes)
1172# Generate normalized lists of symbols, versions, and data sizes.
1173# This is handy for checking against existing library binaries.
1174
1175%.symlist: $(..)scripts/abilist.awk %.dynsym
1176 LC_ALL=C $(AWK) -f $^ > $@T
1177 mv -f $@T $@
1178
1179%.dynsym: %.so
1180 $(OBJDUMP) --dynamic-syms $< > $@T
1181 mv -f $@T $@
1182
1c68c264 1183check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
9ae10332
RM
1184 $(..)abilist/%.abilist $(objpfx)%.symlist
1185 $(check-abi)
1186check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1187 $(..)abilist/%.abilist $(common-objpfx)%.symlist
1188 $(check-abi)
1189define check-abi
1c68c264 1190 LC_ALL=C \
9ae10332 1191 $(AWK) -f $< -v 'config=$(check-abi-config)' \
1c68c264
RM
1192 $(filter %.abilist,$^) \
1193 | diff -pu0 - $(filter %.symlist,$^)
9ae10332 1194endef
1c68c264 1195
643931fb 1196ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
0e56981e 1197-include $(common-objpfx)tls.make
9ae10332
RM
1198config-tls-yes := tls
1199config-tls-no := notls
1200check-abi-config := \
1201 $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls-$(use-thread))
1202endif
1203
1204update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1205 $(objpfx)%.symlist
1206 $(update-abi)
1207update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1208 $(common-objpfx)%.symlist
1209 $(update-abi)
1c68c264 1210ifndef update-abi-config
9ae10332 1211define update-abi
1c68c264 1212 @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
9ae10332 1213endef
1c68c264 1214else
9ae10332
RM
1215define update-abi
1216LC_ALL=C $(AWK) -v config=$(update-abi-config) -f $^ \
1217 > $(..)abilist/$*.abilist.new
1218@if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1219 then rm -f $(..)abilist/$*.abilist.new; \
1220 echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1221 else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1222 echo '*** Now check $*.abilist changes for correctness ***'; \
1223 fi
1224endef
1c68c264
RM
1225endif
1226
1227.PHONY: update-abi check-abi
1228update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1229check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1230ifdef subdir
1231subdir_check-abi: check-abi
1232subdir_update-abi: update-abi
1233else
1234check-abi: subdir_check-abi
1235update-abi: subdir_update-abi
1236endif
1237
9ae10332 1238# Enable this when all the .abilist files are in place.
1c68c264 1239#tests: check-abi
1c68c264
RM
1240
1241ifeq ($(subdir),elf)
1242check-abi: check-abi-libc
1243update-abi: update-abi-libc
1244common-generated += libc.symlist
1245endif
1246
1247endif
aad08dba 1248
9ae10332
RM
1249# There's no good place to put this - here will do.
1250# The dependencies are wrong if it's run from the top level.
1251ifeq ($(filter %posix, $(sysdirs)),)
1252L_tmpnam = 1
1253TMP_MAX = 0
1254L_ctermid = 1
1255L_cuserid = 1
1256else
1257L_tmpnam = 20
1258TMP_MAX = 238328
1259L_ctermid = 9
1260L_cuserid = 9
1261endif
1262stdio_lim = $(common-objpfx)bits/stdio_lim.h
1263
1264$(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1265$(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1266 $(common-objpfx)config.make
1267 $(make-target-directory)
1268 echo '#include "$(..)posix/bits/posix1_lim.h"' | \
1269 SUNPRO_DEPENDENCIES='$(@:st=dT) $@' \
1270 $(CC) $(+includes) -E -dM -xc - -o $(@:st=hT)
1271 echo '#include "$(..)misc/sys/uio.h"' | \
1272 SUNPRO_DEPENDENCIES='$(@:st=dT) $@' \
1273 $(CC) -D_LIBC=1 $(+includes) -E -dM -xc - | cat - >> $(@:st=hT)
1274ifdef sed-remove-objpfx
1275 sed $(sed-remove-objpfx) $(@:st=dT) > $(@:st=dt)
1276 cat $(@:st=dt) >> $(@:st=d)
1277else
1278 cat $(@:st=dT) >> $(@:st=d)
1279endif
1280 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1281 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1282 iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
1283 fopen_max=$${fopen_max:-16}; \
1284 filename_max=$${filename_max:-1024}; \
1285 if [ -z $$iov_max ]; then \
1286 define_iov_max="# undef IOV_MAX"; \
1287 else \
1288 define_iov_max="# define IOV_MAX $$iov_max"; \
1289 fi; \
1290 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1291 -e "s/@FILENAME_MAX@/$$filename_max/" \
1292 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1293 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1294 -e "s/@L_ctermid@/$(L_ctermid)/" \
1295 -e "s/@L_cuserid@/$(L_cuserid)/" \
1296 -e "s/@define_IOV_MAX@/$$define_iov_max/" \
1297 $< > $(@:st=h.new)
1298 $(move-if-change) $(@:st=h.new) $(@:st=h)
1299# Remove these last so that they can be examined if something went wrong.
1300 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1301 touch $@
1302# Get dependencies.
1303ifndef no_deps
1304-include $(stdio_lim:h=d)
1305endif
1306common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1c68c264
RM
1307\f
1308.PHONY: TAGS
1309TAGS: $(objpfx)distinfo $(..)MakeTAGS
1310 $(MAKE) $(addprefix -f ,$^) $@
1311
1312$(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1313 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1314FORCE:
1315
1316
1317.PHONY: echo-headers
1318echo-headers:
1319 @echo $(headers)
1320
1321\f
1322# Common cleaning targets.
1323
1324.PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1325clean: common-clean
1326mostlyclean: common-mostlyclean
1327
1328do-tests-clean:
1329 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1330 $(test-srcs)) \
1331 $(addsuffix -bp.out,$(tests) $(xtests) \
1332 $(test-srcs)))
1333
1334# Remove the object files.
1335common-mostlyclean:
1336 -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1337 $(others) $(sysdep-others) stubs \
1338 $(addsuffix .o,$(tests) $(xtests) \
1339 $(test-srcs) $(others) \
1340 $(sysdep-others)) \
1341 $(addsuffix -bp,$(tests) $(xtests) \
1342 $(test-srcs)) \
1343 $(addsuffix .out,$(tests) $(xtests) \
1344 $(test-srcs)) \
1345 $(addsuffix -bp.out,$(tests) $(xtests) \
1346 $(test-srcs)))
1347 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1348 $(install-lib.so) \
1349 $(install-lib.so:%.so=%_pic.a))
1350 -rm -f core
1351 -rm -f $(objpfx)rtld-*.os
1352 $(rmobjs)
1353define rmobjs
1354$(foreach o,$(object-suffixes-for-libc),
1355-rm -f $(objpfx)stamp$o $(o-objects))
1356endef
1357
1358# Also remove the dependencies and generated source files.
1359common-clean: common-mostlyclean
1360 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
1361 -rm -f $(objpfx)rtld-*.d
1362 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1363 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1364 -rm -f $(objpfx)distinfo
1365\f
1366# Produce a file `stubs' which contains `#define __stub_FUNCTION'
1367# for each function which is a stub. We grovel over all the .d files
1368# looking for references to <stub-tag.h>. Then we grovel over each
1369# referenced source file to see what stub function it defines.
1370
1371ifdef objpfx
1372.PHONY: stubs # The parent Makefile calls this target.
1373stubs: $(objpfx)stubs
1374endif
1375s = $(sysdep_dir)/generic
1376$(objpfx)stubs: $(+depfiles)
1377# Use /dev/null since `...` might expand to empty.
1378 (s=`cd $s && $(PWD_P)`; \
1379 $(patsubst %/,cd % &&,$(objpfx)) \
1380 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1381 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
1382 -e '/stub-tag\.h/{; g; p; }' \
1383 $(patsubst $(objpfx)%,%,$^) /dev/null` \
1384 /dev/null) > $@T
1385 mv -f $@T $@
1386\f
1387# Make the distribution tar file.
1388
1389.PHONY: dist
1390dist: $(objpfx)distinfo $(..)Make-dist
1391 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1392
1393# Avoid depending on source files found in sysdeps dirs,
1394# because the references affect implicit rule selection.
1395dist: $(filter-out %.c %.S %.s,$(distribute))
1396
1397# We used to simply export all these variables, but that frequently made the
1398# environment get too large. Instead, we write all the information into
1399# a generated makefile fragment `distinfo', and then include it with -f in
1400# the sub-make that makes the distribution (above).
1401$(objpfx)distinfo: Makefile $(..)Makerules \
1402 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1403 $(make-target-directory)
1404 $(distinfo-vars)
1405 mv -f $@.new $@
1406.PHONY: subdir_distinfo
1407subdir_distinfo: $(objpfx)distinfo
1408
1409define distinfo-vars
1410rm -f $@.new
1411echo > $@.new 'subdir := $(subdir)'
1412$(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1413 headers sysdep_headers distribute dont_distribute generated \
1414 others tests xtests test-srcs extra-libs versioned \
1415 $(extra-libs:%=%-routines) \
1416 $(addprefix install-,lib lib.so data bin bin-script sbin others),
1417echo >> $@.new '$(subdir)-$(var) := $($(var))'
1418echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1419endef
1420\f
1421ifneq (,$(strip $(gpl2lgpl)))
1422ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1423# Snarf from the master source and frob the copying notice.
1424$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1425 sed -f $^ > $@-tmp
1426# So I don't edit them by mistake.
1427 chmod a-w $@-tmp
1428 mv -f $@-tmp $@
1429ifeq ($(with-cvs),yes)
1430 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1431endif
1432endif
1433endif
1434
1435# Local Variables:
1436# mode: makefile
1437# End: