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?

Example:

[env:ttgobeam]
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 = 
    ${common_env_data.lib_deps_all}
    ${common_env_data.lib_deps_gps}
build_flags = 
    ${common_env_data.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.

Sure:

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 =
${common_env_data.build_flags}
-include “src/hal/${env_name}.h”

Ah… Just use

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

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

1 Like

@ivankravets

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?

Like

[common]
platform = espressif32
framework = arduino
monitor_speed = 115200

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

[env:type2]
include $[common]
board = foo2

sure.

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

http://docs.platformio.org/en/latest/projectconf/dynamic_variables.html

Hope this helps!!

1 Like