on master help sign in
Merge pull request #4280 from asandroq/set-build-env-flags
a9b30adEdwin Brady
CHANGELOG.md+4−1
@@ -118,7 +118,10 @@
118## Packaging Updates
118## Packaging Updates
119
119
120+ Package names now only accept a restrictive charset of letters, numbers and the `-_` characters.
120+ 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.
122
125
123# New in 1.1.1
126# New in 1.1.1
124
127
docs/reference/packages.rst+4−1
@@ -91,7 +91,10 @@ external ``C`` libraries, the following options are available:
91
91
92+ ``makefile = <file>``, which specifies a ``Makefile``, to be built
92+ ``makefile = <file>``, which specifies a ``Makefile``, to be built
93 before the Idris modules, for example to support linking with a
93 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``.
95
98
96+ ``libs = <libs>``, which takes a comma separated list of libraries
99+ ``libs = <libs>``, which takes a comma separated list of libraries
97 which must be present for the package to be usable.
100 which must be present for the package to be usable.
src/Idris/Package.hs+18−6
@@ -10,6 +10,7 @@ module Idris.Package where
10
10
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
438
439
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 }
452+ waitForProcess r
453+ return ()
454+
455+
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]
444− return ()
445
459
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"]
450− return ()
451
463
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.