ARMCMx GCC rules.mk: allow to add to $(OUTFILES)
Posted: Sat Apr 11, 2026 1:34 pm
Hi,
I originally posted this in viewtopic.php?p=43841#p43841, but since this is about the generic rules.mk for all ARMCMx and not just about RP2 specifics, emulator asked me to move this discussion here.
Currenly the file os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk contains this part:
and a bit below:
This means it sets OUTFILES, overwriting anything that already is in OUTFILES. Then when a bit later the "all" target is defined, it uses exactly this definition of OUTFILES.
Makefile syntax is very sensitive to ordering. So any .mk files included before rules.mk can't store anything in OUTFILES as it will be overwritten. .mk files included after rules.mk can add something to OUTFILES, but now this isn't used in the "all"-target anymore since it has already been defined.
I suggest to change this in a way that OUTFILES can be modified by .mk files coming before rules.mk:
What is the reason for this change? The RP2 MCUs have a factory integrated bootloader that wants firmware supplied in a special format, .uf2. I want to create an optional .mk file you can include that will automatically build the .uf2 file whenever you build the "all" target. The change to OUTFILES above is a prerequisite before I can do that.
Please consider merging this.
The patch is available at https://github.com/electroniceel/ChibiO ... k-outfiles and also attached to this post.
I originally posted this in viewtopic.php?p=43841#p43841, but since this is about the generic rules.mk for all ARMCMx and not just about RP2 specifics, emulator asked me to move this discussion here.
Currenly the file os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk contains this part:
Code: Select all
OUTFILES := $(BUILDDIR)/$(PROJECT).elf \
$(BUILDDIR)/$(PROJECT).hex \
$(BUILDDIR)/$(PROJECT).bin \
$(BUILDDIR)/$(PROJECT).dmp \
Code: Select all
all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK
Makefile syntax is very sensitive to ordering. So any .mk files included before rules.mk can't store anything in OUTFILES as it will be overwritten. .mk files included after rules.mk can add something to OUTFILES, but now this isn't used in the "all"-target anymore since it has already been defined.
I suggest to change this in a way that OUTFILES can be modified by .mk files coming before rules.mk:
Code: Select all
--- a/os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk
+++ b/os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk
@@ -79,7 +79,8 @@ ifeq ($(DEPDIR),.)
DEPDIR = .dep
endif
-OUTFILES := $(BUILDDIR)/$(PROJECT).elf \
+# use += to allow previous .mk files to also add to OUTFILES
+OUTFILES += $(BUILDDIR)/$(PROJECT).elf \
$(BUILDDIR)/$(PROJECT).hex \
$(BUILDDIR)/$(PROJECT).bin \
$(BUILDDIR)/$(PROJECT).dmp \
Please consider merging this.
The patch is available at https://github.com/electroniceel/ChibiO ... k-outfiles and also attached to this post.