Skip to content

Commit

Permalink
Use the same custom hook for cabal copy in wxc/Setup.hs
Browse files Browse the repository at this point in the history
This copies the changes from pull request jodonoghue#2 to the master branch
wxHaskell#2
and probably solves bug ticket 56
https://sourceforge.net/p/wxhaskell/bugs/56/
  • Loading branch information
HJvT committed Jun 28, 2014
1 parent 2305172 commit 002e6f4
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions wxc/Setup.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import Distribution.Simple.InstallDirs (InstallDirs(..))
import Distribution.Simple.LocalBuildInfo (LocalBuildInfo, localPkgDescr, installedPkgs, withPrograms, buildDir, absoluteInstallDirs)
import Distribution.Simple.PackageIndex(SearchResult (..), searchByName )
import Distribution.Simple.Program (ConfiguredProgram (..), lookupProgram, runProgram, simpleProgram, locationPath)
import Distribution.Simple.Setup (ConfigFlags, BuildFlags, InstallFlags, CopyDest(..), fromFlag, installVerbosity)
import Distribution.Simple.Setup ( BuildFlags, ConfigFlags
, CopyDest(..), CopyFlags, copyVerbosity
, InstallFlags, installVerbosity
, fromFlag
)
import Distribution.Simple.Utils (installOrdinaryFile)
import Distribution.System (OS (..), Arch (..), buildOS, buildArch)
import Distribution.Verbosity (normal, verbose)
import Distribution.Verbosity (Verbosity, normal, verbose)
import System.Cmd (system)
import System.Directory ( createDirectoryIfMissing, doesFileExist
, findExecutable, getCurrentDirectory
Expand Down Expand Up @@ -43,7 +47,12 @@ whenM mp e = mp >>= \p -> when p e


main :: IO ()
main = defaultMainWithHooks simpleUserHooks { confHook = myConfHook, buildHook = myBuildHook, instHook = myInstHook }
main = defaultMainWithHooks simpleUserHooks
{ confHook = myConfHook
, buildHook = myBuildHook
, copyHook = myCopyHook
, instHook = myInstHook
}

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Expand Down Expand Up @@ -470,11 +479,20 @@ ldconfig path = case buildOS of
ExitSuccess -> return ()
otherwise -> error "Couldn't execute ldconfig, ensure it is on your path"

myCopyHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> CopyFlags -> IO ()
myCopyHook = hookHelper (fromFlag . copyVerbosity) (copyHook simpleUserHooks)

myInstHook :: PackageDescription -> LocalBuildInfo -> UserHooks -> InstallFlags -> IO ()
myInstHook pkg_descr local_bld_info user_hooks inst_flags =
myInstHook = hookHelper (fromFlag . installVerbosity) (instHook simpleUserHooks)

hookHelper ::
(a -> Verbosity) ->
(PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()) ->
PackageDescription -> LocalBuildInfo -> UserHooks -> a -> IO ()
hookHelper verbosity origHook pkg_descr local_bld_info user_hooks flags =
do
-- Perform simpleUserHooks instHook (to copy installIncludes)
instHook simpleUserHooks pkg_descr local_bld_info user_hooks inst_flags
-- Perform simpleUserHooks (copyHook/instHook => to copy installIncludes)
origHook pkg_descr local_bld_info user_hooks flags

-- Copy shared library
let bld_dir = buildDir local_bld_info
Expand All @@ -488,6 +506,6 @@ myInstHook pkg_descr local_bld_info user_hooks inst_flags =

inst_lib_dir = libdir $ absoluteInstallDirs pkg_descr local_bld_info NoCopyDest

installOrdinaryFile (fromFlag (installVerbosity inst_flags)) (bld_dir </> lib_name) (inst_lib_dir </> lib_name)
installOrdinaryFile (verbosity flags) (bld_dir </> lib_name) (inst_lib_dir </> lib_name)
ldconfig inst_lib_dir

0 comments on commit 002e6f4

Please sign in to comment.