From 47e6aafa84a5c3a68dc65941c467b677277e8000 Mon Sep 17 00:00:00 2001 From: rina Date: Mon, 26 Feb 2024 16:35:43 +1000 Subject: [PATCH] more robust llvm-config usage. --- bin/dune | 2 +- llvm-disas/dune | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/bin/dune b/bin/dune index 1b7a3d0..a29b42a 100644 --- a/bin/dune +++ b/bin/dune @@ -3,6 +3,6 @@ (name main) (modules main) (libraries gtirb_semantics base64 yojson asli.libASL llvm_disas) - (flags :standard -cclib (:include ../llvm-disas/llvmconf.sexp)) + (flags :standard (:include ../llvm-disas/llvmconf.sexp)) ) diff --git a/llvm-disas/dune b/llvm-disas/dune index 99fff35..e7c737e 100644 --- a/llvm-disas/dune +++ b/llvm-disas/dune @@ -3,12 +3,23 @@ (name llvm_disas) (libraries ctypes ctypes.foreign) - (library_flags :standard -cclib (:include llvmconf.sexp)) + (library_flags :standard (:include llvmconf.sexp)) ) +; use opam's detected llvm if present, otherwise fall back to 'llvm-config' +(rule + (target llvmconf.pth) + (action (with-stdout-to %{target} + (bash "if command -v opam &>/dev/null ; then opam var conf-llvm:config ; else command -v llvm-config ; fi")))) + +; https://dune.readthedocs.io/en/latest/reference/actions/index.html (rule - (targets llvmconf.sexp) - ; use opam if present otherwise fall back to $LLVM_CONFIG - (action (bash "if command -v opam; then llvm_config=$(opam var conf-llvm:config); fi ; ${llvm_config:-$LLVM_CONFIG} --libs > llvmconf.sexp")) -) + (target llvmconf.sexp) + (action (with-stdout-to %{target} + (setenv conf "%{read:llvmconf.pth}" + (pipe-stdout + ; (bash "printf 'llvm-config: %q\n' $conf >&2") + (bash "printf -- '-cclib %s\n' $($conf --libs)") + (bash "cat ; printf -- '-ccopt %s\n' $($conf --ldflags) $($conf --cflags)") + (bash "echo '(' ; cat ; echo ')'"))))))