Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Add --dynlibdir" to 1.24 #4011

Merged
merged 1 commit into from
Oct 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cabal/Distribution/InstalledPackageInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ data InstalledPackageInfo
trusted :: Bool,
importDirs :: [FilePath],
libraryDirs :: [FilePath],
libraryDynDirs :: [FilePath],
dataDir :: FilePath,
hsLibraries :: [String],
extraLibraries :: [String],
Expand Down Expand Up @@ -143,6 +144,7 @@ emptyInstalledPackageInfo
trusted = False,
importDirs = [],
libraryDirs = [],
libraryDynDirs = [],
dataDir = "",
hsLibraries = [],
extraLibraries = [],
Expand Down Expand Up @@ -315,6 +317,9 @@ installedFieldDescrs = [
, listField "library-dirs"
showFilePath parseFilePathQ
libraryDirs (\xs pkg -> pkg{libraryDirs=xs})
, listField "dynamic-library-dirs"
showFilePath parseFilePathQ
libraryDynDirs (\xs pkg -> pkg{libraryDynDirs=xs})
, simpleField "data-dir"
showFilePath (parseFilePathQ Parse.<++ return "")
dataDir (\val pkg -> pkg{dataDir=val})
Expand Down
16 changes: 12 additions & 4 deletions Cabal/Distribution/Simple/Build/PathsModule.hs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ generate pkg_descr lbi =
pragmas++
"module " ++ display paths_modulename ++ " (\n"++
" version,\n"++
" getBinDir, getLibDir, getDataDir, getLibexecDir,\n"++
" getBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir,\n"++
" getDataFileName, getSysconfDir\n"++
" ) where\n"++
"\n"++
Expand Down Expand Up @@ -108,9 +108,10 @@ generate pkg_descr lbi =
"\n\nbindirrel :: FilePath\n" ++
"bindirrel = " ++ show flat_bindirreloc ++
"\n"++
"\ngetBinDir, getLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath\n"++
"\ngetBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath\n"++
"getBinDir = "++mkGetEnvOrReloc "bindir" flat_bindirreloc++"\n"++
"getLibDir = "++mkGetEnvOrReloc "libdir" flat_libdirreloc++"\n"++
"getDynLibDir = "++mkGetEnvOrReloc "dynlibdir" flat_dynlibdirreloc++"\n"++
"getDataDir = "++mkGetEnvOrReloc "datadir" flat_datadirreloc++"\n"++
"getLibexecDir = "++mkGetEnvOrReloc "libexecdir" flat_libexecdirreloc++"\n"++
"getSysconfDir = "++mkGetEnvOrReloc "sysconfdir" flat_sysconfdirreloc++"\n"++
Expand All @@ -124,16 +125,18 @@ generate pkg_descr lbi =
"\n"++
filename_stuff
| absolute =
"\nbindir, libdir, datadir, libexecdir, sysconfdir :: FilePath\n"++
"\nbindir, libdir, dynlibdir, datadir, libexecdir, sysconfdir :: FilePath\n"++
"\nbindir = " ++ show flat_bindir ++
"\nlibdir = " ++ show flat_libdir ++
"\ndynlibdir = " ++ show flat_dynlibdir ++
"\ndatadir = " ++ show flat_datadir ++
"\nlibexecdir = " ++ show flat_libexecdir ++
"\nsysconfdir = " ++ show flat_sysconfdir ++
"\n"++
"\ngetBinDir, getLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath\n"++
"\ngetBinDir, getLibDir, getDynLibDir, getDataDir, getLibexecDir, getSysconfDir :: IO FilePath\n"++
"getBinDir = "++mkGetEnvOr "bindir" "return bindir"++"\n"++
"getLibDir = "++mkGetEnvOr "libdir" "return libdir"++"\n"++
"getDynLibDir = "++mkGetEnvOr "dynlibdir" "return dynlibdir"++"\n"++
"getDataDir = "++mkGetEnvOr "datadir" "return datadir"++"\n"++
"getLibexecDir = "++mkGetEnvOr "libexecdir" "return libexecdir"++"\n"++
"getSysconfDir = "++mkGetEnvOr "sysconfdir" "return sysconfdir"++"\n"++
Expand All @@ -151,6 +154,8 @@ generate pkg_descr lbi =
"getBinDir = getPrefixDirRel bindirrel\n\n"++
"getLibDir :: IO FilePath\n"++
"getLibDir = "++mkGetDir flat_libdir flat_libdirrel++"\n\n"++
"getDynLibDir :: IO FilePath\n"++
"getDynLibDir = "++mkGetDir flat_dynlibdir flat_dynlibdirrel++"\n\n"++
"getDataDir :: IO FilePath\n"++
"getDataDir = "++ mkGetEnvOr "datadir"
(mkGetDir flat_datadir flat_datadirrel)++"\n\n"++
Expand All @@ -173,20 +178,23 @@ generate pkg_descr lbi =
prefix = flat_prefix,
bindir = flat_bindir,
libdir = flat_libdir,
dynlibdir = flat_dynlibdir,
datadir = flat_datadir,
libexecdir = flat_libexecdir,
sysconfdir = flat_sysconfdir
} = absoluteInstallDirs pkg_descr lbi NoCopyDest
InstallDirs {
bindir = flat_bindirrel,
libdir = flat_libdirrel,
dynlibdir = flat_dynlibdirrel,
datadir = flat_datadirrel,
libexecdir = flat_libexecdirrel,
sysconfdir = flat_sysconfdirrel
} = prefixRelativeInstallDirs (packageId pkg_descr) lbi

flat_bindirreloc = shortRelativePath flat_prefix flat_bindir
flat_libdirreloc = shortRelativePath flat_prefix flat_libdir
flat_dynlibdirreloc = shortRelativePath flat_prefix flat_dynlibdir
flat_datadirreloc = shortRelativePath flat_prefix flat_datadir
flat_libexecdirreloc = shortRelativePath flat_prefix flat_libexecdir
flat_sysconfdirreloc = shortRelativePath flat_prefix flat_sysconfdir
Expand Down
8 changes: 8 additions & 0 deletions Cabal/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ module Distribution.Simple.Compiler (
unifiedIPIDRequired,
packageKeySupported,
unitIdSupported,
libraryDynDirSupported,

-- * Support for profiling detail levels
ProfDetailLevel(..),
Expand Down Expand Up @@ -291,6 +292,13 @@ packageKeySupported = ghcSupported "Uses package keys"
unitIdSupported :: Compiler -> Bool
unitIdSupported = ghcSupported "Uses unit IDs"

-- | Does this compiler support a package database entry with:
-- "dynamic-library-dirs"?
libraryDynDirSupported :: Compiler -> Bool
libraryDynDirSupported comp = case compilerFlavor comp of
GHC -> compilerVersion comp >= Version [8,0,1,20161021] []
_ -> False

-- | Utility function for GHC only features
ghcSupported :: String -> Compiler -> Bool
ghcSupported key comp =
Expand Down
1 change: 1 addition & 0 deletions Cabal/Distribution/Simple/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ configure (pkg_descr0', pbi) cfg = do

dirinfo "Binaries" (bindir dirs) (bindir relative)
dirinfo "Libraries" (libdir dirs) (libdir relative)
dirinfo "Dynamic libraries" (dynlibdir dirs) (dynlibdir relative)
dirinfo "Private binaries" (libexecdir dirs) (libexecdir relative)
dirinfo "Data files" (datadir dirs) (datadir relative)
dirinfo "Documentation" (docdir dirs) (docdir relative)
Expand Down
1 change: 1 addition & 0 deletions Cabal/Distribution/Simple/GHC/IPI642.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ toCurrent ipi@InstalledPackageInfo{} =
Current.trusted = Current.trusted Current.emptyInstalledPackageInfo,
Current.importDirs = importDirs ipi,
Current.libraryDirs = libraryDirs ipi,
Current.libraryDynDirs = [],
Current.dataDir = "",
Current.hsLibraries = hsLibraries ipi,
Current.extraLibraries = extraLibraries ipi,
Expand Down
7 changes: 1 addition & 6 deletions Cabal/Distribution/Simple/Install.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ install pkg_descr lbi flags = do
installDirs@(InstallDirs {
bindir = binPref,
libdir = libPref,
-- dynlibdir = dynlibPref, --see TODO below
dynlibdir = dynlibPref,
datadir = dataPref,
docdir = docPref,
htmldir = htmlPref,
Expand All @@ -70,11 +70,6 @@ install pkg_descr lbi flags = do
-- binPref should be computed per executable
= absoluteInstallDirs pkg_descr lbi copydest

--TODO: decide if we need the user to be able to control the libdir
-- for shared libs independently of the one for static libs. If so
-- it should also have a flag in the command line UI
-- For the moment use dynlibdir = libdir
dynlibPref = libPref
progPrefixPref = substPathTemplate (packageId pkg_descr) lbi (progPrefix lbi)
progSuffixPref = substPathTemplate (packageId pkg_descr) lbi (progSuffix lbi)

Expand Down
10 changes: 9 additions & 1 deletion Cabal/Distribution/Simple/InstallDirs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ defaultInstallDirs comp userInstall _hasLibs = do
LHC -> "$compiler"
UHC -> "$pkgid"
_other -> "$abi" </> "$libname",
dynlibdir = "$libdir",
dynlibdir = "$libdir" </> case comp of
JHC -> "$compiler"
LHC -> "$compiler"
UHC -> "$pkgid"
_other -> "$abi",
libexecdir = case buildOS of
Windows -> "$prefix" </> "$libname"
_other -> "$prefix" </> "libexec",
Expand Down Expand Up @@ -331,6 +335,7 @@ data PathTemplateVariable =
| BindirVar -- ^ The @$bindir@ path variable
| LibdirVar -- ^ The @$libdir@ path variable
| LibsubdirVar -- ^ The @$libsubdir@ path variable
| DynlibdirVar -- ^ The @$dynlibdir@ path variable
| DatadirVar -- ^ The @$datadir@ path variable
| DatasubdirVar -- ^ The @$datasubdir@ path variable
| DocdirVar -- ^ The @$docdir@ path variable
Expand Down Expand Up @@ -426,6 +431,7 @@ installDirsTemplateEnv dirs =
,(BindirVar, bindir dirs)
,(LibdirVar, libdir dirs)
,(LibsubdirVar, libsubdir dirs)
,(DynlibdirVar, dynlibdir dirs)
,(DatadirVar, datadir dirs)
,(DatasubdirVar, datasubdir dirs)
,(DocdirVar, docdir dirs)
Expand All @@ -448,6 +454,7 @@ instance Show PathTemplateVariable where
show BindirVar = "bindir"
show LibdirVar = "libdir"
show LibsubdirVar = "libsubdir"
show DynlibdirVar = "dynlibdir"
show DatadirVar = "datadir"
show DatasubdirVar = "datasubdir"
show DocdirVar = "docdir"
Expand Down Expand Up @@ -476,6 +483,7 @@ instance Read PathTemplateVariable where
,("bindir", BindirVar)
,("libdir", LibdirVar)
,("libsubdir", LibsubdirVar)
,("dynlibdir", DynlibdirVar)
,("datadir", DatadirVar)
,("datasubdir", DatasubdirVar)
,("docdir", DocdirVar)
Expand Down
9 changes: 7 additions & 2 deletions Cabal/Distribution/Simple/LocalBuildInfo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,15 @@ depLibraryPaths inplace relative lbi clbi = do
]

let ipkgs = allPackages (installedPkgs lbi)
allDepLibDirs = concatMap Installed.libraryDirs ipkgs
-- First look for dynamic libraries in `dynamic-library-dirs`, and use
-- `library-dirs` as a fall back.
getDynDir pkg = case Installed.libraryDynDirs pkg of
[] -> Installed.libraryDirs pkg
d -> d
allDepLibDirs = concatMap getDynDir ipkgs
internalLib
| inplace = buildDir lbi
| otherwise = libdir installDirs
| otherwise = dynlibdir installDirs
allDepLibDirs' = if hasInternalDeps
then internalLib : allDepLibDirs
else allDepLibDirs
Expand Down
23 changes: 19 additions & 4 deletions Cabal/Distribution/Simple/Register.hs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,8 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
IPI.importDirs = [ libdir installDirs | hasModules ],
-- Note. the libsubdir and datasubdir templates have already been expanded
-- into libdir and datadir.
IPI.libraryDirs = if hasLibrary
then libdir installDirs : extraLibDirs bi
else extraLibDirs bi,
IPI.libraryDirs = libdirs,
IPI.libraryDynDirs = dynlibdirs,
IPI.dataDir = datadir installDirs,
IPI.hsLibraries = if hasLibrary
then [getHSLibraryName (componentUnitId clbi)]
Expand All @@ -349,9 +348,24 @@ generalInstalledPackageInfo adjustRelIncDirs pkg abi_hash lib lbi clbi installDi
bi = libBuildInfo lib
(absinc, relinc) = partition isAbsolute (includeDirs bi)
hasModules = not $ null (libModules lib)
comp = compiler lbi
hasLibrary = hasModules || not (null (cSources bi))
|| (not (null (jsSources bi)) &&
compilerFlavor (compiler lbi) == GHCJS)
compilerFlavor comp == GHCJS)
(libdirs, dynlibdirs)
| not hasLibrary
= (extraLibDirs bi, [])
-- the dynamic-library-dirs defaults to the library-dirs if not specified,
-- so this works whether the dynamic-library-dirs field is supported or not

| libraryDynDirSupported comp
= (libdir installDirs : extraLibDirs bi,
dynlibdir installDirs : extraLibDirs bi)

| otherwise
= (libdir installDirs : dynlibdir installDirs : extraLibDirs bi, [])
-- the compiler doesn't understand the dynamic-library-dirs field so we
-- add the dyn directory to the "normal" list in the library-dirs field

-- | Construct 'InstalledPackageInfo' for a library that is in place in the
-- build tree.
Expand All @@ -377,6 +391,7 @@ inplaceInstalledPackageInfo inplaceDir distPref pkg abi_hash lib lbi clbi =
installDirs =
(absoluteInstallDirs pkg lbi NoCopyDest) {
libdir = inplaceDir </> libTargetDir,
dynlibdir = inplaceDir </> libTargetDir,
datadir = inplaceDir </> dataDir pkg,
docdir = inplaceDocdir,
htmldir = inplaceHtmldir,
Expand Down
5 changes: 5 additions & 0 deletions Cabal/Distribution/Simple/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -767,6 +767,11 @@ installDirsOptions =
libsubdir (\v flags -> flags { libsubdir = v })
installDirArg

, option "" ["dynlibdir"]
"installation directory for dynamic libraries"
dynlibdir (\v flags -> flags { dynlibdir = v })
installDirArg

, option "" ["libexecdir"]
"installation directory for program executables"
libexecdir (\v flags -> flags { libexecdir = v })
Expand Down
4 changes: 3 additions & 1 deletion Cabal/doc/developing-packages.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,7 @@ version :: Version

getBinDir :: IO FilePath
getLibDir :: IO FilePath
getDynLibDir :: IO FilePath
getDataDir :: IO FilePath
getLibexecDir :: IO FilePath
getSysconfDir :: IO FilePath
Expand Down Expand Up @@ -2185,7 +2186,7 @@ a few options:
`unregister`, `clean`, `dist` and `docs`. Some options to commands
are passed through as follows:

* The `--with-hc-pkg`, `--prefix`, `--bindir`, `--libdir`, `--datadir`,
* The `--with-hc-pkg`, `--prefix`, `--bindir`, `--libdir`, `--dynlibdir`, `--datadir`,
`--libexecdir` and `--sysconfdir` options to the `configure` command are
passed on to the `configure` script. In addition the value of the
`--with-compiler` option is passed in a `--with-hc` option and all
Expand All @@ -2201,6 +2202,7 @@ a few options:
$(MAKE) install prefix=$(destdir)/$(prefix) \
bindir=$(destdir)/$(bindir) \
libdir=$(destdir)/$(libdir) \
dynlibdir=$(destdir)/$(dynlibdir) \
datadir=$(destdir)/$(datadir) \
libexecdir=$(destdir)/$(libexecdir) \
sysconfdir=$(destdir)/$(sysconfdir) \
Expand Down
19 changes: 17 additions & 2 deletions Cabal/doc/installing-packages.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ If a user-supplied `configure` script is run (see the section on
[system-dependent
parameters](developing-packages.html#system-dependent-parameters) or on
[complex packages](developing-packages.html#more-complex-packages)), it
is passed the `--with-hc-pkg`, `--prefix`, `--bindir`, `--libdir`,
is passed the `--with-hc-pkg`, `--prefix`, `--bindir`, `--libdir`, `--dynlibdir`,
`--datadir`, `--libexecdir` and `--sysconfdir` options. In addition the
value of the `--with-compiler` option is passed in a `--with-hc` option
and all options specified with `--configure-option=` are passed on.
Expand Down Expand Up @@ -498,6 +498,17 @@ package:
variables: `$prefix`, `$bindir`, `$pkgid`, `$pkg`, `$version`,
`$compiler`, `$os`, `$arch`, `$abi`, `$abitag`

`--dynlibdir=`_dir_
: Dynamic libraries are installed here.

By default, this is set to `$libdir/$abi`, which is usually not equal to
`$libdir/$libsubdir`.

In the simple build system, _dir_ may contain the following path
variables: `$prefix`, `$bindir`, `$libdir`, `$pkgid`, `$pkg`, `$version`,
`$compiler`, `$os`, `$arch`, `$abi`, `$abitag`


`--libexecdir=`_dir_
: Executables that are not expected to be invoked directly by the user
are installed here.
Expand Down Expand Up @@ -590,6 +601,9 @@ independence](#prefix-independence)).
`$libdir`
: As above but for `--libdir`

`$dynlibdir`
: As above but for `--dynlibdir`

`$libsubdir`
: As above but for `--libsubdir`

Expand Down Expand Up @@ -643,6 +657,7 @@ Option Windows Default
`--bindir` `$prefix\bin` `$prefix/bin`
`--libdir` `$prefix` `$prefix/lib`
`--libsubdir` (others) `$pkgid\$compiler` `$pkgid/$compiler`
`--dynlibdir` `$libdir\$abi` `$libdir/$abi`
`--libexecdir` `$prefix\$pkgid` `$prefix/libexec`
`--datadir` (executable) `$prefix` `$prefix/share`
`--datadir` (library) `C:\Program Files\Haskell` `$prefix/share`
Expand All @@ -666,7 +681,7 @@ install-time, rather than having to bake the path into the binary when it is
built.

In order to achieve this, we require that for an executable on Windows,
all of `$bindir`, `$libdir`, `$datadir` and `$libexecdir` begin with
all of `$bindir`, `$libdir`, `$dynlibdir`, `$datadir` and `$libexecdir` begin with
`$prefix`. If this is not the case then the compiled executable will
have baked-in all absolute paths.

Expand Down
Loading