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