I have an Erlang program that can be compiled for multiple platforms.
What I want is to separate code for the different platforms. What would be the most Erlang way to go about this?
I want to achieve something like this:
-module(platform_1).
-export([platform_init/0, platform_do_work/1, platform_stop/0]).
...
-module(platform_2).
-export([platform_init/0, platform_do_work/1, platform_stop/0]).
...
-module(main).
-export([start/0]).
main() ->
platform::init(),
platform::do_work("The work"),
platform::stop().
(Obviously the above code does not work, it's missing the part I'm asking about.)
- I could name both modules
platformand provide only one of them during compilation. - I could use
-ifdefsin aplatformmodule to wrap the platform specific modules. - I could use
-behaviorto specify a common contract. - I could use a header file with
-exportmacros to provide a common contract.
I'm sure there are other solutions out there. I just didn't find any idioms out there for this general use case.