module Distribution.Simple.BuildPaths (
defaultDistPref, srcPref,
hscolourPref, haddockPref,
autogenModulesDir,
autogenModuleName,
cppHeaderName,
haddockName,
mkLibName,
mkProfLibName,
mkSharedLibName,
exeExtension,
objExtension,
dllExtension,
) where
import System.FilePath ((</>), (<.>))
import Distribution.Package
( packageName )
import Distribution.ModuleName (ModuleName)
import qualified Distribution.ModuleName as ModuleName
import Distribution.Compiler
( CompilerId(..) )
import Distribution.PackageDescription (PackageDescription)
import Distribution.Simple.LocalBuildInfo
( LocalBuildInfo(buildDir), LibraryName(..) )
import Distribution.Simple.Setup (defaultDistPref)
import Distribution.Text
( display )
import Distribution.System (OS(..), buildOS)
srcPref :: FilePath -> FilePath
srcPref distPref = distPref </> "src"
hscolourPref :: FilePath -> PackageDescription -> FilePath
hscolourPref = haddockPref
haddockPref :: FilePath -> PackageDescription -> FilePath
haddockPref distPref pkg_descr
= distPref </> "doc" </> "html" </> display (packageName pkg_descr)
autogenModulesDir :: LocalBuildInfo -> String
autogenModulesDir lbi = buildDir lbi </> "autogen"
cppHeaderName :: String
cppHeaderName = "cabal_macros.h"
autogenModuleName :: PackageDescription -> ModuleName
autogenModuleName pkg_descr =
ModuleName.fromString $
"Paths_" ++ map fixchar (display (packageName pkg_descr))
where fixchar '-' = '_'
fixchar c = c
haddockName :: PackageDescription -> FilePath
haddockName pkg_descr = display (packageName pkg_descr) <.> "haddock"
mkLibName :: LibraryName -> String
mkLibName (LibraryName lib) = "lib" ++ lib <.> "a"
mkProfLibName :: LibraryName -> String
mkProfLibName (LibraryName lib) = "lib" ++ lib ++ "_p" <.> "a"
mkSharedLibName :: CompilerId -> LibraryName -> String
mkSharedLibName (CompilerId compilerFlavor compilerVersion) (LibraryName lib)
= "lib" ++ lib ++ "-" ++ comp <.> dllExtension
where comp = display compilerFlavor ++ display compilerVersion
exeExtension :: String
exeExtension = case buildOS of
Windows -> "exe"
_ -> ""
objExtension :: String
objExtension = "o"
dllExtension :: String
dllExtension = case buildOS of
Windows -> "dll"
OSX -> "dylib"
_ -> "so"