| 1 | # SPDX-License-Identifier: GPL-2.0-only |
| 2 | |
| 3 | PHONY := __default |
| 4 | __default: vmlinux |
| 5 | |
| 6 | include include/config/auto.conf |
| 7 | include $(srctree)/scripts/Kbuild.include |
| 8 | include $(srctree)/scripts/Makefile.lib |
| 9 | |
| 10 | targets := |
| 11 | |
| 12 | ifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS |
| 13 | vmlinux-final := vmlinux.unstripped |
| 14 | |
| 15 | quiet_cmd_strip_relocs = RSTRIP $@ |
| 16 | cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' $< $@ |
| 17 | |
| 18 | vmlinux: $(vmlinux-final) FORCE |
| 19 | $(call if_changed,strip_relocs) |
| 20 | |
| 21 | targets += vmlinux |
| 22 | else |
| 23 | vmlinux-final := vmlinux |
| 24 | endif |
| 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 | |
| 35 | quiet_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 | |
| 53 | quiet_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 | |
| 60 | targets += .builtin-dtbs-list |
| 61 | |
| 62 | ifdef CONFIG_GENERIC_BUILTIN_DTB |
| 63 | targets += .builtin-dtbs.S .builtin-dtbs.o |
| 64 | $(vmlinux-final): .builtin-dtbs.o |
| 65 | endif |
| 66 | |
| 67 | # vmlinux |
| 68 | # --------------------------------------------------------------------------- |
| 69 | |
| 70 | ifdef CONFIG_MODULES |
| 71 | targets += .vmlinux.export.o |
| 72 | $(vmlinux-final): .vmlinux.export.o |
| 73 | endif |
| 74 | |
| 75 | ifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX |
| 76 | $(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o |
| 77 | |
| 78 | arch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE |
| 79 | $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ |
| 80 | endif |
| 81 | |
| 82 | ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) |
| 83 | |
| 84 | # Final link of vmlinux with optional arch pass after final link |
| 85 | cmd_link_vmlinux = \ |
| 86 | $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ |
| 87 | $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) |
| 88 | |
| 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) |
| 94 | endif |
| 95 | |
| 96 | ifdef CONFIG_BUILDTIME_TABLE_SORT |
| 97 | vmlinux: scripts/sorttable |
| 98 | endif |
| 99 | |
| 100 | # module.builtin.ranges |
| 101 | # --------------------------------------------------------------------------- |
| 102 | ifdef CONFIG_BUILTIN_MODULE_RANGES |
| 103 | __default: modules.builtin.ranges |
| 104 | |
| 105 | quiet_cmd_modules_builtin_ranges = GEN $@ |
| 106 | cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ |
| 107 | |
| 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) |
| 112 | |
| 113 | vmlinux.map: $(vmlinux-final) |
| 114 | @: |
| 115 | |
| 116 | endif |
| 117 | |
| 118 | # Add FORCE to the prerequisites of a target to force it to be always rebuilt. |
| 119 | # --------------------------------------------------------------------------- |
| 120 | |
| 121 | PHONY += FORCE |
| 122 | FORCE: |
| 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 | |
| 129 | existing-targets := $(wildcard $(sort $(targets))) |
| 130 | |
| 131 | -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) |
| 132 | |
| 133 | .PHONY: $(PHONY) |