/
rebar.config.script
102 lines (90 loc) · 3.83 KB
/
rebar.config.script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ft=erlang ts=4 sw=4 et
%% generate a default test/t11/src/srcdir_test.hrl file so rebar can
%% compile the tests
ok = file:write_file("test/t11/src/srcdir_test.hrl",
<<"-define(SRCDIR_VERSION, \"1.0\").\n">>),
%% generate a charset include file
ok = file:write_file("src/yaws_charset.hrl",
case os:getenv("YAWS_CHARSET") of
false ->
<<"-define(YAWS_CHARSET, undefined).\n">>;
Charset ->
[<<"-define(YAWS_CHARSET, \"">>,
Charset, <<"\").\n">>]
end),
%% generate src/yaws.app.src file from src/yaws.app.src.in and
%% src/yaws_appdeps.hrl from src/yaws_appdeps.hrl.in
AppDeps = case os:getenv("YAWS_APPDEPS") of
false ->
"";
AppDeps0 ->
case string:tokens(AppDeps0, " ,") of
[] ->
"";
AppDepsList ->
","++string:join(AppDepsList, ",")
end
end,
{ok, AppBin0} = file:read_file("src/yaws.app.src.in"),
AppBin = binary:replace(AppBin0, <<"@APPDEPS@">>, list_to_binary(AppDeps)),
ok = file:write_file("src/yaws.app.src", AppBin),
{ok, AppHrl0} = file:read_file("src/yaws_appdeps.hrl.in"),
AppHrl = binary:replace(AppHrl0, <<"@APPDEPS@">>, list_to_binary(AppDeps)),
ok = file:write_file("src/yaws_appdeps.hrl", AppHrl),
SoapDeps = [{erlsom, ".*", {git, "git://github.com/willemdj/erlsom.git", {branch, "master"}}},
{xmlrpc, ".*", {git, "git://github.com/rwbr/exmlrpc.git", {branch, "master"}}}],
Cfg0 = case os:getenv("YAWS_SOAP") of
false ->
CONFIG;
_ ->
case lists:keyfind(deps, 1, CONFIG) of
{deps, Deps} ->
NDeps = Deps ++ SoapDeps,
lists:keyreplace(deps, 1, CONFIG, {deps, NDeps});
false ->
CONFIG ++ [{deps, SoapDeps}]
end
end,
ErlOpts0 = case lists:keyfind(erl_opts, 1, Cfg0) of
{erl_opts, EOpts} -> EOpts;
false -> []
end,
PortEnv0 = case lists:keyfind(port_env, 1, Cfg0) of
{port_env, PEnv} -> PEnv;
false -> []
end,
PortSpecs0 = case lists:keyfind(port_specs, 1, Cfg0) of
{port_specs, PSpecs} ->
case os:getenv("YAWS_DISABLE_PAM") of
false ->
PSpecs;
_ ->
lists:keydelete("priv/lib/epam.so", 1, PSpecs)
end;
false -> []
end,
code:ensure_loaded(file),
ErlOpts1 = case erlang:function_exported(file,sendfile,5) of
true -> ErlOpts0 ++ [{d,'HAVE_ERLANG_SENDFILE'}];
false -> ErlOpts0
end,
code:ensure_loaded(crypto),
ErlOpts2 = case erlang:function_exported(crypto,hash,2) of
true -> ErlOpts1 ++ [{d,'HAVE_CRYPTO_HASH'}];
false -> ErlOpts1
end,
HaveSendFile = lists:keymember('HAVE_SENDFILE', 3, ErlOpts2),
{PortEnv1, PortSpecs1} =
if
HaveSendFile ->
{PortEnv0 ++ [{"DRV_CFLAGS", "$DRV_CFLAGS -DHAVE_SENDFILE"}],
PortSpecs0 ++ [{"priv/lib/yaws_sendfile_drv.so",
["c_src/yaws_sendfile_drv.c", "c_src/hashtable.c"]}]};
true ->
{PortEnv0, PortSpecs0}
end,
Cfg1 = lists:keyreplace(erl_opts, 1, Cfg0, {erl_opts, ErlOpts2}),
Cfg2 = lists:keyreplace(port_env, 1, Cfg1, {port_env, PortEnv1}),
Cfg3 = lists:keyreplace(port_specs, 1, Cfg2, {port_specs, PortSpecs1}),
Cfg3.