compilationerlangrebar

Skip port compilation for certain OS?


I have a Rebar-based Erlang application that builds a port program. This port program is Linux-specific, so compilation fails on Mac OS. However, I'd like Rebar to just skip the port program when building on Mac OS. How can I do that?

The current spec in rebar.config looks like this:

{port_specs, [{"priv/my_port", ["c_src/foo.c", "c_src/bar.c"]}]}.

Solution

  • As documented in comments in rebar_port_compiler.erl, the list elements for port_specs have an alternative form {ArchRegex, TargetFile, Sources}. So write your Rebar configuration like this:

    {port_specs, [{"linux", "priv/my_port", ["c_src/foo.c", "c_src/bar.c"]}]}.
    

    "What is that regex matched against?", you might ask. It is matched against the return value of rebar_utils:get_arch, which consists of the following parts, separated by hyphens:

    So the end result will be something like "R15B01-i386-apple-darwin10.8.0-32-unix" or "R15B02-x86_64-unknown-linux-gnu-64-unix".