{-# LANGUAGE PatternGuards #-}

module Distribution.Franchise.AutoHeader ( autoHeader ) where

import Distribution.Franchise.SplitFile
import Distribution.Franchise.Buildable
import Distribution.Franchise.ConfigureState

-- |This is the split function for @splitFile@.  We need to provide the output filename
-- explicitly since it's not in the file, and we also need to provide the list of all
-- definitions since it's a pure function.
ahSplit :: FilePath -> [(String,String)] -> String -> [(FilePath,String)]
ahSplit outfile subs content = [(outfile,unlines $ map repl $ lines content)]
    where repl s | ("#undef ",ss) <- splitAt 7 s
                 , Just v <- lookup ss subs = "#define " ++ ss ++ if null v then ""
                                                                            else " " ++ v
                 | otherwise = s

autoHeader :: FilePath -> FilePath -> C ()
autoHeader target src = do defs <- getDefinitions
                           splitFile src (ahSplit target defs)
                           return ()

{-# LANGUAGE PatternGuards #-}

module Distribution.Franchise.AutoHeader ( autoHeader ) where

import Distribution.Franchise.SplitFile
import Distribution.Franchise.Buildable
import Distribution.Franchise.ConfigureState

-- |This is the split function for @splitFile@.  We need to provide the output filename
-- explicitly since it's not in the file, and we also need to provide the list of all
-- definitions since it's a pure function.
ahSplit :: FilePath -> [(String,String)] -> String -> [(FilePath,String)]
ahSplit outfile subs content = [(outfile,unlines $ map repl $ lines content)]
    where repl s | ("#undef ",ss) <- splitAt 7 s
                 , Just v <- lookup ss subs = "#define " ++ ss ++ if null v then ""
                                                                            else " " ++ v
                 | otherwise = s

autoHeader :: FilePath -> C ()
autoHeader target = do defs <- getDefinitions
                       splitFile (target++".in") (ahSplit target defs)
                       return ()

Fix autoHeader API to only take target Ignore-this: b09fc568db849aed6d200f8c7fdd4b1b
Fix autoHeader API to only take target
Ignore-this: b09fc568db849aed6d200f8c7fdd4b1b
