From 4be0c3018a2af32207398c08635d634c502af736 Mon Sep 17 00:00:00 2001 From: xinyangli Date: Wed, 11 Dec 2024 14:28:28 +0800 Subject: [PATCH] Makefile: add ADD_IMAGE helper --- scripts/helpers/rules.mk | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/helpers/rules.mk b/scripts/helpers/rules.mk index ad8e187..7ce4255 100644 --- a/scripts/helpers/rules.mk +++ b/scripts/helpers/rules.mk @@ -34,7 +34,7 @@ $$(filter %.S.o, $$($(1)OBJS)): $$(BUILDDIR)/%.S.o: %.S endef # Usage: -# $(1): Library name +# $(1): Library build path # $(2): Library variable prefix # E.g: # $(eval $(call ADD_LIBRARY,am-riscv,AM_)) @@ -46,3 +46,19 @@ $(1): $$($(2)OBJS) @$$(AR) rcs $$@ $$($(2)OBJS) endef +# Usage: +# $(1): Image build path +# $(2): Image variable prefix +# E.g: +# $(eval $(call ADD_IMAGE,dummy,DUMMY_)) +define ADD_IMAGE +$(eval $(call COMPILE_RULES,$(2))) +$(1).elf: $$($(2)OBJS) + @mkdir -p $$(dir $$@) + @echo + LD "->" $$(patsubst $$(CURDIR)/%,%,$(1).elf) + @$$(LD) $$($(2)_LDFLAGS) -o $$@ --start-group $$($(2)OBJS) --end-group +$(1).bin: $(1).elf + @echo + OBJCOPY "->" $$(patsubst $$(CURDIR)/%,%,$(1)) + @$$(OBJCOPY) -S --set-section-flags .bss=alloc,contents -O binary $(1).elf $(1).bin +endef +