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