forked from rvirding/luerl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_comp_opts.escript
More file actions
48 lines (40 loc) · 1.69 KB
/
get_comp_opts.escript
File metadata and controls
48 lines (40 loc) · 1.69 KB
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
#! /usr/bin/env escript
%% -*- mode: erlang; indent-tabs-mode: nil -*-
%% Define a number of compiler options. We first work out the current
%% Erlang version and from the we can define the various options.
%% Bloody useful.
-define(IF(Test,True,False), case Test of true -> True; false -> False end).
%% Define the makefile variables HAS_MAPS and HAS_FULL_KEYS depending
%% on whether this version of erlang has maps (17) and general map
%% keys (18), or NEW_CORE_REC for new core definition of records (19).
-define(HAS_MAPS_OPT, "-DHAS_MAPS=true").
-define(FULL_KEYS_OPT, "-DHAS_FULL_KEYS=true").
-define(NEW_REC_OPT, "-DNEW_REC_CORE=true").
-define(NEW_RAND_OPT, "-DNEW_RAND=true").
main(_) ->
Version = otp_release(),
CompOpts = comp_opts(Version),
file:write_file("comp_opts.mk", "COMP_OPTS = " ++ CompOpts ++ "\n").
comp_opts(Version) ->
Copts0 = "-DERLANG_VERSION=" ++ Version,
Copts1 = ?IF(Version >= "17", Copts0 ++ " " ++ ?HAS_MAPS_OPT, Copts0),
Copts2 = ?IF(Version >= "18", Copts1 ++ " " ++ ?FULL_KEYS_OPT, Copts1),
Copts3 = ?IF(Version >= "19",
Copts2 ++ append_copts([?NEW_REC_OPT,?NEW_RAND_OPT]),
Copts2),
Copts3.
append_copts([Copt|Copts]) ->
" " ++ Copt ++ append_copts(Copts);
append_copts([]) -> [].
%% Get the major release number.
%% We have stolen the idea for this code from rebar3.
otp_release() ->
case erlang:system_info(otp_release) of
[$R,N1,N2|_] when is_integer(N1), is_integer(N2) ->
%% If OTP <= R16, take the digits.
[N1,N2];
Rel ->
%% If OTP >= 17.x, erlang:system_info(otp_release) returns just
%% the major version number.
Rel
end.