{-# LANGUAGE GADTs #-}
{-# LANGUAGE TypeOperators #-}

module Types where

import qualified Data.Set as Set

type Set = Set.Set

-- | Data Definitions

--------------------------------------------------------------------------------

-- | Name of source file
type SourceFile = String

-- | Name of target file
type TargetFile = String

-- | Either source xor target
type BuildFile = String

type Command = String

data MakeFile where
  MakeFile ::
    { MakeFile -> Set SourceFile
sourceFiles :: Set SourceFile,
      MakeFile -> MakeRule
defaultGoal :: MakeRule,
      MakeFile -> Set MakeRule
allrules :: Set MakeRule
    } ->
    MakeFile
  deriving (Int -> MakeFile -> ShowS
[MakeFile] -> ShowS
MakeFile -> SourceFile
(Int -> MakeFile -> ShowS)
-> (MakeFile -> SourceFile)
-> ([MakeFile] -> ShowS)
-> Show MakeFile
forall a.
(Int -> a -> ShowS)
-> (a -> SourceFile) -> ([a] -> ShowS) -> Show a
showList :: [MakeFile] -> ShowS
$cshowList :: [MakeFile] -> ShowS
show :: MakeFile -> SourceFile
$cshow :: MakeFile -> SourceFile
showsPrec :: Int -> MakeFile -> ShowS
$cshowsPrec :: Int -> MakeFile -> ShowS
Show)

data MakeRule where
  MakeRule :: TargetFile -> Set BuildFile -> Command -> MakeRule
  deriving (MakeRule -> MakeRule -> Bool
(MakeRule -> MakeRule -> Bool)
-> (MakeRule -> MakeRule -> Bool) -> Eq MakeRule
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MakeRule -> MakeRule -> Bool
$c/= :: MakeRule -> MakeRule -> Bool
== :: MakeRule -> MakeRule -> Bool
$c== :: MakeRule -> MakeRule -> Bool
Eq, Eq MakeRule
Eq MakeRule
-> (MakeRule -> MakeRule -> Ordering)
-> (MakeRule -> MakeRule -> Bool)
-> (MakeRule -> MakeRule -> Bool)
-> (MakeRule -> MakeRule -> Bool)
-> (MakeRule -> MakeRule -> Bool)
-> (MakeRule -> MakeRule -> MakeRule)
-> (MakeRule -> MakeRule -> MakeRule)
-> Ord MakeRule
MakeRule -> MakeRule -> Bool
MakeRule -> MakeRule -> Ordering
MakeRule -> MakeRule -> MakeRule
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: MakeRule -> MakeRule -> MakeRule
$cmin :: MakeRule -> MakeRule -> MakeRule
max :: MakeRule -> MakeRule -> MakeRule
$cmax :: MakeRule -> MakeRule -> MakeRule
>= :: MakeRule -> MakeRule -> Bool
$c>= :: MakeRule -> MakeRule -> Bool
> :: MakeRule -> MakeRule -> Bool
$c> :: MakeRule -> MakeRule -> Bool
<= :: MakeRule -> MakeRule -> Bool
$c<= :: MakeRule -> MakeRule -> Bool
< :: MakeRule -> MakeRule -> Bool
$c< :: MakeRule -> MakeRule -> Bool
compare :: MakeRule -> MakeRule -> Ordering
$ccompare :: MakeRule -> MakeRule -> Ordering
$cp1Ord :: Eq MakeRule
Ord, Int -> MakeRule -> ShowS
[MakeRule] -> ShowS
MakeRule -> SourceFile
(Int -> MakeRule -> ShowS)
-> (MakeRule -> SourceFile)
-> ([MakeRule] -> ShowS)
-> Show MakeRule
forall a.
(Int -> a -> ShowS)
-> (a -> SourceFile) -> ([a] -> ShowS) -> Show a
showList :: [MakeRule] -> ShowS
$cshowList :: [MakeRule] -> ShowS
show :: MakeRule -> SourceFile
$cshow :: MakeRule -> SourceFile
showsPrec :: Int -> MakeRule -> ShowS
$cshowsPrec :: Int -> MakeRule -> ShowS
Show)

-- Makefile error type
newtype MFError = MFError String

-- | Accessors

--------------------------------------------------------------------------------
mkRuleTarNm :: MakeRule -> String
mkRuleTarNm :: MakeRule -> SourceFile
mkRuleTarNm (MakeRule SourceFile
tf Set SourceFile
_ SourceFile
_) = SourceFile
tf