1 # Subroutine makefile for compiling libc modules linked into dynamic linker.
3 # Copyright (C) 2002-2024 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
20 # This makefile is never used by itself, but only from the rtld-libc.a
21 # rule in Makefile, which does make -f librtld.mk -f rtld-Rules.
22 # librtld.mk is the generated file containing variable definitions for
23 # `rtld-subdirs', a subset of the top-level $(subdirs) list; and for each
24 # SUBDIR in $(rtld-subdirs), `rtld-SUBDIR' listing `module.os' file names.
29 # When run from the elf/Makefile to build rtld-libc.a, $(subdir) is elf.
32 $(error rtld-modules not set)
37 # Running to build rtld-libc.a, driving runs of $(rtld-subdir-make), below.
40 $(error This makefile is a subroutine of elf/Makefile not to be used directly)
45 rtld-all: $(objpfx)rtld-libc.a
47 $(objpfx)rtld-libc.a: $(foreach dir,$(rtld-subdirs),\
48 $(addprefix $(common-objpfx)$(dir)/rtld-,\
51 $(AR) cq$(verbose) $@T $^
54 # Use the verbose option of ar and tar when not running silently.
55 ifeq ($(silent-make),no) # if not -s
62 # For each subdirectory, define a pattern rule that makes all of that
63 # subdirectory's modules at once with one recursive make command.
64 object-suffixes-left := $(rtld-subdirs)
65 define o-iterator-doit
66 $(foreach obj,$(rtld-$o),$(common-objpfx)%/rtld-$(obj)): FORCE ; \
69 include $(patsubst %,../o-iterator.mk,$(object-suffixes-left))
71 # This is how we descend into each subdirectory. See below.
72 define rtld-subdir-make
73 $(MAKE) $(subdir-args) objdir=$(objdir) \
74 -f Makefile -f ../elf/rtld-Rules rtld-all \
75 rtld-modules='$(addprefix rtld-,$(rtld-$*))'
78 # See subdir-target-args in ../Makefile for the model.
79 subdir-args = subdir=$*$(if $($*-srcdir),\
80 -C $($*-srcdir) ..=`pwd`/,\
87 # In this case we are being run by $(rtld-subdir-make), above.
88 # Some other subdir's Makefile has provided all its normal rules,
89 # and we just provide some additional definitions.
91 rtld-compile-command.S = $(compile-command.S) $(rtld-CPPFLAGS)
92 rtld-compile-command.s = $(compile-command.s) $(rtld-CPPFLAGS)
93 rtld-compile-command.c = $(compile-command.c) $(rtld-CPPFLAGS) $(rtld-CFLAGS)
95 # These are the basic compilation rules corresponding to the Makerules ones.
96 # The sysd-rules generated makefile already defines pattern rules for rtld-%
97 # targets built from sysdeps source files.
98 $(objpfx)rtld-%.os: rtld-%.S $(before-compile)
99 $(rtld-compile-command.S)
100 $(objpfx)rtld-%.os: rtld-%.s $(before-compile)
101 $(rtld-compile-command.s)
102 $(objpfx)rtld-%.os: rtld-%.c $(before-compile)
103 $(rtld-compile-command.c)
104 $(objpfx)rtld-%.os: %.S $(before-compile)
105 $(rtld-compile-command.S)
106 $(objpfx)rtld-%.os: %.s $(before-compile)
107 $(rtld-compile-command.s)
108 $(objpfx)rtld-%.os: %.c $(before-compile)
109 $(rtld-compile-command.c)
111 # The rules for generated source files.
112 $(objpfx)rtld-%.os: $(objpfx)rtld-%.S $(before-compile)
113 $(rtld-compile-command.S)
114 $(objpfx)rtld-%.os: $(objpfx)rtld-%.s $(before-compile)
115 $(rtld-compile-command.s)
116 $(objpfx)rtld-%.os: $(objpfx)rtld-%.c $(before-compile)
117 $(rtld-compile-command.c)
118 $(objpfx)rtld-%.os: $(objpfx)%.S $(before-compile)
119 $(rtld-compile-command.S)
120 $(objpfx)rtld-%.os: $(objpfx)%.s $(before-compile)
121 $(rtld-compile-command.s)
122 $(objpfx)rtld-%.os: $(objpfx)%.c $(before-compile)
123 $(rtld-compile-command.c)
125 # The command line setting of rtld-modules (see above) tells us
126 # what we need to build, and that tells us what dependency files we need.
127 rtld-all: $(addprefix $(objpfx),$(rtld-modules))
129 # Figure out the dependency files we need. After respecting the $(omit-deps)
130 # list as applied to the names without the `rtld-', there may be none left.
131 rtld-depfiles := $(patsubst %,$(objpfx)rtld-%.os.d,\
132 $(filter-out $(omit-deps),\
133 $(rtld-modules:rtld-%.os=%)))
134 rtld-depfiles := $(strip $(wildcard $(rtld-depfiles)) \
135 $(patsubst %.dt,%.d,\
136 $(wildcard $(rtld-depfiles:.d=.dt))))
138 -include $(rtld-depfiles)
141 # This here is the whole point of all the shenanigans.
142 # Set libof-* for each routine.
143 cpp-srcs-left := $(rtld-modules:%.os=%)
145 include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
147 rtld-CFLAGS += $(no-stack-protector) $(no-fortify-source)