Platform 'native': copy compiled program to target folder

I am building a couple of utility programs in ‘native’ mode on a Linux box. The platformio.ini is as follows:

[env]
platform = native
build_flags = 
  -Wextra
  -leModbus
  -pthread
  -lexplain
  -DLOG_LEVEL=3

[env:Smartdose]
build_src_filter = -<*> +<Smartdose.cpp>

[env:DewAir]
build_src_filter = -<*> +<DewAir.cpp>

[env:E3DC]
build_src_filter = -<*> +<E3DC.cpp>

[env:OVAG]
build_src_filter = -<*> +<OVAG.cpp>

[env:PulseCount]
build_src_filter = -<*> +<PulseCount.cpp>

[env:SEmeter]
build_src_filter = -<*> +<SEmeter.cpp>

[env:TempControl]
build_src_filter = -<*> +<TempControl.cpp>

Since every single build will write the generic .pio/build/<envname>/program, I would like to have that copied to some other folder with the name of the env, like

cp .pio/build/<envname>/program bin/<envname>

Alternatively, specifying the respective target destination with some build_flags parameter would be even more convenient.

Extra script with post program action that does a shutil.copy()

You can write an extra_script that dynamically creates the right env["SRC_FILTER]" based off the environment name. This one was e.g. discussed in

1 Like