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 8 9# for c_flags 10include $(srctree)/scripts/Makefile.lib 11 12targets := 13 14quiet_cmd_cc_o_c = CC $@ 15 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< 16 17%.o: %.c FORCE 18 $(call if_changed_dep,cc_o_c) 19 20quiet_cmd_as_o_S = AS $@ 21 cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< 22 23%.o: %.S FORCE 24 $(call if_changed_dep,as_o_S) 25 26# Built-in dtb 27# --------------------------------------------------------------------------- 28 29quiet_cmd_wrap_dtbs = WRAP $@ 30 cmd_wrap_dtbs = { \ 31 echo '\#include <asm-generic/vmlinux.lds.h>'; \ 32 echo '.section .dtb.init.rodata,"a"'; \ 33 while read dtb; do \ 34 symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \ 35 echo '.balign STRUCT_ALIGNMENT'; \ 36 echo ".global $${symbase}_begin"; \ 37 echo "$${symbase}_begin:"; \ 38 echo '.incbin "'$$dtb'" '; \ 39 echo ".global $${symbase}_end"; \ 40 echo "$${symbase}_end:"; \ 41 done < $<; \ 42 } > $@ 43 44.builtin-dtbs.S: .builtin-dtbs-list FORCE 45 $(call if_changed,wrap_dtbs) 46 47quiet_cmd_gen_dtbs_list = GEN $@ 48 cmd_gen_dtbs_list = \ 49 $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@ 50 51.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE 52 $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list)) 53 54targets += .builtin-dtbs-list 55 56ifdef CONFIG_GENERIC_BUILTIN_DTB 57targets += .builtin-dtbs.S .builtin-dtbs.o 58vmlinux: .builtin-dtbs.o 59endif 60 61# vmlinux 62# --------------------------------------------------------------------------- 63 64ifdef CONFIG_MODULES 65targets += .vmlinux.export.o 66vmlinux: .vmlinux.export.o 67endif 68 69ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) 70 71# Final link of vmlinux with optional arch pass after final link 72cmd_link_vmlinux = \ 73 $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \ 74 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 75 76targets += vmlinux 77vmlinux: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE 78 +$(call if_changed_dep,link_vmlinux) 79 80# module.builtin.ranges 81# --------------------------------------------------------------------------- 82ifdef CONFIG_BUILTIN_MODULE_RANGES 83__default: modules.builtin.ranges 84 85quiet_cmd_modules_builtin_ranges = GEN $@ 86 cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ 87 88targets += modules.builtin.ranges 89modules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ 90 modules.builtin vmlinux.map vmlinux.o.map FORCE 91 $(call if_changed,modules_builtin_ranges) 92 93vmlinux.map: vmlinux 94 @: 95 96endif 97 98# Add FORCE to the prerequisites of a target to force it to be always rebuilt. 99# --------------------------------------------------------------------------- 100 101PHONY += FORCE 102FORCE: 103 104# Read all saved command lines and dependencies for the $(targets) we 105# may be building above, using $(if_changed{,_dep}). As an 106# optimization, we don't need to read them if the target does not 107# exist, we will rebuild anyway in that case. 108 109existing-targets := $(wildcard $(sort $(targets))) 110 111-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 112 113.PHONY: $(PHONY) 114