Blame elf/rtld-Rules

Packit 6c4009
# Subroutine makefile for compiling libc modules linked into dynamic linker.
Packit 6c4009
Packit 6c4009
# Copyright (C) 2002-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
# This makefile is never used by itself, but only from the rtld-libc.a
Packit 6c4009
# rule in Makefile, which does make -f librtld.mk -f rtld-Rules.
Packit 6c4009
# librtld.mk is the generated file containing variable definitions for
Packit 6c4009
# `rtld-subdirs', a subset of the top-level $(subdirs) list; and for each
Packit 6c4009
# SUBDIR in $(rtld-subdirs), `rtld-SUBDIR' listing `module.os' file names.
Packit 6c4009
Packit 6c4009
.PHONY: rtld-all
Packit 6c4009
rtld-all:
Packit 6c4009
Packit 6c4009
# When run from the elf/Makefile to build rtld-libc.a, $(subdir) is elf.
Packit 6c4009
ifneq ($(subdir),elf)
Packit 6c4009
ifndef rtld-modules
Packit 6c4009
$(error rtld-modules not set)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifndef rtld-modules
Packit 6c4009
# Running to build rtld-libc.a, driving runs of $(rtld-subdir-make), below.
Packit 6c4009
Packit 6c4009
ifndef rtld-subdirs
Packit 6c4009
$(error This makefile is a subroutine of elf/Makefile not to be used directly)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
include ../Makeconfig
Packit 6c4009
Packit 6c4009
rtld-all: $(objpfx)rtld-libc.a
Packit 6c4009
Packit 6c4009
$(objpfx)rtld-libc.a: $(foreach dir,$(rtld-subdirs),\
Packit 6c4009
				$(addprefix $(common-objpfx)$(dir)/rtld-,\
Packit 6c4009
					    $(rtld-$(dir))))
Packit 6c4009
	@-rm -f $@T
Packit 6c4009
	$(AR) cq$(verbose) $@T $^
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
Packit 6c4009
# Use the verbose option of ar and tar when not running silently.
Packit 6c4009
ifeq	"$(findstring s,$(MAKEFLAGS))" ""	# if not -s
Packit 6c4009
verbose := v
Packit 6c4009
else						# -s
Packit 6c4009
verbose	:=
Packit 6c4009
endif						# not -s
Packit 6c4009
Packit 6c4009
Packit 6c4009
# For each subdirectory, define a pattern rule that makes all of that
Packit 6c4009
# subdirectory's modules at once with one recursive make command.
Packit 6c4009
object-suffixes-left := $(rtld-subdirs)
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(foreach obj,$(rtld-$o),$(common-objpfx)%/rtld-$(obj)): FORCE ; \
Packit 6c4009
	+$$(rtld-subdir-make)
Packit 6c4009
endef
Packit 6c4009
include $(patsubst %,../o-iterator.mk,$(object-suffixes-left))
Packit 6c4009
Packit 6c4009
# This is how we descend into each subdirectory.  See below.
Packit 6c4009
define rtld-subdir-make
Packit 6c4009
$(MAKE) $(subdir-args) objdir=$(objdir) \
Packit 6c4009
	-f Makefile -f ../elf/rtld-Rules rtld-all \
Packit 6c4009
	rtld-modules='$(addprefix rtld-,$(rtld-$*))'
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# See subdir-target-args in ../Makefile for the model.
Packit 6c4009
subdir-args = subdir=$*$(if $($*-srcdir),\
Packit 6c4009
			    -C $($*-srcdir) ..=`pwd`/,\
Packit 6c4009
			    -C $(..)$* ..=../)
Packit 6c4009
Packit 6c4009
FORCE:
Packit 6c4009
Packit 6c4009
else
Packit 6c4009
Packit 6c4009
# In this case we are being run by $(rtld-subdir-make), above.
Packit 6c4009
# Some other subdir's Makefile has provided all its normal rules,
Packit 6c4009
# and we just provide some additional definitions.
Packit 6c4009
Packit 6c4009
rtld-compile-command.S = $(compile-command.S) $(rtld-CPPFLAGS)
Packit 6c4009
rtld-compile-command.s = $(compile-command.s) $(rtld-CPPFLAGS)
Packit 6c4009
rtld-compile-command.c = $(compile-command.c) $(rtld-CPPFLAGS) $(rtld-CFLAGS)
Packit 6c4009
Packit 6c4009
# These are the basic compilation rules corresponding to the Makerules ones.
Packit 6c4009
# The sysd-rules generated makefile already defines pattern rules for rtld-%
Packit 6c4009
# targets built from sysdeps source files.
Packit 6c4009
$(objpfx)rtld-%.os: rtld-%.S $(before-compile)
Packit 6c4009
	$(rtld-compile-command.S)
Packit 6c4009
$(objpfx)rtld-%.os: rtld-%.s $(before-compile)
Packit 6c4009
	$(rtld-compile-command.s)
Packit 6c4009
$(objpfx)rtld-%.os: rtld-%.c $(before-compile)
Packit 6c4009
	$(rtld-compile-command.c)
Packit 6c4009
$(objpfx)rtld-%.os: %.S $(before-compile)
Packit 6c4009
	$(rtld-compile-command.S)
Packit 6c4009
$(objpfx)rtld-%.os: %.s $(before-compile)
Packit 6c4009
	$(rtld-compile-command.s)
Packit 6c4009
$(objpfx)rtld-%.os: %.c $(before-compile)
Packit 6c4009
	$(rtld-compile-command.c)
Packit 6c4009
Packit 6c4009
# The rules for generated source files.
Packit 6c4009
$(objpfx)rtld-%.os: $(objpfx)rtld-%.S $(before-compile)
Packit 6c4009
	$(rtld-compile-command.S)
Packit 6c4009
$(objpfx)rtld-%.os: $(objpfx)rtld-%.s $(before-compile)
Packit 6c4009
	$(rtld-compile-command.s)
Packit 6c4009
$(objpfx)rtld-%.os: $(objpfx)rtld-%.c $(before-compile)
Packit 6c4009
	$(rtld-compile-command.c)
Packit 6c4009
$(objpfx)rtld-%.os: $(objpfx)%.S $(before-compile)
Packit 6c4009
	$(rtld-compile-command.S)
Packit 6c4009
$(objpfx)rtld-%.os: $(objpfx)%.s $(before-compile)
Packit 6c4009
	$(rtld-compile-command.s)
Packit 6c4009
$(objpfx)rtld-%.os: $(objpfx)%.c $(before-compile)
Packit 6c4009
	$(rtld-compile-command.c)
Packit 6c4009
Packit 6c4009
# The command line setting of rtld-modules (see above) tells us
Packit 6c4009
# what we need to build, and that tells us what dependency files we need.
Packit 6c4009
rtld-all: $(addprefix $(objpfx),$(rtld-modules))
Packit 6c4009
Packit 6c4009
# Figure out the dependency files we need.  After respecting the $(omit-deps)
Packit 6c4009
# list as applied to the names without the `rtld-', there may be none left.
Packit 6c4009
rtld-depfiles := $(patsubst %,$(objpfx)rtld-%.os.d,\
Packit 6c4009
			    $(filter-out $(omit-deps),\
Packit 6c4009
					 $(rtld-modules:rtld-%.os=%)))
Packit 6c4009
rtld-depfiles := $(strip $(wildcard $(rtld-depfiles)) \
Packit 6c4009
			 $(patsubst %.dt,%.d,\
Packit 6c4009
				    $(wildcard $(rtld-depfiles:.d=.dt))))
Packit 6c4009
ifdef rtld-depfiles
Packit 6c4009
-include $(rtld-depfiles)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# This here is the whole point of all the shenanigans.
Packit 6c4009
# Set libof-* for each routine.
Packit 6c4009
cpp-srcs-left := $(rtld-modules:%.os=%)
Packit 6c4009
lib := rtld
Packit 6c4009
include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
Packit 6c4009
Packit 6c4009
rtld-CFLAGS += $(no-stack-protector)
Packit 6c4009
Packit 6c4009
endif