2016-02-21 13:21:41 +03:00
|
|
|
#!/usr/bin/env stack
|
2016-04-06 01:23:20 +03:00
|
|
|
{- stack runghc --verbosity info
|
2016-04-05 16:59:52 +03:00
|
|
|
--package base-prelude
|
|
|
|
--package directory
|
|
|
|
--package extra
|
|
|
|
--package here
|
|
|
|
--package safe
|
|
|
|
--package shake
|
|
|
|
--package time
|
2016-04-06 01:23:20 +03:00
|
|
|
--package pandoc
|
2016-04-05 16:59:52 +03:00
|
|
|
-}
|
|
|
|
{-
|
|
|
|
Usage: see below.
|
|
|
|
Shake.hs is a more powerful Makefile, providing a number of commands
|
|
|
|
for performing useful tasks. Compiling this script is suggested, so that
|
|
|
|
it runs quicker and will not be affected eg when exploring old code versions.
|
|
|
|
More about Shake: http://shakebuild.com/manual
|
|
|
|
Requires: https://www.haskell.org/downloads#stack
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2016-04-05 16:59:52 +03:00
|
|
|
Shake notes:
|
|
|
|
notes:
|
|
|
|
unclear:
|
|
|
|
oracles
|
|
|
|
wishlist:
|
|
|
|
wildcards in phony rules
|
|
|
|
multiple individually accessible wildcards
|
|
|
|
just one shake import
|
|
|
|
-}
|
|
|
|
|
|
|
|
{-# LANGUAGE PackageImports, QuasiQuotes #-}
|
|
|
|
|
|
|
|
import Prelude ()
|
|
|
|
import "base-prelude" BasePrelude
|
|
|
|
-- import "base" System.Console.GetOpt
|
|
|
|
import "extra" Data.List.Extra
|
|
|
|
import "here" Data.String.Here
|
|
|
|
import "safe" Safe
|
|
|
|
import "shake" Development.Shake
|
|
|
|
import "shake" Development.Shake.FilePath
|
|
|
|
import "time" Data.Time
|
|
|
|
import "directory" System.Directory as S (getDirectoryContents)
|
|
|
|
|
|
|
|
usage = [i|Usage:
|
2016-04-06 01:56:14 +03:00
|
|
|
./Shake.hs compile # compile this script (optional)
|
|
|
|
./Shake --help # show options, eg --color
|
2016-04-06 02:07:37 +03:00
|
|
|
./Shake # show commands
|
2016-04-06 02:16:38 +03:00
|
|
|
./Shake docs # generate all docs
|
2016-04-06 01:56:14 +03:00
|
|
|
./Shake manpages # generate nroff files for man
|
|
|
|
./Shake webmanpages # generate web man pages for hakyll
|
2016-04-05 16:59:52 +03:00
|
|
|
|]
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2016-04-06 01:56:14 +03:00
|
|
|
buildDir = ".build"
|
|
|
|
pandocExe = "stack exec -- pandoc" -- use the pandoc required above
|
|
|
|
pandocFiltersResolver = ""
|
2016-02-21 13:21:41 +03:00
|
|
|
manpages = [
|
|
|
|
"hledger_csv.5"
|
|
|
|
,"hledger_journal.5"
|
|
|
|
,"hledger_timedot.5"
|
|
|
|
,"hledger_timelog.5"
|
|
|
|
,"hledger.1"
|
|
|
|
,"hledger-api.1"
|
|
|
|
,"hledger-ui.1"
|
|
|
|
,"hledger-web.1"
|
|
|
|
]
|
|
|
|
|
|
|
|
manpageDir p
|
|
|
|
| '_' `elem` p = "hledger-lib"
|
|
|
|
| otherwise = dropExtension p
|
|
|
|
|
|
|
|
main = do
|
|
|
|
|
|
|
|
pandocFilters <-
|
2016-04-06 01:46:44 +03:00
|
|
|
map ("doc" </>). nub . sort . map (-<.> "") . filter ("pandoc-" `isPrefixOf`)
|
|
|
|
<$> S.getDirectoryContents "doc"
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2016-04-05 16:59:52 +03:00
|
|
|
shakeArgs
|
|
|
|
shakeOptions{
|
|
|
|
shakeFiles=buildDir
|
|
|
|
,shakeVerbosity=Loud
|
|
|
|
-- ,shakeReport=[".shake.html"]
|
|
|
|
} $ do
|
|
|
|
|
|
|
|
want ["help"]
|
|
|
|
|
|
|
|
phony "help" $ liftIO $ putStrLn usage
|
|
|
|
|
|
|
|
phony "compile" $ need ["Shake"]
|
|
|
|
|
|
|
|
"Shake" %> \out -> do
|
|
|
|
need ["Shake.hs"]
|
|
|
|
cmd "stack ghc Shake.hs" :: Action ExitCode
|
|
|
|
putLoud "Compiled ./Shake, you can now use this instead of ./Shake.hs"
|
|
|
|
|
2016-04-06 02:16:38 +03:00
|
|
|
phony "docs" $ need [
|
|
|
|
"manpages"
|
|
|
|
,"webmanpages"
|
|
|
|
]
|
|
|
|
|
2016-04-05 16:59:52 +03:00
|
|
|
-- docs
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2016-04-06 02:07:37 +03:00
|
|
|
let manpageNroffs = [manpageDir p </> p | p <- manpages]
|
2016-04-06 02:16:38 +03:00
|
|
|
webManpageMds = ["site" </> p <.>".md" | p <- manpages]
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2016-04-06 02:07:37 +03:00
|
|
|
phony "manpages" $ need manpageNroffs
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2016-04-06 02:16:38 +03:00
|
|
|
-- man pages converted to nroff, with web-only sections removed
|
2016-04-06 02:07:37 +03:00
|
|
|
manpageNroffs |%> \out -> do
|
2016-02-21 13:21:41 +03:00
|
|
|
let
|
|
|
|
md = out <.> "md"
|
|
|
|
tmpl = "doc/manpage.nroff"
|
|
|
|
need $ md : tmpl : pandocFilters
|
2016-04-06 18:20:27 +03:00
|
|
|
cmd pandocExe md "--to-man -s --template" tmpl
|
|
|
|
"--filter doc/pandoc-drop-web-blocks"
|
2016-04-06 01:46:44 +03:00
|
|
|
"--filter doc/pandoc-drop-html-blocks"
|
|
|
|
"--filter doc/pandoc-drop-html-inlines"
|
|
|
|
"--filter doc/pandoc-drop-links"
|
|
|
|
"--filter doc/pandoc-drop-notes"
|
|
|
|
"--filter doc/pandoc-capitalize-headers"
|
2016-02-21 13:21:41 +03:00
|
|
|
"-o" out
|
|
|
|
|
2016-04-06 02:07:37 +03:00
|
|
|
phony "webmanpages" $ need webManpageMds
|
2016-04-06 01:40:59 +03:00
|
|
|
|
2016-04-06 02:16:38 +03:00
|
|
|
-- man pages still as markdown, but with man-only sections removed
|
|
|
|
-- (hakyll does the final rendering)
|
2016-04-06 02:07:37 +03:00
|
|
|
webManpageMds |%> \out -> do
|
2016-02-21 13:21:41 +03:00
|
|
|
let
|
|
|
|
p = dropExtension $ takeFileName out
|
|
|
|
md = manpageDir p </> p <.> "md"
|
|
|
|
tmpl = "doc/manpage.html"
|
|
|
|
need $ md : tmpl : pandocFilters
|
2016-04-06 01:23:20 +03:00
|
|
|
cmd pandocExe md "--to markdown"
|
2016-04-06 01:46:44 +03:00
|
|
|
"--filter doc/pandoc-drop-man-blocks"
|
2016-02-21 13:21:41 +03:00
|
|
|
"-o" out
|
|
|
|
|
2016-04-06 01:40:59 +03:00
|
|
|
phony "pandocfilters" $ need pandocFilters
|
|
|
|
|
2016-02-21 13:21:41 +03:00
|
|
|
pandocFilters |%> \out -> do
|
|
|
|
need [out <.> "hs"]
|
2016-04-05 21:56:42 +03:00
|
|
|
cmd ("stack "++pandocFiltersResolver++" ghc") out
|
2016-02-21 13:21:41 +03:00
|
|
|
|
2016-04-06 01:40:59 +03:00
|
|
|
-- cleanup
|
|
|
|
|
2016-02-21 13:21:41 +03:00
|
|
|
phony "clean" $ do
|
|
|
|
putNormal "Cleaning generated files"
|
2016-04-06 02:07:37 +03:00
|
|
|
removeFilesAfter "" manpageNroffs
|
|
|
|
removeFilesAfter "" webManpageMds
|
2016-02-21 13:21:41 +03:00
|
|
|
putNormal "Cleaning object files"
|
2016-04-06 02:16:38 +03:00
|
|
|
removeFilesAfter "doc" ["*.o","*.p_o","*.hi"]
|
2016-02-21 13:21:41 +03:00
|
|
|
putNormal "Cleaning shake build files"
|
|
|
|
removeFilesAfter buildDir ["//*"]
|
|
|
|
|