-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSetup.hs
47 lines (42 loc) · 1.26 KB
/
Setup.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import System.Directory
( copyFile
, getAppUserDataDirectory
, createDirectoryIfMissing
)
import Text.LaTeX.Guide.Update
import System.FilePath ((</>),(<.>))
import Control.Applicative ((<$>))
-- Cabal
import Distribution.Simple
import Distribution.PackageDescription
import Distribution.PackageDescription.Parsec (readGenericPackageDescription)
import Distribution.Verbosity (normal)
main :: IO ()
main = do
-- Update (create if missing) guide files
updateGuide "."
-- Write aux module
let dg = "Text" </> "LaTeX" </> "Guide"
createDirectoryIfMissing True dg
getAux >>= writeFile (dg </> "Auto" <.> "hs") . auxmodule
--
defaultMain
data Aux = Aux { guideVersion :: Version }
getAux :: IO Aux
getAux = do
pd <- packageDescription <$> readGenericPackageDescription normal "hatex-guide.cabal"
return $ Aux (pkgVersion $ package pd)
auxmodule :: Aux -> String
auxmodule a = unlines [
"-- | Automatically generated module."
, "module Text.LaTeX.Guide.Auto ("
, " guideVersion"
, " ) where"
, ""
, "import Data.Version"
, ""
, "-- | The version of the guide. Based on the version of the package."
, "guideVersion :: Version"
, "guideVersion = " ++ (let v = guideVersion a
in "makeVersion " ++ show (versionNumbers v))
]