Page 1 of 1

ARMCMx GCC rules.mk: allow to add to $(OUTFILES)

Posted: Sat Apr 11, 2026 1:34 pm
by electronic_eel
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:

Code: Select all

OUTFILES := $(BUILDDIR)/$(PROJECT).elf \
             $(BUILDDIR)/$(PROJECT).hex \
             $(BUILDDIR)/$(PROJECT).bin \
             $(BUILDDIR)/$(PROJECT).dmp \
and a bit below:

Code: Select all

all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK
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:

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 \
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.

Re: ARMCMx GCC rules.mk: allow to add to $(OUTFILES)

Posted: Sat Apr 11, 2026 8:15 pm
by electronic_eel
Another way to solve this issue would be to introduce a separate variable that is designed for such additions like this:

Code: Select all

--- a/os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk
+++ b/os/common/startup/ARMCMx/compilers/GCC/mk/rules.mk
@@ -143,7 +143,7 @@ VPATH     = $(SRCPATHS)
 # Makefile rules
 #
 
-all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) POST_MAKE_ALL_RULE_HOOK
+all: PRE_MAKE_ALL_RULE_HOOK $(OBJS) $(OUTFILES) $(ADDITIONAL_OUTFILES) POST_MAKE_ALL_RULE_HOOK
 
 PRE_MAKE_ALL_RULE_HOOK:

Re: ARMCMx GCC rules.mk: allow to add to $(OUTFILES)

Posted: Mon Apr 13, 2026 7:59 am
by Giovanni
Hi,

A new variable looks easier to use.

Giovanni

Re: ARMCMx GCC rules.mk: allow to add to $(OUTFILES)

Posted: Mon Apr 13, 2026 12:53 pm
by electronic_eel
Giovanni wrote: Mon Apr 13, 2026 7:59 am A new variable looks easier to use.
Ok.

Patch attached and also available at https://github.com/electroniceel/ChibiO ... k-outfiles.

Please consider applying.

Once that is in I will start to work with emulator on the RP2 specific part that will use this new variable.

Thank you.

Re: ARMCMx GCC rules.mk: allow to add to $(OUTFILES)

Posted: Sun Jun 07, 2026 7:17 am
by Giovanni

Re: ARMCMx GCC rules.mk: allow to add to $(OUTFILES)

Posted: Tue Jun 09, 2026 6:19 am
by Giovanni
Hi,

Change merged.

Giovanni