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