1 # SPDX-License-Identifier: GPL-2.0-only
6 include include/config/auto.conf
7 include $(srctree)/scripts/Kbuild.include
8 include $(srctree)/scripts/Makefile.lib
12 ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS
13 vmlinux-final := vmlinux.unstripped
15 quiet_cmd_strip_relocs = RSTRIP $@
16 cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' --remove-section=!'.rel*.dyn' $< $@
18 vmlinux: $(vmlinux-final) FORCE
19 $(call if_changed,strip_relocs)
23 vmlinux-final := vmlinux
27 $(call if_changed_rule,cc_o_c)
30 $(call if_changed_rule,as_o_S)
33 # ---------------------------------------------------------------------------
35 quiet_cmd_wrap_dtbs = WRAP $@
37 echo '\#include <asm-generic/vmlinux.lds.h>'; \
38 echo '.section .dtb.init.rodata,"a"'; \
40 symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \
41 echo '.balign STRUCT_ALIGNMENT'; \
42 echo ".global $${symbase}_begin"; \
43 echo "$${symbase}_begin:"; \
44 echo '.incbin "'$$dtb'" '; \
45 echo ".global $${symbase}_end"; \
46 echo "$${symbase}_end:"; \
50 .builtin-dtbs.S: .builtin-dtbs-list FORCE
51 $(call if_changed,wrap_dtbs)
53 quiet_cmd_gen_dtbs_list = GEN $@
55 $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@
57 .builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE
58 $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list))
60 targets += .builtin-dtbs-list
62 ifdef CONFIG_GENERIC_BUILTIN_DTB
63 targets += .builtin-dtbs.S .builtin-dtbs.o
64 $(vmlinux-final): .builtin-dtbs.o
68 # ---------------------------------------------------------------------------
71 targets += .vmlinux.export.o
72 $(vmlinux-final): .vmlinux.export.o
75 ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
76 $(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o
78 arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE
79 $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@
82 ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
84 # Final link of vmlinux with optional arch pass after final link
86 $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \
87 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
89 targets += $(vmlinux-final)
90 $(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
91 +$(call if_changed_dep,link_vmlinux)
92 ifdef CONFIG_DEBUG_INFO_BTF
93 $(vmlinux-final): $(RESOLVE_BTFIDS)
96 ifdef CONFIG_BUILDTIME_TABLE_SORT
97 $(vmlinux-final): scripts/sorttable
100 # modules.builtin.ranges
101 # ---------------------------------------------------------------------------
102 ifdef CONFIG_BUILTIN_MODULE_RANGES
103 __default: modules.builtin.ranges
105 quiet_cmd_modules_builtin_ranges = GEN $@
106 cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@
108 targets += modules.builtin.ranges
109 modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \
110 modules.builtin vmlinux.map vmlinux.o.map FORCE
111 $(call if_changed,modules_builtin_ranges)
113 vmlinux.map: $(vmlinux-final)
118 # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
119 # ---------------------------------------------------------------------------
124 # Read all saved command lines and dependencies for the $(targets) we
125 # may be building above, using $(if_changed{,_dep}). As an
126 # optimization, we don't need to read them if the target does not
127 # exist, we will rebuild anyway in that case.
129 existing-targets := $(wildcard $(sort $(targets)))
131 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)