- -- If there is no Template flag explicitly specified, try
- -- to find one by looking near the executable. This only
- -- works on Win32 or Hugs (getExecDir). On Unix, there's a wrapper
- -- script which specifies an explicit template flag.
- flags_w_tpl0 <- if any template_flag flags then
- return flags
- else
- do mb_path <- getExecDir "/bin/hsc2hs.exe"
- add_opt <-
- case mb_path of
- Nothing -> return id
- Just path -> do
- let templ = path ++ "/template-hsc.h"
- flg <- doesFileExist templ
- if flg
- then return ((Template templ):)
- else return id
- return (add_opt flags)
+ -- If there is no Template flag explicitly specified, try
+ -- to find one. We first look near the executable. This only
+ -- works on Win32 or Hugs (getExecDir). If this finds a template
+ -- file then it's certainly the one we want, even if hsc2hs isn't
+ -- installed where we told Cabal it would be installed.
+ --
+ -- Next we try the location we told Cabal about.
+ --
+ -- If neither of the above work, then hopefully we're on Unix and
+ -- there's a wrapper script which specifies an explicit template flag.
+ flags_w_tpl0 <-
+ if any template_flag flags then return flags
+ else do mb_path <- getExecDir "/bin/hsc2hs.exe"
+ mb_templ1 <-
+ case mb_path of
+ Nothing -> return Nothing
+ Just path -> do
+ -- Euch, this is horrible. Unfortunately
+ -- Paths_hsc2hs isn't too useful for a
+ -- relocatable binary, though.
+ let templ1 = path ++ "/hsc2hs-" ++ display Paths_hsc2hs.version ++ "/template-hsc.h"
+ exists1 <- doesFileExist templ1
+ if exists1
+ then return (Just templ1)
+ else return Nothing
+ case mb_templ1 of
+ Just templ1 -> return (Template templ1 : flags)
+ Nothing -> do
+ templ2 <- getDataFileName "template-hsc.h"
+ exists2 <- doesFileExist templ2
+ if exists2 then return (Template templ2 : flags)
+ else return flags