]> git.ipfire.org Git - thirdparty/glibc.git/blob - Makerules
nptl: Fix tst-cancel30 on kernels without ppoll_time64 support
[thirdparty/glibc.git] / Makerules
1 # Copyright (C) 1991-2019 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 # <http://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 endif
428
429 # Generate .dT files as we compile.
430 compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
431 compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
432 compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
433 compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
434
435 # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
436 # track system includes here, they may spuriously trigger an install rule,
437 # and would cause the check-local-headers test to fail.
438 native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
439
440 # GCC can grok options after the file name, and it looks nicer that way.
441 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
442 compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
443 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
444 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
445 COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
446 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
447 $(ASFLAGS) $(ASFLAGS-$(suffix $@))
448
449 # We need this for the output to go in the right place. It will default to
450 # empty if make was configured to work with a cc that can't grok -c and -o
451 # together. You can't compile the C library with such a compiler.
452 OUTPUT_OPTION = -o $@
453
454 # This is the end of the pipeline for compiling generated C code.
455 compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
456
457 # We need the $(CFLAGS) to be in there to have the right predefines during
458 # the dependency run for C sources. But having it for assembly sources can
459 # get the wrong predefines.
460 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
461
462 define +make-deps
463 $(make-target-directory)
464 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
465 $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
466 's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
467 $(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
468 mv -f $(@:.d=.T) $@ $(generate-md5)
469 endef
470
471 ifneq (,$(objpfx))
472 # Continuation lines here are dangerous because they introduce spaces!
473 define sed-remove-objpfx
474 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
475 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
476 endef
477 endif
478 \f
479 # Modify the list of routines we build for different targets
480
481 ifeq (yes,$(build-shared))
482 ifndef libc.so-version
483 # Undefine this because it can't work when we libc.so is unversioned.
484 static-only-routines =
485 endif
486 endif
487
488 elide-routines.oS += $(filter-out $(static-only-routines),\
489 $(routines) $(aux) $(sysdep_routines))
490 elide-routines.os += $(static-only-routines)
491
492 # If we have versioned code we don't need the old versions in any of the
493 # static libraries.
494 elide-routines.o += $(shared-only-routines)
495 elide-routines.op += $(shared-only-routines)
496 \f
497 # Shared library building.
498
499 ifeq (yes,$(build-shared))
500
501 # Reference map file only when shared libraries are built and a map file name
502 # is given.
503 ifeq ($(build-shared),yes)
504 map-file = $(firstword $($(@F:.so=-map)) \
505 $(addprefix $(common-objpfx), \
506 $(filter $(@F:.so=.map),$(version-maps))))
507 load-map-file = $(map-file:%=-Wl,--version-script=%)
508 endif
509
510 # Compiler arguments to use to link a shared object with libc and
511 # ld.so. This is intended to be as similar as possible to a default
512 # link with an installed libc.
513 link-libc-args = -Wl,--start-group \
514 $(libc-for-link) \
515 $(common-objpfx)libc_nonshared.a \
516 $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
517 -Wl,--end-group
518
519 # The corresponding shared libc to use. This may be modified for a
520 # particular target.
521 libc-for-link = $(common-objpfx)libc.so
522
523 # The corresponding dependencies. As these are used in dependencies,
524 # not just commands, they cannot use target-specific variables so need
525 # to name both possible libc.so objects.
526 link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
527 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
528
529 # Pattern rule to build a shared object from an archive of PIC objects.
530 # This must come after the installation rules so Make doesn't try to
531 # build shared libraries in place from the installed *_pic.a files.
532 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
533 # on other shared objects. The linking with libc and ld.so is intended
534 # to be as similar as possible to a default link with an installed libc.
535 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
536 $(build-shlib) $(link-libc-args)
537 $(call after-link,$@)
538
539 define build-shlib-helper
540 $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
541 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
542 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
543 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
544 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
545 $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
546 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
547 endef
548
549 ifeq (yes,$(use-default-link))
550 # If the linker is good enough, we can let it use its default linker script.
551 shlib-lds =
552 shlib-lds-flags =
553 else
554 # binutils only position loadable notes into the first page for binaries,
555 # not for shared objects
556 $(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
557 $(LINK.o) -shared -Wl,-O1 \
558 -nostdlib -nostartfiles \
559 $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
560 -Wl,--verbose 2>&1 | \
561 sed > $@T \
562 -e '/^=========/,/^=========/!d;/^=========/d' \
563 $(if $(filter yes,$(have-hash-style)), \
564 -e 's/^.*\.gnu\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
565 -e '/^[ ]*\.hash[ ]*:.*$$/{h;d;}' \
566 -e '/DATA_SEGMENT_ALIGN/{H;g}' \
567 , \
568 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
569 ) \
570 -e 's/^.*\*(\.dynbss).*$$/& \
571 PROVIDE(__start___libc_freeres_ptrs = .); \
572 *(__libc_freeres_ptrs) \
573 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
574 -e 's@^.*\*(\.jcr).*$$@& \
575 PROVIDE(__start___libc_subfreeres = .);\
576 __libc_subfreeres : { *(__libc_subfreeres) }\
577 PROVIDE(__stop___libc_subfreeres = .);\
578 PROVIDE(__start___libc_atexit = .);\
579 __libc_atexit : { *(__libc_atexit) }\
580 PROVIDE(__stop___libc_atexit = .);\
581 PROVIDE(__start___libc_IO_vtables = .);\
582 __libc_IO_vtables : { *(__libc_IO_vtables) }\
583 PROVIDE(__stop___libc_IO_vtables = .);\
584 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
585 test -s $@T
586 mv -f $@T $@
587 common-generated += shlib.lds
588
589 shlib-lds = $(common-objpfx)shlib.lds
590 shlib-lds-flags = -T $(shlib-lds)
591 endif
592
593 define build-shlib
594 $(build-shlib-helper) -o $@ $(shlib-lds-flags) \
595 $(csu-objpfx)abi-note.o $(build-shlib-objlist)
596 endef
597
598 define build-module-helper
599 $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
600 $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
601 -B$(csu-objpfx) $(load-map-file) \
602 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
603 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
604 endef
605
606 # This macro is similar to build-shlib but it does not define a soname
607 # and it does not depend on the destination name to start with `lib'.
608 # binutils only position loadable notes into the first page for binaries,
609 # not for shared objects
610 define build-module
611 $(build-module-helper) -o $@ $(shlib-lds-flags) \
612 $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
613 $(call after-link,$@)
614 endef
615 define build-module-asneeded
616 $(build-module-helper) -o $@ $(shlib-lds-flags) \
617 $(csu-objpfx)abi-note.o \
618 -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
619 $(link-libc-args)
620 $(call after-link,$@)
621 endef
622
623 # sofini.os must be placed last since it terminates .eh_frame section.
624 build-module-helper-objlist = \
625 $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
626 $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
627 $(elf-objpfx)sofini.os \
628 $(link-libc-deps),$^))
629
630 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
631 build-shlib-objlist = $(build-module-helper-objlist) \
632 $(LDLIBS-$(@F:lib%.so=%).so) \
633 $(filter $(elf-objpfx)sofini.os,$^)
634
635 # Don't try to use -lc when making libc.so itself.
636 # Also omits crti.o and crtn.o, which we do not want
637 # since we define our own `.init' section specially.
638 LDFLAGS-c.so = -nostdlib -nostartfiles
639 # But we still want to link libc.so against $(libc.so-gnulib).
640 LDLIBS-c.so += $(libc.so-gnulib)
641 # Give libc.so an entry point and make it directly runnable itself.
642 LDFLAGS-c.so += -e __libc_main
643 # Pre-link the objects of libc_pic.a so that we can locally resolve
644 # COMMON symbols before we link against ld.so. This is because ld.so
645 # contains some of libc_pic.a already, which will prevent the COMMONs
646 # from being allocated in libc.so, which introduces evil dependencies
647 # between libc.so and ld.so, which can make it impossible to upgrade.
648 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
649 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
650 $(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
651
652 ifeq (,$(strip $(shlib-lds-flags)))
653 # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
654 $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
655 $(OBJDUMP) -h $< | \
656 $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
657 > $@T
658 mv -f $@T $@
659 # Apply those -R options.
660 $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
661 $(common-objpfx)libc_pic.os
662 $(OBJCOPY) @$^ $@
663 generated += libc_pic.opts libc_pic.os.clean
664
665 libc_pic_clean := .clean
666 endif
667
668 # Build a possibly-modified version of libc_pic.a for use in building
669 # linkobj/libc.so.
670 ifeq (,$(filter sunrpc,$(subdirs)))
671 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
672 $(make-target-directory)
673 ln -f $< $@
674 else
675 $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
676 $(common-objpfx)sunrpc/librpc_compat_pic.a
677 $(make-target-directory)
678 (cd $(common-objpfx)linkobj; \
679 $(AR) x ../libc_pic.a; \
680 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
681 $(AR) x ../sunrpc/librpc_compat_pic.a; \
682 $(AR) cr libc_pic.a *.os; \
683 rm *.os)
684 endif # $(subdirs) contains sunrpc
685
686 # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
687 # filter ld.so out of the list of linked objects.
688 $(common-objpfx)libc.so: link-libc-deps = # empty
689 $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
690
691 # Use our own special initializer and finalizer files for the libc.so
692 # libraries.
693 $(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
694 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
695 $(elf-objpfx)sofini.os \
696 $(elf-objpfx)interp.os \
697 $(elf-objpfx)ld.so \
698 $(shlib-lds)
699 $(build-shlib)
700 $(call after-link,$@)
701
702 $(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
703 $(common-objpfx)linkobj/libc_pic.a \
704 $(elf-objpfx)sofini.os \
705 $(elf-objpfx)interp.os \
706 $(elf-objpfx)ld.so \
707 $(shlib-lds)
708 $(build-shlib)
709 $(call after-link,$@)
710
711 ifeq ($(build-shared),yes)
712 $(common-objpfx)libc.so: $(common-objpfx)libc.map
713 endif
714 common-generated += libc.so libc_pic.os
715 ifdef libc.so-version
716 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
717 $(make-link)
718 common-generated += libc.so$(libc.so-version)
719 endif
720 endif
721 \f
722 # Figure out the source filenames in this directory.
723
724 override sources := $(addsuffix .c,\
725 $(filter-out $(elided-routines),\
726 $(routines) $(aux) \
727 $(sysdep_routines)))
728 sysdep_routines := $(sysdep_routines)
729
730 headers := $(headers) $(sysdep_headers)
731
732 # This is the list of all object files, gotten by
733 # replacing every ".c" in `sources' with a ".o".
734 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
735
736
737 # The makefile may define $(extra-libs) with `libfoo libbar'
738 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
739 ifdef extra-libs
740 # extra-lib.mk is included once for each extra lib to define rules
741 # to build it, and to add its objects to the various variables.
742 # During its evaluation, $(lib) is set to the name of the library.
743 extra-libs-left := $(extra-libs)
744 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
745 endif
746
747
748 # The makefile may define $(modules-names) to build additional modules.
749 # These are built with $(build-module), except any in $(modules-names-nobuild).
750 # MODULE_NAME=extramodules, except any in $(modules-names-tests).
751 ifdef modules-names
752 cpp-srcs-left := $(filter-out $(modules-names-tests),$(modules-names))
753 ifneq (,$(cpp-srcs-left))
754 lib := extramodules
755 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
756 endif
757
758 ifdef modules-names-tests
759 cpp-srcs-left := $(filter $(modules-names-tests),$(modules-names))
760 ifneq (,$(cpp-srcs-left))
761 lib := testsuite
762 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
763 endif
764 endif
765
766 extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
767 $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
768 $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
769 $(build-module)
770 endif
771 \f
772 +depfiles := $(sources:.c=.d) \
773 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
774 $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
775 $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
776 $(addsuffix .d,$(tests) $(tests-internal) $(xtests) $(test-srcs))
777 ifeq ($(build-programs),yes)
778 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
779 endif
780 +depfiles := $(addprefix $(objpfx),\
781 $(filter-out $(addsuffix .d,$(omit-deps)),\
782 $(+depfiles)))
783 all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
784 +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
785 $(wildcard $(all-dt-files:.dt=.d))
786
787 # This is a funny rule in that it removes its input file.
788 %.d: %.dt
789 @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
790 mv -f $(@:.d=.T) $@ && \
791 rm -f $<
792
793 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
794 # They will be generated when they're needed, and trying too early won't work.
795 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
796 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
797 $(+gen-as-const)))
798
799 ifdef +depfiles
800 ifneq ($(no_deps),t)
801 -include $(+depfiles)
802 endif
803 endif
804 \f\f
805 # Maximize efficiency by minimizing the number of rules.
806 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
807 # Don't define any builtin rules.
808 MAKEFLAGS := $(MAKEFLAGS)r
809
810 # Generic rule for making directories.
811 %/:
812 # mkdir isn't smart enough to strip a trailing /.
813 # We always require a mkdir which supports the -p option to avoid error
814 # messages in case of races.
815 mkdir -p $(@:%/=%)
816 \f
817 # Make sure that object files are not removed
818 # when they are intermediates between sources and library members.
819 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
820
821 # Make sure that the parent library archive is never removed.
822 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
823 \f
824 # Use the verbose option of ar and tar when not running silently.
825 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
826 verbose := v
827 else # -s
828 verbose :=
829 endif # not -s
830
831 ARFLAGS := r$(verbose)
832 CREATE_ARFLAGS := cru$(verbose)
833 \f
834 # This makes all the object files in the parent library archive.
835
836 .PHONY: lib lib-noranlib
837 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
838 lib-noranlib: libobjs
839
840 # For object-suffix $o, the list of objects with that suffix.
841 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
842 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
843 $(elide-routines$o)),\
844 $(objects))) \
845 $(addprefix $(objpfx),$(o-objects$o))
846
847 others: $(addprefix $(objpfx),$(install-lib))
848
849 ifndef objects
850
851 # Create the stamp$o files to keep the parent makefile happy.
852 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
853 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
854 $(make-target-directory)
855 rm -f $@; > $@
856 else
857
858 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
859 # timestamp file; these rules (one explicit rule is generated for each
860 # object suffix) write a list of objects to update in the stamp file.
861 # The parent will then actually add them all to the archive in the
862 # archive rule, below.
863 define o-iterator-doit
864 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
865 endef
866 define do-stamp
867 $(make-target-directory)
868 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
869 mv -f $@T $@
870 endef
871 object-suffixes-left := $(object-suffixes-for-libc)
872 include $(o-iterator)
873
874 endif
875
876 # Now define explicit rules to build the library archives; these depend
877 # on the stamp files built above.
878 define o-iterator-doit
879 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
880 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
881 endef
882 define do-makelib
883 cd $(common-objdir) && \
884 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
885 endef
886 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
887 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
888 ifndef subdir
889 $(subdirs-stamps): subdir_lib;
890 endif
891 object-suffixes-left = $(object-suffixes-for-libc)
892 include $(o-iterator)
893
894
895 # This makes all the object files.
896 .PHONY: objects objs libobjs extra-objs
897 objects objs: libobjs extra-objs
898 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
899 extra-objs: $(addprefix $(objpfx),$(extra-objs))
900
901 # Canned sequence for building an extra library archive.
902 define build-extra-lib
903 $(patsubst %/,cd % &&,$(objpfx)) \
904 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
905 $(patsubst $(objpfx)%,%,$^)
906 endef
907 \f
908 # Installation.
909
910 .PHONY: force-install
911 force-install:
912
913 # $(install-lib) are installed from the object directory into $(libdir);
914 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
915 # unless they also appear in $(non-lib.a). $(install-data) are installed as
916 # they are into $(datadir). $(headers) are installed as they are in
917 # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
918 # are installed from the object directory into $(bindir), $(bindir) and
919 # $(sbindir), respectively. $(install-others) and $(install-others-programs)
920 # are absolute path names of files to install; rules to install them are
921 # defined elsewhere.
922
923 # The simple library name to install libc.a under.
924 # This could be defined by a sysdep Makefile.
925 ifndef libc-name
926 libc-name := c
927 endif
928
929 define do-install
930 $(make-target-directory)
931 $(INSTALL_DATA) $< $@
932 endef
933
934 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
935 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
936 define make-target-directory
937 $(addprefix $(..)./scripts/mkinstalldirs ,\
938 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
939 endef
940
941 # Any directory (parent or subdir) should install libc.a; this way
942 # "make install" in a subdir is guaranteed to install everything it changes.
943 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
944 $(inst_libdir)/$(patsubst %,$(libtype$o),\
945 $(libprefix)$(libc-name)))
946
947 .PHONY: check-install-supported
948 check-install-supported:
949
950 # Check to see if the prefix or exec_prefix GNU standard variable
951 # has been overridden on the command line and, if so, fail with
952 # an error message since doing so is not supported (set DESTDIR
953 # instead).
954 ifeq ($(origin prefix),command line)
955 check-install-supported:
956 $(error Overriding prefix is not supported. Set DESTDIR instead.)
957 endif
958
959 ifeq ($(origin exec_prefix),command line)
960 check-install-supported:
961 $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
962 endif
963
964 install: check-install-supported
965
966 install: $(installed-libcs)
967 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
968 $(make-target-directory)
969 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
970
971 define do-install-program
972 $(make-target-directory)
973 $(INSTALL_PROGRAM) $< $@.new
974 mv -f $@.new $@
975 endef
976
977 define do-install-script
978 $(make-target-directory)
979 $(INSTALL_SCRIPT) $< $@.new
980 mv -f $@.new $@
981 endef
982
983 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
984 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
985
986 ifeq (yes,$(build-shared))
987 # Find which .so's have versions.
988 versioned := $(strip $(foreach so,$(install-lib.so),\
989 $(patsubst %,$(so),$($(so)-version))))
990
991 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
992 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
993
994 # For versioned libraries, we install three files:
995 # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
996 # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
997 # $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
998 lib-version := $(firstword $($(subdir)-version) $(version))
999 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
1000 $(foreach L,$(install-lib.so-versioned),\
1001 $(inst_libdir)/$L \
1002 $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
1003 $(inst_slibdir)/$L$($L-version))
1004
1005 # Install all the unversioned shared libraries.
1006 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
1007 $(objpfx)%.so $(+force)
1008 $(do-install-program)
1009
1010 ifneq ($(findstring -s,$(LN_S)),)
1011 define make-link
1012 rm -f $@.new
1013 $(SHELL) $(..)scripts/rellns-sh $< $@.new
1014 mv -f $@.new $@
1015 endef
1016 define make-link-multidir
1017 $(patsubst %/,cd %,$(objpfx)); \
1018 $(addprefix $(abspath $(..)scripts/mkinstalldirs) ,$(dir $(multidir))); \
1019 $(LN_S) . $(multidir) 2> /dev/null; \
1020 test -L $(multidir)
1021 endef
1022 else
1023 # If we have no symbolic links don't bother with rellns-sh.
1024 define make-link
1025 rm -f $@.new
1026 $(LN_S) $< $@.new
1027 mv -f $@.new $@
1028 endef
1029 define make-link-multidir
1030 $(make-target-directory)
1031 ln -f $(objpfx)/$(@F) $@
1032 endef
1033 endif
1034
1035 ifeq (yes,$(build-shared))
1036 ifeq (no,$(cross-compiling))
1037 symbolic-link-prog := $(elf-objpfx)sln
1038 symbolic-link-list := $(elf-objpfx)symlink.list
1039 define make-shlib-link
1040 echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
1041 endef
1042 else # cross-compiling
1043 # We need a definition that can be used by elf/Makefile's install rules.
1044 symbolic-link-prog = $(LN_S)
1045 endif
1046 endif
1047 ifndef make-shlib-link
1048 define make-shlib-link
1049 rm -f $@
1050 $(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
1051 endef
1052 endif
1053
1054 ifdef libc.so-version
1055 # For a library specified to be version N, install three files:
1056 # libc.so -> libc.so.N (e.g. libc.so.6)
1057 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
1058
1059 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
1060 $(+force)
1061 $(make-shlib-link)
1062 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
1063 $(do-install-program)
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: $(..)scripts/output-format.sed \
1071 $(common-objpfx)config.make \
1072 $(common-objpfx)config.h $(..)Makerules
1073 ifneq (unknown,$(output-format))
1074 echo > $@.new 'OUTPUT_FORMAT($(output-format))'
1075 else
1076 $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
1077 $(LDFLAGS.so) $(LDFLAGS-lib.so) \
1078 -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
1079 | sed -n -f $< > $@.new
1080 test -s $@.new
1081 rm -f $@.so
1082 endif
1083 mv -f $@.new $@
1084 common-generated += format.lds
1085
1086 ifndef subdir
1087 # What we install as libc.so for programs to link against is in fact a
1088 # link script. It contains references for the various libraries we need.
1089 # The libc.so object is not complete since some functions are only defined
1090 # in libc_nonshared.a.
1091 # We need to use absolute paths since otherwise local copies (if they exist)
1092 # of the files are taken by the linker.
1093 install: $(inst_libdir)/libc.so
1094 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
1095 $(common-objpfx)libc.so$(libc.so-version) \
1096 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
1097 $(libprefix)$(libc-name)) \
1098 $(+force)
1099 (echo '/* GNU ld script';\
1100 echo ' Use the shared library, but some functions are only in';\
1101 echo ' the static library, so try that secondarily. */';\
1102 cat $<; \
1103 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
1104 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
1105 ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
1106 ) > $@.new
1107 mv -f $@.new $@
1108
1109 endif
1110
1111 else
1112 install: $(inst_slibdir)/libc.so
1113 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
1114 $(do-install-program)
1115 endif
1116
1117 ifneq (,$(versioned))
1118 # Produce three sets of rules as above for all the smaller versioned libraries.
1119
1120 define o-iterator-doit
1121 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
1122 endef
1123 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
1124 ifneq (,$(object-suffixes-left))
1125 include $(o-iterator)
1126 endif
1127
1128 # Make symlinks in the build directory, because the versioned names might
1129 # be referenced by a DT_NEEDED in another library.
1130 define o-iterator-doit
1131 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
1132 endef
1133 object-suffixes-left := $(versioned)
1134 include $(o-iterator)
1135
1136 generated += $(foreach o,$(versioned),$o$($o-version))
1137
1138 ifeq (,$($(subdir)-version))
1139 define o-iterator-doit
1140 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1141 $(+force);
1142 $$(make-shlib-link)
1143 endef
1144 object-suffixes-left := $(versioned)
1145 include $(o-iterator)
1146
1147 define o-iterator-doit
1148 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1149 $$(do-install-program)
1150 endef
1151 object-suffixes-left := $(versioned)
1152 include $(o-iterator)
1153 else
1154 define o-iterator-doit
1155 $(inst_slibdir)/$o$($o-version): \
1156 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1157 $$(make-shlib-link)
1158 endef
1159 object-suffixes-left := $(versioned)
1160 include $(o-iterator)
1161
1162 define o-iterator-doit
1163 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1164 $$(do-install-program)
1165 endef
1166 object-suffixes-left := $(versioned)
1167 include $(o-iterator)
1168 endif
1169 endif
1170
1171 define do-install-so
1172 $(do-install-program)
1173 $(patsubst %,$(LN_S) -f $(@F) \
1174 $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1175 $(filter-out %.so,$@))
1176 endef
1177
1178 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1179 $(foreach v,$(so-versions),\
1180 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1181 $(+force)
1182 $(do-install-so)
1183 $(foreach v,$(so-versions),\
1184 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1185 $(do-install-so)
1186 endif
1187
1188 ifdef install-bin
1189 $(addprefix $(inst_bindir)/,$(install-bin)): \
1190 $(inst_bindir)/%: $(objpfx)% $(+force)
1191 $(do-install-program)
1192 endif
1193 ifdef install-bin-script
1194 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1195 $(inst_bindir)/%: $(objpfx)% $(+force)
1196 $(do-install-script)
1197 endif
1198 ifdef install-rootsbin
1199 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1200 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1201 $(do-install-program)
1202 endif
1203 ifdef install-sbin
1204 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1205 $(inst_sbindir)/%: $(objpfx)% $(+force)
1206 $(do-install-program)
1207 endif
1208 ifdef install-lib
1209 install-lib.a := $(filter lib%.a,$(install-lib))
1210 install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
1211 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1212 ifdef install-lib-non.a
1213 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1214 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1215 $(do-install)
1216 endif
1217 ifdef install-lib.a
1218 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1219 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1220 $(do-install)
1221 endif
1222 endif
1223 ifdef install-data
1224 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1225 $(do-install)
1226 endif
1227 headers := $(strip $(headers))
1228 ifdef headers
1229 # This implicit rule installs headers from the source directory.
1230 # It may be ignored in preference to rules from sysd-rules to find
1231 # headers in the sysdeps tree.
1232 $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
1233 $(do-install)
1234 $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
1235 $(do-install)
1236 $(inst_includedir)/%.h: %.h $(+force)
1237 $(do-install)
1238 $(inst_includedir)/%.h: $(..)include/%.h $(+force)
1239 $(do-install)
1240 headers-nonh := $(filter-out %.h,$(headers))
1241 ifdef headers-nonh
1242 $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
1243 % $(+force)
1244 $(do-install)
1245 endif # headers-nonh
1246 endif # headers
1247
1248 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1249 install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1250 install-data-nosubdir install-headers-nosubdir
1251 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1252 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1253 install-rootsbin-nosubdir: \
1254 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1255 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1256 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1257 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1258 $(addprefix $(libprefix),$(install-lib-non.a)))
1259 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1260 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1261 install-others-nosubdir: $(install-others)
1262 install-others-programs-nosubdir: $(install-others-programs)
1263
1264 # We need all the `-nosubdir' targets so that `install' in the parent
1265 # doesn't depend on several things which each iterate over the subdirs.
1266 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1267 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
1268 install-%:: install-%-nosubdir ;
1269
1270 .PHONY: install install-no-libc.a-nosubdir
1271 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
1272 install-lib-nosubdir install-others-nosubdir
1273 ifeq ($(build-programs),yes)
1274 install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
1275 install-rootsbin-nosubdir install-sbin-nosubdir \
1276 install-others-programs-nosubdir
1277 endif
1278 install: install-no-libc.a-nosubdir
1279 \f
1280 # Command to compile $< using the native libraries.
1281 define native-compile
1282 $(make-target-directory)
1283 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1284 $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
1285 endef
1286
1287 # We always want to use configuration definitions.
1288 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
1289 -DIS_IN_build -include $(common-objpfx)config.h
1290
1291 # Support the GNU standard name for this target.
1292 .PHONY: check
1293 check: tests
1294 # Special target to run tests which cannot be run unconditionally.
1295 # Maintainers should use this target.
1296 .PHONY: xcheck
1297 xcheck: xtests
1298
1299 # The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
1300 # that almost all internal declarations from config.h, libc-symbols.h, and
1301 # include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
1302 all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) \
1303 $(tests-container))
1304 ifneq (,$(all-testsuite))
1305 cpp-srcs-left = $(all-testsuite)
1306 lib := testsuite
1307 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1308 endif
1309
1310 all-nonlib := $(strip $(tests-internal) $(test-internal-extras) \
1311 $(others) $(others-extras))
1312 ifneq (,$(all-nonlib))
1313 cpp-srcs-left = $(all-nonlib)
1314 lib := nonlib
1315 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
1316 endif
1317
1318
1319 ifeq ($(build-shared),yes)
1320 # Generate normalized lists of symbols, versions, and data sizes.
1321 # This is handy for checking against existing library binaries.
1322
1323 %.symlist: $(..)scripts/abilist.awk %.dynsym
1324 LC_ALL=C $(AWK) -f $^ > $@T
1325 mv -f $@T $@
1326
1327 %.dynsym: %.so
1328 LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
1329 mv -f $@T $@
1330
1331 vpath %.abilist $(+sysdep_dirs)
1332
1333 # The .PRECIOUS rule prevents the files built by an implicit rule whose
1334 # target pattern is %.symlist from being considered "intermediate files"
1335 # and automatically removed. We only want these files to be removed by
1336 # 'make clean', which is handled by the 'generated' variable.
1337 .PRECIOUS: %.symlist
1338 generated += $(extra-libs:=.symlist)
1339
1340 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1341 $(objpfx)%.symlist
1342 $(check-abi); \
1343 $(evaluate-test)
1344 $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
1345 $(common-objpfx)%.symlist
1346 $(check-abi); \
1347 $(evaluate-test)
1348 define check-abi
1349 diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
1350 endef
1351
1352 update-abi-%: $(objpfx)%.symlist %.abilist
1353 $(update-abi)
1354 update-abi-%: $(common-objpfx)%.symlist %.abilist
1355 $(update-abi)
1356 define update-abi
1357 @if cmp -s $^ 2> /dev/null; \
1358 then \
1359 echo '+++ $(filter %.abilist,$^) is unchanged'; \
1360 else cp -f $^; \
1361 echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
1362 fi
1363 endef
1364
1365 # Patch all .abilist files for one DSO. The find command locates abilist
1366 # files for all architectures. The abilist files in /generic/ are
1367 # filtered out because these are expected to remain empty.
1368 define update-all-abi
1369 $(SHELL) $(..)scripts/update-abilist.sh $^ \
1370 $$(find $(..)sysdeps -name '$*.abilist' \! -path '*/generic/*')
1371 endef
1372 update-all-abi-%: %.abilist $(objpfx)%.symlist
1373 $(update-all-abi)
1374 update-all-abi-%: %.abilist $(common-objpfx)%.symlist
1375 $(update-all-abi)
1376
1377 .PHONY: update-abi update-all-abi check-abi
1378 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1379 update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
1380 check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
1381 $(install-lib.so-versioned))
1382 check-abi: $(check-abi-list)
1383 ifdef subdir
1384 subdir_check-abi: check-abi
1385 subdir_update-abi: update-abi
1386 subdir_update-all-abi: update-all-abi
1387 else
1388 check-abi: subdir_check-abi
1389 if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
1390 cat $(objpfx)*/check-abi*.out && exit 1; fi
1391 update-abi: subdir_update-abi
1392 update-all-abi: subdir_update-all-abi
1393 endif
1394
1395 ifeq ($(subdir),elf)
1396 check-abi: $(objpfx)check-abi-libc.out
1397 tests-special += $(objpfx)check-abi-libc.out
1398 update-abi: update-abi-libc
1399 update-all-abi: update-all-abi-libc
1400 common-generated += libc.symlist
1401 endif
1402
1403 ifeq ($(build-shared),yes)
1404 ifdef subdir
1405 tests-special += $(check-abi-list)
1406 endif
1407 endif
1408
1409 endif
1410 \f
1411 # These will have been set by sysdeps/posix/Makefile.
1412 L_tmpnam ?= 1
1413 TMP_MAX ?= 0
1414 L_ctermid ?= 1
1415 L_cuserid ?= 1
1416
1417 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1418
1419 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1420 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1421 $(common-objpfx)config.make
1422 $(make-target-directory)
1423 { echo '#include "$(..)posix/bits/posix1_lim.h"'; \
1424 } | \
1425 $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
1426 $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
1427 sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
1428 $(@:st=dT) > $(@:st=dt)
1429 mv -f $(@:st=dt) $(@:st=d)
1430 fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
1431 filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
1432 fopen_max=$${fopen_max:-16}; \
1433 filename_max=$${filename_max:-1024}; \
1434 sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
1435 -e "s/@FILENAME_MAX@/$$filename_max/" \
1436 -e "s/@L_tmpnam@/$(L_tmpnam)/" \
1437 -e "s/@TMP_MAX@/$(TMP_MAX)/" \
1438 -e "s/@L_ctermid@/$(L_ctermid)/" \
1439 -e "s/@L_cuserid@/$(L_cuserid)/" \
1440 $< > $(@:st=h.new)
1441 $(move-if-change) $(@:st=h.new) $(@:st=h)
1442 # Remove these last so that they can be examined if something went wrong.
1443 rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1444 touch $@
1445 # Get dependencies.
1446 ifndef no_deps
1447 -include $(stdio_lim:h=d)
1448 endif
1449 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1450 \f
1451 FORCE:
1452
1453 .PHONY: echo-headers
1454 echo-headers:
1455 @echo $(headers)
1456
1457 %.bz2: %; bzip2 -9vk $<
1458 %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
1459 %.xz: %; xz -9evk $<
1460 \f
1461 # Common cleaning targets.
1462
1463 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1464 clean: common-clean
1465 mostlyclean: common-mostlyclean
1466
1467 do-tests-clean:
1468 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) \
1469 $(tests-internal) \
1470 $(xtests) \
1471 $(test-srcs)) \
1472 $(addsuffix .test-result,$(tests) \
1473 $(tests-internal) \
1474 $(xtests) \
1475 $(test-srcs)))
1476
1477 # Remove the object files.
1478 common-mostlyclean:
1479 -rm -f $(addprefix $(objpfx),$(tests) $(tests-internal) $(xtests) \
1480 $(test-srcs) \
1481 $(others) $(sysdep-others) stubs \
1482 $(addsuffix .o,$(tests) \
1483 $(tests-internal) \
1484 $(xtests) \
1485 $(test-srcs) \
1486 $(others) \
1487 $(sysdep-others)) \
1488 $(addsuffix .out,$(tests) \
1489 $(tests-internal) \
1490 $(xtests) \
1491 $(test-srcs)) \
1492 $(addsuffix .test-result,$(tests) \
1493 $(tests-internal) \
1494 $(xtests) \
1495 $(test-srcs)))
1496 -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
1497 $(install-lib) $(install-lib.so) \
1498 $(install-lib.so:%.so=%_pic.a))
1499 -rm -f core
1500 -rm -f $(objpfx)rtld-*.os
1501 $(rmobjs)
1502 define rmobjs
1503 $(foreach o,$(object-suffixes-for-libc),
1504 -rm -f $(objpfx)stamp$o $(o-objects))
1505 endef
1506
1507 # Also remove the dependencies and generated source files.
1508 common-clean: common-mostlyclean
1509 -rm -f $(addprefix $(objpfx),$(generated))
1510 -rm -f $(objpfx)*.d $(objpfx)*.dt
1511 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1512 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1513 -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1514 \f
1515 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1516 # for each function which is a stub.
1517
1518 ifdef objpfx
1519 .PHONY: stubs # The parent Makefile calls this target.
1520 stubs: $(objpfx)stubs
1521 endif
1522 objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
1523 $(addprefix $(objpfx),$(extra-objs))
1524 $(objpfx)stubs: $(objs-for-stubs)
1525 ifneq (,$(strip $(objs-for-stubs)))
1526 (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
1527 $(AWK) '/\.gnu\.glibc-stub\./ { \
1528 sub(/\.gnu\.glibc-stub\./, "", $$2); \
1529 stubs[$$2] = 1; } \
1530 END { for (s in stubs) print "#define __stub_" s }' > $@T
1531 mv -f $@T $@
1532 else
1533 > $@
1534 endif
1535 \f
1536 ifneq (,$(strip $(gpl2lgpl)))
1537 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1538 # Snarf from the master source and frob the copying notice.
1539 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1540 sed -f $^ > $@-tmp
1541 # So I don't edit them by mistake.
1542 chmod a-w $@-tmp
1543 mv -f $@-tmp $@
1544 endif
1545 endif
1546
1547 # Local Variables:
1548 # mode: makefile
1549 # End: