@@ -10,6 +10,7 @@ module Idris.Package where
11import System.Directory
11import System.Directory
12import System.Directory (copyFile, createDirectoryIfMissing)
12import System.Directory (copyFile, createDirectoryIfMissing)
13+import System.Environment
13import System.Exit
14import System.Exit
14import System.FilePath (addExtension, addTrailingPathSeparator, dropExtension,
15import System.FilePath (addExtension, addTrailingPathSeparator, dropExtension,
15 hasExtension, takeDirectory, takeExtension,
16 hasExtension, takeDirectory, takeExtension,
@@ -437,17 +438,28 @@ inPkgDir pkgdesc action =
437 return res
438 return res
439-- ------------------------------------------------------- [ Makefile Commands ]
440-- ------------------------------------------------------- [ Makefile Commands ]
441+-- | Invoke a Makefile's target with an enriched system environment
442+makeTarget :: Maybe String -> Maybe String -> IO ()
443+makeTarget _ Nothing = return ()
444+makeTarget mtgt (Just s) = do incFlags <- intercalate " " <$> getIncFlags
445+ libFlags <- intercalate " " <$> getLibFlags
446+ newEnv <- (++ [("IDRIS_INCLUDES", incFlags),
447+ ("IDRIS_LDFLAGS", libFlags)]) <$> getEnvironment
448+ let cmdLine = case mtgt of
449+ Nothing -> "make -f " ++ s
450+ Just tgt -> "make -f " ++ s ++ " " ++ tgt
451+ (_, _, _, r) <- createProcess (shell cmdLine) { env = Just newEnv }
440-- | Invoke a Makefile's default target.
456-- | Invoke a Makefile's default target.
441make :: Maybe String -> IO ()
457make :: Maybe String -> IO ()
442−make Nothing = return ()
458+make = makeTarget Nothing
443−make (Just s) = do rawSystem "make" ["-f", s]
446-- | Invoke a Makefile's clean target.
460-- | Invoke a Makefile's clean target.
447clean :: Maybe String -> IO ()
461clean :: Maybe String -> IO ()
448−clean Nothing = return ()
462+clean = makeTarget (Just "clean")
449−clean (Just s) = do rawSystem "make" ["-f", s, "clean"]
452-- | Merge an option list representing the command line options into
464-- | Merge an option list representing the command line options into
453-- those specified for a package description.
465-- those specified for a package description.