% This file is part of Jiffy released under the MIT license.
|
|
% See the LICENSE file for more information.
|
|
%
|
|
% Only run the EQC checks when EQC is present.
|
|
|
|
HaveEQC = code:which(eqc) =/= non_existing,
|
|
|
|
ErlOpts = if not HaveEQC -> []; true ->
|
|
[{d, 'HAVE_EQC'}]
|
|
end,
|
|
|
|
Config1 = case lists:keyfind(erl_opts, 1, CONFIG) of
|
|
{erl_opts, Opts} ->
|
|
NewOpts = {erl_opts, Opts ++ ErlOpts},
|
|
lists:keyreplace(erl_opts, 1, CONFIG, NewOpts);
|
|
false ->
|
|
CONFIG ++ [{erl_opts, ErlOpts}]
|
|
end,
|
|
|
|
Config2 = case os:type() of
|
|
{unix, _} ->
|
|
CC = case os:getenv("CC") of
|
|
false -> "cc";
|
|
Else -> Else
|
|
end,
|
|
FLTO_CHECK = "echo 'int main(int argc, char *argv[]) {return 0;}' | "
|
|
++ CC ++ " -c -x c -o /dev/null -flto -",
|
|
case os:cmd(FLTO_CHECK) of
|
|
[] ->
|
|
{port_env, PortEnv} = lists:keyfind(port_env, 1, Config1),
|
|
NewFlag = {".*", "FLTO_FLAG", "-flto"},
|
|
NewPortEnv = lists:keyreplace("FLTO_FLAG", 2, PortEnv, NewFlag),
|
|
lists:keyreplace(port_env, 1, Config1, {port_env, NewPortEnv});
|
|
_ ->
|
|
Config1
|
|
end;
|
|
_ ->
|
|
Config1
|
|
end,
|
|
|
|
IsRebar3 = code:which(rebar3) /= non_existing,
|
|
OTPRel = erlang:system_info(otp_release),
|
|
OTPVsn = case re:run(OTPRel, "R?(\\d+)", [{capture, all_but_first, list}]) of
|
|
{match, [V]} -> list_to_integer(V);
|
|
nomatch -> erlang:error(unknown_otp_release)
|
|
end,
|
|
|
|
case {IsRebar3, OTPVsn} of
|
|
{false, _} ->
|
|
Config2;
|
|
{true, Vsn} when Vsn < 25 ->
|
|
Config2 ++ [
|
|
{pre_hooks, [{"", compile, "escript enc compile"}]},
|
|
{post_hooks, [{"", clean, "escript enc clean"}]}
|
|
];
|
|
{true, Vsn} when Vsn >= 25 ->
|
|
Config2 ++ [
|
|
{plugins, [{pc, "~> 1.0"}]},
|
|
{artifacts, ["priv/jiffy.so"]},
|
|
{provider_hooks, [
|
|
{post, [
|
|
{compile, {pc, compile}},
|
|
{clean, {pc, clean}}
|
|
]}
|
|
]}
|
|
]
|
|
end.
|