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

Report here problems in any of ChibiOS components. This forum is NOT for support.
Post Reply
electronic_eel
Posts: 95
Joined: Sat Mar 19, 2016 8:07 pm
Has thanked: 8 times
Been thanked: 23 times

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

Post 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.
Attachments
rules.mk-outfiles.zip
(577 Bytes) Downloaded 31 times
electronic_eel
Posts: 95
Joined: Sat Mar 19, 2016 8:07 pm
Has thanked: 8 times
Been thanked: 23 times

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

Post 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:
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post by Giovanni »

Hi,

A new variable looks easier to use.

Giovanni
electronic_eel
Posts: 95
Joined: Sat Mar 19, 2016 8:07 pm
Has thanked: 8 times
Been thanked: 23 times

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

Post 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.
Attachments
rules.mk-outfiles.zip
(592 Bytes) Downloaded 39 times
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post by Giovanni »

User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

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

Post by Giovanni »

Hi,

Change merged.

Giovanni
Post Reply