What is an alternative to autotools in Haskell world? I want to be able to choose between different configurations of the same source code.
For example, there are at least two implementations of MD5 in Haskell: Data.Digest.OpenSSL.MD5
and Data.Digest.Pure.MD5
. I'd like to write code in such a way that it can figure out which library is already installed, and didn't require to install the other.
In C I can use Autotools/Scons/CMake + cpp
. In Python I can catch ImportError
. Which tools should I use in Haskell?
In Haskell you use Cabal configurations. At your project top-level directory, you put a file with the extension .cabal
, e.g., <yourprojectname>.cabal
. The contents are roughly:
Name: myfancypackage
Version: 0.0
Description: myfancypackage
License: BSD3
License-file: LICENSE
Author: John Doe
Maintainer: [email protected]
Build-Type: Simple
Cabal-Version: >=1.4
Flag pure-haskell-md5
Description: Choose the purely Haskell MD5 implementation
Default: False
Executable haq
Main-is: Haq.hs
Build-Depends: base-4.*
if flag(pure-haskell-md5)
Build-Depends: pureMD5-0.2.*
else
Build-Depends: hopenssl-1.1.*
The Cabal documentation has more details, in particular the section on Configurations.
As nominolo says, Cabal is the tool to use. In particular, the 'configurations" syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With