Skip to content

Instantly share code, notes, and snippets.

@drobakowski
Created January 14, 2014 09:25
Show Gist options
  • Save drobakowski/8415575 to your computer and use it in GitHub Desktop.
Save drobakowski/8415575 to your computer and use it in GitHub Desktop.
Rebar config script to set compiler directives. In this example the directive "have_callback_support" will be set as long as an Erlang release with version 15 or higher is available.
-module(module_with_compiler_directive).
-ifdef(have_callback_support).
-callback start_link(Args) -> {ok, Pid} |
{error, {already_started, Pid}} |
{error, Reason} when
Args :: proplists:proplist(),
Pid :: pid(),
Reason :: term().
-else.
-export([behaviour_info/1]).
behaviour_info(callbacks) ->
[{start_link, 1}];
behaviour_info(_Other) ->
undefined.
-endif.
{match, [ErtsNumber]} = re:run(erlang:system_info(otp_release), "R(\\d+).+", [{capture, [1], list}]),
ErtsVsn = erlang:list_to_integer(ErtsNumber),
if
ErtsVsn >= 15 ->
OldOpts = proplists:get_value(erl_opts, CONFIG, []),
NewOpts = [{d, have_callback_support} | OldOpts],
lists:keystore(erl_opts, 1, CONFIG, {erl_opts, NewOpts});
true ->
CONFIG
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment