@@ -3,14 +3,12 @@
33> module Main ( main ) where
44>
55> import Data.Char
6+> import Data.Maybe
67> import Distribution.PackageDescription
78> import Distribution.Simple
8−> import Distribution.Simple.BuildPaths
99> import Distribution.Simple.LocalBuildInfo
1010> import Distribution.Simple.Program
1111> import Distribution.Simple.Setup
12−> import System.Directory ( createDirectoryIfMissing )
13−> import System.FilePath
1412>
1513> main :: IO ()
1614> main = defaultMainWithHooks simpleUserHooks
@@ -23,23 +21,20 @@
2321>
2422> configure :: (GenericPackageDescription, HookedBuildInfo) -> ConfigFlags -> IO LocalBuildInfo
2523> configure (gpd, hbi) flags = do
26−> lbi <- confHook simpleUserHooks (gpd, hbi) flags
24+> lbi' <- confHook simpleUserHooks (gpd, hbi) flags
2725> let paths = [ (p, programPath pc) | p <- programs, Just pc <- [lookupProgram (simpleProgram p) (withPrograms lbi)] ]
28−> dirPath = autogenModulesDir lbi </> "Nix"
29−> createDirectoryIfMissing True dirPath
30−> writeFile (dirPath </> "Paths.hs") $
31−> unlines $
32−> "module Nix.Paths where\n" : map (uncurry fmtPath) paths
26+> descr = localPkgDescr lbi'
27+> lib = fromJust (library descr)
28+> libbi = libBuildInfo lib
29+> lbi = lbi' { localPkgDescr = descr
30+> { library = Just (lib { libBuildInfo = libbi { cppOptions = cppOptions libbi ++ map fmtCppArg paths } })
31+> }
32+> }
3333> return lbi
3434>
35−> fmtPath :: String -> FilePath -> String
36−> fmtPath name path = unlines
37−> [ "-- | Complete path to the @" ++ name ++ "@ executable."
38−> , mangle name ++ " :: FilePath"
39−> , mangle name ++ " = " ++ show path
40−> ]
41−>
42−> mangle :: String -> String
43−> mangle [] = []
44−> mangle ('-':c:cs) = toUpper c : mangle cs
45−> mangle (c:cs) = c : mangle cs
35+> fmtCppArg :: (String, FilePath) -> String
36+> fmtCppArg (prg, path) = "-DPATH_TO_" ++ map mangle prg ++ "=" ++ show path
37+> where
38+> mangle :: Char -> Char
39+> mangle '-' = '_'
40+> mangle c = toUpper c