forked from msantos/procket
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebar.config.script
80 lines (71 loc) · 1.73 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
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]},
[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,
Only = fun(OS, Name, Prog, Supported, Unsupported) ->
case os:type() of
OS ->
Test(Name, Prog, Supported, Unsupported);
_ ->
Unsupported
end
end,
Linux = fun(Name, Prog, Supported, Unsupported) ->
Only({unix,linux}, Name, Prog, Supported, Unsupported)
end,
Append = fun(Str, Flag) ->
string:join(sets:to_list(sets:add_element(Flag,
sets:from_list(string:tokens(Str, " ")))), " ")
end,
Setenv = fun(_Key, "") ->
true;
(Key, Val) ->
Cur = os:getenv(Key, ""),
os:putenv(Key, Append(Cur, Val))
end,
%%
%% Tests
%%
% Linux: support for setns(2)
Setns = fun(Config) ->
Prog = "
#define _GNU_SOURCE
#include <sched.h>
int main(int argc, char *argv[]) {
(void)setns(0,0);
return 0;
}",
case os:getenv("CROSSCOMPILE") of
false ->
Flag = Linux("test_setns.c", Prog, "-DHAVE_SETNS", ""),
true = Setenv("PROCKET_DEFINE", Flag);
_ ->
true
end,
Config
end,
lists:foldl(fun(Fun, Cfg) ->
Fun(Cfg)
end,
CONFIG,
[Setns]
).