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