You can use location
from Language.Haskell.TH.Syntax
to extract the file name of the file being compiled, and use this to assemble the correct path:
-- | Uses 'addDependentFile' on a file relative to the current file
-- to mark it as being checked for changes when compiled with TemplateHaskell.
--
-- Returns an empty list of declarations so that it can be used with:
--
-- >$(addDependentFileRelative "MyDependency.txt")
addDependentFileRelative :: FilePath -> Q [Dec]
addDependentFileRelative relativeFile = do
currentFilename <- loc_filename <$> location
pwd <- runIO getCurrentDirectory
let invocationRelativePath = takeDirectory (pwd </> currentFilename) </> relativeFile
addDependentFile invocationRelativePath
return []
(public domain code)