Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
52 lines (47 sloc) 1.87 KB
import Data.Maybe
import Distribution.PackageDescription hiding (Flag)
import Distribution.Simple
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.Simple.Utils
import System.Directory
main = defaultMainWithHooks simpleUserHooks
{
preConf = makeExtLib
, confHook = \a f -> confHook simpleUserHooks a f >>= updateExtraLibDirs
, postCopy = copyExtLib
, postClean = cleanExtLib
}
makeExtLib :: Args -> ConfigFlags -> IO HookedBuildInfo
makeExtLib _ flags = do
let verbosity = fromFlag $ configVerbosity flags
rawSystemExit verbosity "env"
["make", "--directory=ext_lib"]
return emptyHookedBuildInfo
updateExtraLibDirs :: LocalBuildInfo -> IO LocalBuildInfo
updateExtraLibDirs localBuildInfo = do
let packageDescription = localPkgDescr localBuildInfo
lib = fromJust $ library packageDescription
libBuild = libBuildInfo lib
dir <- getCurrentDirectory
return localBuildInfo {
localPkgDescr = packageDescription {
library = Just $ lib {
libBuildInfo = libBuild {
extraLibDirs = (dir ++ "/ext_lib/lib") :
extraLibDirs libBuild
}
}
}
}
copyExtLib :: Args -> CopyFlags -> PackageDescription -> LocalBuildInfo -> IO ()
copyExtLib _ flags pkg_descr lbi = do
let libPref = libdir . absoluteInstallDirs pkg_descr lbi
. fromFlag . copyDest
$ flags
let verbosity = fromFlag $ copyVerbosity flags
rawSystemExit verbosity "cp" ["ext_lib/lib/libext.a", libPref]
cleanExtLib :: Args -> CleanFlags -> PackageDescription -> () -> IO ()
cleanExtLib _ flags _ _ =
let verbosity = fromFlag $ cleanVerbosity flags
in rawSystemExit verbosity "env" ["make", "--directory=ext_lib", "clean"]