summaryrefslogtreecommitdiff
path: root/Merge/Dependencies.hs
blob: d49ed983d9690ad45c94bfdc2d22203ab1bea01c (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
{-# LANGUAGE CPP #-}

{- | Merge a package from hackage to an ebuild.
 -}
module Merge.Dependencies
  ( EDep(..)
  , resolveDependencies
  ) where

import Data.Maybe ( isJust, isNothing )
import Data.Monoid ( Monoid, mempty, mappend)
import qualified Data.List as L
import qualified Data.Set as S

import qualified Distribution.Package as Cabal
import qualified Distribution.PackageDescription as Cabal
import qualified Distribution.Version as Cabal
import qualified Distribution.Text as Cabal
import qualified Distribution.Types.LegacyExeDependency as Cabal
import qualified Distribution.Types.PkgconfigDependency as Cabal

import qualified Distribution.Compiler as Cabal

import qualified Portage.Cabal as Portage
import qualified Portage.Dependency as Portage
import qualified Portage.Dependency.Normalize as PN
import qualified Portage.Overlay as Portage
import qualified Portage.PackageId as Portage
import qualified Portage.Use as Portage
import qualified Portage.Tables as Portage
import qualified Cabal2Ebuild as C2E

import qualified Portage.GHCCore as GHCCore

import Debug.Trace ( trace )

#if MIN_VERSION_base(4,9,0)
import Data.Semigroup (Semigroup(..))
#endif

-- | Dependencies of an ebuild
data EDep = EDep
  {
    rdep :: Portage.Dependency,
    rdep_e :: S.Set String,
    dep :: Portage.Dependency,
    dep_e :: S.Set String
  }
  deriving (Show, Eq, Ord)

#if MIN_VERSION_base(4,9,0)
instance Semigroup EDep where
  (EDep rdepA rdep_eA depA dep_eA) <> (EDep rdepB rdep_eB depB dep_eB) = EDep
    { rdep   = Portage.DependAllOf [rdepA, rdepB]
    , rdep_e = rdep_eA `S.union` rdep_eB
    , dep    = Portage.DependAllOf [depA, depB]
    , dep_e  = dep_eA  `S.union` dep_eB
    }
#endif  
  
instance Monoid EDep where
  mempty = EDep
      {
        rdep = Portage.empty_dependency,
        rdep_e = S.empty,
        dep = Portage.empty_dependency,
        dep_e = S.empty
      }
#if !(MIN_VERSION_base(4,11,0))
  (EDep rdepA rdep_eA depA dep_eA) `mappend` (EDep rdepB rdep_eB depB dep_eB) = EDep
    { rdep   = Portage.DependAllOf [rdepA, rdepB]
    , rdep_e = rdep_eA `S.union` rdep_eB
    , dep    = Portage.DependAllOf [depA, depB]
    , dep_e  = dep_eA  `S.union` dep_eB
    }
#endif

resolveDependencies :: Portage.Overlay -> Cabal.PackageDescription -> Cabal.CompilerInfo
                    -> [Cabal.PackageName] -> Cabal.PackageName
                    -> EDep
resolveDependencies overlay pkg compiler_info ghc_package_names merged_cabal_pkg_name = edeps
  where
    -- hasBuildableExes p = any (buildable . buildInfo) . executables $ p
    treatAsLibrary :: Bool
    treatAsLibrary = isJust (Cabal.library pkg)
    -- without slot business
    raw_haskell_deps :: Portage.Dependency
    raw_haskell_deps = PN.normalize_depend $ Portage.DependAllOf $ haskellDependencies overlay (Cabal.buildDepends pkg)
    test_deps :: Portage.Dependency
    test_deps = Portage.mkUseDependency (True, Portage.Use "test") $
                    Portage.DependAllOf $
                    remove_raw_common $
                    testDependencies overlay pkg ghc_package_names merged_cabal_pkg_name
    cabal_dep :: Portage.Dependency
    cabal_dep = cabalDependency overlay pkg compiler_info
    ghc_dep :: Portage.Dependency
    ghc_dep = compilerInfoToDependency compiler_info
    extra_libs :: Portage.Dependency
    extra_libs = Portage.DependAllOf $ findCLibs pkg
    pkg_config_libs :: [Portage.Dependency]
    pkg_config_libs = pkgConfigDependencies overlay pkg
    pkg_config_tools :: Portage.Dependency
    pkg_config_tools = Portage.DependAllOf $ if L.null pkg_config_libs
                           then []
                           else [any_c_p "virtual" "pkgconfig"]
    build_tools :: Portage.Dependency
    build_tools = Portage.DependAllOf $ pkg_config_tools : buildToolsDependencies pkg

    setup_deps :: Portage.Dependency
    setup_deps = PN.normalize_depend $ Portage.DependAllOf $
                     remove_raw_common $
                     setupDependencies overlay pkg ghc_package_names merged_cabal_pkg_name

    edeps :: EDep
    edeps
        | treatAsLibrary = mempty
                  {
                    dep = Portage.DependAllOf
                              [ cabal_dep
                              , setup_deps
                              , build_tools
                              , test_deps
                              ],
                    dep_e = S.singleton "${RDEPEND}",
                    rdep = Portage.DependAllOf
                               [ Portage.set_build_slot ghc_dep
                               , Portage.set_build_slot $ add_profile $ raw_haskell_deps
                               , extra_libs
                               , Portage.DependAllOf pkg_config_libs
                               ]
                  }
        | otherwise = mempty
                  {
                    dep = Portage.DependAllOf
                              [ cabal_dep
                              , setup_deps
                              , build_tools
                              , test_deps
                              ],
                    dep_e = S.singleton "${RDEPEND}",
                    rdep = Portage.DependAllOf
                               [ Portage.set_build_slot ghc_dep
                               , Portage.set_build_slot $ raw_haskell_deps
                               , extra_libs
                               , Portage.DependAllOf pkg_config_libs
                               ]
                  }
    add_profile    = Portage.addDepUseFlag (Portage.mkQUse (Portage.Use "profile"))
    -- remove depends present in common section
    remove_raw_common = filter (\d -> not (Portage.dep_as_broad_as d raw_haskell_deps))
                      . map PN.normalize_depend

---------------------------------------------------------------
-- Custom-setup dependencies
-- TODO: move partitioning part to Merge:mergeGenericPackageDescription
---------------------------------------------------------------

setupDependencies :: Portage.Overlay -> Cabal.PackageDescription -> [Cabal.PackageName] -> Cabal.PackageName -> [Portage.Dependency]
setupDependencies overlay pkg ghc_package_names merged_cabal_pkg_name = deps
    where cabalDeps = maybe [] id $ Cabal.setupDepends `fmap` Cabal.setupBuildInfo pkg
          cabalDeps' = fst $ Portage.partition_depends ghc_package_names merged_cabal_pkg_name cabalDeps
          deps = C2E.convertDependencies overlay (Portage.Category "dev-haskell") cabalDeps'

---------------------------------------------------------------
-- Test-suite dependencies
-- TODO: move partitioning part to Merge:mergeGenericPackageDescription
---------------------------------------------------------------

testDependencies :: Portage.Overlay -> Cabal.PackageDescription -> [Cabal.PackageName] -> Cabal.PackageName -> [Portage.Dependency]
testDependencies overlay pkg ghc_package_names merged_cabal_pkg_name = deps
    where cabalDeps = concat $ map Cabal.targetBuildDepends $ map Cabal.testBuildInfo (Cabal.testSuites pkg)
          cabalDeps' = fst $ Portage.partition_depends ghc_package_names merged_cabal_pkg_name cabalDeps
          deps = C2E.convertDependencies overlay (Portage.Category "dev-haskell") cabalDeps'

---------------------------------------------------------------
-- Haskell packages
---------------------------------------------------------------

haskellDependencies :: Portage.Overlay -> [Cabal.Dependency] {- PackageDescription -} -> [Portage.Dependency]
haskellDependencies overlay deps =
    C2E.convertDependencies overlay (Portage.Category "dev-haskell") deps

---------------------------------------------------------------
-- Cabal Dependency
---------------------------------------------------------------

-- | Select the most restrictive dependency on Cabal, either the .cabal
-- file's descCabalVersion, or the Cabal GHC shipped with.
cabalDependency :: Portage.Overlay -> Cabal.PackageDescription -> Cabal.CompilerInfo -> Portage.Dependency
cabalDependency overlay pkg ~(Cabal.CompilerInfo {
                                  Cabal.compilerInfoId =
                                      Cabal.CompilerId Cabal.GHC cabal_version
                              }) =
         C2E.convertDependency overlay
                               (Portage.Category "dev-haskell")
                               (Cabal.Dependency (Cabal.mkPackageName "Cabal")
                                                 finalCabalDep)
  where
    versionNumbers = Cabal.versionNumbers cabal_version
    userCabalVersion = Cabal.orLaterVersion (Cabal.specVersion pkg)
    shippedCabalVersion = GHCCore.cabalFromGHC versionNumbers
    shippedCabalDep = maybe Cabal.anyVersion Cabal.orLaterVersion shippedCabalVersion
    finalCabalDep = Cabal.simplifyVersionRange
                                (Cabal.intersectVersionRanges
                                          userCabalVersion
                                          shippedCabalDep)

---------------------------------------------------------------
-- GHC Dependency
---------------------------------------------------------------

compilerInfoToDependency :: Cabal.CompilerInfo -> Portage.Dependency
compilerInfoToDependency ~(Cabal.CompilerInfo {
                               Cabal.compilerInfoId =
                                   Cabal.CompilerId Cabal.GHC cabal_version}) =
  at_least_c_p_v "dev-lang" "ghc" (Cabal.versionNumbers cabal_version)

---------------------------------------------------------------
-- C Libraries
---------------------------------------------------------------

findCLibs :: Cabal.PackageDescription -> [Portage.Dependency]
findCLibs (Cabal.PackageDescription { Cabal.library = lib, Cabal.executables = exes }) =
  [ trace ("WARNING: This package depends on a C library we don't know the portage name for: " ++ p ++ ". Check the generated ebuild.")
          (any_c_p "unknown-c-lib" p)
  | p <- notFound
  ] ++
  found
  where
  libE = concatMap (Cabal.extraLibs . Cabal.libBuildInfo) $ maybe [] return lib
  exeE = concatMap Cabal.extraLibs (filter Cabal.buildable (map Cabal.buildInfo exes))
  allE = libE ++ exeE

  notFound = [ p | p <- allE, isNothing (staticTranslateExtraLib p) ]
  found =    [ p | Just p <- map staticTranslateExtraLib allE ]

any_c_p_s_u :: String -> String -> Portage.SlotDepend -> [Portage.UseFlag] -> Portage.Dependency
any_c_p_s_u cat pn slot uses = Portage.DependAtom $
    Portage.Atom (Portage.mkPackageName cat pn)
                 (Portage.DRange Portage.ZeroB Portage.InfinityB)
                 (Portage.DAttr slot uses)

any_c_p :: String -> String -> Portage.Dependency
any_c_p cat pn = any_c_p_s_u cat pn Portage.AnySlot []

at_least_c_p_v :: String -> String -> [Int] -> Portage.Dependency
at_least_c_p_v cat pn v = Portage.DependAtom $
  Portage.Atom (Portage.mkPackageName cat pn)
               (Portage.DRange (Portage.NonstrictLB (Portage.Version v Nothing [] 0)) Portage.InfinityB)
               (Portage.DAttr Portage.AnySlot [])

staticTranslateExtraLib :: String -> Maybe Portage.Dependency
staticTranslateExtraLib lib = lookup lib m
  where
  m = [ ("z", any_c_p "sys-libs" "zlib")
      , ("bz2", any_c_p "app-arch" "bzip2")
      , ("mysqlclient", at_least_c_p_v "virtual" "mysql" [4,0])
      , ("pq", at_least_c_p_v "dev-db" "postgresql" [7])
      , ("ev", any_c_p "dev-libs" "libev")
      , ("expat", any_c_p "dev-libs" "expat")
      , ("curl", any_c_p "net-misc" "curl")
      , ("xml2", any_c_p "dev-libs" "libxml2")
      , ("mecab", any_c_p "app-text" "mecab")
      , ("zmq", any_c_p "net-libs" "zeromq")
      , ("SDL", any_c_p "media-libs" "libsdl")
      , ("adns", any_c_p "net-libs" "adns")
      , ("pcre", any_c_p "dev-libs" "libpcre")
      , ("GL", any_c_p "virtual" "opengl")
      , ("GLU", any_c_p "virtual" "glu")
      , ("glut", any_c_p "media-libs" "freeglut")
      , ("X11", any_c_p "x11-libs" "libX11")
      , ("libzip", any_c_p "dev-libs" "libzip")
      , ("ssl", any_c_p "dev-libs" "openssl")
      , ("Judy", any_c_p "dev-libs" "judy")
      , ("fcgi", any_c_p "dev-libs" "fcgi")
      , ("gnutls", any_c_p "net-libs" "gnutls")
      , ("idn", any_c_p "net-dns" "libidn")
      , ("tre", any_c_p "dev-libs" "tre")
      , ("m", any_c_p "virtual" "libc")
      , ("asound", any_c_p "media-libs" "alsa-lib")
      , ("sqlite3", at_least_c_p_v "dev-db" "sqlite" [3,0])
      , ("stdc++", any_c_p_s_u "sys-devel" "gcc" Portage.AnySlot [Portage.mkUse (Portage.Use "cxx")])
      , ("crack", any_c_p "sys-libs" "cracklib")
      , ("exif", any_c_p "media-libs" "libexif")
      , ("IL", any_c_p "media-libs" "devil")
      , ("Imlib2", any_c_p "media-libs" "imlib2")
      , ("pcap", any_c_p "net-libs" "libpcap")
      , ("lber", any_c_p "net-nds" "openldap")
      , ("ldap", any_c_p "net-nds" "openldap")
      , ("expect", any_c_p "dev-tcltk" "expect")
      , ("tcl", any_c_p "dev-lang" "tcl")
      , ("Xext", any_c_p "x11-libs" "libXext")
      , ("Xrandr", any_c_p "x11-libs" "libXrandr")
      , ("crypto", any_c_p "dev-libs" "openssl")
      , ("gmp", any_c_p "dev-libs" "gmp")
      , ("fuse", any_c_p "sys-fs" "fuse")
      , ("zip", any_c_p "dev-libs" "libzip")
      , ("QtCore", any_c_p "dev-qt" "qtcore")
      , ("QtDeclarative", any_c_p "dev-qt" "qtdeclarative")
      , ("QtGui", any_c_p "dev-qt" "qtgui")
      , ("QtOpenGL", any_c_p "dev-qt" "qtopengl")
      , ("QtScript", any_c_p "dev-qt" "qtscript")
      , ("gsl", any_c_p "sci-libs" "gsl")
      , ("gslcblas", any_c_p "sci-libs" "gsl")
      , ("mkl_core", any_c_p "sci-libs" "mkl")
      , ("mkl_intel_lp64", any_c_p "sci-libs" "mkl")
      , ("mkl_lapack", any_c_p "sci-libs" "mkl")
      , ("mkl_sequential", any_c_p "sci-libs" "mkl")
      , ("Xi", any_c_p "x11-libs" "libXi")
      , ("Xxf86vm", any_c_p "x11-libs" "libXxf86vm")
      , ("pthread", any_c_p "virtual" "libc")
      , ("panelw", any_c_p "sys-libs" "ncurses")
      , ("ncursesw", any_c_p "sys-libs" "ncurses")
      , ("ftgl", any_c_p "media-libs" "ftgl")
      , ("glpk", any_c_p "sci-mathematics" "glpk")
      , ("sndfile", any_c_p "media-libs" "libsndfile")
      , ("portaudio", any_c_p "media-libs" "portaudio")
      , ("icudata", any_c_p "dev-libs" "icu")
      , ("icui18n", any_c_p "dev-libs" "icu")
      , ("icuuc", any_c_p "dev-libs" "icu")
      , ("chipmunk", any_c_p "sci-physics" "chipmunk")
      , ("alut", any_c_p "media-libs" "freealut")
      , ("openal", any_c_p "media-libs" "openal")
      , ("iw", any_c_p "net-wireless" "wireless-tools")
      , ("attr", any_c_p "sys-apps" "attr")
      , ("ncurses", any_c_p "sys-libs" "ncurses")
      , ("panel", any_c_p "sys-libs" "ncurses")
      , ("nanomsg", any_c_p "dev-libs" "nanomsg")
      , ("pgf", any_c_p "media-libs" "libpgf")
      , ("ssh2", any_c_p "net-libs" "libssh2")
      , ("dl", any_c_p "virtual" "libc")
      , ("glfw", any_c_p "media-libs" "glfw")
      , ("nettle", any_c_p "dev-libs" "nettle")
      , ("Xpm",    any_c_p "x11-libs" "libXpm")
      , ("Xss",    any_c_p "x11-libs" "libXScrnSaver")
      , ("tag_c",  any_c_p "media-libs" "taglib")
      , ("magic",  any_c_p "sys-apps" "file")
      , ("crypt",  any_c_p "virtual" "libc")
      , ("Xrender", any_c_p "x11-libs" "libXrender")
      , ("Xcursor", any_c_p "x11-libs" "libXcursor")
      , ("Xinerama", any_c_p "x11-libs" "libXinerama")
      , ("wayland-client", any_c_p "dev-libs" "wayland")
      , ("wayland-cursor", any_c_p "dev-libs" "wayland")
      , ("wayland-server", any_c_p "dev-libs" "wayland")
      , ("wayland-egl", any_c_p_s_u "media-libs" "mesa" Portage.AnySlot [Portage.mkUse (Portage.Use "wayland")])
      , ("xkbcommon", any_c_p "x11-libs" "libxkbcommon")
      , ("SDL_gfx", any_c_p "media-libs" "sdl-gfx")
      , ("SDL_image", any_c_p "media-libs" "sdl-image")
      , ("SDL_ttf", any_c_p "media-libs" "sdl-ttf")
      , ("odbc", any_c_p "dev-db" "unixODBC")
      , ("uuid", any_c_p "sys-apps" "util-linux")
      , ("notify", any_c_p "x11-libs" "libnotify")
      , ("SDL2", any_c_p " media-libs" "libsdl2")
      , ("SDL2_mixer", any_c_p "media-libs" "sdl2-mixer")
      ]

---------------------------------------------------------------
-- Build Tools
---------------------------------------------------------------

buildToolsDependencies :: Cabal.PackageDescription -> [Portage.Dependency]
buildToolsDependencies (Cabal.PackageDescription { Cabal.library = lib, Cabal.executables = exes }) = L.nub $
  [ case pkg of
      Just p -> p
      Nothing -> trace ("WARNING: Unknown build tool '" ++ Cabal.display exe ++ "'. Check the generated ebuild.")
                       (any_c_p "unknown-build-tool" pn)
  | exe@(Cabal.LegacyExeDependency pn _range) <- cabalDeps
  , pkg <- return (lookup pn buildToolsTable)
  ]
  where
  cabalDeps = filter notProvided $ depL ++ depE
  depL = concatMap (Cabal.buildTools . Cabal.libBuildInfo) $ maybe [] return lib
  depE = concatMap Cabal.buildTools (filter Cabal.buildable (map Cabal.buildInfo exes))
  notProvided (Cabal.LegacyExeDependency pn _range) = pn `notElem` buildToolsProvided

buildToolsTable :: [(String, Portage.Dependency)]
buildToolsTable =
  [ ("happy", any_c_p "dev-haskell" "happy")
  , ("alex", any_c_p "dev-haskell" "alex")
  , ("c2hs", any_c_p "dev-haskell" "c2hs")
  , ("cabal",               any_c_p "dev-haskell" "cabal-install")
  , ("cabal-install", any_c_p "dev-haskell" "cabal-install")
  , ("cpphs",               any_c_p "dev-haskell" "cpphs")
  , ("ghc",                 any_c_p "dev-lang" "ghc")
  , ("gtk2hsTypeGen",       any_c_p "dev-haskell" "gtk2hs-buildtools")
  , ("gtk2hsHookGenerator", any_c_p "dev-haskell" "gtk2hs-buildtools")
  , ("gtk2hsC2hs",          any_c_p "dev-haskell" "gtk2hs-buildtools")
  , ("hsb2hs",              any_c_p "dev-haskell" "hsb2hs")
  , ("hsx2hs",              any_c_p "dev-haskell" "hsx2hs")
  , ("llvm-config",         any_c_p "sys-devel" "llvm")
  ]

-- tools that are provided by ghc or some other existing program
-- so we do not need dependencies on them
buildToolsProvided :: [String]
buildToolsProvided = ["hsc2hs"]


---------------------------------------------------------------
-- pkg-config
---------------------------------------------------------------

pkgConfigDependencies :: Portage.Overlay -> Cabal.PackageDescription -> [Portage.Dependency]
pkgConfigDependencies overlay (Cabal.PackageDescription { Cabal.library = lib, Cabal.executables = exes }) = L.nub $ resolvePkgConfigs overlay cabalDeps
  where
  cabalDeps = depL ++ depE
  depL = concatMap (Cabal.pkgconfigDepends . Cabal.libBuildInfo) $ maybe [] return lib
  depE = concatMap Cabal.pkgconfigDepends (filter Cabal.buildable (map Cabal.buildInfo exes))

resolvePkgConfigs :: Portage.Overlay -> [Cabal.PkgconfigDependency] -> [Portage.Dependency]
resolvePkgConfigs overlay cdeps =
  [ case resolvePkgConfig overlay pkg of
      Just d -> d
      Nothing -> trace ("WARNING: Could not resolve pkg-config: " ++ Cabal.display pkg ++ ". Check generated ebuild.")
                       (any_c_p "unknown-pkg-config" pn)
  | pkg@(Cabal.PkgconfigDependency cabal_pn _range) <- cdeps
  , let pn = Cabal.unPkgconfigName cabal_pn
  ]

resolvePkgConfig :: Portage.Overlay -> Cabal.PkgconfigDependency -> Maybe Portage.Dependency
resolvePkgConfig _overlay (Cabal.PkgconfigDependency cabal_pn _cabalVersion) = do
  (cat,portname, slot) <- lookup (Cabal.unPkgconfigName cabal_pn) pkgconfig_table
  return $ any_c_p_s_u cat portname slot []

pkgconfig_table :: [(String, (String, String, Portage.SlotDepend))]
pkgconfig_table =
  [
   ("alsa",         ("media-libs", "alsa-lib", Portage.AnySlot))
  ,("atk",          ("dev-libs", "atk", Portage.AnySlot))
  ,("gconf-2.0",    ("gnome-base", "gconf", Portage.AnySlot))

  ,("gio-2.0",                ("dev-libs", "glib", Portage.GivenSlot "2"))
  ,("gio-unix-2.0",           ("dev-libs", "glib", Portage.GivenSlot "2"))
  ,("glib-2.0",               ("dev-libs", "glib", Portage.GivenSlot "2"))
  ,("gmodule-2.0",            ("dev-libs", "glib", Portage.GivenSlot "2"))
  ,("gmodule-export-2.0",     ("dev-libs", "glib", Portage.GivenSlot "2"))
  ,("gmodule-no-export-2.0",  ("dev-libs", "glib", Portage.GivenSlot "2"))
  ,("gobject-2.0",            ("dev-libs", "glib", Portage.GivenSlot "2"))
  ,("gthread-2.0",            ("dev-libs", "glib", Portage.GivenSlot "2"))

  ,("gtk+-2.0",            ("x11-libs", "gtk+", Portage.GivenSlot "2"))
  ,("gdk-2.0",             ("x11-libs", "gtk+", Portage.GivenSlot "2"))
  ,("gdk-3.0",             ("x11-libs", "gtk+", Portage.GivenSlot "3"))
  ,("gdk-pixbuf-2.0",      ("x11-libs", "gtk+", Portage.GivenSlot "2"))
  ,("gdk-pixbuf-xlib-2.0", ("x11-libs", "gtk+", Portage.GivenSlot "2"))
  ,("gdk-x11-2.0",         ("x11-libs", "gtk+", Portage.GivenSlot "2"))
  ,("gtk+-unix-print-2.0", ("x11-libs", "gtk+", Portage.GivenSlot "2"))
  ,("gtk+-x11-2.0",        ("x11-libs", "gtk+", Portage.GivenSlot "2"))

  ,("gtk+-3.0",            ("x11-libs", "gtk+", Portage.GivenSlot "3"))
  ,("webkitgtk-3.0",       ("net-libs", "webkit-gtk", Portage.GivenSlot "3"))

  ,("cairo",            ("x11-libs", "cairo", Portage.AnySlot)) -- need [svg] for dev-haskell/cairo
  ,("cairo-gobject",    ("x11-libs", "cairo", Portage.AnySlot)) -- need [glib] for dev-haskell/cairo
  ,("cairo-ft",         ("x11-libs", "cairo", Portage.AnySlot))
  ,("cairo-ps",         ("x11-libs", "cairo", Portage.AnySlot))
  ,("cairo-png",        ("x11-libs", "cairo", Portage.AnySlot))
  ,("cairo-pdf",        ("x11-libs", "cairo", Portage.AnySlot))
  ,("cairo-svg",        ("x11-libs", "cairo", Portage.AnySlot))
  ,("cairo-xlib",         ("x11-libs", "cairo", Portage.AnySlot))
  ,("cairo-xlib-xrender", ("x11-libs", "cairo", Portage.AnySlot))

  ,("javascriptcoregtk-4.0",   ("net-libs", "webkit-gtk", Portage.GivenSlot "4"))
  ,("webkit2gtk-4.0",          ("net-libs", "webkit-gtk", Portage.GivenSlot "4"))

  ,("pangocairo",       ("x11-libs", "pango", Portage.AnySlot))
  ,("pangoft2",         ("x11-libs", "pango", Portage.AnySlot))
  ,("pango",            ("x11-libs", "pango", Portage.AnySlot))
  ,("pangoxft",         ("x11-libs", "pango", Portage.AnySlot))
  ,("pangox",           ("x11-libs", "pango", Portage.AnySlot))

  ,("libglade-2.0", ("gnome-base", "libglade", Portage.AnySlot))
  ,("libsoup-2.4",   ("net-libs", "libsoup", Portage.GivenSlot "2.4"))
  ,("gnome-vfs-2.0", ("gnome-base", "gnome-vfs", Portage.AnySlot))
  ,("gnome-vfs-module-2.0", ("gnome-base", "gnome-vfs", Portage.AnySlot))
  ,("webkit-1.0", ("net-libs","webkit-gtk", Portage.GivenSlot "2"))
  ,("gtksourceview-3.0", ("x11-libs", "gtksourceview", Portage.GivenSlot "3.0"))

  ,("gstreamer-0.10",              ("media-libs", "gstreamer", Portage.AnySlot))
  ,("gstreamer-base-0.10",         ("media-libs", "gstreamer", Portage.AnySlot))
  ,("gstreamer-check-0.10",        ("media-libs", "gstreamer", Portage.AnySlot))
  ,("gstreamer-controller-0.10",   ("media-libs", "gstreamer", Portage.AnySlot))
  ,("gstreamer-dataprotocol-0.10", ("media-libs", "gstreamer", Portage.AnySlot))
  ,("gstreamer-net-0.10",          ("media-libs", "gstreamer", Portage.AnySlot))

  ,("gstreamer-app-0.10",          ("media-libs", "gst-plugins-base", Portage.AnySlot))
  ,("gstreamer-audio-0.10",        ("media-libs", "gst-plugins-base", Portage.AnySlot))
  ,("gstreamer-video-0.10",        ("media-libs", "gst-plugins-base", Portage.AnySlot))
  ,("gstreamer-plugins-base-0.10", ("media-libs", "gst-plugins-base", Portage.AnySlot))

  ,("gtksourceview-2.0",           ("x11-libs", "gtksourceview", Portage.GivenSlot "2.0"))
  ,("librsvg-2.0",                 ("gnome-base","librsvg", Portage.AnySlot))
  ,("vte",                         ("x11-libs","vte", Portage.GivenSlot "0"))
  ,("gtkglext-1.0",                ("x11-libs","gtkglext", Portage.AnySlot))

  ,("curl",                        ("net-misc", "curl", Portage.AnySlot))
  ,("libxml2",                     ("dev-libs", "libxml2", Portage.AnySlot))
  ,("libgsasl",                    ("virtual", "gsasl", Portage.AnySlot))
  ,("libzip",                      ("dev-libs", "libzip", Portage.AnySlot))
  ,("gnutls",                      ("net-libs", "gnutls", Portage.AnySlot))
  ,("libidn",                      ("net-dns", "libidn", Portage.AnySlot))
  ,("libxml-2.0",                  ("dev-libs", "libxml2", Portage.AnySlot))
  ,("yaml-0.1",                    ("dev-libs", "libyaml", Portage.AnySlot))
  ,("QtCore",                      ("dev-qt", "qtcore", Portage.AnySlot))
  ,("lua",                         ("dev-lang", "lua", Portage.AnySlot))
  ,("QtDeclarative",               ("dev-qt", "qtdeclarative", Portage.AnySlot))
  ,("QtGui",                       ("dev-qt", "qtgui", Portage.AnySlot))
  ,("QtOpenGL",                    ("dev-qt", "qtopengl", Portage.AnySlot))
  ,("QtScript",                    ("dev-qt", "qtscript", Portage.AnySlot))
  ,("ImageMagick",                 ("media-gfx", "imagemagick", Portage.AnySlot))
  ,("MagickWand",                  ("media-gfx", "imagemagick", Portage.AnySlot))
  ,("ncurses",                     ("sys-libs", "ncurses", Portage.AnySlot))
  ,("ncursesw",                    ("sys-libs", "ncurses", Portage.AnySlot))
  ,("panel",                       ("sys-libs", "ncurses", Portage.AnySlot))
  ,("panelw",                      ("sys-libs", "ncurses", Portage.AnySlot))
  ,("libssh2",                     ("net-libs", "libssh2", Portage.AnySlot))
  ,("SDL_image",                   ("media-libs", "sdl-image", Portage.AnySlot))
  ,("libzmq",                      ("net-libs", "zeromq", Portage.AnySlot))
  ,("taglib_c",                    ("media-libs", "taglib", Portage.AnySlot))
  ,("libcurl",                     ("net-misc", "curl", Portage.AnySlot))
  ,("libpq",                       ("dev-db", "postgresql", Portage.AnySlot))
  ,("poppler-glib",                ("app-text", "poppler", Portage.AnySlot))
  ,("gsl",                         ("sci-libs", "gsl", Portage.AnySlot))
  ,("libvirt",                     ("app-emulation", "libvirt", Portage.AnySlot))

  ,("Qt5Core",                     ("dev-qt", "qtcore", Portage.GivenSlot "5"))
  ,("Qt5Gui",                      ("dev-qt", "qtgui", Portage.GivenSlot "5"))
  ,("Qt5Qml",                      ("dev-qt", "qtdeclarative", Portage.GivenSlot "5"))
  ,("Qt5Quick",                    ("dev-qt", "qtdeclarative", Portage.GivenSlot "5"))
  ,("Qt5Widgets",                  ("dev-qt", "qtwidgets", Portage.GivenSlot "5"))

  ,("sdl2",                        ("media-libs", "libsdl2", Portage.AnySlot))
  ,("SDL2_image",                  ("media-libs", "sdl2-image", Portage.AnySlot))
  ,("SDL2_mixer",                  ("media-libs", "sdl2-mixer", Portage.AnySlot))
  ]