I have a working SDL/Haskell application that I would like to build using Cabal instead of the current Makefile (because that is the “Haskell way”). The Makefile is itself very simple, and I was hoping that the default cabal build process could allow me to reconstruct a build command specified in my Makefile. The problem is that it makes use of “sdl-config”, a utility that gives you all the necessary cc- compiler options:
wrapper.o: SDLWrapper_stub.h
ghc -no-hs-main `sdl-config --cflags` -Wall wrapper.c -c
Cabal does not seem to expand that into a shell call when calling GHC. How can I specify that sdl-config’s options should be fed into GHC when compiling wrapper.o?
Using the
configurestyle 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.General solution: the configure script
The $foo.builinfo.in file
The .cabal file
When you run "cabal configure" the "cc-options" field in z.buildinfo will be created to hold:
which cabal will include in the build.
Done.
Specific solution for pkg-config tools
For tools that support the pkg-config-style of configuration, such as
sdlorcairoand others, Cabal has specific support already:So for
sdlyou just need: