@@ -10,6 +10,7 @@ module Idris.Package where
1010
1111import System.Directory
1212import System.Directory (copyFile, createDirectoryIfMissing)
13+import System.Environment
1314import System.Exit
1415import System.FilePath (addExtension, addTrailingPathSeparator, dropExtension,
1516 hasExtension, takeDirectory, takeExtension,
@@ -437,17 +438,28 @@ inPkgDir pkgdesc action =
437438 return res
438439
439440-- ------------------------------------------------------- [ 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 }
452+ waitForProcess r
453+ return ()
454+
455+
440456-- | Invoke a Makefile's default target.
441457make :: Maybe String -> IO ()
442−make Nothing = return ()
443−make (Just s) = do rawSystem "make" ["-f", s]
444− return ()
458+make = makeTarget Nothing
445459
446460-- | Invoke a Makefile's clean target.
447461clean :: Maybe String -> IO ()
448−clean Nothing = return ()
449−clean (Just s) = do rawSystem "make" ["-f", s, "clean"]
450− return ()
462+clean = makeTarget (Just "clean")
451463
452464-- | Merge an option list representing the command line options into
453465-- those specified for a package description.