summaryrefslogtreecommitdiff
path: root/lakefile.lean
blob: 660403d228ea705deb7e1e84dd529b86ba91836c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import Lean
import Lake
open Lake DSL

def evalPkgConfig (args : Array String) : IO (Array String) := do
  let res ← IO.Process.output { cmd := "pkg-config", args := args }
  if res.exitCode != 0 then
    throw <| IO.userError s!"pkg-config failed: {res.stderr}"
  return res.stdout.split Char.isWhitespace
    |>.map (String.Slice.toString)
    |>.filter (· != "")
    |>.toArray

package «CWayland» {
  moreLinkArgs := #["-L.lake/build/lib", "-lLibCWayland"] ++ (run_io evalPkgConfig #["--libs", "wayland-client"]).filter (· != "-lm")
  extraDepTargets := #[Lean.Name.mkStr1 "LibCWayland"]
}

target «LibCWayland.o» pkg : System.FilePath := do
  let objectFile := pkg.buildDir / "LibCWayland.o"
  let srcJob ← inputFile (text := .true) <| pkg.dir / "lib" / "CWayland" / "CWayland.cc"
  let cFlags ← evalPkgConfig #["--cflags", "wayland-client"]
  buildFileAfterDep objectFile srcJob (fun srcFile ↦ do
    let cFlags := cFlags ++ #["-I", (← getLeanIncludeDir).toString, "-I", (← IO.getEnv "C_INCLUDE_PATH").getD "", "-fPIC"]
    compileO objectFile srcFile cFlags)

target «LibCWayland» pkg : System.FilePath := do
  let name := nameToStaticLib "LibCWayland"
  let objectFile ← fetch <| pkg.target (Lean.Name.mkStr1 "LibCWayland.o")
  buildStaticLib (pkg.buildDir / "lib" / name) #[objectFile]

lean_lib «Wayland» {
  srcDir := "lib"
  roots := #[`Wayland]
}

lean_exe «Waylean» {
  srcDir := "src"
  root := `Waylean
}