Personal tools

Cabal

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
 
m
Line 31: Line 31:
 
> putStrLn buildCmd
 
> putStrLn buildCmd
 
> system buildCmd
 
> system buildCmd
> let cpCmd = "cp "++(dllFile pkg)++" "++(name pkg)++"\\"++(dllFile pkg)
+
> let dll = dllFile pkg
> putStrLn cpCmd
+
> let cpDllCmd = "cp " ++ dll ++ " " ++ (name pkg) ++ "\\" ++ dll
> system cpCmd
+
> putStrLn cpDllCmd
  +
> system cpDllCmd
 
> ghcExe :: LocalBuildInfo -> String
 
> ghcExe :: LocalBuildInfo -> String
 
> ghcExe info = "\"" ++ (compilerPath (compiler info)) ++ "\""
 
> ghcExe info = "\"" ++ (compilerPath (compiler info)) ++ "\""

Revision as of 20:51, 26 July 2006

The Haskell Cabal The Common Architecture for Building Applications and Libraries

http://www.haskell.org/cabal/

Building Dlls on Windows with Cabal

Cabal does not currently support building dlls on windows out of the box. Some details about why can be found here: http://www.haskell.org/ghc/docs/6.4.2/html/users_guide/packages.html http://www.haskell.org/ghc/docs/6.4.2/html/users_guide/win32-dlls.html

This means that we have to do a bit of hackery to get Cabal to build a dll from a library. As long as we build a single DLL from the entire project the dll should behave as expected.

The following Setup.lhs should do the trick for most projects which consist of a single library which needs to be built as a dll. If you need to specify a dll export file you'll need to modify the function cmd to take this into account.

#! /usr/bin/runghc
 
> import Distribution.Simple
> import Distribution.Simple.LocalBuildInfo
> import Distribution.PackageDescription
> import System.Cmd
> import System.Directory
> import Data.List
>
>
> main = defaultMainWithHooks (defaultUserHooks { postBuild = buildDll })
>   where
>   buildDll _ _ pkg info = do putStrLn "Building Dll..."
>                              setCurrentDirectory (buildDir info)
>                              let buildCmd = cmd pkg info
>                              putStrLn buildCmd
>                              system buildCmd
>                              let dll = dllFile pkg
>                              let cpDllCmd = "cp " ++ dll ++ " " ++ (name pkg) ++ "\\" ++ dll
>                              putStrLn cpDllCmd
>                              system cpDllCmd
>   ghcExe :: LocalBuildInfo -> String
>   ghcExe info = "\"" ++ (compilerPath (compiler info)) ++ "\""
>   mainOFile :: PackageDescription -> String
>   mainOFile pd = "HS" ++ (name pd) ++ "-" ++ (showVersion (pkgVersion (package pd))) ++ ".o"
>   cmd :: PackageDescription -> LocalBuildInfo -> String
>   cmd pd i = (ghcExe i) ++ " --mk-dll -o " ++ (dllFile pd) ++ " " ++ (mainOFile pd) ++ " " ++ (packages i)
>   packages :: LocalBuildInfo -> String
>   packages i = foldl1 (\x y -> x ++ " " ++ y) (map showPackage (packageDeps i))
>   showPackage :: PackageIdentifier -> String
>   showPackage pi = "-package " ++ showPackageId pi
>   name :: PackageDescription -> String
>   name = pkgName . package 
>   dllFile :: PackageDescription -> String
>   dllFile pd = (name pd) ++ ".dll"