BuildPaths.hs 3.47 KB
Newer Older
1
2
3
4
5
-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.Simple.BuildPaths
-- Copyright   :  Isaac Jones 2003-2004,
--                Duncan Coutts 2008
6
-- License     :  BSD3
7
--
Duncan Coutts's avatar
Duncan Coutts committed
8
-- Maintainer  :  cabal-devel@haskell.org
9
10
11
12
13
14
-- Portability :  portable
--
-- A bunch of dirs, paths and file names used for intermediate build steps.
--

module Distribution.Simple.BuildPaths (
15
    defaultDistPref, srcPref,
16
17
18
19
    hscolourPref, haddockPref,
    autogenModulesDir,

    autogenModuleName,
20
    cppHeaderName,
21
22
23
24
25
26
27
28
29
30
31
32
33
    haddockName,

    mkLibName,
    mkProfLibName,
    mkSharedLibName,

    exeExtension,
    objExtension,
    dllExtension,

  ) where


34
import Distribution.Package
35
import Distribution.ModuleName as ModuleName
36
import Distribution.Compiler
37
import Distribution.PackageDescription
38
import Distribution.Simple.LocalBuildInfo
39
import Distribution.Simple.Setup
40
import Distribution.Text
41
42
43
import Distribution.System

import System.FilePath ((</>), (<.>))
44
45
46
47

-- ---------------------------------------------------------------------------
-- Build directories and files

48
49
srcPref :: FilePath -> FilePath
srcPref distPref = distPref </> "src"
50

51
hscolourPref :: FilePath -> PackageDescription -> FilePath
52
53
hscolourPref = haddockPref

54
55
haddockPref :: FilePath -> PackageDescription -> FilePath
haddockPref distPref pkg_descr
Duncan Coutts's avatar
Duncan Coutts committed
56
    = distPref </> "doc" </> "html" </> display (packageName pkg_descr)
57
58
59
60
61

-- |The directory in which we put auto-generated modules
autogenModulesDir :: LocalBuildInfo -> String
autogenModulesDir lbi = buildDir lbi </> "autogen"

62
63
cppHeaderName :: String
cppHeaderName = "cabal_macros.h"
64
65

-- |The name of the auto-generated module associated with a package
66
autogenModuleName :: PackageDescription -> ModuleName
67
autogenModuleName pkg_descr =
68
69
  ModuleName.fromString $
    "Paths_" ++ map fixchar (display (packageName pkg_descr))
70
71
72
73
  where fixchar '-' = '_'
        fixchar c   = c

haddockName :: PackageDescription -> FilePath
Duncan Coutts's avatar
Duncan Coutts committed
74
haddockName pkg_descr = display (packageName pkg_descr) <.> "haddock"
75
76
77
78

-- ---------------------------------------------------------------------------
-- Library file names

79
mkLibName :: UnitId -> String
80
mkLibName lib = "lib" ++ getHSLibraryName lib <.> "a"
81

82
mkProfLibName :: UnitId -> String
83
mkProfLibName lib =  "lib" ++ getHSLibraryName lib ++ "_p" <.> "a"
84
85
86
87

-- Implement proper name mangling for dynamical shared objects
-- libHS<packagename>-<compilerFlavour><compilerVersion>
-- e.g. libHSbase-2.1-ghc6.6.1.so
88
mkSharedLibName :: CompilerId -> UnitId -> String
89
90
mkSharedLibName (CompilerId compilerFlavor compilerVersion) lib
  = "lib" ++ getHSLibraryName lib ++ "-" ++ comp <.> dllExtension
91
  where comp = display compilerFlavor ++ display compilerVersion
92
93
94

-- ------------------------------------------------------------
-- * Platform file extensions
95
-- ------------------------------------------------------------
96

Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
97
-- | Default extension for executable files on the current platform.
98
99
-- (typically @\"\"@ on Unix and @\"exe\"@ on Windows or OS\/2)
exeExtension :: String
100
101
102
exeExtension = case buildOS of
                   Windows -> "exe"
                   _       -> ""
103

104
-- | Extension for object files. For GHC the extension is @\"o\"@.
105
106
107
108
109
110
objExtension :: String
objExtension = "o"

-- | Extension for dynamically linked (or shared) libraries
-- (typically @\"so\"@ on Unix and @\"dll\"@ on Windows)
dllExtension :: String
111
112
113
114
dllExtension = case buildOS of
                   Windows -> "dll"
                   OSX     -> "dylib"
                   _       -> "so"