data GhcOptions = GhcOptions {

  ghcOptMode          :: GhcMode,

  ghcOptSearchPath    :: [FilePath],
  ghcOptOutputDir     :: Maybe FilePath,
  ghcOptSuffixHi      :: Maybe String,
  ghcOptSuffixObj     :: Maybe String,

  ghcOptExtraPre      :: [String],
  ghcOptExtraPost     :: [String],

  ghcOptPackageName   :: Maybe PackageId,
  ghcOptPackageDBs    :: PackageDBStack,
  ghcOptPackages      :: [PackageId],

  ghcOptFrameworks    :: [String],
  ghcOptFrameworkDirs :: [FilePath],
  ghcOptExtraLibs     :: [String],
  ghcOptExtraLibDirs  :: [FilePath],
  ghcOptIncludes      :: [FilePath],
  ghcOptIncludeDirs   :: [FilePath],
  $
  ghcOptcppOptions    :: [String],
  ghcOptccOptions     :: [String],
  ghcOptldOptions     :: [String],

  ghcOptVerbosity     :: Verbosity,
  ghcOptOptimisation  :: OptimisationLevel,
  ghcOptExtensions    :: [Extension],

  ghcOptSplitObjs     :: Bool
}

data GhcMode
   = BatchMode {
       ghcOptInputFile   :: FilePath,
       ghcOptOutputFile  :: FilePath
     }
   | MakeMode {
       ghcOptModules     :: [ModuleName.ModuleName],
       ghcOptSourceFiles :: [FilePath]
     }
   | OtherMode

renderGhcOptions :: GhcOptions -> [String]
renderGhcOptions opts =
     ghcOptExtraPre opts

  -- source search path
  ++ [ "-i" | not (null (ghcOptSearchPath opts)) ]
  ++ [ "-i" ++ dir | dir <- ghcOptSearchPath opts ]

  -- output directory
  ++ (case ghcOptOutputDir opts of
        Nothing   -> []
        Just odir -> [ "-odir",  odir, "-hidir", odir ])

  -- package name
  ++ case ghcOptPackageName opts of
       Nothing    -> []
       Just pkgid -> ["-package-name", display pkgid ]

  -- package databases
  ++ [ "-no-user-package-conf" | UserPackageDb `notElem` ghcOptPackageDBs opts ]
  ++ concat
     [ ["-package-conf", db]   | SpecificPackageDB db <- ghcOptPackageDBs opts ]

  -- packages
  ++ concat [ ["-package", display pkg] | pkg <- ghcOptPackages opts ]

  ++ maybeOpts (ghcOptSuffixHi opts) $ \suf ->
       ["-hisuf", suf]
  ++ maybeOpts (ghcOptSuffixHi opts) $ \suf ->
       ["-osuf", suf]


maybeOpts Nothing  _ = []
maybeOpts (Just x) _ = f x

--packageHsGhcOptions :: BuildInfo -> LocalBuildInfo -> GhcOptions
--packageHsGhcOptions = undefined

--packageCGhcOptions :: BuildInfo -> LocalBuildInfo -> GhcOptions
--packageHsGhcOptions = undefined
