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