------------------------------------------------------------------------------- |-- Module : Distribution.Simple.Setup-- Copyright : Isaac Jones 2003-2004-- Duncan Coutts 2007---- Maintainer : cabal-devel@haskell.org-- Portability : portable---- This is a big module, but not very complicated. The code is very regular-- and repetitive. It defines the command line interface for all the Cabal-- commands. For each command (like @configure@, @build@ etc) it defines a type-- that holds all the flags, the default set of flags and a 'CommandUI' that-- maps command line flags to and from the corresponding flags type.---- All the flags types are instances of 'Monoid', see-- <http://www.haskell.org/pipermail/cabal-devel/2007-December/001509.html>-- for an explanation.---- The types defined here get used in the front end and especially in-- @cabal-install@ which has to do quite a bit of manipulating sets of command-- line flags.---- This is actually relatively nice, it works quite well. The main change it-- needs is to unify it with the code for managing sets of fields that can be-- read and written from files. This would allow us to save configure flags in-- config files.{- 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.Setup(GlobalFlags(..),emptyGlobalFlags,defaultGlobalFlags,globalCommand,ConfigFlags(..),emptyConfigFlags,defaultConfigFlags,configureCommand,CopyFlags(..),emptyCopyFlags,defaultCopyFlags,copyCommand,InstallFlags(..),emptyInstallFlags,defaultInstallFlags,installCommand,HaddockFlags(..),emptyHaddockFlags,defaultHaddockFlags,haddockCommand,HscolourFlags(..),emptyHscolourFlags,defaultHscolourFlags,hscolourCommand,BuildFlags(..),emptyBuildFlags,defaultBuildFlags,buildCommand,buildVerbose,CleanFlags(..),emptyCleanFlags,defaultCleanFlags,cleanCommand,RegisterFlags(..),emptyRegisterFlags,defaultRegisterFlags,registerCommand,unregisterCommand,SDistFlags(..),emptySDistFlags,defaultSDistFlags,sdistCommand,TestFlags(..),emptyTestFlags,defaultTestFlags,testCommand,TestShowDetails(..),BenchmarkFlags(..),emptyBenchmarkFlags,defaultBenchmarkFlags,benchmarkCommand,CopyDest(..),configureArgs,configureOptions,configureCCompiler,configureLinker,installDirsOptions,defaultDistPref,Flag(..),toFlag,fromFlag,fromFlagOrDefault,flagToMaybe,flagToList,boolOpt,boolOpt',trueArg,falseArg,optionVerbosity)whereimportDistribution.Compiler()importDistribution.ReadEimportDistribution.Text(Text(..),display)importqualifiedDistribution.Compat.ReadPasParseimportqualifiedText.PrettyPrintasDispimportDistribution.Package(Dependency(..))importDistribution.PackageDescription(FlagName(..),FlagAssignment)importDistribution.Simple.Commandhiding(boolOpt,boolOpt')importqualifiedDistribution.Simple.CommandasCommandimportDistribution.Simple.Compiler(CompilerFlavor(..),defaultCompilerFlavor,PackageDB(..),OptimisationLevel(..),flagToOptimisationLevel)importDistribution.Simple.Utils(wrapLine,lowercase,intercalate)importDistribution.Simple.Program(Program(..),ProgramConfiguration,requireProgram,programInvocation,progInvokePath,progInvokeArgs,knownPrograms,addKnownProgram,emptyProgramConfiguration,haddockProgram,ghcProgram,gccProgram,ldProgram)importDistribution.Simple.InstallDirs(InstallDirs(..),CopyDest(..),PathTemplate,toPathTemplate,fromPathTemplate)importDistribution.VerbosityimportData.List(sort)importData.Char(isSpace,isAlpha)importData.Monoid(Monoid(..))-- FIXME Not sure where this should livedefaultDistPref::FilePathdefaultDistPref="dist"-- -------------------------------------------------------------- * Flag type-- -------------------------------------------------------------- | All flags are monoids, they come in two flavours:---- 1. list flags eg---- > --ghc-option=foo --ghc-option=bar---- gives us all the values ["foo", "bar"]---- 2. singular value flags, eg:---- > --enable-foo --disable-foo---- gives us Just False-- So this Flag type is for the latter singular kind of flag.-- Its monoid instance gives us the behaviour where it starts out as-- 'NoFlag' and later flags override earlier ones.--dataFlaga=Flaga|NoFlagderiving(Show,Read,Eq)instanceFunctorFlagwherefmapf(Flagx)=Flag(fx)fmap_NoFlag=NoFlaginstanceMonoid(Flaga)wheremempty=NoFlag_`mappend`f@(Flag_)=ff`mappend`NoFlag=finstanceBoundeda=>Bounded(Flaga)whereminBound=toFlagminBoundmaxBound=toFlagmaxBoundinstanceEnuma=>Enum(Flaga)wherefromEnum=fromEnum.fromFlagtoEnum=toFlag.toEnumenumFrom(Flaga)=maptoFlag.enumFrom$aenumFrom_=[]enumFromThen(Flaga)(Flagb)=toFlag`map`enumFromThenabenumFromThen__=[]enumFromTo(Flaga)(Flagb)=toFlag`map`enumFromToabenumFromTo__=[]enumFromThenTo(Flaga)(Flagb)(Flagc)=toFlag`map`enumFromThenToabcenumFromThenTo___=[]toFlag::a->FlagatoFlag=FlagfromFlag::Flaga->afromFlag(Flagx)=xfromFlagNoFlag=error"fromFlag NoFlag. Use fromFlagOrDefault"fromFlagOrDefault::a->Flaga->afromFlagOrDefault_(Flagx)=xfromFlagOrDefaultdefNoFlag=defflagToMaybe::Flaga->MaybeaflagToMaybe(Flagx)=JustxflagToMaybeNoFlag=NothingflagToList::Flaga->[a]flagToList(Flagx)=[x]flagToListNoFlag=[]-- -------------------------------------------------------------- * Global flags-- -------------------------------------------------------------- In fact since individual flags types are monoids and these are just sets of-- flags then they are also monoids pointwise. This turns out to be really-- useful. The mempty is the set of empty flags and mappend allows us to-- override specific flags. For example we can start with default flags and-- override with the ones we get from a file or the command line, or both.-- | Flags that apply at the top level, not to any sub-command.dataGlobalFlags=GlobalFlags{globalVersion::FlagBool,globalNumericVersion::FlagBool}defaultGlobalFlags::GlobalFlagsdefaultGlobalFlags=GlobalFlags{globalVersion=FlagFalse,globalNumericVersion=FlagFalse}globalCommand::CommandUIGlobalFlagsglobalCommand=CommandUI{commandName="",commandSynopsis="",commandUsage=\_->"This Setup program uses the Haskell Cabal Infrastructure.\n"++"See http://www.haskell.org/cabal/ for more information.\n",commandDescription=Just$\pname->"For more information about a command use\n"++" "++pname++" COMMAND --help\n\n"++"Typical steps for installing Cabal packages:\n"++concat[" "++pname++" "++x++"\n"|x<-["configure","build","install"]],commandDefaultFlags=defaultGlobalFlags,commandOptions=\_->[option['V']["version"]"Print version information"globalVersion(\vflags->flags{globalVersion=v})trueArg,option[]["numeric-version"]"Print just the version number"globalNumericVersion(\vflags->flags{globalNumericVersion=v})trueArg]}emptyGlobalFlags::GlobalFlagsemptyGlobalFlags=memptyinstanceMonoidGlobalFlagswheremempty=GlobalFlags{globalVersion=mempty,globalNumericVersion=mempty}mappendab=GlobalFlags{globalVersion=combineglobalVersion,globalNumericVersion=combineglobalNumericVersion}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Config flags-- -------------------------------------------------------------- | Flags to @configure@ commanddataConfigFlags=ConfigFlags{--FIXME: the configPrograms is only here to pass info through to configure-- because the type of configure is constrained by the UserHooks.-- when we change UserHooks next we should pass the initial-- ProgramConfiguration directly and not via ConfigFlagsconfigPrograms::ProgramConfiguration,-- ^All programs that cabal may runconfigProgramPaths::[(String,FilePath)],-- ^user specifed programs pathsconfigProgramArgs::[(String,[String])],-- ^user specifed programs argsconfigHcFlavor::FlagCompilerFlavor,-- ^The \"flavor\" of the compiler, sugh as GHC or Hugs.configHcPath::FlagFilePath,-- ^given compiler locationconfigHcPkg::FlagFilePath,-- ^given hc-pkg locationconfigVanillaLib::FlagBool,-- ^Enable vanilla libraryconfigProfLib::FlagBool,-- ^Enable profiling in the libraryconfigSharedLib::FlagBool,-- ^Build shared libraryconfigDynExe::FlagBool,-- ^Enable dynamic linking of the executables.configProfExe::FlagBool,-- ^Enable profiling in the executables.configConfigureArgs::[String],-- ^Extra arguments to @configure@configOptimization::FlagOptimisationLevel,-- ^Enable optimization.configProgPrefix::FlagPathTemplate,-- ^Installed executable prefix.configProgSuffix::FlagPathTemplate,-- ^Installed executable suffix.configInstallDirs::InstallDirs(FlagPathTemplate),-- ^Installation pathsconfigScratchDir::FlagFilePath,configExtraLibDirs::[FilePath],-- ^ path to search for extra librariesconfigExtraIncludeDirs::[FilePath],-- ^ path to search for header filesconfigDistPref::FlagFilePath,-- ^"dist" prefixconfigVerbosity::FlagVerbosity,-- ^verbosity levelconfigUserInstall::FlagBool,-- ^The --user\/--global flagconfigPackageDB::FlagPackageDB,-- ^Which package DB to useconfigGHCiLib::FlagBool,-- ^Enable compiling library for GHCiconfigSplitObjs::FlagBool,-- ^Enable -split-objs with GHCconfigStripExes::FlagBool,-- ^Enable executable strippingconfigConstraints::[Dependency],-- ^Additional constraints for-- dependenciesconfigConfigurationsFlags::FlagAssignment,configTests::FlagBool,-- ^Enable test suite compilationconfigBenchmarks::FlagBool,-- ^Enable benchmark compilationconfigLibCoverage::FlagBool-- ^ Enable test suite program coverage}deriving(Read,Show)defaultConfigFlags::ProgramConfiguration->ConfigFlagsdefaultConfigFlagsprogConf=emptyConfigFlags{configPrograms=progConf,configHcFlavor=maybeNoFlagFlagdefaultCompilerFlavor,configVanillaLib=FlagTrue,configProfLib=FlagFalse,configSharedLib=FlagFalse,configDynExe=FlagFalse,configProfExe=FlagFalse,configOptimization=FlagNormalOptimisation,configProgPrefix=Flag(toPathTemplate""),configProgSuffix=Flag(toPathTemplate""),configDistPref=FlagdefaultDistPref,configVerbosity=Flagnormal,configUserInstall=FlagFalse,--TODO: reverse thisconfigGHCiLib=FlagTrue,configSplitObjs=FlagFalse,-- takes longer, so turn off by defaultconfigStripExes=FlagTrue,configTests=FlagFalse,configBenchmarks=FlagFalse,configLibCoverage=FlagFalse}configureCommand::ProgramConfiguration->CommandUIConfigFlagsconfigureCommandprogConf=makeCommandnameshortDesclongDescdefaultFlagsoptionswherename="configure"shortDesc="Prepare to build the package."longDesc=Just(\_->programFlagsDescriptionprogConf)defaultFlags=defaultConfigFlagsprogConfoptionsshowOrParseArgs=configureOptionsshowOrParseArgs++programConfigurationPathsprogConfshowOrParseArgsconfigProgramPaths(\vfs->fs{configProgramPaths=v})++programConfigurationOptionsprogConfshowOrParseArgsconfigProgramArgs(\vfs->fs{configProgramArgs=v})configureOptions::ShowOrParseArgs->[OptionFieldConfigFlags]configureOptionsshowOrParseArgs=[optionVerbosityconfigVerbosity(\vflags->flags{configVerbosity=v}),optionDistPrefconfigDistPref(\dflags->flags{configDistPref=d})showOrParseArgs,option[]["compiler"]"compiler"configHcFlavor(\vflags->flags{configHcFlavor=v})(choiceOpt[(FlagGHC,("g",["ghc"]),"compile with GHC"),(FlagNHC,([],["nhc98"]),"compile with NHC"),(FlagJHC,([],["jhc"]),"compile with JHC"),(FlagLHC,([],["lhc"]),"compile with LHC"),(FlagHugs,([],["hugs"]),"compile with Hugs"),(FlagUHC,([],["uhc"]),"compile with UHC")]),option"w"["with-compiler"]"give the path to a particular compiler"configHcPath(\vflags->flags{configHcPath=v})(reqArgFlag"PATH"),option""["with-hc-pkg"]"give the path to the package tool"configHcPkg(\vflags->flags{configHcPkg=v})(reqArgFlag"PATH")]++mapliftInstallDirsinstallDirsOptions++[option"b"["scratchdir"]"directory to receive the built package (hugs-only)"configScratchDir(\vflags->flags{configScratchDir=v})(reqArgFlag"DIR")--TODO: eliminate scratchdir flag,option""["program-prefix"]"prefix to be applied to installed executables"configProgPrefix(\vflags->flags{configProgPrefix=v})(reqPathTemplateArgFlag"PREFIX"),option""["program-suffix"]"suffix to be applied to installed executables"configProgSuffix(\vflags->flags{configProgSuffix=v})(reqPathTemplateArgFlag"SUFFIX"),option""["library-vanilla"]"Vanilla libraries"configVanillaLib(\vflags->flags{configVanillaLib=v})(boolOpt[][]),option"p"["library-profiling"]"Library profiling"configProfLib(\vflags->flags{configProfLib=v})(boolOpt"p"[]),option""["shared"]"Shared library"configSharedLib(\vflags->flags{configSharedLib=v})(boolOpt[][]),option""["executable-dynamic"]"Executable dynamic linking"configDynExe(\vflags->flags{configDynExe=v})(boolOpt[][]),option""["executable-profiling"]"Executable profiling"configProfExe(\vflags->flags{configProfExe=v})(boolOpt[][]),multiOption"optimization"configOptimization(\vflags->flags{configOptimization=v})[optArg'"n"(Flag.flagToOptimisationLevel)(\f->casefofFlagNoOptimisation->[]FlagNormalOptimisation->[Nothing]FlagMaximumOptimisation->[Just"2"]_->[])"O"["enable-optimization","enable-optimisation"]"Build with optimization (n is 0--2, default is 1)",noArg(FlagNoOptimisation)[]["disable-optimization","disable-optimisation"]"Build without optimization"],option""["library-for-ghci"]"compile library for use with GHCi"configGHCiLib(\vflags->flags{configGHCiLib=v})(boolOpt[][]),option""["split-objs"]"split library into smaller objects to reduce binary sizes (GHC 6.6+)"configSplitObjs(\vflags->flags{configSplitObjs=v})(boolOpt[][]),option""["executable-stripping"]"strip executables upon installation to reduce binary sizes"configStripExes(\vflags->flags{configStripExes=v})(boolOpt[][]),option""["configure-option"]"Extra option for configure"configConfigureArgs(\vflags->flags{configConfigureArgs=v})(reqArg'"OPT"(\x->[x])id),option""["user-install"]"doing a per-user installation"configUserInstall(\vflags->flags{configUserInstall=v})(boolOpt'([],["user"])([],["global"])),option""["package-db"]"Use a specific package database (to satisfy dependencies and register in)"configPackageDB(\vflags->flags{configPackageDB=v})(reqArg'"PATH"(Flag.SpecificPackageDB)(\f->casefofFlag(SpecificPackageDBdb)->[db]_->[])),option"f"["flags"]"Force values for the given flags in Cabal conditionals in the .cabal file. E.g., --flags=\"debug -usebytestrings\" forces the flag \"debug\" to true and \"usebytestrings\" to false."configConfigurationsFlags(\vflags->flags{configConfigurationsFlags=v})(reqArg'"FLAGS"readFlagListshowFlagList),option""["extra-include-dirs"]"A list of directories to search for header files"configExtraIncludeDirs(\vflags->flags{configExtraIncludeDirs=v})(reqArg'"PATH"(\x->[x])id),option""["extra-lib-dirs"]"A list of directories to search for external libraries"configExtraLibDirs(\vflags->flags{configExtraLibDirs=v})(reqArg'"PATH"(\x->[x])id),option""["constraint"]"A list of additional constraints on the dependencies."configConstraints(\vflags->flags{configConstraints=v})(reqArg"DEPENDENCY"(readP_to_E(const"dependency expected")((\x->[x])`fmap`parse))(map(\x->displayx))),option""["tests"]"dependency checking and compilation for test suites listed in the package description file."configTests(\vflags->flags{configTests=v})(boolOpt[][]),option""["library-coverage"]"build library and test suites with Haskell Program Coverage enabled. (GHC only)"configLibCoverage(\vflags->flags{configLibCoverage=v})(boolOpt[][]),option""["benchmarks"]"dependency checking and compilation for benchmarks listed in the package description file."configBenchmarks(\vflags->flags{configBenchmarks=v})(boolOpt[][])]wherereadFlagList::String->FlagAssignmentreadFlagList=maptagWithValue.wordswheretagWithValue('-':fname)=(FlagName(lowercasefname),False)tagWithValuefname=(FlagName(lowercasefname),True)showFlagList::FlagAssignment->[String]showFlagListfs=[ifnotsetthen'-':fnameelsefname|(FlagNamefname,set)<-fs]liftInstallDirs=liftOptionconfigInstallDirs(\vflags->flags{configInstallDirs=v})reqPathTemplateArgFlagtitle_sf_lfdgetset=reqArgFlagtitle_sf_lfd(fmapfromPathTemplate.get)(set.fmaptoPathTemplate)installDirsOptions::[OptionField(InstallDirs(FlagPathTemplate))]installDirsOptions=[option""["prefix"]"bake this prefix in preparation of installation"prefix(\vflags->flags{prefix=v})installDirArg,option""["bindir"]"installation directory for executables"bindir(\vflags->flags{bindir=v})installDirArg,option""["libdir"]"installation directory for libraries"libdir(\vflags->flags{libdir=v})installDirArg,option""["libsubdir"]"subdirectory of libdir in which libs are installed"libsubdir(\vflags->flags{libsubdir=v})installDirArg,option""["libexecdir"]"installation directory for program executables"libexecdir(\vflags->flags{libexecdir=v})installDirArg,option""["datadir"]"installation directory for read-only data"datadir(\vflags->flags{datadir=v})installDirArg,option""["datasubdir"]"subdirectory of datadir in which data files are installed"datasubdir(\vflags->flags{datasubdir=v})installDirArg,option""["docdir"]"installation directory for documentation"docdir(\vflags->flags{docdir=v})installDirArg,option""["htmldir"]"installation directory for HTML documentation"htmldir(\vflags->flags{htmldir=v})installDirArg,option""["haddockdir"]"installation directory for haddock interfaces"haddockdir(\vflags->flags{haddockdir=v})installDirArg]whereinstallDirArg_sf_lfdgetset=reqArgFlag"DIR"_sf_lfd(fmapfromPathTemplate.get)(set.fmaptoPathTemplate)emptyConfigFlags::ConfigFlagsemptyConfigFlags=memptyinstanceMonoidConfigFlagswheremempty=ConfigFlags{configPrograms=error"FIXME: remove configPrograms",configProgramPaths=mempty,configProgramArgs=mempty,configHcFlavor=mempty,configHcPath=mempty,configHcPkg=mempty,configVanillaLib=mempty,configProfLib=mempty,configSharedLib=mempty,configDynExe=mempty,configProfExe=mempty,configConfigureArgs=mempty,configOptimization=mempty,configProgPrefix=mempty,configProgSuffix=mempty,configInstallDirs=mempty,configScratchDir=mempty,configDistPref=mempty,configVerbosity=mempty,configUserInstall=mempty,configPackageDB=mempty,configGHCiLib=mempty,configSplitObjs=mempty,configStripExes=mempty,configExtraLibDirs=mempty,configConstraints=mempty,configExtraIncludeDirs=mempty,configConfigurationsFlags=mempty,configTests=mempty,configLibCoverage=mempty,configBenchmarks=mempty}mappendab=ConfigFlags{configPrograms=configProgramsb,configProgramPaths=combineconfigProgramPaths,configProgramArgs=combineconfigProgramArgs,configHcFlavor=combineconfigHcFlavor,configHcPath=combineconfigHcPath,configHcPkg=combineconfigHcPkg,configVanillaLib=combineconfigVanillaLib,configProfLib=combineconfigProfLib,configSharedLib=combineconfigSharedLib,configDynExe=combineconfigDynExe,configProfExe=combineconfigProfExe,configConfigureArgs=combineconfigConfigureArgs,configOptimization=combineconfigOptimization,configProgPrefix=combineconfigProgPrefix,configProgSuffix=combineconfigProgSuffix,configInstallDirs=combineconfigInstallDirs,configScratchDir=combineconfigScratchDir,configDistPref=combineconfigDistPref,configVerbosity=combineconfigVerbosity,configUserInstall=combineconfigUserInstall,configPackageDB=combineconfigPackageDB,configGHCiLib=combineconfigGHCiLib,configSplitObjs=combineconfigSplitObjs,configStripExes=combineconfigStripExes,configExtraLibDirs=combineconfigExtraLibDirs,configConstraints=combineconfigConstraints,configExtraIncludeDirs=combineconfigExtraIncludeDirs,configConfigurationsFlags=combineconfigConfigurationsFlags,configTests=combineconfigTests,configLibCoverage=combineconfigLibCoverage,configBenchmarks=combineconfigBenchmarks}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Copy flags-- -------------------------------------------------------------- | Flags to @copy@: (destdir, copy-prefix (backwards compat), verbosity)dataCopyFlags=CopyFlags{copyDest::FlagCopyDest,copyDistPref::FlagFilePath,copyVerbosity::FlagVerbosity}derivingShowdefaultCopyFlags::CopyFlagsdefaultCopyFlags=CopyFlags{copyDest=FlagNoCopyDest,copyDistPref=FlagdefaultDistPref,copyVerbosity=Flagnormal}copyCommand::CommandUICopyFlagscopyCommand=makeCommandnameshortDesclongDescdefaultCopyFlagsoptionswherename="copy"shortDesc="Copy the files into the install locations."longDesc=Just$\_->"Does not call register, and allows a prefix at install time\n"++"Without the --destdir flag, configure determines location.\n"optionsshowOrParseArgs=[optionVerbositycopyVerbosity(\vflags->flags{copyVerbosity=v}),optionDistPrefcopyDistPref(\dflags->flags{copyDistPref=d})showOrParseArgs,option""["destdir"]"directory to copy files to, prepended to installation directories"copyDest(\vflags->flags{copyDest=v})(reqArg"DIR"(succeedReadE(Flag.CopyTo))(\f->casefofFlag(CopyTop)->[p];_->[]))]emptyCopyFlags::CopyFlagsemptyCopyFlags=memptyinstanceMonoidCopyFlagswheremempty=CopyFlags{copyDest=mempty,copyDistPref=mempty,copyVerbosity=mempty}mappendab=CopyFlags{copyDest=combinecopyDest,copyDistPref=combinecopyDistPref,copyVerbosity=combinecopyVerbosity}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Install flags-- -------------------------------------------------------------- | Flags to @install@: (package db, verbosity)dataInstallFlags=InstallFlags{installPackageDB::FlagPackageDB,installDistPref::FlagFilePath,installUseWrapper::FlagBool,installInPlace::FlagBool,installVerbosity::FlagVerbosity}derivingShowdefaultInstallFlags::InstallFlagsdefaultInstallFlags=InstallFlags{installPackageDB=NoFlag,installDistPref=FlagdefaultDistPref,installUseWrapper=FlagFalse,installInPlace=FlagFalse,installVerbosity=Flagnormal}installCommand::CommandUIInstallFlagsinstallCommand=makeCommandnameshortDesclongDescdefaultInstallFlagsoptionswherename="install"shortDesc="Copy the files into the install locations. Run register."longDesc=Just$\_->"Unlike the copy command, install calls the register command.\n"++"If you want to install into a location that is not what was\n"++"specified in the configure step, use the copy command.\n"optionsshowOrParseArgs=[optionVerbosityinstallVerbosity(\vflags->flags{installVerbosity=v}),optionDistPrefinstallDistPref(\dflags->flags{installDistPref=d})showOrParseArgs,option""["inplace"]"install the package in the install subdirectory of the dist prefix, so it can be used without being installed"installInPlace(\vflags->flags{installInPlace=v})trueArg,option""["shell-wrappers"]"using shell script wrappers around executables"installUseWrapper(\vflags->flags{installUseWrapper=v})(boolOpt[][]),option""["package-db"]""installPackageDB(\vflags->flags{installPackageDB=v})(choiceOpt[(FlagUserPackageDB,([],["user"]),"upon configuration register this package in the user's local package database"),(FlagGlobalPackageDB,([],["global"]),"(default) upon configuration register this package in the system-wide package database")])]emptyInstallFlags::InstallFlagsemptyInstallFlags=memptyinstanceMonoidInstallFlagswheremempty=InstallFlags{installPackageDB=mempty,installDistPref=mempty,installUseWrapper=mempty,installInPlace=mempty,installVerbosity=mempty}mappendab=InstallFlags{installPackageDB=combineinstallPackageDB,installDistPref=combineinstallDistPref,installUseWrapper=combineinstallUseWrapper,installInPlace=combineinstallInPlace,installVerbosity=combineinstallVerbosity}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * SDist flags-- -------------------------------------------------------------- | Flags to @sdist@: (snapshot, verbosity)dataSDistFlags=SDistFlags{sDistSnapshot::FlagBool,sDistDirectory::FlagFilePath,sDistDistPref::FlagFilePath,sDistVerbosity::FlagVerbosity}derivingShowdefaultSDistFlags::SDistFlagsdefaultSDistFlags=SDistFlags{sDistSnapshot=FlagFalse,sDistDirectory=mempty,sDistDistPref=FlagdefaultDistPref,sDistVerbosity=Flagnormal}sdistCommand::CommandUISDistFlagssdistCommand=makeCommandnameshortDesclongDescdefaultSDistFlagsoptionswherename="sdist"shortDesc="Generate a source distribution file (.tar.gz)."longDesc=NothingoptionsshowOrParseArgs=[optionVerbositysDistVerbosity(\vflags->flags{sDistVerbosity=v}),optionDistPrefsDistDistPref(\dflags->flags{sDistDistPref=d})showOrParseArgs,option""["snapshot"]"Produce a snapshot source distribution"sDistSnapshot(\vflags->flags{sDistSnapshot=v})trueArg,option""["output-directory"]"Generate a source distribution in the given directory"sDistDirectory(\vflags->flags{sDistDirectory=v})(reqArgFlag"DIR")]emptySDistFlags::SDistFlagsemptySDistFlags=memptyinstanceMonoidSDistFlagswheremempty=SDistFlags{sDistSnapshot=mempty,sDistDirectory=mempty,sDistDistPref=mempty,sDistVerbosity=mempty}mappendab=SDistFlags{sDistSnapshot=combinesDistSnapshot,sDistDirectory=combinesDistDirectory,sDistDistPref=combinesDistDistPref,sDistVerbosity=combinesDistVerbosity}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Register flags-- -------------------------------------------------------------- | Flags to @register@ and @unregister@: (user package, gen-script,-- in-place, verbosity)dataRegisterFlags=RegisterFlags{regPackageDB::FlagPackageDB,regGenScript::FlagBool,regGenPkgConf::Flag(MaybeFilePath),regInPlace::FlagBool,regDistPref::FlagFilePath,regVerbosity::FlagVerbosity}derivingShowdefaultRegisterFlags::RegisterFlagsdefaultRegisterFlags=RegisterFlags{regPackageDB=NoFlag,regGenScript=FlagFalse,regGenPkgConf=NoFlag,regInPlace=FlagFalse,regDistPref=FlagdefaultDistPref,regVerbosity=Flagnormal}registerCommand::CommandUIRegisterFlagsregisterCommand=makeCommandnameshortDesclongDescdefaultRegisterFlagsoptionswherename="register"shortDesc="Register this package with the compiler."longDesc=NothingoptionsshowOrParseArgs=[optionVerbosityregVerbosity(\vflags->flags{regVerbosity=v}),optionDistPrefregDistPref(\dflags->flags{regDistPref=d})showOrParseArgs,option""["packageDB"]""regPackageDB(\vflags->flags{regPackageDB=v})(choiceOpt[(FlagUserPackageDB,([],["user"]),"upon registration, register this package in the user's local package database"),(FlagGlobalPackageDB,([],["global"]),"(default)upon registration, register this package in the system-wide package database")]),option""["inplace"]"register the package in the build location, so it can be used without being installed"regInPlace(\vflags->flags{regInPlace=v})trueArg,option""["gen-script"]"instead of registering, generate a script to register later"regGenScript(\vflags->flags{regGenScript=v})trueArg,option""["gen-pkg-config"]"instead of registering, generate a package registration file"regGenPkgConf(\vflags->flags{regGenPkgConf=v})(optArg'"PKG"FlagflagToList)]unregisterCommand::CommandUIRegisterFlagsunregisterCommand=makeCommandnameshortDesclongDescdefaultRegisterFlagsoptionswherename="unregister"shortDesc="Unregister this package with the compiler."longDesc=NothingoptionsshowOrParseArgs=[optionVerbosityregVerbosity(\vflags->flags{regVerbosity=v}),optionDistPrefregDistPref(\dflags->flags{regDistPref=d})showOrParseArgs,option""["user"]""regPackageDB(\vflags->flags{regPackageDB=v})(choiceOpt[(FlagUserPackageDB,([],["user"]),"unregister this package in the user's local package database"),(FlagGlobalPackageDB,([],["global"]),"(default) unregister this package in the system-wide package database")]),option""["gen-script"]"Instead of performing the unregister command, generate a script to unregister later"regGenScript(\vflags->flags{regGenScript=v})trueArg]emptyRegisterFlags::RegisterFlagsemptyRegisterFlags=memptyinstanceMonoidRegisterFlagswheremempty=RegisterFlags{regPackageDB=mempty,regGenScript=mempty,regGenPkgConf=mempty,regInPlace=mempty,regDistPref=mempty,regVerbosity=mempty}mappendab=RegisterFlags{regPackageDB=combineregPackageDB,regGenScript=combineregGenScript,regGenPkgConf=combineregGenPkgConf,regInPlace=combineregInPlace,regDistPref=combineregDistPref,regVerbosity=combineregVerbosity}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * HsColour flags-- ------------------------------------------------------------dataHscolourFlags=HscolourFlags{hscolourCSS::FlagFilePath,hscolourExecutables::FlagBool,hscolourDistPref::FlagFilePath,hscolourVerbosity::FlagVerbosity}derivingShowemptyHscolourFlags::HscolourFlagsemptyHscolourFlags=memptydefaultHscolourFlags::HscolourFlagsdefaultHscolourFlags=HscolourFlags{hscolourCSS=NoFlag,hscolourExecutables=FlagFalse,hscolourDistPref=FlagdefaultDistPref,hscolourVerbosity=Flagnormal}instanceMonoidHscolourFlagswheremempty=HscolourFlags{hscolourCSS=mempty,hscolourExecutables=mempty,hscolourDistPref=mempty,hscolourVerbosity=mempty}mappendab=HscolourFlags{hscolourCSS=combinehscolourCSS,hscolourExecutables=combinehscolourExecutables,hscolourDistPref=combinehscolourDistPref,hscolourVerbosity=combinehscolourVerbosity}wherecombinefield=fielda`mappend`fieldbhscolourCommand::CommandUIHscolourFlagshscolourCommand=makeCommandnameshortDesclongDescdefaultHscolourFlagsoptionswherename="hscolour"shortDesc="Generate HsColour colourised code, in HTML format."longDesc=Just(\_->"Requires hscolour.\n")optionsshowOrParseArgs=[optionVerbosityhscolourVerbosity(\vflags->flags{hscolourVerbosity=v}),optionDistPrefhscolourDistPref(\dflags->flags{hscolourDistPref=d})showOrParseArgs,option""["executables"]"Run hscolour for Executables targets"hscolourExecutables(\vflags->flags{hscolourExecutables=v})trueArg,option""["css"]"Use a cascading style sheet"hscolourCSS(\vflags->flags{hscolourCSS=v})(reqArgFlag"PATH")]-- -------------------------------------------------------------- * Haddock flags-- ------------------------------------------------------------dataHaddockFlags=HaddockFlags{haddockProgramPaths::[(String,FilePath)],haddockProgramArgs::[(String,[String])],haddockHoogle::FlagBool,haddockHtml::FlagBool,haddockHtmlLocation::FlagString,haddockExecutables::FlagBool,haddockInternal::FlagBool,haddockCss::FlagFilePath,haddockHscolour::FlagBool,haddockHscolourCss::FlagFilePath,haddockContents::FlagPathTemplate,haddockDistPref::FlagFilePath,haddockVerbosity::FlagVerbosity}derivingShowdefaultHaddockFlags::HaddockFlagsdefaultHaddockFlags=HaddockFlags{haddockProgramPaths=mempty,haddockProgramArgs=[],haddockHoogle=FlagFalse,haddockHtml=FlagFalse,haddockHtmlLocation=NoFlag,haddockExecutables=FlagFalse,haddockInternal=FlagFalse,haddockCss=NoFlag,haddockHscolour=FlagFalse,haddockHscolourCss=NoFlag,haddockContents=NoFlag,haddockDistPref=FlagdefaultDistPref,haddockVerbosity=Flagnormal}haddockCommand::CommandUIHaddockFlagshaddockCommand=makeCommandnameshortDesclongDescdefaultHaddockFlagsoptionswherename="haddock"shortDesc="Generate Haddock HTML documentation."longDesc=Just$\_->"Requires the program haddock, either version 0.x or 2.x.\n"optionsshowOrParseArgs=[optionVerbosityhaddockVerbosity(\vflags->flags{haddockVerbosity=v}),optionDistPrefhaddockDistPref(\dflags->flags{haddockDistPref=d})showOrParseArgs,option""["hoogle"]"Generate a hoogle database"haddockHoogle(\vflags->flags{haddockHoogle=v})trueArg,option""["html"]"Generate HTML documentation (the default)"haddockHtml(\vflags->flags{haddockHtml=v})trueArg,option""["html-location"]"Location of HTML documentation for pre-requisite packages"haddockHtmlLocation(\vflags->flags{haddockHtmlLocation=v})(reqArgFlag"URL"),option""["executables"]"Run haddock for Executables targets"haddockExecutables(\vflags->flags{haddockExecutables=v})trueArg,option""["internal"]"Run haddock for internal modules and include all symbols"haddockInternal(\vflags->flags{haddockInternal=v})trueArg,option""["css"]"Use PATH as the haddock stylesheet"haddockCss(\vflags->flags{haddockCss=v})(reqArgFlag"PATH"),option""["hyperlink-source","hyperlink-sources"]"Hyperlink the documentation to the source code (using HsColour)"haddockHscolour(\vflags->flags{haddockHscolour=v})trueArg,option""["hscolour-css"]"Use PATH as the HsColour stylesheet"haddockHscolourCss(\vflags->flags{haddockHscolourCss=v})(reqArgFlag"PATH"),option""["contents-location"]"Bake URL in as the location for the contents page"haddockContents(\vflags->flags{haddockContents=v})(reqArg'"URL"(toFlag.toPathTemplate)(flagToList.fmapfromPathTemplate))]++programConfigurationPathsprogConfParseArgshaddockProgramPaths(\vflags->flags{haddockProgramPaths=v})++programConfigurationOptionsprogConfParseArgshaddockProgramArgs(\vflags->flags{haddockProgramArgs=v})progConf=addKnownProgramhaddockProgram$addKnownProgramghcProgram$emptyProgramConfigurationemptyHaddockFlags::HaddockFlagsemptyHaddockFlags=memptyinstanceMonoidHaddockFlagswheremempty=HaddockFlags{haddockProgramPaths=mempty,haddockProgramArgs=mempty,haddockHoogle=mempty,haddockHtml=mempty,haddockHtmlLocation=mempty,haddockExecutables=mempty,haddockInternal=mempty,haddockCss=mempty,haddockHscolour=mempty,haddockHscolourCss=mempty,haddockContents=mempty,haddockDistPref=mempty,haddockVerbosity=mempty}mappendab=HaddockFlags{haddockProgramPaths=combinehaddockProgramPaths,haddockProgramArgs=combinehaddockProgramArgs,haddockHoogle=combinehaddockHoogle,haddockHtml=combinehaddockHoogle,haddockHtmlLocation=combinehaddockHtmlLocation,haddockExecutables=combinehaddockExecutables,haddockInternal=combinehaddockInternal,haddockCss=combinehaddockCss,haddockHscolour=combinehaddockHscolour,haddockHscolourCss=combinehaddockHscolourCss,haddockContents=combinehaddockContents,haddockDistPref=combinehaddockDistPref,haddockVerbosity=combinehaddockVerbosity}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Clean flags-- ------------------------------------------------------------dataCleanFlags=CleanFlags{cleanSaveConf::FlagBool,cleanDistPref::FlagFilePath,cleanVerbosity::FlagVerbosity}derivingShowdefaultCleanFlags::CleanFlagsdefaultCleanFlags=CleanFlags{cleanSaveConf=FlagFalse,cleanDistPref=FlagdefaultDistPref,cleanVerbosity=Flagnormal}cleanCommand::CommandUICleanFlagscleanCommand=makeCommandnameshortDesclongDescdefaultCleanFlagsoptionswherename="clean"shortDesc="Clean up after a build."longDesc=Just(\_->"Removes .hi, .o, preprocessed sources, etc.\n")optionsshowOrParseArgs=[optionVerbositycleanVerbosity(\vflags->flags{cleanVerbosity=v}),optionDistPrefcleanDistPref(\dflags->flags{cleanDistPref=d})showOrParseArgs,option"s"["save-configure"]"Do not remove the configuration file (dist/setup-config) during cleaning. Saves need to reconfigure."cleanSaveConf(\vflags->flags{cleanSaveConf=v})trueArg]emptyCleanFlags::CleanFlagsemptyCleanFlags=memptyinstanceMonoidCleanFlagswheremempty=CleanFlags{cleanSaveConf=mempty,cleanDistPref=mempty,cleanVerbosity=mempty}mappendab=CleanFlags{cleanSaveConf=combinecleanSaveConf,cleanDistPref=combinecleanDistPref,cleanVerbosity=combinecleanVerbosity}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Build flags-- ------------------------------------------------------------dataBuildFlags=BuildFlags{buildProgramPaths::[(String,FilePath)],buildProgramArgs::[(String,[String])],buildDistPref::FlagFilePath,buildVerbosity::FlagVerbosity}derivingShow{-# DEPRECATED buildVerbose "Use buildVerbosity instead" #-}buildVerbose::BuildFlags->VerbositybuildVerbose=fromFlagOrDefaultnormal.buildVerbositydefaultBuildFlags::BuildFlagsdefaultBuildFlags=BuildFlags{buildProgramPaths=mempty,buildProgramArgs=[],buildDistPref=FlagdefaultDistPref,buildVerbosity=Flagnormal}buildCommand::ProgramConfiguration->CommandUIBuildFlagsbuildCommandprogConf=makeCommandnameshortDesclongDescdefaultBuildFlagsoptionswherename="build"shortDesc="Make this package ready for installation."longDesc=NothingoptionsshowOrParseArgs=optionVerbositybuildVerbosity(\vflags->flags{buildVerbosity=v}):optionDistPrefbuildDistPref(\dflags->flags{buildDistPref=d})showOrParseArgs:programConfigurationPathsprogConfshowOrParseArgsbuildProgramPaths(\vflags->flags{buildProgramPaths=v})++programConfigurationOptionsprogConfshowOrParseArgsbuildProgramArgs(\vflags->flags{buildProgramArgs=v})emptyBuildFlags::BuildFlagsemptyBuildFlags=memptyinstanceMonoidBuildFlagswheremempty=BuildFlags{buildProgramPaths=mempty,buildProgramArgs=mempty,buildVerbosity=mempty,buildDistPref=mempty}mappendab=BuildFlags{buildProgramPaths=combinebuildProgramPaths,buildProgramArgs=combinebuildProgramArgs,buildVerbosity=combinebuildVerbosity,buildDistPref=combinebuildDistPref}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Test flags-- ------------------------------------------------------------dataTestShowDetails=Never|Failures|Alwaysderiving(Eq,Ord,Enum,Bounded,Show)knownTestShowDetails::[TestShowDetails]knownTestShowDetails=[minBound..maxBound]instanceTextTestShowDetailswheredisp=Disp.text.lowercase.showparse=maybeParse.pfailreturn.classify=<<identwhereident=Parse.munch1(\c->isAlphac||c=='_'||c=='-')classifystr=lookup(lowercasestr)enumMapenumMap::[(String,TestShowDetails)]enumMap=[(displayx,x)|x<-knownTestShowDetails]--TODO: do we need this instance?instanceMonoidTestShowDetailswheremempty=Nevermappendab=ifa<bthenbelseadataTestFlags=TestFlags{testDistPref::FlagFilePath,testVerbosity::FlagVerbosity,testHumanLog::FlagPathTemplate,testMachineLog::FlagPathTemplate,testShowDetails::FlagTestShowDetails,testKeepTix::FlagBool,--TODO: eliminate the test list and pass it directly as positional args to the testHooktestList::Flag[String],-- TODO: think about if/how options are passed to test exestestOptions::[PathTemplate]}defaultTestFlags::TestFlagsdefaultTestFlags=TestFlags{testDistPref=FlagdefaultDistPref,testVerbosity=Flagnormal,testHumanLog=toFlag$toPathTemplate$"$pkgid-$test-suite.log",testMachineLog=toFlag$toPathTemplate$"$pkgid.log",testShowDetails=toFlagFailures,testKeepTix=toFlagFalse,testList=Flag[],testOptions=[]}testCommand::CommandUITestFlagstestCommand=makeCommandnameshortDesclongDescdefaultTestFlagsoptionswherename="test"shortDesc="Run the test suite, if any (configure with UserHooks)."longDesc=NothingoptionsshowOrParseArgs=[optionVerbositytestVerbosity(\vflags->flags{testVerbosity=v}),optionDistPreftestDistPref(\dflags->flags{testDistPref=d})showOrParseArgs,option[]["log"]("Log all test suite results to file (name template can use "++"$pkgid, $compiler, $os, $arch, $test-suite, $result)")testHumanLog(\vflags->flags{testHumanLog=v})(reqArg'"TEMPLATE"(toFlag.toPathTemplate)(flagToList.fmapfromPathTemplate)),option[]["machine-log"]("Produce a machine-readable log file (name template can use "++"$pkgid, $compiler, $os, $arch, $result)")testMachineLog(\vflags->flags{testMachineLog=v})(reqArg'"TEMPLATE"(toFlag.toPathTemplate)(flagToList.fmapfromPathTemplate)),option[]["show-details"]("'always': always show results of individual test cases. "++"'never': never show results of individual test cases. "++"'failures': show results of failing test cases.")testShowDetails(\vflags->flags{testShowDetails=v})(reqArg"FILTER"(readP_to_E(\_->"--show-details flag expects one of "++intercalate", "(mapdisplayknownTestShowDetails))(fmaptoFlagparse))(flagToList.fmapdisplay)),option[]["keep-tix-files"]"keep .tix files for HPC between test runs"testKeepTix(\vflags->flags{testKeepTix=v})trueArg,option[]["test-options"]("give extra options to test executables "++"(name templates can use $pkgid, $compiler, "++"$os, $arch, $test-suite)")testOptions(\vflags->flags{testOptions=v})(reqArg'"TEMPLATES"(maptoPathTemplate.splitArgs)(const[])),option[]["test-option"]("give extra option to test executables "++"(no need to quote options containing spaces, "++"name template can use $pkgid, $compiler, "++"$os, $arch, $test-suite)")testOptions(\vflags->flags{testOptions=v})(reqArg'"TEMPLATE"(\x->[toPathTemplatex])(mapfromPathTemplate))]emptyTestFlags::TestFlagsemptyTestFlags=memptyinstanceMonoidTestFlagswheremempty=TestFlags{testDistPref=mempty,testVerbosity=mempty,testHumanLog=mempty,testMachineLog=mempty,testShowDetails=mempty,testKeepTix=mempty,testList=mempty,testOptions=mempty}mappendab=TestFlags{testDistPref=combinetestDistPref,testVerbosity=combinetestVerbosity,testHumanLog=combinetestHumanLog,testMachineLog=combinetestMachineLog,testShowDetails=combinetestShowDetails,testKeepTix=combinetestKeepTix,testList=combinetestList,testOptions=combinetestOptions}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Benchmark flags-- ------------------------------------------------------------dataBenchmarkFlags=BenchmarkFlags{benchmarkDistPref::FlagFilePath,benchmarkVerbosity::FlagVerbosity,benchmarkOptions::[PathTemplate]}defaultBenchmarkFlags::BenchmarkFlagsdefaultBenchmarkFlags=BenchmarkFlags{benchmarkDistPref=FlagdefaultDistPref,benchmarkVerbosity=Flagnormal,benchmarkOptions=[]}benchmarkCommand::CommandUIBenchmarkFlagsbenchmarkCommand=makeCommandnameshortDesclongDescdefaultBenchmarkFlagsoptionswherename="bench"shortDesc="Run the benchmark, if any (configure with UserHooks)."longDesc=NothingoptionsshowOrParseArgs=[optionVerbositybenchmarkVerbosity(\vflags->flags{benchmarkVerbosity=v}),optionDistPrefbenchmarkDistPref(\dflags->flags{benchmarkDistPref=d})showOrParseArgs,option[]["benchmark-options"]("give extra options to benchmark executables "++"(name templates can use $pkgid, $compiler, "++"$os, $arch, $benchmark)")benchmarkOptions(\vflags->flags{benchmarkOptions=v})(reqArg'"TEMPLATES"(maptoPathTemplate.splitArgs)(const[])),option[]["benchmark-option"]("give extra option to benchmark executables "++"(no need to quote options containing spaces, "++"name template can use $pkgid, $compiler, "++"$os, $arch, $benchmark)")benchmarkOptions(\vflags->flags{benchmarkOptions=v})(reqArg'"TEMPLATE"(\x->[toPathTemplatex])(mapfromPathTemplate))]emptyBenchmarkFlags::BenchmarkFlagsemptyBenchmarkFlags=memptyinstanceMonoidBenchmarkFlagswheremempty=BenchmarkFlags{benchmarkDistPref=mempty,benchmarkVerbosity=mempty,benchmarkOptions=mempty}mappendab=BenchmarkFlags{benchmarkDistPref=combinebenchmarkDistPref,benchmarkVerbosity=combinebenchmarkVerbosity,benchmarkOptions=combinebenchmarkOptions}wherecombinefield=fielda`mappend`fieldb-- -------------------------------------------------------------- * Shared options utils-- ------------------------------------------------------------programFlagsDescription::ProgramConfiguration->StringprogramFlagsDescriptionprogConf="The flags --with-PROG and --PROG-option(s) can be used with"++" the following programs:"++(concatMap(\line->"\n "++unwordsline).wrapLine77.sort)[programNameprog|(prog,_)<-knownProgramsprogConf]++"\n"programConfigurationPaths::ProgramConfiguration->ShowOrParseArgs->(flags->[(String,FilePath)])->([(String,FilePath)]->(flags->flags))->[OptionFieldflags]programConfigurationPathsprogConfshowOrParseArgsgetset=caseshowOrParseArgsof-- we don't want a verbose help text list so we just show a generic one:ShowArgs->[withProgramPath"PROG"]ParseArgs->map(withProgramPath.programName.fst)(knownProgramsprogConf)wherewithProgramPathprog=option""["with-"++prog]("give the path to "++prog)getset(reqArg'"PATH"(\path->[(prog,path)])(\progPaths->[path|(prog',path)<-progPaths,prog==prog']))programConfigurationOptions::ProgramConfiguration->ShowOrParseArgs->(flags->[(String,[String])])->([(String,[String])]->(flags->flags))->[OptionFieldflags]programConfigurationOptionsprogConfshowOrParseArgsgetset=caseshowOrParseArgsof-- we don't want a verbose help text list so we just show a generic one:ShowArgs->[programOptions"PROG",programOption"PROG"]ParseArgs->map(programOptions.programName.fst)(knownProgramsprogConf)++map(programOption.programName.fst)(knownProgramsprogConf)whereprogramOptionsprog=option""[prog++"-options"]("give extra options to "++prog)getset(reqArg'"OPTS"(\args->[(prog,splitArgsargs)])(const[]))programOptionprog=option""[prog++"-option"]("give an extra option to "++prog++" (no need to quote options containing spaces)")getset(reqArg'"OPT"(\arg->[(prog,[arg])])(\progArgs->concat[args|(prog',args)<-progArgs,prog==prog']))-- -------------------------------------------------------------- * GetOpt Utils-- ------------------------------------------------------------boolOpt::SFlags->SFlags->MkOptDescr(a->FlagBool)(FlagBool->a->a)aboolOpt=Command.boolOptflagToMaybeFlagboolOpt'::OptFlags->OptFlags->MkOptDescr(a->FlagBool)(FlagBool->a->a)aboolOpt'=Command.boolOpt'flagToMaybeFlagtrueArg,falseArg::SFlags->LFlags->Description->(b->FlagBool)->(FlagBool->(b->b))->OptDescrbtrueArg=noArg(FlagTrue)falseArg=noArg(FlagFalse)reqArgFlag::ArgPlaceHolder->SFlags->LFlags->Description->(b->FlagString)->(FlagString->b->b)->OptDescrbreqArgFlagad=reqArgad(succeedReadEFlag)flagToListoptionDistPref::(flags->FlagFilePath)->(FlagFilePath->flags->flags)->ShowOrParseArgs->OptionFieldflagsoptionDistPrefgetset=\showOrParseArgs->option""(distPrefFlagNameshowOrParseArgs)("The directory where Cabal puts generated build files "++"(default "++defaultDistPref++")")getset(reqArgFlag"DIR")wheredistPrefFlagNameShowArgs=["builddir"]distPrefFlagNameParseArgs=["builddir","distdir","distpref"]optionVerbosity::(flags->FlagVerbosity)->(FlagVerbosity->flags->flags)->OptionFieldflagsoptionVerbositygetset=option"v"["verbose"]"Control verbosity (n is 0--3, default verbosity level is 1)"getset(optArg"n"(fmapFlagflagToVerbosity)(Flagverbose)-- default Value if no n is given(fmap(Just.showForCabal).flagToList))-- -------------------------------------------------------------- * Other Utils-- -------------------------------------------------------------- | Arguments to pass to a @configure@ script, e.g. generated by-- @autoconf@.configureArgs::Bool->ConfigFlags->[String]configureArgsbcHackflags=hc_flag++optFlag"with-hc-pkg"configHcPkg++optFlag'"prefix"prefix++optFlag'"bindir"bindir++optFlag'"libdir"libdir++optFlag'"libexecdir"libexecdir++optFlag'"datadir"datadir++configConfigureArgsflagswherehc_flag=case(configHcFlavorflags,configHcPathflags)of(_,Flaghc_path)->[hc_flag_name++hc_path](Flaghc,NoFlag)->[hc_flag_name++displayhc](NoFlag,NoFlag)->[]hc_flag_name--TODO kill off thic bc hack when defaultUserHooks is removed.|bcHack="--with-hc="|otherwise="--with-compiler="optFlagnameconfig_field=caseconfig_fieldflagsofFlagp->["--"++name++"="++p]NoFlag->[]optFlag'nameconfig_field=optFlagname(fmapfromPathTemplate.config_field.configInstallDirs)configureCCompiler::Verbosity->ProgramConfiguration->IO(FilePath,[String])configureCCompilerverbositylbi=configureProgverbositylbigccProgramconfigureLinker::Verbosity->ProgramConfiguration->IO(FilePath,[String])configureLinkerverbositylbi=configureProgverbositylbildProgramconfigureProg::Verbosity->ProgramConfiguration->Program->IO(FilePath,[String])configureProgverbosityprogramConfigprog=do(p,_)<-requireProgramverbosityprogprogramConfigletpInv=programInvocationp[]return(progInvokePathpInv,progInvokeArgspInv)-- | Helper function to split a string into a list of arguments.-- It's supposed to handle quoted things sensibly, eg:---- > splitArgs "--foo=\"C:\Program Files\Bar\" --baz"-- > = ["--foo=C:\Program Files\Bar", "--baz"]--splitArgs::String->[String]splitArgs=space[]wherespace::String->String->[String]spacew[]=wordw[]spacew(c:s)|isSpacec=wordw(space[]s)spacew('"':s)=stringwsspacews=nonstringwsstring::String->String->[String]stringw[]=wordw[]stringw('"':s)=spacewsstringw(c:s)=string(c:w)snonstring::String->String->[String]nonstringw[]=wordw[]nonstringw('"':s)=stringwsnonstringw(c:s)=space(c:w)sword[]s=swordws=reversew:s-- The test cases kinda have to be rewritten from the ground up... :/--hunitTests :: [Test]--hunitTests =-- let m = [("ghc", GHC), ("nhc98", NHC), ("hugs", Hugs)]-- (flags, commands', unkFlags, ers)-- = getOpt Permute options ["configure", "foobar", "--prefix=/foo", "--ghc", "--nhc98", "--hugs", "--with-compiler=/comp", "--unknown1", "--unknown2", "--install-prefix=/foo", "--user", "--global"]-- in [TestLabel "very basic option parsing" $ TestList [-- "getOpt flags" ~: "failed" ~:-- [Prefix "/foo", GhcFlag, NhcFlag, HugsFlag,-- WithCompiler "/comp", InstPrefix "/foo", UserFlag, GlobalFlag]-- ~=? flags,-- "getOpt commands" ~: "failed" ~: ["configure", "foobar"] ~=? commands',-- "getOpt unknown opts" ~: "failed" ~:-- ["--unknown1", "--unknown2"] ~=? unkFlags,-- "getOpt errors" ~: "failed" ~: [] ~=? ers],---- TestLabel "test location of various compilers" $ TestList-- ["configure parsing for prefix and compiler flag" ~: "failed" ~:-- (Right (ConfigCmd (Just comp, Nothing, Just "/usr/local"), []))-- ~=? (parseArgs ["--prefix=/usr/local", "--"++name, "configure"])-- | (name, comp) <- m],---- TestLabel "find the package tool" $ TestList-- ["configure parsing for prefix comp flag, withcompiler" ~: "failed" ~:-- (Right (ConfigCmd (Just comp, Just "/foo/comp", Just "/usr/local"), []))-- ~=? (parseArgs ["--prefix=/usr/local", "--"++name,-- "--with-compiler=/foo/comp", "configure"])-- | (name, comp) <- m],---- TestLabel "simpler commands" $ TestList-- [flag ~: "failed" ~: (Right (flagCmd, [])) ~=? (parseArgs [flag])-- | (flag, flagCmd) <- [("build", BuildCmd),-- ("install", InstallCmd Nothing False),-- ("sdist", SDistCmd),-- ("register", RegisterCmd False)]-- ]-- ]{- Testing ideas:
* IO to look for hugs and hugs-pkg (which hugs, etc)
* quickCheck to test permutations of arguments
* what other options can we over-ride with a command-line flag?
-}