PRE_MAKE_ALL_RULE_HOOK to generate board files Topic is solved

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: utzig, lbednarz, tfAteba, barthess, RoccoMarco

faisal
Posts: 290
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 38 times
Been thanked: 39 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby faisal » Tue Jun 15, 2021 7:17 pm

I'm trying to do something similar where I check if board.mk does *not* exist, and then do a touch board.mk to generate an empty one. I read this:
https://www.gnu.org/software/make/manua ... files.html

I think that means if we include the empty board.mk file early on, then generate it, make will automagically reinclude the generated version and then proceed.

faisal
Posts: 290
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 38 times
Been thanked: 39 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby faisal » Tue Jun 15, 2021 8:51 pm

For some reason the PRE_MAKE_ALL_RULE_HOOK runs every time when I run make clean. My CLEAN_RULE_HOOK just deletes the board.c/.h/.mk files . I don't see why calling make clean would result in the PRE_MAKE_ALL_RULE_HOOK running.

I tried commenting out PRE_MAKE_ALL_RULE_HOOK : $(BOARD_FILES) , so that only the $(BOARD_FILES) rule exists (but no link to the eventual make all or clean targets) - but that didn't work. When I run a make clean multiple times, it keeps running the $(BOARD_FILES) rule and generates the board files, which clean then deletes right after ...

faisal
Posts: 290
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 38 times
Been thanked: 39 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby faisal » Tue Jun 15, 2021 11:18 pm

I'm finding out some more stuff ... Make's order-only-prerequisites don't really enforce an order when running with multiple jobs (i.e. -j4). You need to introduce actual dependencies between them to enforce ordering ..

faisal
Posts: 290
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 38 times
Been thanked: 39 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby faisal » Wed Jun 16, 2021 12:24 am

Going further down the rabbit hole - Ever wanted a GNU Make debugger to step thru and inspect variables? Give remake a try. It works!

https://remake.readthedocs.io/en/latest/

faisal
Posts: 290
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 38 times
Been thanked: 39 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby faisal » Wed Jun 16, 2021 6:12 pm

I think I get it now, if anyone else is interested in learning a little more:
https://github.com/faisal-shah/makefile-experiments

User avatar
Giovanni
Site Admin
Posts: 13629
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 888 times
Been thanked: 768 times
Contact:

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby Giovanni » Wed Jun 16, 2021 6:19 pm

Is that a generic example not related to boards right?

Giovanni

faisal
Posts: 290
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 38 times
Been thanked: 39 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby faisal » Wed Jun 16, 2021 6:21 pm

Giovanni wrote:Is that a generic example not related to boards right?

Giovanni


Yep. It follows the same concept though .. just a simple makefile to play with.

Code: Select all

.PHONY: clean all


-include module.mk

SRC := foo.c bar.c $(MODULE_SRC)
SRCBUILT := $(foreach f,$(SRC),$(f).built)
$(info restarts = $(MAKE_RESTARTS))
$(info SRC = $(SRC))

all: PRE_MAKE_ALL_HOOK $(SRCBUILT)

$(SRCBUILT): $(SRC)
   @echo built $@
   @touch $@

MODULE_FILES = module.c module.mk

PRE_MAKE_ALL_HOOK: $(MODULE_FILES)

$(MODULE_FILES) &: module.template
   @echo "generating module"
   @touch module.c
   @echo "MODULE_SRC = module.c" > module.mk

clean:
   @echo - module.mk
   @echo - module.c
   @echo - *.built
   @rm -f module.mk 2>/dev/null
   @rm -f module.c 2>/dev/null
   @rm -f *.built 2>/dev/null


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 2 guests