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