i did it slightly differently, i used a makefile
viewtopic.php?f=41&t=183
viewtopic.php?f=47&t=37
but really using a makefile isn't the most portable means
these days it seemed the 'best practice' approach seem to be
arduino cli - for the build
https://blog.arduino.cc/2020/03/13/ardu ... roduction/
and integrated with IDE
https://marketplace.visualstudio.com/it ... de-arduino
https://www.arduino.cc/en/Tutorial/gett ... ith-ide-v2
the key concept is you should use incremental build and not use /tmp/ directories. this is so that each time you rebuild the old pre-compiled object files is simply re-linked. And only those files that you edit are rebuilt
i'm not against pre-compiled HAL/LL files, in fact i think both the 'old' arduino ide , arduino-cli and the recent build stacks and tool chains supports that.
it is kind of compile the object files into a .a library. then all the linking uses that .a file.
it'd take researching a little to figure out how to do that, shouldn't be too difficult.
and you can still keep your sources there. it is 2 steps, first build the lib (.a file) then build the sketch sources linked against the .a file.
the *catch* i think is if you have 1001 if-defs for each different mcu and boards combinations, then you would end up with 1001 .a / lib files for each of those permutations, assuming that the if-defs results in different codes being assembled into the object files. that is simply fixed if you only use 1 mcu and 1 board, most of the time it is. And u'd only need to figure out how to build that .a lib and link against it.
to understand the state-of-the-art of all that if-defs, try reviewing the adafruit ili9341 lcd library codes and feel the complexity.
there are n number of if-defs you can use standard gpio (i.e. digitalWrite), digitalWrite fast, software spi, hardware spi, then if defs for each different mcu combinations, then maybe if defs for each different core, and more if defs for n number of permutations of possible configurations in the most fluid possible way. the code assembled into the object file can range from everything to nothing, simply changing the if-defs
https://github.com/adafruit/Adafruit_ILI9341
and didn't everyone only want an lcd library? if only all the mcus every created this far has 1 GB of sram and 1GB of flash.
all that if-defs can be 'dynamic', the program decides at run time what code to run
write 1 firmware, it can run on all the mcus and cpus ever created