1+ import Lean
12import Lake
23open Lake DSL
34
45package «SDL » {
56 moreLinkArgs := #["-L.lake/build/lib" , "-lsdl2-shim" , "-lSDL2" , "-lSDL2_image" ]
6- extraDepTargets := #["sdl2-shim" ]
7+ extraDepTargets := #[Lean.Name.mkStr1 "sdl2-shim" ]
78}
89
910lean_lib «SDL » {
@@ -15,15 +16,17 @@ def ffiSrc := "sdl2-shim.c"
1516def ffiO := "sdl2-shim.o"
1617def ffiLib := "sdl2-shim"
1718
18- target ffi.o pkg : FilePath := do
19+ target ffi.o pkg : System. FilePath := do
1920 let oFile := pkg.buildDir / ffiO
20- let srcJob ← inputFile <| pkg.dir / cDir / ffiSrc
21+ let srcJob ← inputFile (text:=.true ) <| pkg.dir / cDir / ffiSrc
22+ let cflags <- captureProc { cmd := "sdl2-config" , args := #["--cflags" ]}
23+ let cflags := cflags.splitOn " "
2124 buildFileAfterDep oFile srcJob fun srcFile => do
2225 let flags := #["-I" , (← getLeanIncludeDir).toString,
2326 "-I" , (<- IO.getEnv "C_INCLUDE_PATH" ).getD "" , "-fPIC" ]
24- compileO ffiSrc oFile srcFile flags
27+ compileO oFile srcFile (cflags.toArray ++ flags)
2528
26- target «sdl2-shim » pkg : FilePath := do
29+ target «sdl2-shim » pkg : System. FilePath := do
2730 let name := nameToStaticLib ffiLib
2831 let ffiO ← fetch <| pkg.target ``ffi.o
2932 buildStaticLib (pkg.buildDir / "lib" / name) #[ffiO]
0 commit comments