1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE DeriveGeneric #-}
3module Distribution.CabalSpecVersion where
4
5import Prelude ()
6import Distribution.Compat.Prelude
7
8-- | Different Cabal-the-spec versions.
9--
10-- We branch based on this at least in the parser.
11--
12data CabalSpecVersion
13    = CabalSpecV1_0 -- ^ this is older than 'CabalSpecV1_2'
14    | CabalSpecV1_2 -- ^ new syntax (sections)
15    | CabalSpecV1_4
16    | CabalSpecV1_6
17    | CabalSpecV1_8
18    | CabalSpecV1_10
19    | CabalSpecV1_12
20    -- 1.16 -- 1.14: no changes
21    | CabalSpecV1_18
22    | CabalSpecV1_20
23    | CabalSpecV1_22
24    | CabalSpecV1_24
25    | CabalSpecV2_0
26    | CabalSpecV2_2
27    | CabalSpecV2_4
28    | CabalSpecV3_0
29  deriving (Eq, Ord, Show, Read, Enum, Bounded, Typeable, Data, Generic)
30
31-- | Show cabal spec version, but not the way in the .cabal files
32--
33-- @since 3.0.0.0
34showCabalSpecVersion :: CabalSpecVersion -> String
35showCabalSpecVersion CabalSpecV3_0  = "3.0"
36showCabalSpecVersion CabalSpecV2_4  = "2.4"
37showCabalSpecVersion CabalSpecV2_2  = "2.2"
38showCabalSpecVersion CabalSpecV2_0  = "2.0"
39showCabalSpecVersion CabalSpecV1_24 = "1.24"
40showCabalSpecVersion CabalSpecV1_22 = "1.22"
41showCabalSpecVersion CabalSpecV1_20 = "1.20"
42showCabalSpecVersion CabalSpecV1_18 = "1.18"
43showCabalSpecVersion CabalSpecV1_12 = "1.12"
44showCabalSpecVersion CabalSpecV1_10 = "1.10"
45showCabalSpecVersion CabalSpecV1_8  = "1.8"
46showCabalSpecVersion CabalSpecV1_6  = "1.6"
47showCabalSpecVersion CabalSpecV1_4  = "1.4"
48showCabalSpecVersion CabalSpecV1_2  = "1.2"
49showCabalSpecVersion CabalSpecV1_0  = "1.0"
50
51cabalSpecLatest :: CabalSpecVersion
52cabalSpecLatest = CabalSpecV3_0
53
54cabalSpecFromVersionDigits :: [Int] -> CabalSpecVersion
55cabalSpecFromVersionDigits v
56    | v >= [2,5]  = CabalSpecV3_0
57    | v >= [2,3]  = CabalSpecV2_4
58    | v >= [2,1]  = CabalSpecV2_2
59    | v >= [1,25] = CabalSpecV2_0
60    | v >= [1,23] = CabalSpecV1_24
61    | v >= [1,21] = CabalSpecV1_22
62    | v >= [1,19] = CabalSpecV1_20
63    | v >= [1,17] = CabalSpecV1_18
64    | v >= [1,11] = CabalSpecV1_12
65    | v >= [1,9]  = CabalSpecV1_10
66    | v >= [1,7]  = CabalSpecV1_8
67    | v >= [1,5]  = CabalSpecV1_6
68    | v >= [1,3]  = CabalSpecV1_4
69    | v >= [1,1]  = CabalSpecV1_2
70    | otherwise   = CabalSpecV1_0
71
72specHasCommonStanzas :: CabalSpecVersion -> HasCommonStanzas
73specHasCommonStanzas v =
74    if v >= CabalSpecV2_2
75    then HasCommonStanzas
76    else NoCommonStanzas
77
78specHasElif :: CabalSpecVersion -> HasElif
79specHasElif v =
80    if v >= CabalSpecV2_2
81    then HasElif
82    else NoElif
83
84-------------------------------------------------------------------------------
85-- Booleans
86-------------------------------------------------------------------------------
87
88-- IDEA: make some kind of tagged booleans?
89data HasElif = HasElif | NoElif
90  deriving (Eq, Show)
91
92data HasCommonStanzas = HasCommonStanzas | NoCommonStanzas
93  deriving (Eq, Show)
94
95data HasGlobstar = HasGlobstar | NoGlobstar
96