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