0

I am developing C code for five different embedded controllers. In the past, I used to have a separate project for each of those controllers, yet the amount of shared code is around 98%. Therefore, I merged the all projects and abstracted the hardware access by preprocessor macros. Example:

Compiler:

gcc ... -D FS_CONTROLLER_A=STD_ON

Code:

#if FS_CONTROLLER_A == STD_ON
int8_t accessPin = 0;
#else
int8_t accessPin = 1; 
#endif

This solutions saves a lot of time and works like a charm. Unfortunately, iterative builds do not work. If I build controller A, the decider of my build environment 'sCons' creates an MD5 Checksum of each file it builds. When I switch to controller B, only the preprocessor macros are changed. Therefore, the MD5 checksum stays the same and the decider does not detect any changes and refuses to rebuild the file.

I could implement and register a custom decider in sCons, yet this sounds like a lot of dirty hustle. Is there a solution to this problem already? I wouldn't hesistate to switch to cMake or Gradle if they offer a native solution. From my point of view, any solution would needs to run the preprocessor before calling a decider.

PS: I know that the Keil Arm IDE comes with this functionality, yet I want and need to use my own build environment.

Jens
  • 69,818
  • 15
  • 125
  • 179
lukas
  • 1
  • 1
  • Do you compile a source "x.c" into a single "x.o" when it has variants depending on the compiler switches? Consider to compile separated object files. – the busybee Sep 14 '20 at 10:02
  • That's a nice idea, i will implement that. That you for the idea. Unfortunately, i still need to find a way to change the decider since i also have a lot of features based on precompiler switches. For example i can make the controller use either CAN oder LIN via feature switch. – lukas Sep 14 '20 at 13:52
  • If you change the command line of the compile, it should rebuild. The build "action" is part of the signature for a file which is checked to determine if it needs to recompile. You don't have to create a custom decider. What you're doing is vanilla scons. Please bring your issue to the users mailing list, irc, or discord server we can help you resolve it there. – bdbaddog Sep 14 '20 at 16:07
  • What is a "precompiler switch"? Did you me preprocessor flags? Or is this something different? – bdbaddog Sep 14 '20 at 16:13
  • Just repeating: the fact that the *content* signature has not changed is not enough to decide a rebuild is not needed, as the *build* signature is different if the flags are different and it's also considered. So there's something else going on keeping this from working the way you want. – Mats Wichmann Sep 14 '20 at 20:25
  • @bdbaddog thanks a lot for your support, i will join your discord server during the next days. – lukas Sep 17 '20 at 13:44
  • @bdaddog your guess is right, i was indeed talking about preprocessor flags but couldn't find the precise description. – lukas Sep 17 '20 at 13:45
  • @bdaddog The issue might be caused by my project structure. The sConstruct file lies within to "build_tools" folder that sits next to "source_code" and "build_results". I tried to solve this by the "VariantDir" option but failed. Therefore, objects are compiled in place and copied by a python script after the build process. Yet the .elf file is placed in the right location. – lukas Sep 17 '20 at 13:47
  • @lukas - there's a way to remove that extra copy. Please come to the support channel and we'll help you there. – bdbaddog Sep 19 '20 at 03:49

0 Answers0