{-# LANGUAGE OverloadedStrings #-}
module BNFC.Backend.Common.Makefile where
import BNFC.Prelude
import Data.String (fromString)
import Prettyprinter
mkRule :: String
-> [String]
-> String
-> Doc ()
mkRule :: String -> [String] -> String -> Doc ()
mkRule String
target [String]
dependencies String
recipe =
if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
recipe
then String -> Doc ()
forall a. IsString a => String -> a
fromString String
target Doc () -> Doc () -> Doc ()
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ()
forall ann. Doc ann
colon Doc () -> Doc () -> Doc ()
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ()] -> Doc ()
forall ann. [Doc ann] -> Doc ann
hsep (String -> Doc ()
forall a. IsString a => String -> a
fromString (String -> Doc ()) -> [String] -> [Doc ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [String]
dependencies)
else [Doc ()] -> Doc ()
forall ann. [Doc ann] -> Doc ann
vsep
[ String -> Doc ()
forall a. IsString a => String -> a
fromString String
target Doc () -> Doc () -> Doc ()
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ()
forall ann. Doc ann
colon Doc () -> Doc () -> Doc ()
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ()] -> Doc ()
forall ann. [Doc ann] -> Doc ann
hsep (String -> Doc ()
forall a. IsString a => String -> a
fromString (String -> Doc ()) -> [String] -> [Doc ()]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [String]
dependencies)
, Doc ()
"\t" Doc () -> Doc () -> Doc ()
forall a. Semigroup a => a -> a -> a
<> String -> Doc ()
forall a. IsString a => String -> a
fromString String
recipe
]
mkVar :: String -> String -> Doc ()
mkVar :: String -> String -> Doc ()
mkVar String
n String
v = String -> Doc ()
forall a. IsString a => String -> a
fromString String
n Doc () -> Doc () -> Doc ()
forall a. Semigroup a => a -> a -> a
<> Doc ()
"=" Doc () -> Doc () -> Doc ()
forall a. Semigroup a => a -> a -> a
<> String -> Doc ()
forall a. IsString a => String -> a
fromString String
v
refVar :: String -> Doc ()
refVar :: String -> Doc ()
refVar String
m = Doc ()
"${" Doc () -> Doc () -> Doc ()
forall ann. Doc ann -> Doc ann -> Doc ann
<+> String -> Doc ()
forall a. IsString a => String -> a
fromString String
m Doc () -> Doc () -> Doc ()
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ()
"}"