-
Notifications
You must be signed in to change notification settings - Fork 56
/
rebar.config.script
76 lines (67 loc) · 2.57 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
TMPDIR = os:getenv("TMPDIR", "/tmp"),
Compile = fun(Name0, Prog) ->
Name = filename:join(TMPDIR, Name0),
ok = file:write_file(Name, Prog, [write, exclusive]),
Cmd = erlang:open_port({spawn, ["${CC-cc} -o /dev/null ", Name, " -lpcap"]},
[stream, exit_status]),
Status = receive
{Cmd, {exit_status, 0}} ->
true;
{Cmd, {exit_status, _}} ->
false
end,
ok = file:delete(Name),
Status
end,
Test = fun(Name, Prog, Supported, Unsupported) ->
case Compile(Name, Prog) of
true ->
Supported;
false ->
Unsupported
end
end,
Append = fun(Str, Flag) ->
string:join(sets:to_list(sets:add_element(Flag,
sets:from_list(string:tokens(Str, " ")))), " ")
end,
Setenv = fun(Key, Val) ->
Cur = os:getenv(Key, ""),
os:putenv(Key, Append(Cur, Val))
end,
%%
%% Tests
%%
PFRING = fun(Config) -> case os:getenv("PFRING") of
false ->
ok;
Value ->
case filelib:is_dir(Value) of
true ->
LDFLAGS = os:getenv("EPCAP_LDFLAGS", ""),
true = Setenv("EPCAP_LDFLAGS", "-L" ++ Value);
_ ->
ok
end
end,
Config
end,
Pcap_create = fun(Config) ->
Check = "
#include <pcap.h>
int main(int argc, char *argv[])
{
char errbuf[PCAP_ERRBUF_SIZE];
(void)pcap_create(NULL, errbuf);
return 0;
}",
Flag = Test("test_pcap_create.c", Check, "-DHAVE_PCAP_CREATE", ""),
true = Setenv("EPCAP_DEFINE", Flag),
Config
end,
lists:foldl(fun(Fun, Cfg) ->
Fun(Cfg)
end,
CONFIG,
[PFRING, Pcap_create]
).