I've found this shell script for configuration in the wild:
export PKG_CONFIG_PATH="$(opam config var lib)/pkgconfig"
flags="$(pkg-config --static ocaml-freestanding --cflags)"
echo "($flags)"
Porting this to configurator is a problem because it's not possible to access opam variables and pass --static to pkg-config. We should support these features.