-- | Defines classes and constructors for Makefile generators.
module Build.Drasil.Make.Import where

import Build.Drasil.Make.AST (Makefile(M), Rule)

-- * Classes

-- | Members can be transformed into a make rule.
class RuleTransformer c where
  makeRule :: c -> [Rule]

-- * Constructors

-- | Creates a Makefile (calls 'makeRules').
toMake :: RuleTransformer c => [c] -> Makefile
toMake :: forall c. RuleTransformer c => [c] -> Makefile
toMake = [Rule] -> Makefile
M ([Rule] -> Makefile) -> ([c] -> [Rule]) -> [c] -> Makefile
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [c] -> [Rule]
forall c. RuleTransformer c => [c] -> [Rule]
makeRules

-- | Helper for creating make rules for different document types.
makeRules :: RuleTransformer c => [c] -> [Rule]
makeRules :: forall c. RuleTransformer c => [c] -> [Rule]
makeRules = (c -> [Rule]) -> [c] -> [Rule]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap c -> [Rule]
forall c. RuleTransformer c => c -> [Rule]
makeRule