kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o
[linux-block.git] / scripts / Makefile.vmlinux_o
CommitLineData
5d45950d
MY
1# SPDX-License-Identifier: GPL-2.0-only
2
3PHONY := __default
4__default: vmlinux.o
5
6include include/config/auto.conf
7include $(srctree)/scripts/Kbuild.include
8
9# Generate a linker script to ensure correct ordering of initcalls for Clang LTO
10# ---------------------------------------------------------------------------
11
12quiet_cmd_gen_initcalls_lds = GEN $@
13 cmd_gen_initcalls_lds = \
14 $(PYTHON3) $(srctree)/scripts/jobserver-exec \
15 $(PERL) $(real-prereqs) > $@
16
17.tmp_initcalls.lds: $(srctree)/scripts/generate_initcall_order.pl \
18 $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
19 $(call if_changed,gen_initcalls_lds)
20
21targets := .tmp_initcalls.lds
22
23ifdef CONFIG_LTO_CLANG
24initcalls-lds := .tmp_initcalls.lds
25endif
26
27# Link of vmlinux.o used for section mismatch analysis
28# ---------------------------------------------------------------------------
29
30quiet_cmd_ld_vmlinux.o = LD $@
31 cmd_ld_vmlinux.o = \
32 $(LD) ${KBUILD_LDFLAGS} -r -o $@ \
33 $(addprefix -T , $(initcalls-lds)) \
34 --whole-archive $(KBUILD_VMLINUX_OBJS) --no-whole-archive \
35 --start-group $(KBUILD_VMLINUX_LIBS) --end-group \
36
37define rule_ld_vmlinux.o
38 $(call cmd_and_savecmd,ld_vmlinux.o)
39endef
40
41vmlinux.o: $(initcalls-lds) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS) FORCE
42 $(call if_changed_rule,ld_vmlinux.o)
43
44targets += vmlinux.o
45
46# Add FORCE to the prequisites of a target to force it to be always rebuilt.
47# ---------------------------------------------------------------------------
48
49PHONY += FORCE
50FORCE:
51
52# Read all saved command lines and dependencies for the $(targets) we
53# may be building above, using $(if_changed{,_dep}). As an
54# optimization, we don't need to read them if the target does not
55# exist, we will rebuild anyway in that case.
56
57existing-targets := $(wildcard $(sort $(targets)))
58
59-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
60
61.PHONY: $(PHONY)