I have one microcontroller, but several projects that are compiled from the same source code. I think my script is similar to yours, at least to some extent. My solution was also inspired by the Linux kernel.
config.h
All the source code that needs to access some configuration parameter simply includes a header file called config.h .
config.h consists of only one line:
#include <config/project.h>
project.h
I have several configuration header files, one per project. A project.h consists of macro definitions with values ββsuch as true , false or constants:
#define CONFIG_FOO true #define CONFIG_BAR false #define CONFIG_TIME 100
check.c
This file checks the configuration parameters for correctness: - all parameters must be defined, even if they are not used or significant for this project - unwanted combinations of parameters are signaled - parameter values ββare limited.
#if !defined(CONFIG_FOO) #error CONFIG_FOO not defined #endif #if !defined(CONFIG_BAR) #error CONFIG_BAR not defined #endif #if !defined(CONFIG_TIME) #error CONFIG_TIME not defined #endif #if !(CONFIG_FOO ^ CONFIG_BAR) #error either CONFIG_FOO or CONFIG_BAR should be se #endif #if CONFIG_TIME > 250 #error CONFIG_TIME too big #endif
Makefile
By allowing the compiler to output preprocessor macros, it is possible (with a sed expression) to pass the Makefile the same parameter values ββthat were provided for this project.
source share