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