Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/MicroCabal/Backend/MHS.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Data.List(dropWhileEnd, (\\), stripPrefix)
import Data.Maybe
import Data.Version
import System.Directory
import System.IO
import MicroCabal.Cabal
import MicroCabal.Env
import MicroCabal.Macros
Expand Down Expand Up @@ -96,6 +97,7 @@ setupStdArgs env flds = do
opts = getFieldStrings flds [] "mhs-options"
cppOpts = getFieldStrings flds [] "cpp-options"
incs = getFieldStrings flds [] "include-dirs"
lopts = getFieldStrings flds [] "extra-libraries"
exts' = filter (`elem` mhsX) (exts ++ oexts)
deps = getBuildDependsPkg flds
mhsX = ["CPP"]
Expand All @@ -107,6 +109,7 @@ setupStdArgs env flds = do
map ("-X" ++) exts' ++
map ("-I" ++) incs ++
opts ++
map ("-optl -l" ++) lopts ++
macros ++
cppOpts

Expand Down Expand Up @@ -172,21 +175,27 @@ mhsBuildLib env (Section _ _ glob) (Section _ name flds) = do
pkgfn = distDir env ++ "/" ++ namever ++ ".pkg"
cs = getFieldStrings flds [] "c-sources"
ldf = getFieldStrings flds [] "extra-libraries"
args = unwords $ map ("-optc " ++) cs ++
map ("-optl -l" ++) ldf ++
["-P" ++ namever,
"-o" ++ pkgfn] ++
stdArgs ++
["-a."] ++
mdls
cargs = map ("-optc " ++) cs
pargs = ["-P" ++ namever,
"-o" ++ pkgfn,
"-a."]
isMdl (' ':_) = True -- Relies on -L output format
isMdl _ = False
mhs env args
mhs env $ unwords (stdArgs ++ cargs ++ pargs ++ mdls)
pkgmdls <- words . unlines . filter isMdl . lines <$> mhsOut env ("-L" ++ pkgfn)
let bad = pkgmdls \\ (mdls ++ omdls)
when (not (null bad)) $ do
message env (-1) "Warning: package modules not mentioned in exposed-modules nor other-modules"
mapM_ (message env (-1)) bad
unless (null cs && null ldf) $ do
-- we are linking to some c lib so we test if the package compiles
when (verbose env > 0) $
putStrLn $ "Testing the library " ++ namever
(fn, h) <- tmpFile
hPutStr h $ unlines $ map ("import " ++) mdls ++ ["main = return ()"]
hFlush h >> hClose h
mhs env $ unwords $ stdArgs ++ cargs ++ ["-p" ++ pkgfn, "-o" ++ fn ++ ".bin", fn]
mapM_ removeFile [fn ++ ".bin", fn]

mhsInstallExe :: Env -> Section -> Section -> IO ()
mhsInstallExe env (Section _ _ _glob) (Section _ name _) = do
Expand Down
2 changes: 1 addition & 1 deletion src/MicroCabal/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ parsers =
, "other-extensions" # pVOptComma
, "other-languages" # (VItem <$> pItem)
, "other-modules" # pVOptComma
, "pkgconfig-depends" # pVComma
, "pkgconfig-depends" # pVLibs
, "virtual-modules" # pVComma
--- library fields
, "visibility" # (VItem <$> pItem)
Expand Down
1 change: 1 addition & 0 deletions src/MicroCabal/Unix.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module MicroCabal.Unix(
gitClone,
tarx,
rmrf,
tmpFile,
cp, cpr,
copyFiles,
preserveCurrentDirectory,
Expand Down
Loading