{- hake: make tool. ruby : rake = haskell : hake
Copyright (C) 2008-2008 Yoshikuni Jujo <PAF01143@nifty.ne.jp>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-}moduleDevelopment.Hake.HiddenTools(runHake,hakefileUpdateOption,defaultTrgtStr,abortIfFailure,changeSuffix)whereimportSystem.Directory(createDirectory,doesDirectoryExist,doesFileExist)importSystem.Exit(ExitCode(ExitSuccess),exitWith)importSystem.FilePath(takeFileName)importSystem.Process(runProcess,waitForProcess)importSystem.Directory.Tools(doesNotExistOrOldThan)importControl.Monad(when)importControl.Monad.Reader(lift)importControl.Monad.Tools(unlessM)importControl.Applicative.Tools((<.>))importData.List(isSuffixOf)importData.List.Tools(defaultElem)importData.Function.Tools(applyWhen,apply2way)importYJTools.Tribial(ghcMake,updateFile)importDevelopment.Hake.Types(CommandRet)hakeDir,defaultTrgtStr,hakefileUpdateOption,srcSuffix::StringcommentPair::(String,String)hakeDir="_hake/"defaultTrgtStr="default"hakefileUpdateOption="--hakefile-is-updated"srcSuffix=".hs"commentPair=("{- "," -}")runHake::FilePath->FilePath->[FilePath]->[String]->IOExitCoderunHakesrcexeothrsargs=doletexePath=hakeDir++exeexeSrc=hakeDir++exe++srcSuffixmapM_errorExist$src:othrsunlessM(doesDirectoryExisthakeDir)$createDirectoryhakeDirothrsUD<-fmapor$flipmapMothrs$apply2way(updateFilecommentPair)id$(hakeDir++).takeFileNamehakefileUD<-updateFilecommentPairsrcexeSrcnotUpdated<-doesNotExistOrOldThanexePathexeSrcwhen(othrsUD||hakefileUD||notUpdated)$doec<-ghcMakeexehakeDirwhen(ec/=ExitSuccess)$exitWithecletargs_=applyWhen(othrsUD||hakefileUD)(hakefileUpdateOption:)$defaultElemdefaultTrgtStrargsrunProcessexePathargs_NothingNothingNothingNothingNothing>>=waitForProcesserrorExist::FilePath->IO()errorExistfp=unlessM(doesFileExistfp)$error$"runHake: "++fp++" does not exist"abortIfFailure::[CommandRet]->CommandRetabortIfFailure=(<.>)last$mapM$flip(>>=)$\ec->caseecofExitSuccess->returnec_->lift$exitWithecchangeSuffix::String->String->String->StringchangeSuffixoldSfxnewSfxfn|isSuffixOfoldSfxfn=take(lengthfn-lengtholdSfx)fn++newSfx|otherwise=error$"changeSuffix: "++oldSfx++" is not suffix of "++fn