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