module Distribution.Simple.BuildPaths (
defaultDistPref, srcPref,
haddockDirName,
hscolourPref, hscolourPref', haddockPref, haddockPref',
autogenModulesDir,
autogenModuleName,
cppHeaderName,
haddockName,
mkLibName,
mkProfLibName,
mkSharedLibName,
exeExtension,
objExtension,
dllExtension,
) where
import Distribution.Package
import Distribution.ModuleName as ModuleName
import Distribution.Compiler
import Distribution.PackageDescription
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Setup
import Distribution.Text
import Distribution.System
import System.FilePath ((</>), (<.>))
srcPref :: FilePath -> FilePath
srcPref distPref = distPref </> "src"
haddockPref, hscolourPref :: FilePath -> PackageDescription -> FilePath
haddockPref = haddockPref' ForDevelopment
hscolourPref = haddockPref' ForDevelopment
hscolourPref' :: HaddockTarget -> FilePath -> PackageDescription -> FilePath
hscolourPref' = haddockPref'
haddockDirName :: HaddockTarget -> PackageDescription -> FilePath
haddockDirName ForDevelopment = display . packageName
haddockDirName ForHackage = (++ "-docs") . display . packageId
haddockPref' :: HaddockTarget -> FilePath -> PackageDescription -> FilePath
haddockPref' haddockTarget distPref pkg_descr
= distPref </> "doc" </> "html" </> haddockDirName haddockTarget 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 :: UnitId -> String
mkLibName lib = "lib" ++ getHSLibraryName lib <.> "a"
mkProfLibName :: UnitId -> String
mkProfLibName lib = "lib" ++ getHSLibraryName lib ++ "_p" <.> "a"
mkSharedLibName :: CompilerId -> UnitId -> String
mkSharedLibName (CompilerId compilerFlavor compilerVersion) lib
= "lib" ++ getHSLibraryName 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"