-- | Post-build hook for OS X application bundles.  Does nothing if
-- called on another O/S.
appBundleBuildHook ::
  [MacApp] -- ^ List of applications to build; if empty, an
           -- application is built for each executable in the package,
           -- with no icon or plist, and no dependency-chasing.
  -> Args -- ^ All other parameters as per
          -- 'Distribution.Simple.postBuild'.
  -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
appBundleBuildHook apps _ _ pkg localb =
  case os of
    "darwin" -> forM_ apps' $ makeAppBundle localb
      where apps' = case apps of
                      [] -> map mkDefault $ executables pkg
                      xs -> xs
            mkDefault x = MacApp (exeName x) Nothing Nothing [] [] DoNotChase
    _ -> putStrLn "Not OS X, so not building an application bundle."

-- | Given a 'MacApp' in context, make an application bundle in the
-- build area.
appBundleBuildHook ::
  [MacApp] -- ^ List of applications to build; if empty, an
           -- application is built for each executable in the package,
           -- with no icon or plist, and no dependency-chasing.
  -> Args -- ^ All other parameters as per
          -- 'Distribution.Simple.postBuild'.
  -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()
appBundleBuildHook apps _ _ pkg localb =
  case os of
    "darwin" -> forM_ apps' $ makeAppBundle localb
      where apps' = case apps of
                      [] -> map mkDefault $ executables pkg
                      xs -> xs
            mkDefault x = MacApp (exeName x) Nothing Nothing [] [] DoNotChase
    _ -> putStrLn "Not OS X, so not building an application bundle."

-- | Given a 'MacApp' in context, make an application bundle in the
-- build area.
appBundleBuildHook apps _ _ pkg localb =
  case os of
    "darwin" -> forM_ apps' $ makeAppBundle localb
      where apps' = case apps of
                      [] -> map mkDefault $ executables pkg
                      xs -> xs
            mkDefault x = MacApp (exeName x) Nothing Nothing [] [] DoNotChase
    _ -> putStrLn "Not OS X, so not building an application bundle."

-- | Given a 'MacApp' in context, make an application bundle in the
-- build area.