Generate dynamic header .h files from env:NAME

I want to generate the name of a include.h file from the name of the environment section in platformio.ini. Is that possible?


platform = ${common_env_data.platform_espressif32}
framework = arduino
board = esp32dev
board_build.partitions = ${common_env_data.board_build.partitions}
monitor_speed = 115200
upload_speed = 921600
lib_deps = 
build_flags = 
    -include "src/hal/ttgobeam.h"

Is it possible to generate the filename “ttgobeam.h” from the environment name “ttgobeam”?
This way i could have a generic template in platformio.ini.


Thanks for the hint. So, how can i build the inlude path in platformio.ini using the environment variable? Still didn’t understand it.

What does it mean? Please rephrase.

I need something like

build_flags =
-include “src/hal/${env_name}.h”

Ah… Just use

build_flags =
   -include “src/hal/${PIOENV}.h”

Wow, that was amazingly easy!
I love PlatformIO! Great!

1 Like


To make my platformio.ini even more generic, is it possible to have a common block in platformio.ini, that is used by several environments?


platform = espressif32
framework = arduino
monitor_speed = 115200

[env: type1]
include $[common]
board = foo1

include $[common]
board = foo2


Please have a look at the dynamic variables and adapt to your requirements… :slight_smile:

Hope this helps!!

1 Like