17b453719SMasahiro Yamada# SPDX-License-Identifier: GPL-2.0-only 27b453719SMasahiro Yamada 35d4aeffbSMasahiro YamadaPHONY := __default 45d4aeffbSMasahiro Yamada__default: vmlinux 55d4aeffbSMasahiro Yamada 67b453719SMasahiro Yamadainclude include/config/auto.conf 77b453719SMasahiro Yamadainclude $(srctree)/scripts/Kbuild.include 87b453719SMasahiro Yamadainclude $(srctree)/scripts/Makefile.lib 97b453719SMasahiro Yamada 105d4aeffbSMasahiro Yamadatargets := 115d4aeffbSMasahiro Yamada 12ac4f0678SArd Biesheuvelifdef CONFIG_ARCH_VMLINUX_NEEDS_RELOCS 13ac4f0678SArd Biesheuvelvmlinux-final := vmlinux.unstripped 14ac4f0678SArd Biesheuvel 15ac4f0678SArd Biesheuvelquiet_cmd_strip_relocs = RSTRIP $@ 16e9d86b8eSAlexandre Ghiti cmd_strip_relocs = $(OBJCOPY) --remove-section='.rel*' --remove-section=!'.rel*.dyn' $< $@ 17ac4f0678SArd Biesheuvel 18ac4f0678SArd Biesheuvelvmlinux: $(vmlinux-final) FORCE 19ac4f0678SArd Biesheuvel $(call if_changed,strip_relocs) 20ac4f0678SArd Biesheuvel 21ac4f0678SArd Biesheuveltargets += vmlinux 22ac4f0678SArd Biesheuvelelse 23ac4f0678SArd Biesheuvelvmlinux-final := vmlinux 24ac4f0678SArd Biesheuvelendif 25ac4f0678SArd Biesheuvel 267b453719SMasahiro Yamada%.o: %.c FORCE 27bede1696SMasahiro Yamada $(call if_changed_rule,cc_o_c) 287b453719SMasahiro Yamada 29654102dfSMasahiro Yamada%.o: %.S FORCE 30bede1696SMasahiro Yamada $(call if_changed_rule,as_o_S) 31654102dfSMasahiro Yamada 32654102dfSMasahiro Yamada# Built-in dtb 33654102dfSMasahiro Yamada# --------------------------------------------------------------------------- 34654102dfSMasahiro Yamada 35654102dfSMasahiro Yamadaquiet_cmd_wrap_dtbs = WRAP $@ 36654102dfSMasahiro Yamada cmd_wrap_dtbs = { \ 37654102dfSMasahiro Yamada echo '\#include <asm-generic/vmlinux.lds.h>'; \ 38654102dfSMasahiro Yamada echo '.section .dtb.init.rodata,"a"'; \ 39654102dfSMasahiro Yamada while read dtb; do \ 40654102dfSMasahiro Yamada symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \ 41654102dfSMasahiro Yamada echo '.balign STRUCT_ALIGNMENT'; \ 42654102dfSMasahiro Yamada echo ".global $${symbase}_begin"; \ 43654102dfSMasahiro Yamada echo "$${symbase}_begin:"; \ 44654102dfSMasahiro Yamada echo '.incbin "'$$dtb'" '; \ 45654102dfSMasahiro Yamada echo ".global $${symbase}_end"; \ 46654102dfSMasahiro Yamada echo "$${symbase}_end:"; \ 47654102dfSMasahiro Yamada done < $<; \ 48654102dfSMasahiro Yamada } > $@ 49654102dfSMasahiro Yamada 50654102dfSMasahiro Yamada.builtin-dtbs.S: .builtin-dtbs-list FORCE 51654102dfSMasahiro Yamada $(call if_changed,wrap_dtbs) 52654102dfSMasahiro Yamada 53654102dfSMasahiro Yamadaquiet_cmd_gen_dtbs_list = GEN $@ 54654102dfSMasahiro Yamada cmd_gen_dtbs_list = \ 55654102dfSMasahiro Yamada $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@ 56654102dfSMasahiro Yamada 57654102dfSMasahiro Yamada.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE 58654102dfSMasahiro Yamada $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list)) 59654102dfSMasahiro Yamada 60654102dfSMasahiro Yamadatargets += .builtin-dtbs-list 61654102dfSMasahiro Yamada 62654102dfSMasahiro Yamadaifdef CONFIG_GENERIC_BUILTIN_DTB 63654102dfSMasahiro Yamadatargets += .builtin-dtbs.S .builtin-dtbs.o 64ac4f0678SArd Biesheuvel$(vmlinux-final): .builtin-dtbs.o 65654102dfSMasahiro Yamadaendif 66654102dfSMasahiro Yamada 67654102dfSMasahiro Yamada# vmlinux 68654102dfSMasahiro Yamada# --------------------------------------------------------------------------- 697b453719SMasahiro Yamada 705d4aeffbSMasahiro Yamadaifdef CONFIG_MODULES 715d4aeffbSMasahiro Yamadatargets += .vmlinux.export.o 72ac4f0678SArd Biesheuvel$(vmlinux-final): .vmlinux.export.o 735d4aeffbSMasahiro Yamadaendif 745d4aeffbSMasahiro Yamada 751198c9c6SNaveen N Raoifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX 76ac4f0678SArd Biesheuvel$(vmlinux-final): arch/$(SRCARCH)/tools/vmlinux.arch.o 771198c9c6SNaveen N Rao 781198c9c6SNaveen N Raoarch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE 791198c9c6SNaveen N Rao $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ 801198c9c6SNaveen N Raoendif 811198c9c6SNaveen N Rao 825d4aeffbSMasahiro YamadaARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) 835d4aeffbSMasahiro Yamada 845d4aeffbSMasahiro Yamada# Final link of vmlinux with optional arch pass after final link 855d4aeffbSMasahiro Yamadacmd_link_vmlinux = \ 86e22bbb8eSArd Biesheuvel $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ 875d4aeffbSMasahiro Yamada $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 885d4aeffbSMasahiro Yamada 89ac4f0678SArd Biesheuveltargets += $(vmlinux-final) 90ac4f0678SArd Biesheuvel$(vmlinux-final): scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE 915d4aeffbSMasahiro Yamada +$(call if_changed_dep,link_vmlinux) 9218e9944eSThomas Weißschuhifdef CONFIG_DEBUG_INFO_BTF 93ac4f0678SArd Biesheuvel$(vmlinux-final): $(RESOLVE_BTFIDS) 9418e9944eSThomas Weißschuhendif 957b453719SMasahiro Yamada 9682c09de2SXi Ruoyaoifdef CONFIG_BUILDTIME_TABLE_SORT 97f0e4b333SMasahiro Yamada$(vmlinux-final): scripts/sorttable 9882c09de2SXi Ruoyaoendif 9982c09de2SXi Ruoyao 100*e0cd396dSMasahiro Yamada# modules.builtin.ranges 1015f5e7344SKris Van Hees# --------------------------------------------------------------------------- 1025f5e7344SKris Van Heesifdef CONFIG_BUILTIN_MODULE_RANGES 1035f5e7344SKris Van Hees__default: modules.builtin.ranges 1045f5e7344SKris Van Hees 1055f5e7344SKris Van Heesquiet_cmd_modules_builtin_ranges = GEN $@ 1065f5e7344SKris Van Hees cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ 1075f5e7344SKris Van Hees 1085f5e7344SKris Van Heestargets += modules.builtin.ranges 1095f5e7344SKris Van Heesmodules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ 1105f5e7344SKris Van Hees modules.builtin vmlinux.map vmlinux.o.map FORCE 1115f5e7344SKris Van Hees $(call if_changed,modules_builtin_ranges) 1125f5e7344SKris Van Hees 113ac4f0678SArd Biesheuvelvmlinux.map: $(vmlinux-final) 1145f5e7344SKris Van Hees @: 1155f5e7344SKris Van Hees 1165f5e7344SKris Van Heesendif 1175f5e7344SKris Van Hees 1188fb4ac1cSMasahiro Yamada# Add FORCE to the prerequisites of a target to force it to be always rebuilt. 1197b453719SMasahiro Yamada# --------------------------------------------------------------------------- 1207b453719SMasahiro Yamada 1217b453719SMasahiro YamadaPHONY += FORCE 1227b453719SMasahiro YamadaFORCE: 1237b453719SMasahiro Yamada 1247b453719SMasahiro Yamada# Read all saved command lines and dependencies for the $(targets) we 1257b453719SMasahiro Yamada# may be building above, using $(if_changed{,_dep}). As an 1267b453719SMasahiro Yamada# optimization, we don't need to read them if the target does not 1277b453719SMasahiro Yamada# exist, we will rebuild anyway in that case. 1287b453719SMasahiro Yamada 1297b453719SMasahiro Yamadaexisting-targets := $(wildcard $(sort $(targets))) 1307b453719SMasahiro Yamada 1317b453719SMasahiro Yamada-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 1327b453719SMasahiro Yamada 1337b453719SMasahiro Yamada.PHONY: $(PHONY) 134