mach

A work-in-progress implementation of make(1)

git clone https://git.8pit.net/mach.git

  1-- | Provides an abstraction expansion of $Makefile$ macros.
  2module Mach.Types where
  3
  4-- | Supported command line flags.
  5data Flag
  6  = EnvOverwrite
  7  | IgnoreAll
  8  | DryRun
  9  | SilentAll
 10  | ExecCont
 11  | TermOnErr
 12  | NoBuiltin
 13  | Makefile String
 14  | Jobs String
 15  deriving (Show)
 16
 17-- | A macro assignment, can either be evaluated when the macro
 18-- is assigned (immediate) or when the macro is used (delayed).
 19data MacroAssign
 20  = -- | Immediate assignment
 21    AssignI String
 22  | -- | Delayed assignment
 23    AssignD Token
 24  deriving (Show)
 25
 26-- | Tokens of text which are potentially subject to macro expansion.
 27data Token
 28  = -- | Literal, not subject to macro expansion
 29    Lit String
 30  | -- | Macro expansion
 31    Exp Token
 32  | -- | Macro expansion with suffix replacement
 33    ExpSub Token String String
 34  | -- | Sequence text
 35    Seq [Token]
 36  deriving (Show, Eq)
 37
 38-- | A macro definition, i.e. an assignment.
 39data Assign
 40  = Assign
 41      -- | Unique identifier for the macro
 42      Token
 43      -- | Assignment type
 44      Flavor
 45      -- | Right value of the assignment
 46      Token
 47  deriving (Show, Eq)
 48
 49-- | POSIX make supports different macro assignment operators (macro flavors).
 50data Flavor
 51  = -- | Assign and expand macro on use
 52    Delayed
 53  | -- | Assign and expand macro in definition line
 54    Immediate
 55  | -- | Immediately expand rvalue, but expand defined macro on use
 56    StrictDelay
 57  | -- | Shell command assignment, expanded on use
 58    System
 59  | -- | Conditional assignment, expanded on use
 60    Cond
 61  | -- | Appends text to a macro
 62    Append
 63  deriving (Eq)
 64
 65instance Show Flavor where
 66  show Delayed = "="
 67  show Immediate = "::="
 68  show StrictDelay = ":::="
 69  show System = "!="
 70  show Cond = "?="
 71  show Append = "+="
 72
 73------------------------------------------------------------------------
 74
 75-- | Makefile specification, a sequence of statements.
 76type MkFile = [MkStat]
 77
 78-- | Inference rule.
 79data InfRule
 80  = InfRule
 81      -- | Target, always begins with a period
 82      String
 83      -- | Commands (might be empty)
 84      [Token]
 85  deriving
 86    (Show, Eq)
 87
 88-- | Target rule which relates targets to commands for their creation.
 89data TgtRule
 90  = TgtRule
 91      -- | Targets (non-empty)
 92      [Token]
 93      -- | Prerequisites
 94      [Token]
 95      -- | Commands
 96      [Token]
 97  deriving
 98    (Show, Eq)
 99
100-- | A statement within a @Makefile@. Three types of statements are
101-- supported: assignments, includes, and rules.
102data MkStat
103  = MkAssign Assign
104  | MkInclude [Token]
105  | MkTgtRule TgtRule
106  | MkInfRule InfRule
107  deriving (Show, Eq)