7

I recently built a small, one-file Haskell utility to be included in 'tools' section of my otherwise pure PHP (raised eyebrows, I know) project.

Initially I checked in both the .hs source file as well as the binary generated on my Linux development machine into the version control system we use (Git). But now as I think more about it, I'd like to create cross platform makefiles to go along with it so other developers can easily compile it on their systems.

Are there some best practices / guidelines, or even better, Makefile templates available that I can download? Nothing fancy, just something that allows the developers to specify some details about their GHC setup and run a simple script to get started.

4

2 に答える 2

11

The recommended way of distributing your Haskell projects is to use Cabal. Cabal is both a build system and package manager for Haskell code, and it makes it easy to build Haskell code on different platforms while handling dependencies for you.

Here's an example cabal file:

Name:           MyPackage
Version:        0.0
Cabal-Version:  >= 1.2
License:        BSD3
Author:         Angela Author
Synopsis:       Small package an utility program
Build-Type:     Simple

Executable myutility
  Build-Depends:  base
  Main-Is:        Main.hs
  Hs-Source-Dirs: src

You can generate a cabal file interactively by running

$ cabal init

Cabal will then ask you some simple questions and generate a cabal file based on your answers. You can then tweak this file to fit your specific needs.


To install your package just run this in the package directory

$ cabal install

You can also upload your package to Hackage, the standard Haskell package respository. This way, people can download and install your package (and any dependencies) in a single step with the command

$ cabal install mypackage

There also exist tools for converting Cabal packages to other package managers, if you don't want to require your users to have Cabal installed (although Cabal is included in the Haskell Platform).

It also plays well with Haddock for generating reference documentation for your package. Check out some of the packages on Hackage for an example of the results.

There is also work currently being done to improve support for test suites in Cabal.

Overall, these reasons and many more make it a great benefit to use Cabal to organize, build and distribute your Haskell projects.

于 2011-05-11T15:50:40.243 に答える
2

If you can afford another dependency, try cabal. It's a buildsystem specially designed for Haskell.

于 2011-05-11T15:44:52.457 に答える