2016-05-31 17:58:13 +00:00
|
|
|
{- Build man pages.
|
|
|
|
-
|
|
|
|
- Copyright 2016 Joey Hess <id@joeyh.name>
|
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2016-05-31 17:58:13 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
{-# OPTIONS_GHC -fno-warn-tabs #-}
|
|
|
|
|
|
|
|
module Build.Mans where
|
|
|
|
|
|
|
|
import System.Directory
|
|
|
|
import System.FilePath
|
|
|
|
import Data.List
|
|
|
|
import Control.Monad
|
|
|
|
import System.Process
|
|
|
|
import System.Exit
|
|
|
|
import Data.Maybe
|
|
|
|
import Utility.Exception
|
2016-06-13 19:25:05 +00:00
|
|
|
import Control.Applicative
|
|
|
|
import Prelude
|
2016-05-31 17:58:13 +00:00
|
|
|
|
2016-06-02 20:54:13 +00:00
|
|
|
buildMansOrWarn :: IO ()
|
|
|
|
buildMansOrWarn = do
|
2016-05-31 17:58:13 +00:00
|
|
|
mans <- buildMans
|
|
|
|
when (any isNothing mans) $
|
|
|
|
error "mdwn2man failed"
|
|
|
|
|
|
|
|
buildMans :: IO [Maybe FilePath]
|
|
|
|
buildMans = do
|
|
|
|
mansrc <- filter isManSrc <$> getDirectoryContents "doc"
|
|
|
|
createDirectoryIfMissing False "man"
|
|
|
|
forM mansrc $ \f -> do
|
|
|
|
let src = "doc" </> f
|
|
|
|
let dest = srcToDest src
|
|
|
|
srcm <- getModificationTime src
|
|
|
|
destm <- catchMaybeIO $ getModificationTime dest
|
|
|
|
if (Just srcm > destm)
|
|
|
|
then do
|
|
|
|
r <- system $ unwords
|
|
|
|
[ "./Build/mdwn2man"
|
|
|
|
, progName src
|
|
|
|
, "1"
|
|
|
|
, src
|
|
|
|
, "> " ++ dest
|
|
|
|
]
|
|
|
|
if r == ExitSuccess
|
|
|
|
then return (Just dest)
|
|
|
|
else return Nothing
|
|
|
|
else return (Just dest)
|
|
|
|
|
|
|
|
isManSrc :: FilePath -> Bool
|
2016-11-21 21:27:38 +00:00
|
|
|
isManSrc s
|
|
|
|
| not (takeExtension s == ".mdwn") = False
|
|
|
|
| otherwise = "git-annex" `isPrefixOf` f || "git-remote-" `isPrefixOf` f
|
|
|
|
where
|
|
|
|
f = takeFileName s
|
2016-05-31 17:58:13 +00:00
|
|
|
|
|
|
|
srcToDest :: FilePath -> FilePath
|
|
|
|
srcToDest s = "man" </> progName s ++ ".1"
|
|
|
|
|
|
|
|
progName :: FilePath -> FilePath
|
|
|
|
progName = dropExtension . takeFileName
|