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