diff options
author | Ben Sima <ben@bsima.me> | 2022-10-25 21:41:34 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2022-10-26 08:37:05 -0400 |
commit | e5fa903ab1a7a4dd86b799ad209e5b1713382025 (patch) | |
tree | 958bd0522b601d45c27fa2ac1bf1fb8484f4ebd6 /Biz/Bild.hs | |
parent | dbac7bc52f36be86ee63acee357a693ce3d1689f (diff) |
Support building with SDL
As a byproduct this also (sorta) generalizes how I pass flags to the C compiler
using pkg-config, instead of using the guile-config. Now the 'lib' metadata will
be added with 'pkg-config --libs', and the 'sys' metadata will be added with
'pkg-config --cflags'. I'm not *really* sure what the difference is, but if it
works it works.
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 89 |
1 files changed, 57 insertions, 32 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs index a5495f7..35932b5 100644 --- a/Biz/Bild.hs +++ b/Biz/Bild.hs @@ -211,6 +211,8 @@ exitSummary exits = type Dep = String +type Arg = String + data Out = Lib String | Bin String | None deriving (Show, Eq) @@ -388,32 +390,50 @@ analyze hmap ns = case Map.lookup ns hmap of Namespace.Sh -> pure Nothing Namespace.C -> do let out = detectOut (metaOut "//" <|> metaLib "//") contentLines - let sysdeps = detectSysdeps (metaSys "//") contentLines - ("guile_3_0" `elem` sysdeps) - ?. ( pure mempty, - Process.readProcess "guile-config" ["compile"] "" - /> String.words - /> (++ ["-shared", "-fPIC"]) - /> map Text.pack - ) - +> \guileFlags -> - Target - { langdeps = Set.empty, -- c has no lang deps...? - wrapper = Nothing, - compiler = Gcc, - builder = Local <| user, - compilerFlags = - concat - [ [o, dir, Text.pack absPath] ++ guileFlags - | let outable = out /= None, - o <- outable ?: (["-o"], []), - dir <- outable ?: ([Text.pack <| root </> outToPath out], []) - ], - outPath = outToPath out, - .. - } - |> Just - |> pure + let args = detectMeta (metaArg "//") contentLines + let langdeps = detectMeta (metaDep "//") contentLines + langdepFlags <- + if null langdeps + then pure [] + else + Process.readProcess + "pkg-config" + ("--cflags" : Set.toList langdeps) + "" + /> Text.pack + /> Text.words + + let sysdeps = detectMeta (metaSys "//") contentLines + sysdepFlags <- + if null sysdeps + then pure [] + else + Process.readProcess + "pkg-config" + ("--libs" : Set.toList sysdeps) + "" + /> Text.pack + /> Text.words + Target + { langdeps = Set.empty, -- c has no lang deps...? + wrapper = Nothing, + compiler = Gcc, + builder = Local <| user, + compilerFlags = + concat + [ [o, dir, Text.pack absPath] + ++ langdepFlags + ++ sysdepFlags + ++ (map Text.pack <| Set.toList args) + | let outable = out /= None, + o <- outable ?: (["-o"], []), + dir <- outable ?: ([Text.pack <| root </> outToPath out], []) + ], + outPath = outToPath out, + .. + } + |> Just + |> pure Namespace.Hs -> do langdeps <- detectHaskellImports contentLines let out = detectOut (metaOut "--") contentLines @@ -445,7 +465,7 @@ analyze hmap ns = case Map.lookup ns hmap of ], [] ), - sysdeps = detectSysdeps (metaSys "--") contentLines, + sysdeps = detectMeta (metaSys "--") contentLines, outPath = outToPath out, .. } @@ -581,7 +601,7 @@ analyze hmap ns = case Map.lookup ns hmap of |> catMaybes |> head |> fromMaybe None - detectSysdeps m cl = + detectMeta m cl = cl /> Text.unpack /> Regex.match m @@ -737,10 +757,10 @@ logs ns src = nschunk :: Namespace -> Text nschunk = Namespace.toPath .> Text.pack -metaDep :: Regex.RE Char Dep -metaDep = - Regex.string "-- : dep " - *> Regex.many (Regex.psym Char.isAlpha) +metaDep :: [Char] -> Regex.RE Char Dep +metaDep comment = + Regex.string (comment ++ " : dep ") + *> Regex.many (Regex.psym (not <. Char.isSpace)) metaSys :: [Char] -> Regex.RE Char Dep metaSys comment = @@ -759,6 +779,11 @@ metaLib comment = *> Regex.many (Regex.psym (/= ' ')) /> Lib +metaArg :: [Char] -> Regex.RE Char Arg +metaArg comment = + Regex.string (comment ++ " : arg ") + *> Regex.many Regex.anySym + haskellImports :: Regex.RE Char String haskellImports = Regex.string "import" |