xref: /linux/scripts/Makefile.vmlinux (revision 1260ed77798502de9c98020040d2995008de10cc)
1# SPDX-License-Identifier: GPL-2.0-only
2
3PHONY := __default
4__default: vmlinux
5
6include include/config/auto.conf
7include $(srctree)/scripts/Kbuild.include
8include $(srctree)/scripts/Makefile.lib
9
10targets :=
11
12ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS
13vmlinux-final := vmlinux.unstripped
14
15quiet_cmd_strip_relocs = RSTRIP  $@
16      cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $< $@
17
18vmlinux: $(vmlinux-final) FORCE
19	$(call if_changed,strip_relocs)
20
21targets += vmlinux
22else
23vmlinux-final := vmlinux
24endif
25
26%.o: %.c FORCE
27	$(call if_changed_rule,cc_o_c)
28
29%.o: %.S FORCE
30	$(call if_changed_rule,as_o_S)
31
32# Built-in dtb
33# ---------------------------------------------------------------------------
34
35quiet_cmd_wrap_dtbs = WRAP    $@
36      cmd_wrap_dtbs = {							\
37	echo '\#include <asm-generic/vmlinux.lds.h>';			\
38	echo '.section .dtb.init.rodata,"a"';				\
39	while read dtb; do						\
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:";				\
47	done < $<;							\
48	} > $@
49
50.builtin-dtbs.S: .builtin-dtbs-list FORCE
51	$(call if_changed,wrap_dtbs)
52
53quiet_cmd_gen_dtbs_list = GEN     $@
54      cmd_gen_dtbs_list = \
55	$(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@
56
57.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE
58	$(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list))
59
60targets += .builtin-dtbs-list
61
62ifdef CONFIG_GENERIC_BUILTIN_DTB
63targets += .builtin-dtbs.S .builtin-dtbs.o
64$(vmlinux-final): .builtin-dtbs.o
65endif
66
67# vmlinux
68# ---------------------------------------------------------------------------
69
70ifdef CONFIG_MODULES
71targets += .vmlinux.export.o
72$(vmlinux-final): .vmlinux.export.o
73endif
74
75ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
76$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o
77
78arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE
79	$(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@
80endif
81
82ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
83
84# Final link of vmlinux with optional arch pass after final link
85cmd_link_vmlinux =							\
86	$< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@";	\
87	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
88
89targets += $(vmlinux-final)
90$(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
91	+$(call if_changed_dep,link_vmlinux)
92ifdef CONFIG_DEBUG_INFO_BTF
93$(vmlinux-final): $(RESOLVE_BTFIDS)
94endif
95
96ifdef CONFIG_BUILDTIME_TABLE_SORT
97vmlinux: scripts/sorttable
98endif
99
100# module.builtin.ranges
101# ---------------------------------------------------------------------------
102ifdef CONFIG_BUILTIN_MODULE_RANGES
103__default: modules.builtin.ranges
104
105quiet_cmd_modules_builtin_ranges = GEN     $@
106      cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@
107
108targets += modules.builtin.ranges
109modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \
110			modules.builtin vmlinux.map vmlinux.o.map FORCE
111	$(call if_changed,modules_builtin_ranges)
112
113vmlinux.map: $(vmlinux-final)
114	@:
115
116endif
117
118# Add FORCE to the prerequisites of a target to force it to be always rebuilt.
119# ---------------------------------------------------------------------------
120
121PHONY += FORCE
122FORCE:
123
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.
128
129existing-targets := $(wildcard $(sort $(targets)))
130
131-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
132
133.PHONY: $(PHONY)
134