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