Replacing TARGET extentions in Variables?

Hi all,
I’d like to generate dependency files (and src listings later…) which can be accomplished in gcc by


I can use

build_flags = -MF"${TARGET}.d"

which seems to work but since TARGET already contains an “.o” suffix, the dependency file gets “.o.d”
I was just thinking if there is an easy solution (w/o extra_scripts).
The cariables are parsed somehow, since


is used in the environment, and silly things like

${12 + 4}

also work…

With what platformio.ini does that work? I tried with an Uno and STM32 bluepill project and neither compiler accepted it.

cc1.exe: error: to generate dependencies you must specify either ‘-M’ or ‘-MM’

It just generated the compiler option


And btw regular python code evaluations and string splicing works.

build_flags = -MF"${str(TARGET)[:-2]}.d"

generates the compiler option


(but the compiler still rejects this ofc)

yes, the full flags will be:

build_flags =

or/and for source listings replace/add


both options are working in e.g. arm-none-eabi-gcc.

But both generated files does’nt replace the “.o” extention. Its more a cosmetic thing, but I was wondering if this could be easily changed…


build_flags = -MMD -MP -MF"${str(TARGET)[:-4]}.d"

resulting in

-MMD -MP -MF.pio\build\bluepill\SrcWrapper\src\HAL\stm32yyxx_hal_adc_ex.d

would be working right? I.e. just the last 4 characters of the target path removed, then .d appended.

Well okay it works for .c.o.d replacment but not for .cpp.o. Do you want to retain the .c/.cpp extension? If yes [:-2] should work everywhere.

1 Like