Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / scripts / Makefile.vmlinux
blob873caaa553134e09d034e0c4e0ac7f07c9e3f31b
1 # SPDX-License-Identifier: GPL-2.0-only
3 PHONY := __default
4 __default: vmlinux
6 include include/config/auto.conf
7 include $(srctree)/scripts/Kbuild.include
8 include $(srctree)/scripts/Makefile.lib
10 targets :=
12 %.o: %.c FORCE
13         $(call if_changed_rule,cc_o_c)
15 %.o: %.S FORCE
16         $(call if_changed_rule,as_o_S)
18 # Built-in dtb
19 # ---------------------------------------------------------------------------
21 quiet_cmd_wrap_dtbs = WRAP    $@
22       cmd_wrap_dtbs = {                                                 \
23         echo '\#include <asm-generic/vmlinux.lds.h>';                   \
24         echo '.section .dtb.init.rodata,"a"';                           \
25         while read dtb; do                                              \
26                 symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _);  \
27                 echo '.balign STRUCT_ALIGNMENT';                        \
28                 echo ".global $${symbase}_begin";                       \
29                 echo "$${symbase}_begin:";                              \
30                 echo '.incbin "'$$dtb'" ';                              \
31                 echo ".global $${symbase}_end";                         \
32                 echo "$${symbase}_end:";                                \
33         done < $<;                                                      \
34         } > $@
36 .builtin-dtbs.S: .builtin-dtbs-list FORCE
37         $(call if_changed,wrap_dtbs)
39 quiet_cmd_gen_dtbs_list = GEN     $@
40       cmd_gen_dtbs_list = \
41         $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@
43 .builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE
44         $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list))
46 targets += .builtin-dtbs-list
48 ifdef CONFIG_GENERIC_BUILTIN_DTB
49 targets += .builtin-dtbs.S .builtin-dtbs.o
50 vmlinux: .builtin-dtbs.o
51 endif
53 # vmlinux
54 # ---------------------------------------------------------------------------
56 ifdef CONFIG_MODULES
57 targets += .vmlinux.export.o
58 vmlinux: .vmlinux.export.o
59 endif
61 ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX
62 vmlinux: arch/$(SRCARCH)/tools/vmlinux.arch.o
64 arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE
65         $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@
66 endif
68 ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
70 # Final link of vmlinux with optional arch pass after final link
71 cmd_link_vmlinux =                                                      \
72         $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)";            \
73         $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
75 targets += vmlinux
76 vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE
77         +$(call if_changed_dep,link_vmlinux)
78 ifdef CONFIG_DEBUG_INFO_BTF
79 vmlinux: $(RESOLVE_BTFIDS)
80 endif
82 # module.builtin.ranges
83 # ---------------------------------------------------------------------------
84 ifdef CONFIG_BUILTIN_MODULE_RANGES
85 __default: modules.builtin.ranges
87 quiet_cmd_modules_builtin_ranges = GEN     $@
88       cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@
90 targets += modules.builtin.ranges
91 modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \
92                         modules.builtin vmlinux.map vmlinux.o.map FORCE
93         $(call if_changed,modules_builtin_ranges)
95 vmlinux.map: vmlinux
96         @:
98 endif
100 # Add FORCE to the prerequisites of a target to force it to be always rebuilt.
101 # ---------------------------------------------------------------------------
103 PHONY += FORCE
104 FORCE:
106 # Read all saved command lines and dependencies for the $(targets) we
107 # may be building above, using $(if_changed{,_dep}). As an
108 # optimization, we don't need to read them if the target does not
109 # exist, we will rebuild anyway in that case.
111 existing-targets := $(wildcard $(sort $(targets)))
113 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
115 .PHONY: $(PHONY)