License.hs 5.28 KB
Newer Older
simonmar's avatar
simonmar committed
1
2
3
-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.License
ijones's avatar
ijones committed
4
-- Copyright   :  Isaac Jones 2003-2005
simonmar's avatar
simonmar committed
5
6
7
8
9
-- 
-- Maintainer  :  Isaac Jones <ijones@syntaxpolice.org>
-- Stability   :  alpha
-- Portability :  portable
--
ijones's avatar
ijones committed
10
11
12
13
14
15
16
-- The License datatype.  For more information about these and other
-- open-source licenses, you may visit <http://www.opensource.org/>.
--
-- I am not a lawyer, but as a general guideline, most Haskell
-- software seems to be released under a BSD3 license, which is very
-- open and free.  If you don't want to restrict the use of your
-- software or its source code, use BSD3 or PublicDomain.
simonmar's avatar
simonmar committed
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
48
49
50
51

{- All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above
      copyright notice, this list of conditions and the following
      disclaimer in the documentation and/or other materials provided
      with the distribution.

    * Neither the name of Isaac Jones nor the names of other
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -}

module Distribution.License (
	License(..)
  ) where

52
53
54
import Distribution.Version (Version)

import Distribution.Text (Text(..), display)
Duncan Coutts's avatar
Duncan Coutts committed
55
56
import qualified Distribution.Compat.ReadP as Parse
import qualified Text.PrettyPrint as Disp
57
import qualified Data.Char as Char (isAlphaNum)
Duncan Coutts's avatar
Duncan Coutts committed
58

ijones's avatar
ijones committed
59
-- |This datatype indicates the license under which your package is
ijones's avatar
ijones committed
60
61
62
63
64
65
66
-- released.  It is also wise to add your license to each source file
-- using the license-file field.  The 'AllRightsReserved' constructor
-- is not actually a license, but states that you are not giving
-- anyone else a license to use or distribute your work.  The comments
-- below are general guidelines.  Please read the licenses themselves
-- and consult a lawyer if you are unsure of your rights to release
-- the software.
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
--
data License =

--TODO: * deprecate BSD4
--      * add optional gpl versions
--      * add MIT license

    -- | GNU Public License. Source code must accompany alterations.
    GPL --(Maybe Version)

    -- | Lesser GPL, Less restrictive than GPL, useful for libraries.
  | LGPL --(Maybe Version)

    -- | 3-clause BSD license, newer, no advertising clause. Very free license.
  | BSD3

    -- | 4-clause BSD license, older, with advertising clause.
  | BSD4

--    -- | The MIT license, similar to the BSD3. Very free license.
--  | MIT

    -- | Holder makes no claim to ownership, least restrictive license.
  | PublicDomain

    -- | No rights are granted to others. Undistributable. Most restrictive.
  | AllRightsReserved

    -- | Some other license.
  | OtherLicense
97
98
99
100

    -- | Not a recognised license.
    -- Allows us to deal with future extensions more gracefully.
  | UnknownLicense String
101
  deriving (Read, Show, Eq)
simonmar's avatar
simonmar committed
102

103
104
105
106
107
--TODO: use knownLicenses to give a better parse error message
--knownLicenses :: [License]
--knownLicenses = [GPL Nothing, LGPL Nothing, BSD3, BSD4, MIT
--                ,PublicDomain, AllRightsReserved, OtherLicense]

Duncan Coutts's avatar
Duncan Coutts committed
108
instance Text License where
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
--disp (GPL  version)         = "GPL"  <> showOptionalVersion version
--disp (LGPL version)         = "LGPL" <> showOptionalVersion version
  disp (UnknownLicense other) = Disp.text other
  disp other                  = Disp.text (show other)

  parse = do
    name    <- Parse.munch1 Char.isAlphaNum
    version <- Parse.option Nothing (Parse.char '-' >> fmap Just parse)
    -- We parse an optional version but do not yet allow it on any known
    -- license. However parsing the version will allow forwards compatability
    -- for when we do introduce optional (L)GPL license versions.
    return $ case (name, version :: Maybe Version) of
      ("GPL",               Nothing) -> GPL
      ("LGPL",              Nothing) -> LGPL
  --  ("GPL",               version) -> GPL  version
  --  ("LGPL",              version) -> LGPL version
      ("BSD3",              Nothing) -> BSD3
Duncan Coutts's avatar
Duncan Coutts committed
126
      ("BSD4",              Nothing) -> BSD4
127
128
129
130
131
132
  --  ("MIT",               Nothing) -> MIT
      ("PublicDomain",      Nothing) -> PublicDomain
      ("AllRightsReserved", Nothing) -> AllRightsReserved
      ("OtherLicense",      Nothing) -> OtherLicense
      _                              -> UnknownLicense $ name
                                     ++ maybe "" (('-':) . display) version