Recompile libesp32.a library with different sdkconfig options

I need to recompile libesp32.a to use the external RTC crystal. See

The file $HOME/.platformio/packages/framework-arduinoespressif32/tools/sdk/lib/libesp32.a in my Linux PC is from 26/3/2021 (today is 2/3/2022) so I assume PlatfromIO has downloaded a precompiled version. I would like to modify the configuration in
$HOME/.platformio/packages/framework-arduinoespressif32/tools/sdk/sdkconfig
and build the framework again. How can I do that?
I have tried setting build_flags in platformio.ini but it didn’t work. I got warnings stating that my macro was defined multiple times.

Thanks

Duplicate of ESP32 Arduino recompile SDK and Using latest ESP32 Arduino, but with own IDF configuration.