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