Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 304 lines (279 sloc) 11.436 kB
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
1 -- A program for generating a Gentoo ebuild from a .cabal file
2 --
3 -- Author : Duncan Coutts <dcoutts@gentoo.org>
4 --
5 -- Created: 21 July 2005
6 --
7 -- Copyright (C) 2005 Duncan Coutts
8 --
9 -- This library is free software; you can redistribute it and/or
10 -- modify it under the terms of the GNU General Public License
11 -- as published by the Free Software Foundation; either version 2
12 -- of the License, or (at your option) any later version.
13 --
14 -- This library is distributed in the hope that it will be useful,
15 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
16 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 -- General Public License for more details.
18 --
19 -- |
20 -- Maintainer : haskell@gentoo.org
21 --
22 -- cabal2ebuild - a program for generating a Gentoo ebuild from a .cabal file
23 --
24 module Cabal2Ebuild
e35e41e @kolmodin Make merging respect categories
kolmodin authored
25 (EBuild(..)
cb4a7bb @kolmodin Start on translating extra-libraries into ebuild deps
kolmodin authored
26 ,Dependency(..)
e35e41e @kolmodin Make merging respect categories
kolmodin authored
27 ,cabal2ebuild
cb4a7bb @kolmodin Start on translating extra-libraries into ebuild deps
kolmodin authored
28 ,convertDependencies
23fbd30 @kolmodin allow deps to not be in the dev-haskell/ category
kolmodin authored
29 ,convertDependency
e35e41e @kolmodin Make merging respect categories
kolmodin authored
30 ,showEBuild) where
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
31
32 import qualified Distribution.PackageDescription as Cabal
87d875b @kolmodin Wall police
kolmodin authored
33 (PackageDescription(..))
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
34 import qualified Distribution.Package as Cabal (PackageIdentifier(..)
35 , Dependency(..)
36 , PackageName(..))
1585cc6 @trofi Cabal2Ebuild.hs: migrated to foldVersionRange
trofi authored
37 import qualified Distribution.Version as Cabal (VersionRange, foldVersionRange', versionBranch, Version)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
38 import qualified Distribution.License as Cabal (License(..))
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
39 import Distribution.Text (display)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
40
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
41 import Data.Char (toLower,isUpper)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
42
6956e2f @kolmodin Tiny cleanup about different Version structures. Add rdepend to ebuild.
kolmodin authored
43 import Portage.Dependency
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
44 import qualified Portage.PackageId as Portage
6956e2f @kolmodin Tiny cleanup about different Version structures. Add rdepend to ebuild.
kolmodin authored
45 import Portage.Version
46
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
47 data EBuild = EBuild {
48 name :: String,
49 version :: String,
50 description :: String,
51 homepage :: String,
52 src_uri :: String,
53 license :: String,
54 slot :: String,
55 keywords :: [String],
56 iuse :: [String],
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
57 haskell_deps :: [Dependency],
58 build_tools :: [Dependency],
59 extra_libs :: [Dependency],
60 cabal_dep :: Dependency,
61 ghc_dep :: Dependency,
62 depend :: [String],
63 rdepend :: [String],
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
64 features :: [String],
65 -- comments on various fields for communicating stuff to the user
66 licenseComments :: String,
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
67 my_pn :: Maybe String --If the package's name contains upper-case
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
68 }
69
87d875b @kolmodin Wall police
kolmodin authored
70 ebuildTemplate :: EBuild
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
71 ebuildTemplate = EBuild {
72 name = "foobar",
73 version = "0.1",
74 description = "",
75 homepage = "",
76 src_uri = "",
77 license = "",
78 slot = "0",
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
79 keywords = ["~amd64","~x86"],
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
80 iuse = [],
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
81 haskell_deps = [],
82 build_tools = [],
83 extra_libs = [],
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
84 cabal_dep = AnyVersionOf (Portage.mkPackageName "dev-haskell" "cabal"),
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
85 ghc_dep = defaultDepGHC,
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
86 depend = [],
6956e2f @kolmodin Tiny cleanup about different Version structures. Add rdepend to ebuild.
kolmodin authored
87 rdepend = [],
c81b055 profile and haddock only make sense for lib packages
Duncan Coutts authored
88 features = [],
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
89 licenseComments = "",
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
90 my_pn = Nothing
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
91 }
92
93 cabal2ebuild :: Cabal.PackageDescription -> EBuild
94 cabal2ebuild pkg = ebuildTemplate {
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
95 name = map toLower cabalPkgName,
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
96 version = display (Cabal.pkgVersion (Cabal.package pkg)),
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
97 description = if null (Cabal.synopsis pkg) then Cabal.description pkg
98 else Cabal.synopsis pkg,
99 homepage = Cabal.homepage pkg,
100 src_uri = Cabal.pkgUrl pkg,
101 license = convertLicense (Cabal.license pkg),
102 licenseComments = licenseComment (Cabal.license pkg),
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
103 haskell_deps = simplify_deps $ convertDependencies (Portage.Category "dev-haskell") (Cabal.buildDepends pkg),
104 cabal_dep = head $ convertDependency (Portage.Category "dev-haskell")
23fbd30 @kolmodin allow deps to not be in the dev-haskell/ category
kolmodin authored
105 (Cabal.Dependency (Cabal.PackageName "Cabal")
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
106 (Cabal.descCabalVersion pkg)),
20179c4 Set S= properly for packages with upper case names
Duncan Coutts authored
107 my_pn = if any isUpper cabalPkgName then Just cabalPkgName else Nothing,
f5d6f88 reorder the features list
Duncan Coutts authored
108 features = features ebuildTemplate
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
109 ++ (if hasExe then ["bin"] else [])
9d28e5b make sure hscolour does not get the hscolour feature
Stephan Friedrichs authored
110 ++ maybe [] (const (["lib","profile","haddock"]
111 ++ if cabalPkgName == "hscolour" then [] else ["hscolour"])
112 ) (Cabal.library pkg) -- hscolour can't colour its own sources
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
113 } where
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
114 cabalPkgName = display $ Cabal.pkgName (Cabal.package pkg)
2775da0 @trofi -Wall cleanups
trofi authored
115 -- hasLib = isJust (Cabal.library pkg)
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
116 hasExe = (not . null) (Cabal.executables pkg)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
117
87d875b @kolmodin Wall police
kolmodin authored
118 defaultDepGHC :: Dependency
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
119 defaultDepGHC = OrLaterVersionOf (Version [6,8,1] Nothing [] 0) (Portage.mkPackageName "dev-lang" "ghc")
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
120
121 -- map the cabal license type to the gentoo license string format
122 convertLicense :: Cabal.License -> String
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
123 convertLicense (Cabal.GPL mv) = "GPL-" ++ (maybe "2" display mv) -- almost certainly version 2
124 convertLicense (Cabal.LGPL mv) = "LGPL-" ++ (maybe "2.1" display mv) -- probably version 2.1
3516b0d There is a BSD-4 license available for use in the Gentoo tree. Use it.
Ivan.Miljenovic@gmail.com authored
125 convertLicense Cabal.BSD3 = "BSD"
126 convertLicense Cabal.BSD4 = "BSD-4"
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
127 convertLicense Cabal.PublicDomain = "public-domain"
128 convertLicense Cabal.AllRightsReserved = ""
f5a3600 @trofi Adding MIT to list of known licenses
trofi authored
129 convertLicense Cabal.MIT = "MIT"
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
130 convertLicense _ = ""
131
87d875b @kolmodin Wall police
kolmodin authored
132 licenseComment :: Cabal.License -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
133 licenseComment Cabal.AllRightsReserved =
134 "Note: packages without a license cannot be included in portage"
135 licenseComment Cabal.OtherLicense =
136 "Fixme: \"OtherLicense\", please fill in manually"
137 licenseComment _ = ""
138
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
139 convertDependencies :: Portage.Category -> [Cabal.Dependency] -> [Dependency]
23fbd30 @kolmodin allow deps to not be in the dev-haskell/ category
kolmodin authored
140 convertDependencies category = concatMap (convertDependency category)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
141
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
142 convertDependency :: Portage.Category -> Cabal.Dependency -> [Dependency]
23fbd30 @kolmodin allow deps to not be in the dev-haskell/ category
kolmodin authored
143 convertDependency _category (Cabal.Dependency pname@(Cabal.PackageName _name) _)
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
144 | pname `elem` coreLibs = [] -- no explicit dep on core libs
23fbd30 @kolmodin allow deps to not be in the dev-haskell/ category
kolmodin authored
145 convertDependency category (Cabal.Dependency pname versionRange)
1585cc6 @trofi Cabal2Ebuild.hs: migrated to foldVersionRange
trofi authored
146 = convert versionRange
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
147 where
decf164 @kolmodin Bump Copyright header
kolmodin authored
148 -- XXX: not always true, we should look properly for deps in the overlay
149 -- to find the correct category
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
150 ebuildName = Portage.PackageName category (Portage.normalizeCabalPackageName pname)
1585cc6 @trofi Cabal2Ebuild.hs: migrated to foldVersionRange
trofi authored
151 convert :: Cabal.VersionRange -> [Dependency]
152 convert = Cabal.foldVersionRange'
153 ( [AnyVersionOf ebuildName] -- ^ @\"-any\"@ version
154 )(\v -> [ThisVersionOf (cabalVtoHPv v) ebuildName] -- ^ @\"== v\"@
155 )(\v -> [LaterVersionOf (cabalVtoHPv v) ebuildName] -- ^ @\"> v\"@
156 )(\v -> [EarlierVersionOf (cabalVtoHPv v) ebuildName] -- ^ @\"< v\"@
157 )(\v -> [OrLaterVersionOf (cabalVtoHPv v) ebuildName] -- ^ @\">= v\"@
158 )(\v -> [OrEarlierVersionOf (cabalVtoHPv v) ebuildName] -- ^ @\"<= v\"@
159 {- FIXME -} )(\v1 _ -> [ThisMajorOf (cabalVtoHPv v1) ebuildName] -- ^ @\"== v.*\"@ wildcard. (incl lower, excl upper)
160 )(\r1 r2 -> case (r1,r2) of
161 ([r1'], [r2']) -> [DependEither r1' r2'] -- ^ @\"_ || _\"@ union
162 _ -> error "convertDependency: compound either"
163 )(\r1 r2 -> r1 ++ r2
164 )
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
165
6956e2f @kolmodin Tiny cleanup about different Version structures. Add rdepend to ebuild.
kolmodin authored
166 -- converts Cabal version type to hackport version
3726ec1 @trofi hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
167 cabalVtoHPv :: Cabal.Version -> Version
6956e2f @kolmodin Tiny cleanup about different Version structures. Add rdepend to ebuild.
kolmodin authored
168 cabalVtoHPv = (\v -> Version v Nothing [] 0) . Cabal.versionBranch
3726ec1 @trofi hackport-cabal2ebuild-string-to-int-representation.patch
trofi authored
169
8273e68 @kolmodin Update the CLI and start using cabal-install features
kolmodin authored
170 coreLibs :: [Cabal.PackageName]
171 coreLibs = map Cabal.PackageName
61f04b0 Update list of core libs
Duncan Coutts authored
172 ["array"
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
173 ,"base"
eb77d89 @trofi wipe bytestring as a explicit dependency once again
trofi authored
174 ,"bytestring" -- intentionally no ebuild. use ghc's version
175 -- to avoid dreaded 'diamond dependency' problem
61f04b0 Update list of core libs
Duncan Coutts authored
176 ,"containers"
177 ,"directory"
136cbd4 @kolmodin We do need editline dependencies
kolmodin authored
178 --,"editline"
fe19025 @trofi ban one more core package: filepath this time
trofi authored
179 ,"filepath" -- intentionally no ebuild. use ghc's version
61f04b0 Update list of core libs
Duncan Coutts authored
180 ,"ghc"
285f6b1 @kolmodin Add missing core libs to list
kolmodin authored
181 ,"ghc-prim"
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
182 ,"haskell98"
2f85f14 @kolmodin Write comments about core packages
kolmodin authored
183 ,"hpc" --has ebuild, but only in the overlay
285f6b1 @kolmodin Add missing core libs to list
kolmodin authored
184 ,"integer"
61f04b0 Update list of core libs
Duncan Coutts authored
185 ,"old-locale"
186 ,"old-time"
187 ,"packedstring"
188 ,"pretty"
189 ,"process"
190 ,"random"
2f85f14 @kolmodin Write comments about core packages
kolmodin authored
191 ,"readline" --has ebuild, but only in the overlay
61f04b0 Update list of core libs
Duncan Coutts authored
192 ,"rts"
cd68bad @trofi wipe syb as a explicit dependency from generated ebuilds
trofi authored
193 ,"syb" -- intentionally no ebuild. use ghc's version
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
194 ,"template-haskell"
2f85f14 @kolmodin Write comments about core packages
kolmodin authored
195 ,"unix" --has ebuild, but only in the overlay
61f04b0 Update list of core libs
Duncan Coutts authored
196 ]
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
197
198 showEBuild :: EBuild -> String
199 showEBuild ebuild =
e64b3e6 @trofi ebuild: updated generated copyright (2009 -> 2010)
trofi authored
200 ss "# Copyright 1999-2010 Gentoo Foundation". nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
201 ss "# Distributed under the terms of the GNU General Public License v2". nl.
202 ss "# $Header: $". nl.
203 nl.
204 ss "CABAL_FEATURES=". quote' (sepBy " " $ features ebuild). nl.
205 ss "inherit haskell-cabal". nl.
206 nl.
20179c4 Set S= properly for packages with upper case names
Duncan Coutts authored
207 (case my_pn ebuild of
208 Nothing -> id
209 Just pn -> ss "MY_PN=". quote pn. nl.
210 ss "MY_P=". quote "${MY_PN}-${PV}". nl. nl).
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
211 ss "DESCRIPTION=". quote (description ebuild). nl.
212 ss "HOMEPAGE=". quote (homepage ebuild). nl.
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
213 ss "SRC_URI=". quote (replaceVars (src_uri ebuild)).
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
214 (if null (src_uri ebuild) then ss "\t#Fixme: please fill in manually"
215 else id). nl.
5bcf377 Update hackport's ebuild generation to current conventions.
Duncan Coutts authored
216 nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
217 ss "LICENSE=". quote (license ebuild).
218 (if null (licenseComments ebuild) then id
219 else ss "\t#". ss (licenseComments ebuild)). nl.
220 ss "SLOT=". quote (slot ebuild). nl.
63b57b8 Adapted HackPort to the new Hackage interface
der_eq@freenet.de authored
221 ss "KEYWORDS=". quote' (sepBy " " $ keywords ebuild).nl.
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
222 ss "IUSE=". quote' (sepBy ", " $ iuse ebuild). nl.
223 nl.
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
224 ( if (not . null . build_tools $ ebuild)
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
225 then ss "BUILDTOOLS=". quote' (sepBy "\n\t\t" $ map display $ build_tools ebuild). nl
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
226 else id
227 ).
228 ( if (not . null . extra_libs $ ebuild )
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
229 then ss "EXTRALIBS=". quote' (sepBy "\n\t\t" $ map display $ extra_libs ebuild). nl
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
230 else id
231 ).
232 ( if (not . null . haskell_deps $ ebuild)
9e6e1bc @kolmodin Make Portage.Dependency use PackageName instead of just a String
kolmodin authored
233 then ss "HASKELLDEPS=". quote' (sepBy "\n\t\t" $ map display $ haskell_deps ebuild). nl
bd75ad0 @kolmodin first stab at DEPEND / RDEPEND tracking
kolmodin authored
234 else id
235 ).
236 ss "RDEPEND=". quote' (sepBy "\n\t\t" $ rdepend ebuild). nl.
237 ss "DEPEND=". quote' (sepBy "\n\t\t" $ depend ebuild). nl.
20179c4 Set S= properly for packages with upper case names
Duncan Coutts authored
238 (case my_pn ebuild of
239 Nothing -> id
87d875b @kolmodin Wall police
kolmodin authored
240 Just _ -> nl. ss "S=". quote ("${WORKDIR}/${MY_P}"). nl)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
241 $ []
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
242 where replaceVars = replaceCommonVars (name ebuild) (my_pn ebuild) (version ebuild)
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
243
87d875b @kolmodin Wall police
kolmodin authored
244 ss :: String -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
245 ss = showString
87d875b @kolmodin Wall police
kolmodin authored
246
247 sc :: Char -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
248 sc = showChar
87d875b @kolmodin Wall police
kolmodin authored
249
250 nl :: String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
251 nl = sc '\n'
252
87d875b @kolmodin Wall police
kolmodin authored
253 quote :: String -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
254 quote str = sc '"'. ss str. sc '"'
87d875b @kolmodin Wall police
kolmodin authored
255
256 quote' :: (String -> String) -> String -> String
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
257 quote' str = sc '"'. str. sc '"'
258
259 sepBy :: String -> [String] -> ShowS
87d875b @kolmodin Wall police
kolmodin authored
260 sepBy _ [] = id
261 sepBy _ [x] = ss x
aff37c2 First release of HackPort, the Hackage tool for Portage
der_eq@freenet.de authored
262 sepBy s (x:xs) = ss x. ss s. sepBy s xs
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
263
264 getRestIfPrefix ::
265 String -> -- ^ the prefix
266 String -> -- ^ the string
267 Maybe String
268 getRestIfPrefix (p:ps) (x:xs) = if p==x then getRestIfPrefix ps xs else Nothing
269 getRestIfPrefix [] rest = Just rest
270 getRestIfPrefix _ [] = Nothing
271
272 subStr ::
273 String -> -- ^ the search string
274 String -> -- ^ the string to be searched
9448bb7 @kolmodin Rewritten overlayonly functionality
kolmodin authored
275 Maybe (String,String) -- ^ Just (pre,post) if string is found
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
276 subStr sstr str = case getRestIfPrefix sstr str of
277 Nothing -> if null str then Nothing else case subStr sstr (tail str) of
278 Nothing -> Nothing
279 Just (pre,post) -> Just (head str:pre,post)
280 Just rest -> Just ([],rest)
281
282 replaceMultiVars ::
283 [(String,String)] -> -- ^ pairs of variable name and content
284 String -> -- ^ string to be searched
285 String -- ^ the result
286 replaceMultiVars [] str = str
87d875b @kolmodin Wall police
kolmodin authored
287 replaceMultiVars whole@((pname,cont):rest) str = case subStr cont str of
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
288 Nothing -> replaceMultiVars rest str
87d875b @kolmodin Wall police
kolmodin authored
289 Just (pre,post) -> (replaceMultiVars rest pre)++pname++(replaceMultiVars whole post)
8022ddc Adding support for variable substitution in generated ebuilds
der_eq@freenet.de authored
290
291 replaceCommonVars ::
292 String -> -- ^ PN
293 Maybe String -> -- ^ MYPN
294 String -> -- ^ PV
295 String -> -- ^ the string to be replaced
296 String
297 replaceCommonVars pn mypn pv str
298 = replaceMultiVars
299 ([("${P}",pn++"-"++pv)]
300 ++ maybe [] (\x->[("${MY_P}",x++"-"++pv)]) mypn
301 ++[("${PN}",pn)]
302 ++ maybe [] (\x->[("${MY_PN}",x)]) mypn
303 ++[("${PV}",pv)]) str
Something went wrong with that request. Please try again.