Questions about static linking have come up in the past. What is the current best practice to support that conditionally on Linux but not other platforms? The easiest way to link a binary statically is to add
(link_flags (:standard -cclib -static))
to an executable stanza. Is it possible to add this conditionally? Or is it better to organise this in some profile?
You could use a different variable or combination of variables instead of %{os_type} depending on what you want to take into consideration for choosing your flags (system, compiler, etc).
Yes, the difficulty in differentiating between Linux and macOS is a long standing issue.
The more general solution is to write a small script (eg in OCaml) that outputs the right links flags for the current system:
For anyone interested in the detection part of this, Revery has some code to detect the host OS which I’ve also used in OCaml syntax. It’s worked for me on Linux, macOS and Windows.
#!/bin/sh
# https://discuss.ocaml.org/t/dune-how-to-link-statically-on-linux-not-on-others/8537/4?u=mro
case "$(uname -s)" in
Darwin)
# do not link statically on macos.
echo '()'
;;
*)
echo '(-ccopt "-static")'
;;
esac
had postponed that ever since and resolved now, thanks @lindig, @nojb