{-# LANGUAGE OverloadedStrings #-}
module BNFC.Backend.Common.Makefile where
import Prelude hiding ((<>))
import BNFC.Options (SharedOptions(..))
import BNFC.Backend.Base (mkfile, Backend)
import BNFC.PrettyPrint
mkRule :: String
-> [String]
-> [String]
-> Doc
mkRule :: [Char] -> [[Char]] -> [[Char]] -> Doc
mkRule [Char]
target [[Char]]
deps [[Char]]
recipe = [Doc] -> Doc
vcat ([Doc] -> Doc) -> ([[Doc]] -> [Doc]) -> [[Doc]] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Doc]] -> [Doc]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([[Doc]] -> Doc) -> [[Doc]] -> Doc
forall a b. (a -> b) -> a -> b
$
[ [ [Char] -> Doc
text [Char]
target Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> [Doc] -> Doc
hsep (([Char] -> Doc) -> [[Char]] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map [Char] -> Doc
text [[Char]]
deps) ]
, ([Char] -> Doc) -> [[Char]] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((Doc
"\t" Doc -> Doc -> Doc
<>) (Doc -> Doc) -> ([Char] -> Doc) -> [Char] -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Doc
text) [[Char]]
recipe
, [ Doc
"" ]
]
mkVar :: String -> String -> Doc
mkVar :: [Char] -> [Char] -> Doc
mkVar [Char]
n [Char]
v = [Char] -> Doc
text [Char]
n Doc -> Doc -> Doc
<> Doc
"=" Doc -> Doc -> Doc
<> [Char] -> Doc
text [Char]
v
refVar :: String -> String
refVar :: [Char] -> [Char]
refVar [Char]
m = [Char]
"${" [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
m [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++ [Char]
"}"
mkMakefile :: SharedOptions -> (String -> Doc) -> Backend
mkMakefile :: SharedOptions -> ([Char] -> Doc) -> Backend
mkMakefile Options{make :: SharedOptions -> Maybe [Char]
make = Just [Char]
m } [Char] -> Doc
mkContent = [Char] -> ([Char] -> [Char]) -> Doc -> Backend
forall c.
FileContent c =>
[Char] -> ([Char] -> [Char]) -> c -> Backend
mkfile [Char]
m ([Char]
"## " [Char] -> [Char] -> [Char]
forall a. [a] -> [a] -> [a]
++) ([Char] -> Doc
mkContent [Char]
m)
mkMakefile Options{make :: SharedOptions -> Maybe [Char]
make = Maybe [Char]
Nothing} [Char] -> Doc
_ = () -> Backend
forall (m :: * -> *) a. Monad m => a -> m a
return ()