{-# LANGUAGE DeriveGeneric #-}
module Distribution.Simple.Build.Macros.Z (render, Z(..), ZPackage (..), ZTool (..)) where
import Distribution.ZinzaPrelude
data Z
    = Z {Z -> [ZPackage]
zPackages :: ([ZPackage]),
         Z -> [ZTool]
zTools :: ([ZTool]),
         Z -> String
zPackageKey :: String,
         Z -> String
zComponentId :: String,
         Z -> Version
zPackageVersion :: Version,
         Z -> String -> Bool
zNotNull :: (String -> Bool),
         Z -> PackageName -> String
zManglePkgName :: (PackageName -> String),
         Z -> String -> String
zMangleStr :: (String -> String)}
    deriving forall x. Rep Z x -> Z
forall x. Z -> Rep Z x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Z x -> Z
$cfrom :: forall x. Z -> Rep Z x
Generic
data ZPackage
    = ZPackage {ZPackage -> PackageName
zpkgName :: PackageName,
                ZPackage -> Version
zpkgVersion :: Version,
                ZPackage -> String
zpkgX :: String,
                ZPackage -> String
zpkgY :: String,
                ZPackage -> String
zpkgZ :: String}
    deriving forall x. Rep ZPackage x -> ZPackage
forall x. ZPackage -> Rep ZPackage x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ZPackage x -> ZPackage
$cfrom :: forall x. ZPackage -> Rep ZPackage x
Generic
data ZTool
    = ZTool {ZTool -> String
ztoolName :: String,
             ZTool -> Version
ztoolVersion :: Version,
             ZTool -> String
ztoolX :: String,
             ZTool -> String
ztoolY :: String,
             ZTool -> String
ztoolZ :: String}
    deriving forall x. Rep ZTool x -> ZTool
forall x. ZTool -> Rep ZTool x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ZTool x -> ZTool
$cfrom :: forall x. ZTool -> Rep ZTool x
Generic
render :: Z -> String
render :: Z -> String
render Z
z_root = forall a. Writer a -> String
execWriter forall a b. (a -> b) -> a -> b
$ do
  String -> Writer ()
tell String
"/* DO NOT EDIT: This file is automatically generated by Cabal */\n"
  String -> Writer ()
tell String
"\n"
  forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Z -> [ZPackage]
zPackages Z
z_root) forall a b. (a -> b) -> a -> b
$ \ZPackage
z_var0_pkg -> do
    String -> Writer ()
tell String
"/* package "
    String -> Writer ()
tell (forall a. Pretty a => a -> String
prettyShow (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
"-"
    String -> Writer ()
tell (forall a. Pretty a => a -> String
prettyShow (ZPackage -> Version
zpkgVersion ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
" */\n"
    String -> Writer ()
tell String
"#ifndef VERSION_"
    String -> Writer ()
tell (Z -> PackageName -> String
zManglePkgName Z
z_root (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
"\n"
    String -> Writer ()
tell String
"#define VERSION_"
    String -> Writer ()
tell (Z -> PackageName -> String
zManglePkgName Z
z_root (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
" \""
    String -> Writer ()
tell (forall a. Pretty a => a -> String
prettyShow (ZPackage -> Version
zpkgVersion ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
"\"\n"
    String -> Writer ()
tell String
"#endif /* VERSION_"
    String -> Writer ()
tell (Z -> PackageName -> String
zManglePkgName Z
z_root (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
" */\n"
    String -> Writer ()
tell String
"#ifndef MIN_VERSION_"
    String -> Writer ()
tell (Z -> PackageName -> String
zManglePkgName Z
z_root (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
"\n"
    String -> Writer ()
tell String
"#define MIN_VERSION_"
    String -> Writer ()
tell (Z -> PackageName -> String
zManglePkgName Z
z_root (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
"(major1,major2,minor) (\\\n"
    String -> Writer ()
tell String
"  (major1) <  "
    String -> Writer ()
tell (ZPackage -> String
zpkgX ZPackage
z_var0_pkg)
    String -> Writer ()
tell String
" || \\\n"
    String -> Writer ()
tell String
"  (major1) == "
    String -> Writer ()
tell (ZPackage -> String
zpkgX ZPackage
z_var0_pkg)
    String -> Writer ()
tell String
" && (major2) <  "
    String -> Writer ()
tell (ZPackage -> String
zpkgY ZPackage
z_var0_pkg)
    String -> Writer ()
tell String
" || \\\n"
    String -> Writer ()
tell String
"  (major1) == "
    String -> Writer ()
tell (ZPackage -> String
zpkgX ZPackage
z_var0_pkg)
    String -> Writer ()
tell String
" && (major2) == "
    String -> Writer ()
tell (ZPackage -> String
zpkgY ZPackage
z_var0_pkg)
    String -> Writer ()
tell String
" && (minor) <= "
    String -> Writer ()
tell (ZPackage -> String
zpkgZ ZPackage
z_var0_pkg)
    String -> Writer ()
tell String
")\n"
    String -> Writer ()
tell String
"#endif /* MIN_VERSION_"
    String -> Writer ()
tell (Z -> PackageName -> String
zManglePkgName Z
z_root (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
" */\n"
  String -> Writer ()
tell String
"\n"
  forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Z -> [ZTool]
zTools Z
z_root) forall a b. (a -> b) -> a -> b
$ \ZTool
z_var1_tool -> do
    String -> Writer ()
tell String
"/* tool "
    String -> Writer ()
tell (ZTool -> String
ztoolName ZTool
z_var1_tool)
    String -> Writer ()
tell String
"-"
    String -> Writer ()
tell (forall a. Pretty a => a -> String
prettyShow (ZTool -> Version
ztoolVersion ZTool
z_var1_tool))
    String -> Writer ()
tell String
" */\n"
    String -> Writer ()
tell String
"#ifndef TOOL_VERSION_"
    String -> Writer ()
tell (Z -> String -> String
zMangleStr Z
z_root (ZTool -> String
ztoolName ZTool
z_var1_tool))
    String -> Writer ()
tell String
"\n"
    String -> Writer ()
tell String
"#define TOOL_VERSION_"
    String -> Writer ()
tell (Z -> String -> String
zMangleStr Z
z_root (ZTool -> String
ztoolName ZTool
z_var1_tool))
    String -> Writer ()
tell String
" \""
    String -> Writer ()
tell (forall a. Pretty a => a -> String
prettyShow (ZTool -> Version
ztoolVersion ZTool
z_var1_tool))
    String -> Writer ()
tell String
"\"\n"
    String -> Writer ()
tell String
"#endif /* TOOL_VERSION_"
    String -> Writer ()
tell (Z -> String -> String
zMangleStr Z
z_root (ZTool -> String
ztoolName ZTool
z_var1_tool))
    String -> Writer ()
tell String
" */\n"
    String -> Writer ()
tell String
"#ifndef MIN_TOOL_VERSION_"
    String -> Writer ()
tell (Z -> String -> String
zMangleStr Z
z_root (ZTool -> String
ztoolName ZTool
z_var1_tool))
    String -> Writer ()
tell String
"\n"
    String -> Writer ()
tell String
"#define MIN_TOOL_VERSION_"
    String -> Writer ()
tell (Z -> String -> String
zMangleStr Z
z_root (ZTool -> String
ztoolName ZTool
z_var1_tool))
    String -> Writer ()
tell String
"(major1,major2,minor) (\\\n"
    String -> Writer ()
tell String
"  (major1) <  "
    String -> Writer ()
tell (ZTool -> String
ztoolX ZTool
z_var1_tool)
    String -> Writer ()
tell String
" || \\\n"
    String -> Writer ()
tell String
"  (major1) == "
    String -> Writer ()
tell (ZTool -> String
ztoolX ZTool
z_var1_tool)
    String -> Writer ()
tell String
" && (major2) <  "
    String -> Writer ()
tell (ZTool -> String
ztoolY ZTool
z_var1_tool)
    String -> Writer ()
tell String
" || \\\n"
    String -> Writer ()
tell String
"  (major1) == "
    String -> Writer ()
tell (ZTool -> String
ztoolX ZTool
z_var1_tool)
    String -> Writer ()
tell String
" && (major2) == "
    String -> Writer ()
tell (ZTool -> String
ztoolY ZTool
z_var1_tool)
    String -> Writer ()
tell String
" && (minor) <= "
    String -> Writer ()
tell (ZTool -> String
ztoolZ ZTool
z_var1_tool)
    String -> Writer ()
tell String
")\n"
    String -> Writer ()
tell String
"#endif /* MIN_TOOL_VERSION_"
    String -> Writer ()
tell (Z -> String -> String
zMangleStr Z
z_root (ZTool -> String
ztoolName ZTool
z_var1_tool))
    String -> Writer ()
tell String
" */\n"
  String -> Writer ()
tell String
"\n"
  if (Z -> String -> Bool
zNotNull Z
z_root (Z -> String
zPackageKey Z
z_root))
  then do
    String -> Writer ()
tell String
"#ifndef CURRENT_PACKAGE_KEY\n"
    String -> Writer ()
tell String
"#define CURRENT_PACKAGE_KEY \""
    String -> Writer ()
tell (Z -> String
zPackageKey Z
z_root)
    String -> Writer ()
tell String
"\"\n"
    String -> Writer ()
tell String
"#endif /* CURRENT_packageKey */\n"
    forall (m :: * -> *) a. Monad m => a -> m a
return ()
  else do
    forall (m :: * -> *) a. Monad m => a -> m a
return ()
  if (Z -> String -> Bool
zNotNull Z
z_root (Z -> String
zComponentId Z
z_root))
  then do
    String -> Writer ()
tell String
"#ifndef CURRENT_COMPONENT_ID\n"
    String -> Writer ()
tell String
"#define CURRENT_COMPONENT_ID \""
    String -> Writer ()
tell (Z -> String
zComponentId Z
z_root)
    String -> Writer ()
tell String
"\"\n"
    String -> Writer ()
tell String
"#endif /* CURRENT_COMPONENT_ID */\n"
    forall (m :: * -> *) a. Monad m => a -> m a
return ()
  else do
    forall (m :: * -> *) a. Monad m => a -> m a
return ()
  String -> Writer ()
tell String
"#ifndef CURRENT_PACKAGE_VERSION\n"
  String -> Writer ()
tell String
"#define CURRENT_PACKAGE_VERSION \""
  String -> Writer ()
tell (forall a. Pretty a => a -> String
prettyShow (Z -> Version
zPackageVersion Z
z_root))
  String -> Writer ()
tell String
"\"\n"
  String -> Writer ()
tell String
"#endif /* CURRENT_PACKAGE_VERSION */\n"