Created
January 14, 2014 09:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{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