Page 2 of 2

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Posted: Tue Jun 15, 2021 7:17 pm
by faisal
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.

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Posted: Tue Jun 15, 2021 8:51 pm
by faisal
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 ...

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Posted: Tue Jun 15, 2021 11:18 pm
by faisal
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 ..

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Posted: Wed Jun 16, 2021 12:24 am
by faisal
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/

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Posted: Wed Jun 16, 2021 6:12 pm
by faisal
I think I get it now, if anyone else is interested in learning a little more:
https://github.com/faisal-shah/makefile-experiments

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Posted: Wed Jun 16, 2021 6:19 pm
by Giovanni
Is that a generic example not related to boards right?

Giovanni

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Posted: Wed Jun 16, 2021 6:21 pm
by faisal
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