Programmatically Listing `C-sources` in Haskell Cabal Files

321 Views Asked by At

I am involved in a Haskell project which involves a lot of C FFI. Thus, for every src/HaskellFile.hs I have in my project, I have a corresponding src/HaskellFile.c C source file. This means I have to manually this all of these C sources in my cabal project:

C-sources:           src/HaskellFile1.c, src/HaskellFile2.c

...and so forth.

Question: Is it possible to programmatically list out these files in my cabal project file? Something like:

C-sources:           src/*.c

..? (For the record, I tried the above and it didn't work).

2

There are 2 best solutions below

1
On

I wanted to add a comment, but stackoverflow tells me that I need 50 reputation to comment!

You should be able to do this with a custom Setup.hs file. Here is an example that might help you: https://hackage.haskell.org/package/base-noprelude-4.7.0.0/src/Setup.hs

0
On

Sorry, no programming is allowed in cabal files. This level of simplicity has some drawbacks, as you note, but it also has some benefits: tools are more predictable, and it is drop-dead simple to read somebody else's cabal file (you don't have to turn on your programmer brain!).