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