I just need to find some time to review all the changes!
I know, I'm not rushing you
That PR does not contain the project restructuring, that will be part of another PR later.
I was thinking, are project build variables passed to the Makefile?
It does not work. As I said in the earlier posts, I tried quite a few methods, here is why they don't work:
Method A: If there is one subproject per hardware target, it only triggers the build of the "codegen" builder if you build one target. If you try to build all configurations with the "build all" then it fails to trigger the subproject build completely. This is a known 15 year old eclipse CDT bug.
Method B: If you put the codegen step into the main project as a "pre build step" (This is different from a builder!) then eclipse will generate its own makefiles before this step runs thus the generated files won't be compiled. This partially works, but you need to compile the project twice, and refresh the project between them. And this does not work at all with "build all" because that executes a clean after build.
Method C: If you put the codegen step into a builder (like it's currently is) then it will be only triggered once, regardless if you asked it to only compile a specific configuration or compile all. And the eclipse internal variable which holds the "active configuration" does not tell you if its running for only that config or all the configurations. Even if it were executed for each target separately when "build all" the active configuration does not change because that contains the name of the config selected on the UI, not what its currently building.
To translate this to the "board variable":
Method A: works for single targets, but due to the bug build all configs does not.
Method B: does not matter, does not work.
Method C: no such variable available in eclipse in the builder stage.
Sorry, I have very little knowledge about Makefiles!
Your approach is with the "if"s is completely wrong
You try to treat "make" as an imperative language, but it is a declarative one! It does not define steps to run, it defines rules how to obtain artifacts.
all : boardX ;
This means to get the target "all" first target "boardX" need to be present (prerequisite), then do nothing.
If you wan't to introduce a variable for example, there is absolutely no need to "if" anything. Simply
all : $(BOARD);
will work (well, actually it won't and this is not a good approach, will explain later). As this says resolve the BOARD variable and that becomes a target which is needed for all. And its possible to use wildchars, variables, etc in the target's name. So this is why that in my current setup you don't see specific targets for each board:
https://github.com/KocsisV/stm32_soldering_iron_controller/blob/updateProjectStructure/mcu/generate_sources.makefile#L24This matches any target that matches this given pattern. The last "touch generated" part is only there to make an actual file exactly at the target's name. This will be used by make to determine if the rule for this target need to be executed or not. If the file is there AND its timestamp is newer than all of its prerequisite, then the rule is already satisfied. This is why the code-gen becomes incremental. It only runs it if the file named "generated" is not present or if you change the templates or the IOC file.
And to why "$(BOARD)" won't work as a prerequisite: it will not check if "BOARD" exists or not if the target (all) is already up to date. So even if you ask it to build a different board if any files in its prerequisites is older than the one you already built then it will simply skip the rule.
This is why I have one rule that matches all boards (./boards/%/src/generated). If I ask make to build target "./boards/XYZ/src/generated" it will execute the rule if the file at "./boards/XYZ/src/generated" is not present or if one of it's prerequisites is newer than it.
So by listing all boards as prerequisite in the "all" target all it says that to get the "all" target it needs those ./boards/.../src/generated files before it can be satisfied.
I recommend you to read this tutorial:
https://makefiletutorial.com/. It explains the basics pretty good. Only thing I used what's not in there is the "second expansion" trick to resolve env vars with env vars.
But again, no such "BOARD" variable can be obtained in "method C", and "method A" is not executed when building all targets. So neither works. And since this whole code-gen only needs to be executed once it's not that annoying. It takes less than 2 minutes on my machine for all 5 to be done. And again don't confuse the board target to the configuration! One board target can be used by multiple configs. If you check my latest commit of the updateProjectStructure, I already added the configs for the LCD variants. 18 configs get's built if you pick build all, but "only" 5 codegen is executed (one for each hardware variant).