installExe :: CopyFlags -- ^verbosity
           -> LocalBuildInfo
           -> InstallDirs FilePath -- ^Where to copy the files to
           -> InstallDirs FilePath -- ^Where to pretend the files are (i.e. ignores --destdir)
           -> FilePath  -- ^Build location
           -> (FilePath, FilePath)  -- ^Executable (prefix,suffix)
           -> PackageDescription
           -> IO ()
installExe flags lbi installDirs pretendInstallDirs buildPref (progprefix, progsuffix) pkg_descr
    = do let verbosity = fromFlag (copyVerbosity flags)
             useWrapper = fromFlag (copyUseWrapper flags)
             binDir = bindir installDirs
         createDirectoryIfMissingVerbose verbosity True binDir
         withExe pkg_descr $ \Executable { exeName = e } -> do
             let exeFileName = e <.> exeExtension
                 fixedExeBaseName = progprefix ++ e ++ progsuffix
                 installBinary dest = do
                     installExecutableFile verbosity
                       (buildPref </> e </> exeFileName)
                       (dest <.> exeExtension)
                     stripExe verbosity lbi exeFileName (dest <.> exeExtension)
             if useWrapper
                 then do
                     let libExecDir = libexecdir installDirs
                         pretendLibExecDir = libexecdir pretendInstallDirs
                         pretendAbsExeFileName =
                             pretendLibExecDir </> fixedExeBaseName <.> exeExtension
                         wrapperFileName = binDir </> fixedExeBaseName
                         myPkgId = packageId (PD.package (localPkgDescr lbi))
                         myCompilerId = compilerId (compiler lbi)
                         env = (ExecutableNameVar,
                                toPathTemplate pretendAbsExeFileName)
                             : fullPathTemplateEnv myPkgId myCompilerId
                                                   pretendInstallDirs
                     createDirectoryIfMissingVerbose verbosity True libExecDir
                     installBinary (libExecDir </> fixedExeBaseName)
                     -- XXX Should probably look somewhere more sensible
                     -- than just . for wrappers
                     wrapperTemplate <- readFile (e <.> "wrapper")
                     let wrapper = fromPathTemplate
                                 $ substPathTemplate env
                                 $ toPathTemplate wrapperTemplate
                     writeFileAtomic wrapperFileName wrapper
                     setFileExecutable wrapperFileName
                 else do
                     installBinary (binDir </> fixedExeBaseName)
installExe :: CopyFlags -- ^verbosity
           -> LocalBuildInfo
           -> InstallDirs FilePath -- ^Where to copy the files to
           -> InstallDirs FilePath -- ^Where to pretend the files are (i.e. ignores --destdir)
           -> FilePath  -- ^Build location
           -> (FilePath, FilePath)  -- ^Executable (prefix,suffix)
           -> PackageDescription
           -> IO ()
installExe flags lbi installDirs pretendInstallDirs buildPref (progprefix, progsuffix) pkg_descr
    = do let verbosity = fromFlag (copyVerbosity flags)
             useWrapper = fromFlag (copyUseWrapper flags)
             binDir = bindir installDirs
         createDirectoryIfMissingVerbose verbosity True binDir
         withExe pkg_descr $ \Executable { exeName = e } -> do
             let exeFileName = e <.> exeExtension
                 fixedExeBaseName = progprefix ++ e ++ progsuffix
                 installBinary dest = do
                     installExecutableFile verbosity
                       (buildPref </> e </> exeFileName)
                       (dest <.> exeExtension)
                     stripExe verbosity lbi exeFileName (dest <.> exeExtension)
             if useWrapper
                 then do
                     let libExecDir = libexecdir installDirs
                         pretendLibExecDir = libexecdir pretendInstallDirs
                         pretendAbsExeFileName =
                             pretendLibExecDir </> fixedExeBaseName <.> exeExtension
                         wrapperFileName = binDir </> fixedExeBaseName
                         myPkgId = packageId (PD.package (localPkgDescr lbi))
                         myCompilerId = compilerId (compiler lbi)
                         env = (ExecutableNameVar,
                                toPathTemplate pretendAbsExeFileName)
                             : fullPathTemplateEnv myPkgId myCompilerId
                                                   pretendInstallDirs
                     createDirectoryIfMissingVerbose verbosity True libExecDir
                     installBinary (libExecDir </> fixedExeBaseName)
                     -- XXX Should probably look somewhere more sensible
                     -- than just . for wrappers
                     wrapperTemplate <- readFile (e <.> "wrapper")
                     let wrapper = fromPathTemplate
                                 $ substPathTemplate env
                                 $ toPathTemplate wrapperTemplate
                     writeFileAtomic wrapperFileName wrapper
                     setFileExecutable wrapperFileName
                 else do
                     installBinary (binDir </> fixedExeBaseName)
installExe flags lbi installDirs pretendInstallDirs buildPref (progprefix, progsuffix) pkg_descr
    = do let verbosity = fromFlag (copyVerbosity flags)
             useWrapper = fromFlag (copyUseWrapper flags)
             binDir = bindir installDirs
         createDirectoryIfMissingVerbose verbosity True binDir
         withExe pkg_descr $ \Executable { exeName = e } -> do
             let exeFileName = e <.> exeExtension
                 fixedExeBaseName = progprefix ++ e ++ progsuffix
                 installBinary dest = do
                     installExecutableFile verbosity
                       (buildPref </> e </> exeFileName)
                       (dest <.> exeExtension)
                     stripExe verbosity lbi exeFileName (dest <.> exeExtension)
             if useWrapper
                 then do
                     let libExecDir = libexecdir installDirs
                         pretendLibExecDir = libexecdir pretendInstallDirs
                         pretendAbsExeFileName =
                             pretendLibExecDir </> fixedExeBaseName <.> exeExtension
                         wrapperFileName = binDir </> fixedExeBaseName
                         myPkgId = packageId (PD.package (localPkgDescr lbi))
                         myCompilerId = compilerId (compiler lbi)
                         env = (ExecutableNameVar,
                                toPathTemplate pretendAbsExeFileName)
                             : fullPathTemplateEnv myPkgId myCompilerId
                                                   pretendInstallDirs
                     createDirectoryIfMissingVerbose verbosity True libExecDir
                     installBinary (libExecDir </> fixedExeBaseName)
                     -- XXX Should probably look somewhere more sensible
                     -- than just . for wrappers
                     wrapperTemplate <- readFile (e <.> "wrapper")
                     let wrapper = fromPathTemplate
                                 $ substPathTemplate env
                                 $ toPathTemplate wrapperTemplate
                     writeFileAtomic wrapperFileName wrapper
                     setFileExecutable wrapperFileName
                 else do
                     installBinary (binDir </> fixedExeBaseName)