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