module Settings.Packages (
    module Settings.Default,
    packages, getPackages, knownPackages
    ) where

import Package
import Switches
import Expression
import Oracles.Setting
import Settings.User
import Settings.Default

-- Combining default list of packages with user modifications
packages :: Packages
packages = defaultPackages <> userPackages

getPackages :: Expr [Package]
getPackages = fromDiffExpr packages

-- These are the packages we build by default
defaultPackages :: Packages
defaultPackages = mconcat
    [ stage0 ? packagesStage0
    , stage1 ? packagesStage1 ]

packagesStage0 :: Packages
packagesStage0 = mconcat
    [ append [binPackageDb, binary, cabal, compiler, hoopl, hpc, transformers]
    , notWindowsHost ? notTargetOs "ios" ? append [terminfo] ]

packagesStage1 :: Packages
packagesStage1 = mconcat
    [ packagesStage0
    , append [ array, base, bytestring, containers, deepseq, directory
             , filepath, ghcPrim, haskeline, integerLibrary, parallel
             , pretty, primitive, process, stm, templateHaskell, time ]
    , windowsHost    ? append [win32]
    , notWindowsHost ? append [unix]
    , buildHaddock   ? append [xhtml] ]

knownPackages :: [Package]
knownPackages = defaultKnownPackages ++ userKnownPackages

module Settings.Packages (
    module Settings.Default,
    packages, getPackages, knownPackages, findKnownPackage
    ) where

import Package
import Switches
import Expression
import Oracles.Setting
import Settings.User
import Settings.Default
import Data.List

-- Combining default list of packages with user modifications
packages :: Packages
packages = defaultPackages <> userPackages

getPackages :: Expr [Package]
getPackages = fromDiffExpr packages

-- These are the packages we build by default
defaultPackages :: Packages
defaultPackages = mconcat
    [ stage0 ? packagesStage0
    , stage1 ? packagesStage1 ]

packagesStage0 :: Packages
packagesStage0 = mconcat
    [ append [binPackageDb, binary, cabal, compiler, hoopl, hpc, transformers]
    , notWindowsHost ? notTargetOs "ios" ? append [terminfo] ]

packagesStage1 :: Packages
packagesStage1 = mconcat
    [ packagesStage0
    , append [ array, base, bytestring, containers, deepseq, directory
             , filepath, ghcPrim, haskeline, integerLibrary, parallel
             , pretty, primitive, process, stm, templateHaskell, time ]
    , windowsHost    ? append [win32]
    , notWindowsHost ? append [unix]
    , buildHaddock   ? append [xhtml] ]

knownPackages :: [Package]
knownPackages = defaultKnownPackages ++ userKnownPackages

-- Note: this is slow but we keep it simple as there not too many packages (30)
-- We handle integerLibrary in a special way, because packages integerGmp and
-- integerGmp2 have the same package name -- we return the user-selected one.
findKnownPackage :: PackageName -> Maybe Package
findKnownPackage name
    | name == pkgName integerLibrary = Just integerLibrary
    | otherwise = find (\pkg -> pkgName pkg == name) knownPackages

Add findKnownPackage for finding packages by name.
Add findKnownPackage for finding packages by name.
