{-# 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 :: FilePath -> [FilePath] -> [FilePath] -> Doc
mkRule FilePath
target [FilePath]
deps [FilePath]
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
$
[ [ FilePath -> Doc
text FilePath
target Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> [Doc] -> Doc
hsep ((FilePath -> Doc) -> [FilePath] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map FilePath -> Doc
text [FilePath]
deps) ]
, (FilePath -> Doc) -> [FilePath] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map ((Doc
"\t" Doc -> Doc -> Doc
<>) (Doc -> Doc) -> (FilePath -> Doc) -> FilePath -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. FilePath -> Doc
text) [FilePath]
recipe
, [ Doc
"" ]
]
mkVar :: String -> String -> Doc
mkVar :: FilePath -> FilePath -> Doc
mkVar FilePath
n FilePath
v = FilePath -> Doc
text FilePath
n Doc -> Doc -> Doc
<> Doc
"=" Doc -> Doc -> Doc
<> FilePath -> Doc
text FilePath
v
refVar :: String -> String
refVar :: FilePath -> FilePath
refVar FilePath
m = FilePath
"${" FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
m FilePath -> FilePath -> FilePath
forall a. [a] -> [a] -> [a]
++ FilePath
"}"
mkMakefile :: SharedOptions -> (String -> Doc) -> Backend
mkMakefile :: SharedOptions -> (FilePath -> Doc) -> Backend
mkMakefile Options{make :: SharedOptions -> Maybe FilePath
make = Just FilePath
m } FilePath -> Doc
mkContent = FilePath -> Doc -> Backend
forall c. FileContent c => FilePath -> c -> Backend
mkfile FilePath
m (FilePath -> Doc
mkContent FilePath
m)
mkMakefile Options{make :: SharedOptions -> Maybe FilePath
make = Maybe FilePath
Nothing} FilePath -> Doc
_ = () -> Backend
forall (m :: * -> *) a. Monad m => a -> m a
return ()