------------------------------------------------------------------------------- |-- Module : Distribution.Simple.JHC-- Copyright : Isaac Jones 2003-2006---- Maintainer : cabal-devel@haskell.org-- Portability : portable---- This module contains most of the JHC-specific code for configuring, building-- and installing packages.{- Copyright (c) 2003-2005, Isaac Jones
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Isaac Jones nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}moduleDistribution.Simple.JHC(configure,getInstalledPackages,build,installLib,installExe)whereimportDistribution.PackageDescriptionasPD(PackageDescription(..),BuildInfo(..),withLib,Executable(..),withExe,Library(..),libModules,hcOptions)importDistribution.InstalledPackageInfo(InstalledPackageInfo,emptyInstalledPackageInfo)importqualifiedDistribution.InstalledPackageInfoasInstalledPackageInfo(InstalledPackageInfo_(package))importDistribution.Simple.PackageIndex(PackageIndex)importqualifiedDistribution.Simple.PackageIndexasPackageIndeximportDistribution.Simple.LocalBuildInfo(LocalBuildInfo(..))importDistribution.Simple.BuildPaths(autogenModulesDir,exeExtension)importDistribution.Simple.Compiler(CompilerFlavor(..),CompilerId(..),Compiler(..),PackageDB,Flag,extensionsToFlags)importLanguage.Haskell.Extension(Extension(..))importDistribution.Simple.Program(ConfiguredProgram(..),jhcProgram,ProgramConfiguration,userMaybeSpecifyPath,requireProgram,lookupProgram,rawSystemProgram,rawSystemProgramStdoutConf)importDistribution.Version(VersionRange(AnyVersion))importDistribution.Package(Package(..))importDistribution.Simple.Utils(createDirectoryIfMissingVerbose,copyFileVerbose,writeFileAtomic,die,info,intercalate)importSystem.FilePath((</>))importDistribution.VerbosityimportDistribution.Text(Text(parse),display)importDistribution.Compat.ReadP(readP_to_S,many,skipSpaces)importData.List(nub)importData.Char(isSpace)-- ------------------------------------------------------------------------------- Configuringconfigure::Verbosity->MaybeFilePath->MaybeFilePath->ProgramConfiguration->IO(Compiler,ProgramConfiguration)configureverbosityhcPath_hcPkgPathconf=do(jhcProg,conf')<-requireProgramverbosityjhcProgramAnyVersion(userMaybeSpecifyPath"jhc"hcPathconf)letJustversion=programVersionjhcProgcomp=Compiler{compilerId=CompilerIdJHCversion,compilerExtensions=jhcLanguageExtensions}return(comp,conf')-- | The flags for the supported extensionsjhcLanguageExtensions::[(Extension,Flag)]jhcLanguageExtensions=[(TypeSynonymInstances,""),(ForeignFunctionInterface,""),(NoImplicitPrelude,"--noprelude"),(CPP,"-fcpp")]getInstalledPackages::Verbosity->PackageDB->ProgramConfiguration->IO(PackageIndexInstalledPackageInfo)getInstalledPackagesverbosity_packagedbconf=dostr<-rawSystemProgramStdoutConfverbosityjhcProgramconf["--list-libraries"]casepCheck(readP_to_S(many(skipSpaces>>parse))str)of[ps]->return$PackageIndex.fromList[emptyInstalledPackageInfo{InstalledPackageInfo.package=p}|p<-ps]_->die"cannot parse package list"wherepCheck::[(a,[Char])]->[a]pCheckrs=[r|(r,s)<-rs,allisSpaces]-- ------------------------------------------------------------------------------- Building-- | Building a package for JHC.-- Currently C source files are not supported.build::PackageDescription->LocalBuildInfo->Verbosity->IO()buildpkg_descrlbiverbosity=doletJustjhcProg=lookupProgramjhcProgram(withProgramslbi)withLibpkg_descr()$\lib->doinfoverbosity"Building library..."letlibBi=libBuildInfolibletargs=constructJHCCmdLinelbilibBi(buildDirlbi)verbosityrawSystemProgramverbosityjhcProg$["-c"]++args++mapdisplay(libModulespkg_descr)letpkgid=display(packageIdpkg_descr)pfile=buildDirlbi</>"jhc-pkg.conf"hlfile=buildDirlbi</>(pkgid++".hl")writeFileAtomicpfile$jhcPkgConfpkg_descrrawSystemProgramverbosityjhcProg["--build-hl="++pfile,"-o",hlfile]withExepkg_descr$\exe->doinfoverbosity("Building executable "++exeNameexe)letexeBi=buildInfoexeletout=buildDirlbi</>exeNameexeletargs=constructJHCCmdLinelbiexeBi(buildDirlbi)verbosityrawSystemProgramverbosityjhcProg(["-o",out]++args++[modulePathexe])constructJHCCmdLine::LocalBuildInfo->BuildInfo->FilePath->Verbosity->[String]constructJHCCmdLinelbibi_odirverbosity=(ifverbosity>=deafeningthen["-v"]else[])++extensionsToFlags(compilerlbi)(extensionsbi)++hcOptionsJHCbi++["--noauto","-i-"]++concat[["-i",l]|l<-nub(hsSourceDirsbi)]++["-i",autogenModulesDirlbi]++["-optc"++opt|opt<-PD.ccOptionsbi]++(concat[["-p",displaypkg]|pkg<-packageDepslbi])jhcPkgConf::PackageDescription->StringjhcPkgConfpd=letslinenamesel=name++": "++selpdJustlib=librarypdcomma=intercalate",".mapdisplayinunlines[sline"name"(display.packageId),"exposed-modules: "++(comma(PD.exposedModuleslib)),"hidden-modules: "++(comma(otherModules$libBuildInfolib))]installLib::Verbosity->FilePath->FilePath->PackageDescription->Library->IO()installLibverbdestbuild_dirpkg_descr_=doletp=display(packageIdpkg_descr)++".hl"createDirectoryIfMissingVerboseverbTruedestcopyFileVerboseverb(build_dir</>p)(dest</>p)installExe::Verbosity->FilePath->FilePath->(FilePath,FilePath)->PackageDescription->Executable->IO()installExeverbdestbuild_dir(progprefix,progsuffix)_exe=doletexe_name=exeNameexesrc=exe_name</>exeExtensionout=(progprefix++exe_name++progsuffix)</>exeExtensioncreateDirectoryIfMissingVerboseverbTruedestcopyFileVerboseverb(build_dir</>src)(dest</>out)