(rule
 (targets perf_dlfilter.ml)
 (deps
  (:dep perf_dlfilter.c))
 (action
  (progn
   (run mkdir -p dlfilter)
   (run %{bin:gcc} -c -fpic %{dep})
   (run %{bin:gcc} -shared -o dlfilter/perf_dlfilter.so perf_dlfilter.o)
   (run %{bin:ocaml-crunch} -m plain dlfilter -o perf_dlfilter.ml))))

(rule
 (target libLLVM.a)
 (deps llvm_symbolizer_stubs.cpp)
 (action
  (progn
   (bash
    "clang++ -Wall -Wextra -Werror -Wno-unused-parameter -DCAML_NAME_SPACE -I %{ocaml_where} $(llvm-config --cxxflags) -std=c++20 -O3 -march=broadwell -mtune=skylake -ffunction-sections -c llvm_symbolizer_stubs.cpp")
   (bash
    "ld.lld llvm_symbolizer_stubs.o --gc-sections -static -r -plugin-opt=mcpu=broadwell -plugin-opt=O3 --hash-style=gnu --build-id --start-lib $(llvm-config --link-static --libfiles Symbolize) --end-lib -o libLLVM.o")
   (run llvm-strip --strip-debug libLLVM.o)
   (run llvm-ar Drcs %{target} libLLVM.o))))

(library
 (name magic_trace_lib)
 (public_name magic-trace.magic_trace_lib)
 (no_dynlink)
 (flags
  (:standard -cclib -lstdc++))
 (foreign_archives LLVM)
 (foreign_stubs
  (language c)
  (names breakpoint_stubs boot_time_stubs ptrace_stubs))
 (libraries
  core
  async
  core_unix.filename_unix
  fzf
  re
  shell
  core_unix.sys_unix
  cohttp
  cohttp_static_handler
  core_unix.signal_unix
  tracing
  magic_trace
  owee
  angstrom
  expect_test_helpers_core
  vec)
 (inline_tests)
 (preprocess
  (pps ppx_jane)))
