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