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

PRE_MAKE_ALL_RULE_HOOK to generate board files

Postby faisal » Tue Jun 15, 2021 5:45 am

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: 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 » Tue Jun 15, 2021 9:30 am

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: 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 2:14 pm

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: 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 » Tue Jun 15, 2021 3:36 pm

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: 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 » Tue Jun 15, 2021 3:47 pm

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: 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  Topic is solved

Postby Giovanni » Tue Jun 15, 2021 4:01 pm

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: 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 6:28 pm

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: 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 » Tue Jun 15, 2021 6:32 pm

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: 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 6:40 pm

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: 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 » Tue Jun 15, 2021 7:05 pm

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


Return to “General Support”

Who is online

Users browsing this forum: No registered users and 3 guests