The general principle is described in this answer: https://stackoverflow.com/a/6034881/1663197
Using the configure style in Cabal, you can write a little configure
script that substitutes a variable for the output of the sdl-config
command. The values will then be replaced in a $foo.buildinfo.in file,
yielding a $foo.buildinfo file, that Cabal will include in the build
process.
First you need to switch your cabal build-type
to Configure
in project.cabal. Configure style is described in cabal users guide. For build type Configure
the contents of Setup.hs must be:
import Distribution.Simple
main = defaultMainWithHooks autoconfUserHooks
In case of handling GHC runtime version you can have a variable @GHC_VERSION@
corresponding to it in a project.buildinfo.in file:
ghc-options: -lHSrts-ghc@GHC_VERSION@
Finally you write a configure bash script that gets GHC version as mgsloan suggested and generates project.buildinfo file by substitution of @GHC_VERSION@
varibale in project.buildinfo.in file:
GHC_VERSION=$(stack exec -- ghc-pkg field ghc version --simple-output)
sed 's,@GHC_VERSION@,'"$GHC_VERSION"',' project.buildinfo.in > project.buildinfo
This way when build is started it will first execute configure script, then read project.buildinfo file and merge with project.cabal.
Also it may be worth to populate extra-source-files
with configure and
project.buildinfo.in; extra-tmp-files
with project.buildinfo in project.cabal.
A more sophisticated solution may be inspired by this answer: https://stackoverflow.com/a/2940799/1663197