{-# 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. Z -> Rep Z x) -> (forall x. Rep Z x -> Z) -> Generic Z
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
$cfrom :: forall x. Z -> Rep Z x
from :: forall x. Z -> Rep Z x
$cto :: forall x. Rep Z x -> Z
to :: forall x. Rep Z x -> Z
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. ZPackage -> Rep ZPackage x)
-> (forall x. Rep ZPackage x -> ZPackage) -> Generic ZPackage
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
$cfrom :: forall x. ZPackage -> Rep ZPackage x
from :: forall x. ZPackage -> Rep ZPackage x
$cto :: forall x. Rep ZPackage x -> ZPackage
to :: forall x. Rep ZPackage x -> ZPackage
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. ZTool -> Rep ZTool x)
-> (forall x. Rep ZTool x -> ZTool) -> Generic ZTool
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
$cfrom :: forall x. ZTool -> Rep ZTool x
from :: forall x. ZTool -> Rep ZTool x
$cto :: forall x. Rep ZTool x -> ZTool
to :: forall x. Rep ZTool x -> ZTool
Generic
render :: Z -> String
render :: Z -> String
render Z
z_root = Writer () -> String
forall a. Writer a -> String
execWriter (Writer () -> String) -> Writer () -> String
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"
  [ZPackage] -> (ZPackage -> Writer ()) -> Writer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Z -> [ZPackage]
zPackages Z
z_root) ((ZPackage -> Writer ()) -> Writer ())
-> (ZPackage -> Writer ()) -> Writer ()
forall a b. (a -> b) -> a -> b
$ \ZPackage
z_var0_pkg -> do
    String -> Writer ()
tell String
"/* package "
    String -> Writer ()
tell (PackageName -> String
forall a. Pretty a => a -> String
prettyShow (ZPackage -> PackageName
zpkgName ZPackage
z_var0_pkg))
    String -> Writer ()
tell String
"-"
    String -> Writer ()
tell (Version -> String
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 (Version -> String
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"
  [ZTool] -> (ZTool -> Writer ()) -> Writer ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ (Z -> [ZTool]
zTools Z
z_root) ((ZTool -> Writer ()) -> Writer ())
-> (ZTool -> Writer ()) -> Writer ()
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 (Version -> String
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 (Version -> String
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"
    () -> Writer ()
forall a. a -> Writer a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
  else do
    () -> Writer ()
forall a. a -> Writer a
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"
    () -> Writer ()
forall a. a -> Writer a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
  else do
    () -> Writer ()
forall a. a -> Writer a
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 (Version -> String
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"