xf.li | bdd93d5 | 2023-05-12 07:10:14 -0700 | [diff] [blame^] | 1 | # Subroutine makefile for compiling libc modules linked into dynamic linker. |
| 2 | |
| 3 | # Copyright (C) 2002-2016 Free Software Foundation, Inc. |
| 4 | # This file is part of the GNU C Library. |
| 5 | |
| 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. |
| 10 | |
| 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. |
| 15 | |
| 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 | # <http://www.gnu.org/licenses/>. |
| 19 | |
| 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. |
| 25 | |
| 26 | .PHONY: rtld-all |
| 27 | rtld-all: |
| 28 | |
| 29 | # When run from the elf/Makefile to build rtld-libc.a, $(subdir) is elf. |
| 30 | ifneq ($(subdir),elf) |
| 31 | ifndef rtld-modules |
| 32 | error rtld-modules not set |
| 33 | endif |
| 34 | endif |
| 35 | |
| 36 | ifndef rtld-modules |
| 37 | # Running to build rtld-libc.a, driving runs of $(rtld-subdir-make), below. |
| 38 | |
| 39 | ifndef rtld-subdirs |
| 40 | error This makefile is a subroutine of elf/Makefile not to be used directly |
| 41 | endif |
| 42 | |
| 43 | include ../Makeconfig |
| 44 | |
| 45 | rtld-all: $(objpfx)rtld-libc.a |
| 46 | |
| 47 | $(objpfx)rtld-libc.a: $(foreach dir,$(rtld-subdirs),\ |
| 48 | $(addprefix $(common-objpfx)$(dir)/rtld-,\ |
| 49 | $(rtld-$(dir)))) |
| 50 | @-rm -f $@T |
| 51 | $(AR) cq$(verbose) $@T $^ |
| 52 | mv -f $@T $@ |
| 53 | |
| 54 | # Use the verbose option of ar and tar when not running silently. |
| 55 | ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s |
| 56 | verbose := v |
| 57 | else # -s |
| 58 | verbose := |
| 59 | endif # not -s |
| 60 | |
| 61 | |
| 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 ; \ |
| 67 | +$$(rtld-subdir-make) |
| 68 | endef |
| 69 | include $(patsubst %,../o-iterator.mk,$(object-suffixes-left)) |
| 70 | |
| 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-$*))' |
| 76 | endef |
| 77 | |
| 78 | # See subdir-target-args in ../Makefile for the model. |
| 79 | subdir-args = subdir=$*$(if $($*-srcdir),\ |
| 80 | -C $($*-srcdir) ..=`pwd`/,\ |
| 81 | -C $(..)$* ..=../) |
| 82 | |
| 83 | FORCE: |
| 84 | |
| 85 | else |
| 86 | |
| 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. |
| 90 | |
| 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) |
| 94 | |
| 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) |
| 110 | |
| 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) |
| 124 | |
| 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)) |
| 128 | |
| 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)))) |
| 137 | ifdef rtld-depfiles |
| 138 | -include $(rtld-depfiles) |
| 139 | endif |
| 140 | |
| 141 | # This here is the whole point of all the shenanigans. |
| 142 | # Set libof-* for each routine. |
| 143 | cpp-srcs-left := $(rtld-modules:%.os=%) |
| 144 | lib := rtld |
| 145 | include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left)) |
| 146 | |
| 147 | endif |