general: need a better way to select config files at compile time

Bug #1802885 reported by Selene ToyKeeper
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Flashlight Firmware Repository
Fix Released
Medium
Unassigned

Bug Description

The code currently supports a bunch of different drivers and a bunch of different UI configurations, with one config per file. This is nice, but the way it pulls in those files requires having a few extra lines per configuration.

Basically, there are a bunch of "ifdef FOO, include foo.h" clauses. And I want to get rid of those. It's getting messy, as the number of supported build targets increases.

Revision history for this message
Thomas Arthofer (arthofer-thomas) wrote :

Found a way, working on it.

/*
C-preprocessor hack to include the cfg-file specified by the define "DRIVER"

Sources:
  https://www.microchip.com/forums/FindPost/845119
  https://stackoverflow.com/questions/9096201/concatenate-string-in-c-include-filename
  https://stackoverflow.com/questions/6742501/whats-the-exact-step-of-macro-expanding/6742619#6742619

*/

#ifndef DRIVER
#error You must define DRIVER to import the correct cfg_<driver>.h file
#endif

#define str(s) #s
#define xstr(s) str(s)
#define INCFILE2(a, n) a ## n
#define INCFILE(a,b) INCFILE2(a,b)

//#pragma message xstr(INCFILE(cfg_, DRIVER).h)
#include xstr(INCFILE(cfg_, DRIVER).h)

Revision history for this message
Thomas Arthofer (arthofer-thomas) wrote :

Looks like it's working for anduril, but since I had to rename a few header files, I should also check the other projects.

If you want to take a look, here is a preview: https://zeroflow.at/flashlight/flashlight-firmware-ref-include.zip

Revision history for this message
Selene ToyKeeper (toykeeper) wrote :

Thanks! This mechanism seems to work pretty well. I applied it throughout my part of the repository and uploaded a new revision to the fsm branch with the changes. It should be in fsm branch revision 397. Before/after shows no md5sum changes, so I don't think it broke anything.

I used a somewhat simpler version of the include mechanism though, and didn't rename any files.

Changed in flashlight-firmware:
status: Confirmed → Fix Committed
Changed in flashlight-firmware:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.