1 -----------------------------------------------------------------------------
4 -- Module : Distribution.Simple.Build.Macros
5 -- Copyright : Isaac Jones 2003-2005,
7 -- Duncan Coutts 2007-2008
9 -- Maintainer : cabal-devel@haskell.org
10 -- Portability : portable
12 -- Generating the Paths_pkgname module.
14 -- This is a module that Cabal generates for the benefit of packages. It
15 -- enables them to find their version number and find any installed data files
16 -- at runtime. This code should probably be split off into another module.
17 module Distribution
.Simple
.Build
.PathsModule
22 import Distribution
.Compat
.Prelude
25 import Distribution
.Package
26 import Distribution
.PackageDescription
27 import Distribution
.Simple
.Compiler
28 import Distribution
.Simple
.LocalBuildInfo
29 import Distribution
.Simple
.Utils
(shortRelativePath
)
30 import Distribution
.System
31 import Distribution
.Version
33 import qualified Distribution
.Simple
.Build
.PathsModule
.Z
as Z
35 -- ------------------------------------------------------------
37 -- * Building Paths_<pkg>.hs
39 -- ------------------------------------------------------------
41 generatePathsModule
:: PackageDescription
-> LocalBuildInfo
-> ComponentLocalBuildInfo
-> String
42 generatePathsModule pkg_descr lbi clbi
=
45 { Z
.zPackageName
= packageName pkg_descr
46 , Z
.zVersionDigits
= show $ versionNumbers
$ packageVersion pkg_descr
47 , Z
.zSupportsCpp
= supports_cpp
48 , Z
.zSupportsNoRebindableSyntax
= supports_rebindable_syntax
49 , Z
.zAbsolute
= absolute
50 , Z
.zRelocatable
= relocatable lbi
51 , Z
.zIsWindows
= isWindows
52 , Z
.zIsI386
= buildArch
== I386
53 , Z
.zIsX8664
= buildArch
== X86_64
55 , Z
.zManglePkgName
= showPkgName
56 , Z
.zPrefix
= show flat_prefix
59 , Z
.zDynlibdir
= zDynlibdir
60 , Z
.zDatadir
= zDatadir
61 , Z
.zLibexecdir
= zLibexecdir
62 , Z
.zSysconfdir
= zSysconfdir
65 supports_cpp
= supports_language_pragma
66 supports_rebindable_syntax
= ghc_newer_than
(mkVersion
[7, 0, 1])
67 supports_language_pragma
= ghc_newer_than
(mkVersion
[6, 6, 1])
69 ghc_newer_than minVersion
=
70 case compilerCompatVersion GHC
(compiler lbi
) of
72 Just version
-> version `withinRange` orLaterVersion minVersion
74 -- In several cases we cannot make relocatable installations
76 hasLibs pkg_descr
-- we can only make progs relocatable
77 ||
isNothing flat_bindirrel
-- if the bin dir is an absolute path
78 ||
not (supportsRelocatableProgs
(compilerFlavor
(compiler lbi
)))
80 -- TODO: Here, and with zIsI386 & zIs8664 we should use TARGET platform
81 isWindows
= case buildOS
of
85 supportsRelocatableProgs GHC
= isWindows
86 supportsRelocatableProgs GHCJS
= isWindows
87 supportsRelocatableProgs _
= False
89 cid
= componentUnitId clbi
92 { bindir
= flat_bindir
93 , libdir
= flat_libdir
94 , dynlibdir
= flat_dynlibdir
95 , datadir
= flat_datadir
96 , libexecdir
= flat_libexecdir
97 , sysconfdir
= flat_sysconfdir
98 , prefix
= flat_prefix
99 } = absoluteInstallCommandDirs pkg_descr lbi cid NoCopyDest
102 { bindir
= flat_bindirrel
103 , libdir
= flat_libdirrel
104 , dynlibdir
= flat_dynlibdirrel
105 , datadir
= flat_datadirrel
106 , libexecdir
= flat_libexecdirrel
107 , sysconfdir
= flat_sysconfdirrel
108 } = prefixRelativeComponentInstallDirs
(packageId pkg_descr
) lbi cid
110 zBindir
, zLibdir
, zDynlibdir
, zDatadir
, zLibexecdir
, zSysconfdir
:: String
111 (zBindir
, zLibdir
, zDynlibdir
, zDatadir
, zLibexecdir
, zSysconfdir
)
113 ( show flat_bindir_reloc
114 , show flat_libdir_reloc
115 , show flat_dynlibdir_reloc
116 , show flat_datadir_reloc
117 , show flat_libexecdir_reloc
118 , show flat_sysconfdir_reloc
123 , show flat_dynlibdir
125 , show flat_libexecdir
126 , show flat_sysconfdir
129 ( "maybe (error \"PathsModule.generate\") id (" ++ show flat_bindirrel
++ ")"
130 , mkGetDir flat_libdir flat_libdirrel
131 , mkGetDir flat_dynlibdir flat_dynlibdirrel
132 , mkGetDir flat_datadir flat_datadirrel
133 , mkGetDir flat_libexecdir flat_libexecdirrel
134 , mkGetDir flat_sysconfdir flat_sysconfdirrel
137 error "panic! generatePathsModule: should never happen"
139 mkGetDir
:: FilePath -> Maybe FilePath -> String
140 mkGetDir _
(Just dirrel
) = "getPrefixDirRel " ++ show dirrel
141 mkGetDir dir Nothing
= "return " ++ show dir
143 flat_bindir_reloc
= shortRelativePath flat_prefix flat_bindir
144 flat_libdir_reloc
= shortRelativePath flat_prefix flat_libdir
145 flat_dynlibdir_reloc
= shortRelativePath flat_prefix flat_dynlibdir
146 flat_datadir_reloc
= shortRelativePath flat_prefix flat_datadir
147 flat_libexecdir_reloc
= shortRelativePath flat_prefix flat_libexecdir
148 flat_sysconfdir_reloc
= shortRelativePath flat_prefix flat_sysconfdir
150 -- | Generates the name of the environment variable controlling the path
151 -- component of interest.
153 -- Note: The format of these strings is part of Cabal's public API;
154 -- changing this function constitutes a *backwards-compatibility* break.
156 :: PackageDescription
158 -- ^ path component; one of \"bindir\", \"libdir\", -- \"datadir\", \"libexecdir\", or \"sysconfdir\"
160 -- ^ environment variable name
161 pkgPathEnvVar pkg_descr var
=
162 showPkgName
(packageName pkg_descr
) ++ "_" ++ var
164 showPkgName
:: PackageName
-> String
165 showPkgName
= map fixchar
. unPackageName
167 fixchar
:: Char -> Char