on master help sign in
Merge pull request #4280 from asandroq/set-build-env-flags

Set environment with Idris flags while running `make`

commita9b30adea20cab85e61ab6b8919f86b3d7efd47d authorEdwin Brady <edwin.brady@gmail.com> dateSun 7 Jan 2018, 18:04 (9 years ago) parentbeb8e9c946c9e1
3 files changed+26−8
CHANGELOG.md+4−1 docs/reference/packages.rst+4−1 src/Idris/Package.hs+18−6
CHANGELOG.md+4−1
@@ -118,7 +118,10 @@
118118## Packaging Updates
119119
120120+ Package names now only accept a restrictive charset of letters, numbers and the `-_` characters.
121− Package names are also case insensitive
121+ Package names are also case insensitive.
122++ When building makefiles for the FFI, the environment variables
123+ `IDRIS_INCLUDES` and `IDRIS_LDFLAGS` are now set with the correct C
124+ flags.
122125
123126# New in 1.1.1
124127
docs/reference/packages.rst+4−1
@@ -91,7 +91,10 @@ external ``C`` libraries, the following options are available:
9191
9292+ ``makefile = <file>``, which specifies a ``Makefile``, to be built
9393 before the Idris modules, for example to support linking with a
94− ``C`` library.
94+ ``C`` library. When building, Idris sets the environment variables
95+ ``IDRIS_INCLUDES`` (with C include flags) and ``IDRIS_LDFLAGS``
96+ (with C linking flags) so they can be used from inside the
97+ ``Makefile``.
9598
9699+ ``libs = <libs>``, which takes a comma separated list of libraries
97100 which must be present for the package to be usable.
src/Idris/Package.hs+18−6
@@ -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.