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: RoccoMarco, lbednarz, tfAteba

faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by faisal »

I want to generate board files if board.fmpp changes. Figured I would use the PRE_MAKE_ALL_RULE_HOOK as follows:

Code: Select all

PRE_MAKE_ALL_RULE_HOOK: genboard

.PHONY: genboard
genboard: .genboard

.genboard: path/to/board/board.fmpp
     fmpp -C path/to/board/board.fmpp -O path/to/board/
     touch .genboard

CLEAN_RULE_HOOK:
     rm -f .genboard


It generates the board file after a clean, and builds the project with the all target. However, if I touch the board.fmpp file and build all again, it just builds the board file and not all the files that depend on board.c/.h . I tried putting the above before and after the point where rules.mk is included in the top level makefile. Also tried a variant where I didn't use the flag file .genboard.

Help would be appreciated from any make gurus out there.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by Giovanni »

Hi Faisal,

Try this:

Code: Select all

BOARD_PATH  := $(CHIBIOS)/os/hal/boards/ST_NUCLEO64_G474RE
BOARD_FILES := $(BOARD_PATH)/board.c $(BOARD_PATH)/board.h

PRE_MAKE_ALL_RULE_HOOK : $(BOARD_FILES)

$(BOARD_FILES) &: $(BOARD_PATH)/cfg/board.chcfg $(BOARD_PATH)/cfg/board.fmpp
   @echo "Rebuilding board files"
   @echo
   @fmpp -C $(BOARD_PATH)/cfg/board.fmpp -O $(BOARD_PATH)/


Note that it requires make 4.3, it is not included in ChibiStudio, this works: https://packages.msys2.org/package/ming ... 86_64-make

Rename it to "make.exe" and replace the existing one.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by faisal »

Giovanni wrote:Hi Faisal,

Try this:

Code: Select all

BOARD_PATH  := $(CHIBIOS)/os/hal/boards/ST_NUCLEO64_G474RE
BOARD_FILES := $(BOARD_PATH)/board.c $(BOARD_PATH)/board.h

PRE_MAKE_ALL_RULE_HOOK : $(BOARD_FILES)

$(BOARD_FILES) &: $(BOARD_PATH)/cfg/board.chcfg $(BOARD_PATH)/cfg/board.fmpp
   @echo "Rebuilding board files"
   @echo
   @fmpp -C $(BOARD_PATH)/cfg/board.fmpp -O $(BOARD_PATH)/


Note that it requires make 4.3, it is not included in ChibiStudio, this works: https://packages.msys2.org/package/ming ... 86_64-make

Rename it to "make.exe" and replace the existing one.

Giovanni


Sorry, I was half asleep when I made the post - there were several errors. Thanks for your code, it almost works :). I didn't know about the "&:" operator. I placed your code before rules.mk is included. Is that the right spot? Or does it matter?

I do a make clean, then a make all. It builds the board files, and goes on the build the rest of the project. Then, I touch board.chcfg, and do a make all again. It rebuilds the board file, and what looks like most of the files in the project. Here's the kicker - I do another make all, and it continues to build a whole bunch of stuff again. After a third make all, it says there is nothing to do. I picked on a few files to demonstrate:
There are 4 assembly files in the project. The first time I do a make clean, then a make all I get this:
Compiling chcoreasm_v7m.S
Compiling vectors.S
Compiling crt0_v7m.S
Compiling crt1.c

Then I touch board.chcfg and I get this after the next make all:
Compiling vectors.S
Compiling chcoreasm_v7m.S

Then after another make all:
Compiling crt0_v7m.S

Then after another make all:
Nothing to be done for 'all'
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by Giovanni »

I tried before or after, it works the same, same problem with the late .S compilation, really no idea about that yet, very strange.

For sure it does not need recompilation so it is safe after the 1st make all.

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

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by Giovanni »

It is fixed by making all asm files include something, for example by adding:

Code: Select all

#define _FROM_ASM_
#include "cmparams.h"  // This includes board.h too


This is probably caused by how dependencies files are generated by the compiler, not sure yet if/how it can be fixed somehow in rules.mk.

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

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by Giovanni »

Nevermind....

This should be it:

Code: Select all

BOARD_PATH  := $(CHIBIOS)/os/hal/boards/ST_NUCLEO64_G474RE
BOARD_FILES := $(BOARD_PATH)/board.c $(BOARD_PATH)/board.h $(BOARD_PATH)/board.mk

PRE_MAKE_ALL_RULE_HOOK : $(BOARD_FILES)

$(BOARD_FILES) &: $(BOARD_PATH)/cfg/board.chcfg $(BOARD_PATH)/cfg/board.fmpp
   @echo "Rebuilding board files"
   @echo
   @fmpp -C $(BOARD_PATH)/cfg/board.fmpp -O $(BOARD_PATH)/


board.mk needs to be added to dependencies because MAKEFILE_LIST is used as dependency for all files.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by faisal »

Awesome, that works!

So, another issue. The board.mk file is usually included in the makefile - however, that is a generated file itself. The best practice would be for make clean to delete all generated files, and source control should only contain the source files (board.chcfg, board.fmpp). If I do a make clean, then the board.mk will be deleted, and the makefile will no longer run since it needs to include board.mk. Sort of a chicken and egg situation.

So, how can we do a make clean, which deletes the generated files - then do a make all and it generates the files and builds the project?
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by Giovanni »

Well, it depends, board files included in the OS should not be deleted and there should be no point in regenerating those. I imagine you need to clean only custom board files, not sure how to handle that, perhaps not deleting files whose path is prefixed by the $(CHIBIOS) string and not deleting .mk files at all, whatever the path.

Giovanni
faisal
Posts: 382
Joined: Wed Jul 19, 2017 12:44 am
Has thanked: 45 times
Been thanked: 62 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by faisal »

Is it not possible to include board.mk after the PRE_MAKE_ALL_RULE_HOOK runs? That would update ALLCSRC and ALLINC (which board.mk appends to) so that the rest of the project can build correctly.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: PRE_MAKE_ALL_RULE_HOOK to generate board files

Post by Giovanni »

You could 1st check if board.mk exists then include it, this way make can proceed if the file is not yet/more there.

Giovanni
Post Reply