File: write_compile_flags

package info (click to toggle)
erlang-proper 1.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 932 kB
  • ctags: 2,111
  • sloc: erlang: 10,337; sh: 65; makefile: 49
file content (66 lines) | stat: -rwxr-xr-x 2,466 bytes parent folder | download
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
#!/usr/bin/env escript

%%% Copyright 2010-2015 Manolis Papadakis <manopapad@gmail.com>,
%%%                     Eirini Arvaniti <eirinibob@gmail.com>
%%%                 and Kostis Sagonas <kostis@cs.ntua.gr>
%%%
%%% This file is part of PropEr.
%%%
%%% PropEr is free software: you can redistribute it and/or modify
%%% it under the terms of the GNU General Public License as published by
%%% the Free Software Foundation, either version 3 of the License, or
%%% (at your option) any later version.
%%%
%%% PropEr is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%%% GNU General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with PropEr.  If not, see <http://www.gnu.org/licenses/>.

%%% Author:      Manolis Papadakis
%%% Description: Compilation environment setup script: This script computes and
%%%              prints out the correct set of compilation flags for the
%%%              currently running version of the OTP.

-spec main([file:filename(),...]) -> 'ok'.
main([OutFile]) ->
    CurrVer = parse_version_string(erlang:system_info(version)),
    {ok, Handle} = file:open(OutFile, [write]),
    ToDefine =
	case CurrVer < [8,0] of
	    true  -> [];
	    false -> ["AT_LEAST_19"]
	end ++
	%% older than 18.0 => erl_scan:line() type not marked deprecated
	case CurrVer < [7,0] of
	    true  -> ["USE_ERL_SCAN_LINE"];
	    false -> []
	end ++
	%% older than 17.0 => queue(), set(), etc. were built-in types
	case CurrVer < [6,0] of
	    true  -> ["NO_MODULES_IN_OPAQUES"];
	    false -> ["AT_LEAST_17"]
	end ++
	%% older than R15B => no location information in stacktraces
	case CurrVer < [5,9] of
	    true  -> ["OLD_STACKTRACE_FORMAT"];
	    false -> []
	end ++
	%% older than R13B04 => can't handle recursive type declarations
	case CurrVer < [5,7,5] of
	    true  -> ["NO_TYPES"];
	    false -> []
	end,
    lists:foreach(fun(X) -> io:format(Handle, "-define(~s, 1).~n", [X]) end,
		  ToDefine),
    ok = file:close(Handle),
    ok.

%% the stupid try-catch construct below is due to e.g. the R15A
%% release being denoted as having "5.9.pre" as version info :-(
-spec parse_version_string(string()) -> [non_neg_integer()].
parse_version_string(VerStr) ->
    [try list_to_integer(S)
     catch _:_ -> 0 end || S <- string:tokens(VerStr, ".")].