2011-01-31 16:43:31 +00:00
|
|
|
%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
|
2009-12-31 18:42:53 +00:00
|
|
|
%% ex: ts=4 sw=4 et
|
2009-11-30 23:03:45 +00:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
%%
|
|
|
|
%% rebar: Erlang Build Tools
|
|
|
|
%%
|
|
|
|
%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com)
|
|
|
|
%%
|
|
|
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
%% of this software and associated documentation files (the "Software"), to deal
|
|
|
|
%% in the Software without restriction, including without limitation the rights
|
|
|
|
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
%% copies of the Software, and to permit persons to whom the Software is
|
|
|
|
%% furnished to do so, subject to the following conditions:
|
|
|
|
%%
|
|
|
|
%% The above copyright notice and this permission notice shall be included in
|
|
|
|
%% all copies or substantial portions of the Software.
|
|
|
|
%%
|
|
|
|
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
%% THE SOFTWARE.
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
-module(rebar_port_compiler).
|
|
|
|
|
|
|
|
-export([compile/2,
|
2011-04-05 14:04:03 +00:00
|
|
|
clean/2,
|
|
|
|
setup_env/1]).
|
2009-11-30 23:03:45 +00:00
|
|
|
|
|
|
|
-include("rebar.hrl").
|
|
|
|
|
|
|
|
%% ===================================================================
|
|
|
|
%% Public API
|
|
|
|
%% ===================================================================
|
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
%% Supported configuration variables:
|
|
|
|
%%
|
2011-05-26 09:20:45 +00:00
|
|
|
%% * port_sources - Erlang list of filenames or wildcards to be compiled. May
|
|
|
|
%% also contain a tuple consisting of a regular expression to
|
|
|
|
%% be applied against the system architecture and a list of
|
|
|
|
%% filenames or wildcards to include should the expression
|
|
|
|
%% pass.
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
2011-01-28 15:08:27 +00:00
|
|
|
%% * so_specs - Erlang list of tuples of the form
|
|
|
|
%% {"priv/so_name.so", ["c_src/object_file_name.o"]}
|
|
|
|
%% useful for building multiple *.so files.
|
2010-04-28 23:27:54 +00:00
|
|
|
%%
|
2011-01-28 15:08:27 +00:00
|
|
|
%% * port_envs - Erlang list of key/value pairs which will control
|
|
|
|
%% the environment when running the compiler and linker.
|
|
|
|
%%
|
|
|
|
%% By default, the following variables
|
2009-12-01 17:38:30 +00:00
|
|
|
%% are defined:
|
|
|
|
%% CC - C compiler
|
|
|
|
%% CXX - C++ compiler
|
|
|
|
%% CFLAGS - C compiler
|
|
|
|
%% CXXFLAGS - C++ compiler
|
|
|
|
%% LDFLAGS - Link flags
|
2010-02-16 14:05:29 +00:00
|
|
|
%% ERL_CFLAGS - default -I paths for erts and ei
|
|
|
|
%% ERL_LDFLAGS - default -L and -lerl_interface -lei
|
|
|
|
%% DRV_CFLAGS - flags that will be used for compiling the driver
|
|
|
|
%% DRV_LDFLAGS - flags that will be used for linking the driver
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
2011-01-28 15:08:27 +00:00
|
|
|
%% Note that if you wish to extend (vs. replace) these variables,
|
|
|
|
%% you MUST include a shell-style reference in your definition.
|
|
|
|
%% e.g. to extend CFLAGS, do something like:
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
|
|
|
%% {port_envs, [{"CFLAGS", "$CFLAGS -MyOtherOptions"}]}
|
|
|
|
%%
|
2011-01-28 15:08:27 +00:00
|
|
|
%% It is also possible to specify platform specific options
|
|
|
|
%% by specifying a tripletwhere the first string is a regex
|
|
|
|
%% that is checked against erlang's system architecture string.
|
|
|
|
%% e.g. to specify a CFLAG that only applies to x86_64 on linux
|
|
|
|
%% do:
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
2011-01-28 15:08:27 +00:00
|
|
|
%% {port_envs, [{"x86_64.*-linux", "CFLAGS",
|
|
|
|
%% "$CFLAGS -X86Options"}]}
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
2011-01-28 15:08:27 +00:00
|
|
|
%% * port_pre_script - Tuple which specifies a pre-compilation script to run,
|
|
|
|
%% and a filename that exists as a result of the script
|
|
|
|
%% running.
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
2011-01-28 15:08:27 +00:00
|
|
|
%% * port_cleanup_script - String that specifies a script to run during cleanup.
|
|
|
|
%% Use this to remove files/directories created by
|
|
|
|
%% port_pre_script.
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
2009-11-30 23:03:45 +00:00
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
compile(Config, AppFile) ->
|
|
|
|
%% Compose list of sources from config file -- defaults to c_src/*.c
|
2011-01-28 15:08:27 +00:00
|
|
|
Sources = expand_sources(rebar_config:get_list(Config, port_sources,
|
|
|
|
["c_src/*.c"]), []),
|
2009-11-30 23:03:45 +00:00
|
|
|
case Sources of
|
|
|
|
[] ->
|
|
|
|
ok;
|
|
|
|
_ ->
|
2011-04-05 14:04:03 +00:00
|
|
|
Env = setup_env(Config),
|
2009-12-30 12:13:39 +00:00
|
|
|
|
2009-11-30 23:03:45 +00:00
|
|
|
%% Compile each of the sources
|
2011-01-28 15:08:27 +00:00
|
|
|
{NewBins, ExistingBins} = compile_each(Sources, Config, Env,
|
|
|
|
[], []),
|
2009-12-01 17:38:30 +00:00
|
|
|
|
|
|
|
%% Construct the driver name and make sure priv/ exists
|
2010-04-28 23:27:54 +00:00
|
|
|
SoSpecs = so_specs(Config, AppFile, NewBins ++ ExistingBins),
|
|
|
|
?INFO("Using specs ~p\n", [SoSpecs]),
|
2011-01-28 15:08:27 +00:00
|
|
|
lists:foreach(fun({SoName,_}) ->
|
|
|
|
ok = filelib:ensure_dir(SoName)
|
|
|
|
end, SoSpecs),
|
|
|
|
|
|
|
|
%% Only relink if necessary, given the SoName
|
|
|
|
%% and list of new binaries
|
|
|
|
lists:foreach(
|
2011-05-23 10:24:55 +00:00
|
|
|
fun({SoName,Bins}) ->
|
2011-05-23 14:26:24 +00:00
|
|
|
AllBins = [sets:from_list(Bins),
|
|
|
|
sets:from_list(NewBins)],
|
2011-05-23 10:24:55 +00:00
|
|
|
Intersection = sets:intersection(AllBins),
|
|
|
|
case needs_link(SoName, sets:to_list(Intersection)) of
|
|
|
|
true ->
|
|
|
|
rebar_utils:sh(
|
|
|
|
?FMT("$CC ~s $LDFLAGS $DRV_LDFLAGS -o ~s",
|
|
|
|
[string:join(Bins, " "), SoName]),
|
|
|
|
[{env, Env}]);
|
|
|
|
false ->
|
|
|
|
?INFO("Skipping relink of ~s\n", [SoName]),
|
|
|
|
ok
|
|
|
|
end
|
|
|
|
end, SoSpecs)
|
2009-11-30 23:03:45 +00:00
|
|
|
end.
|
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
clean(Config, AppFile) ->
|
|
|
|
%% Build a list of sources so as to derive all the bins we generated
|
2011-01-28 15:08:27 +00:00
|
|
|
Sources = expand_sources(rebar_config:get_list(Config, port_sources,
|
|
|
|
["c_src/*.c"]), []),
|
2009-12-01 17:38:30 +00:00
|
|
|
rebar_file_utils:delete_each([source_to_bin(S) || S <- Sources]),
|
|
|
|
|
|
|
|
%% Delete the .so file
|
2011-01-08 18:09:24 +00:00
|
|
|
ExtractSoName = fun({SoName, _}) -> SoName end,
|
|
|
|
rebar_file_utils:delete_each([ExtractSoName(S)
|
|
|
|
|| S <- so_specs(Config, AppFile,
|
2011-05-25 18:53:16 +00:00
|
|
|
expand_objects(Sources))]).
|
2009-12-01 17:38:30 +00:00
|
|
|
|
2011-04-05 14:04:03 +00:00
|
|
|
setup_env(Config) ->
|
|
|
|
%% Extract environment values from the config (if specified) and
|
|
|
|
%% merge with the default for this operating system. This enables
|
|
|
|
%% max flexibility for users.
|
|
|
|
DefaultEnvs = filter_envs(default_env(), []),
|
|
|
|
PortEnvs = rebar_config:get_list(Config, port_envs, []),
|
|
|
|
OverrideEnvs = filter_envs(PortEnvs, []),
|
2011-05-12 21:14:24 +00:00
|
|
|
RawEnv = apply_defaults(os_env(), DefaultEnvs) ++ OverrideEnvs,
|
2011-04-05 14:04:03 +00:00
|
|
|
expand_vars_loop(merge_each_var(RawEnv, [])).
|
2009-11-30 23:03:45 +00:00
|
|
|
|
|
|
|
%% ===================================================================
|
|
|
|
%% Internal functions
|
|
|
|
%% ===================================================================
|
|
|
|
|
|
|
|
expand_sources([], Acc) ->
|
|
|
|
Acc;
|
2011-01-10 00:29:22 +00:00
|
|
|
expand_sources([{ArchRegex, Spec} | Rest], Acc) ->
|
|
|
|
case rebar_utils:is_arch(ArchRegex) of
|
|
|
|
true ->
|
2011-05-26 09:20:45 +00:00
|
|
|
Acc2 = expand_sources(Spec, Acc),
|
2011-01-10 00:29:22 +00:00
|
|
|
expand_sources(Rest, Acc2);
|
|
|
|
false ->
|
|
|
|
expand_sources(Rest, Acc)
|
|
|
|
end;
|
2009-11-30 23:03:45 +00:00
|
|
|
expand_sources([Spec | Rest], Acc) ->
|
|
|
|
Acc2 = filelib:wildcard(Spec) ++ Acc,
|
|
|
|
expand_sources(Rest, Acc2).
|
2011-01-28 15:08:27 +00:00
|
|
|
|
2010-04-28 23:27:54 +00:00
|
|
|
expand_objects(Sources) ->
|
2010-10-25 22:38:51 +00:00
|
|
|
[filename:join([filename:dirname(F), filename:basename(F) ++ ".o"])
|
|
|
|
|| F <- Sources].
|
2009-11-30 23:03:45 +00:00
|
|
|
|
2009-12-14 13:58:22 +00:00
|
|
|
compile_each([], _Config, _Env, NewBins, ExistingBins) ->
|
2009-12-01 17:38:30 +00:00
|
|
|
{lists:reverse(NewBins), lists:reverse(ExistingBins)};
|
|
|
|
compile_each([Source | Rest], Config, Env, NewBins, ExistingBins) ->
|
2009-11-30 23:03:45 +00:00
|
|
|
Ext = filename:extension(Source),
|
|
|
|
Bin = filename:rootname(Source, Ext) ++ ".o",
|
2009-12-01 17:38:30 +00:00
|
|
|
case needs_compile(Source, Bin) of
|
|
|
|
true ->
|
|
|
|
?CONSOLE("Compiling ~s\n", [Source]),
|
|
|
|
case compiler(Ext) of
|
|
|
|
"$CC" ->
|
2010-12-05 00:07:12 +00:00
|
|
|
rebar_utils:sh(?FMT("$CC -c $CFLAGS $DRV_CFLAGS ~s -o ~s",
|
|
|
|
[Source, Bin]), [{env, Env}]);
|
2009-12-01 17:38:30 +00:00
|
|
|
"$CXX" ->
|
2010-12-05 00:07:12 +00:00
|
|
|
rebar_utils:sh(
|
2011-05-23 10:24:55 +00:00
|
|
|
?FMT("$CXX -c $CXXFLAGS $DRV_CFLAGS ~s -o ~s",
|
|
|
|
[Source, Bin]), [{env, Env}])
|
2009-12-01 17:38:30 +00:00
|
|
|
end,
|
|
|
|
compile_each(Rest, Config, Env, [Bin | NewBins], ExistingBins);
|
2009-12-30 12:13:39 +00:00
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
false ->
|
|
|
|
?INFO("Skipping ~s\n", [Source]),
|
|
|
|
compile_each(Rest, Config, Env, NewBins, [Bin | ExistingBins])
|
|
|
|
end.
|
2009-11-30 23:03:45 +00:00
|
|
|
|
|
|
|
needs_compile(Source, Bin) ->
|
2011-01-28 15:08:27 +00:00
|
|
|
%% TODO: Generate depends using gcc -MM so we can also
|
|
|
|
%% check for include changes
|
2009-11-30 23:03:45 +00:00
|
|
|
filelib:last_modified(Bin) < filelib:last_modified(Source).
|
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
needs_link(SoName, []) ->
|
|
|
|
filelib:last_modified(SoName) == 0;
|
|
|
|
needs_link(SoName, NewBins) ->
|
|
|
|
MaxLastMod = lists:max([filelib:last_modified(B) || B <- NewBins]),
|
|
|
|
case filelib:last_modified(SoName) of
|
|
|
|
0 ->
|
2009-12-16 15:27:14 +00:00
|
|
|
?DEBUG("Last mod is 0 on ~s\n", [SoName]),
|
2009-12-01 17:38:30 +00:00
|
|
|
true;
|
|
|
|
Other ->
|
2011-04-28 16:39:46 +00:00
|
|
|
?DEBUG("Checking ~p >= ~p\n", [MaxLastMod, Other]),
|
2009-12-16 15:27:14 +00:00
|
|
|
MaxLastMod >= Other
|
2009-12-01 17:38:30 +00:00
|
|
|
end.
|
2009-12-30 12:13:39 +00:00
|
|
|
|
2009-11-30 23:03:45 +00:00
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
|
|
|
%% Choose a compiler variable, based on a provided extension
|
|
|
|
%%
|
2009-11-30 23:03:45 +00:00
|
|
|
compiler(".cc") -> "$CXX";
|
|
|
|
compiler(".cp") -> "$CXX";
|
|
|
|
compiler(".cxx") -> "$CXX";
|
|
|
|
compiler(".cpp") -> "$CXX";
|
|
|
|
compiler(".CPP") -> "$CXX";
|
|
|
|
compiler(".c++") -> "$CXX";
|
|
|
|
compiler(".C") -> "$CXX";
|
|
|
|
compiler(_) -> "$CC".
|
2009-12-01 17:38:30 +00:00
|
|
|
|
2011-05-12 21:14:24 +00:00
|
|
|
%%
|
|
|
|
%% Given a list of {Key, Value} variables, and another list of default
|
|
|
|
%% {Key, Value} variables, return a merged list where the rule is if the
|
|
|
|
%% default is expandable expand it with the value of the variable list,
|
|
|
|
%% otherwise just return the value of the variable.
|
|
|
|
%%
|
|
|
|
apply_defaults(Vars, Defaults) ->
|
|
|
|
dict:to_list(
|
2011-05-23 14:26:24 +00:00
|
|
|
dict:merge(fun(Key, VarValue, DefaultValue) ->
|
|
|
|
case is_expandable(DefaultValue) of
|
2011-05-23 10:24:55 +00:00
|
|
|
true ->
|
|
|
|
expand_env_variable(DefaultValue,
|
|
|
|
Key, VarValue);
|
|
|
|
false -> VarValue
|
2011-05-23 14:26:24 +00:00
|
|
|
end
|
|
|
|
end,
|
|
|
|
dict:from_list(Vars),
|
|
|
|
dict:from_list(Defaults))).
|
|
|
|
|
2010-02-16 14:05:29 +00:00
|
|
|
%%
|
|
|
|
%% Given a list of {Key, Value} environment variables, where Key may be defined
|
|
|
|
%% multiple times, walk the list and expand each self-reference so that we
|
|
|
|
%% end with a list of each variable singly-defined.
|
|
|
|
%%
|
|
|
|
merge_each_var([], Vars) ->
|
|
|
|
Vars;
|
|
|
|
merge_each_var([{Key, Value} | Rest], Vars) ->
|
2011-05-11 22:14:25 +00:00
|
|
|
Evalue = case orddict:find(Key, Vars) of
|
|
|
|
error ->
|
|
|
|
%% Nothing yet defined for this key/value.
|
|
|
|
%% Expand any self-references as blank.
|
|
|
|
expand_env_variable(Value, Key, "");
|
|
|
|
{ok, Value0} ->
|
|
|
|
%% Use previous definition in expansion
|
|
|
|
expand_env_variable(Value, Key, Value0)
|
|
|
|
end,
|
2010-02-16 14:05:29 +00:00
|
|
|
merge_each_var(Rest, orddict:store(Key, Evalue, Vars)).
|
|
|
|
|
|
|
|
%%
|
|
|
|
%% Give a unique list of {Key, Value} environment variables, expand each one
|
|
|
|
%% for every other key until no further expansions are possible.
|
|
|
|
%%
|
|
|
|
expand_vars_loop(Vars) ->
|
|
|
|
expand_vars_loop(Vars, 10).
|
|
|
|
|
2010-02-25 18:57:02 +00:00
|
|
|
expand_vars_loop(_, 0) ->
|
2010-02-16 14:05:29 +00:00
|
|
|
?ABORT("Max. expansion reached for ENV vars!\n", []);
|
|
|
|
expand_vars_loop(Vars0, Count) ->
|
|
|
|
Vars = lists:foldl(fun({Key, Value}, Acc) ->
|
|
|
|
expand_vars(Key, Value, Acc)
|
|
|
|
end,
|
|
|
|
Vars0, Vars0),
|
|
|
|
case orddict:from_list(Vars) of
|
|
|
|
Vars0 ->
|
|
|
|
Vars0;
|
2010-02-16 18:00:14 +00:00
|
|
|
_ ->
|
2010-02-16 14:05:29 +00:00
|
|
|
expand_vars_loop(Vars, Count-1)
|
|
|
|
end.
|
|
|
|
|
|
|
|
%%
|
|
|
|
%% Expand all OTHER references to a given K/V pair
|
|
|
|
%%
|
|
|
|
expand_vars(Key, Value, Vars) ->
|
2011-01-28 15:08:27 +00:00
|
|
|
lists:foldl(
|
2011-05-23 10:24:55 +00:00
|
|
|
fun({AKey, AValue}, Acc) ->
|
|
|
|
NewValue = case AKey of
|
|
|
|
Key ->
|
|
|
|
AValue;
|
|
|
|
_ ->
|
|
|
|
expand_env_variable(AValue, Key, Value)
|
|
|
|
end,
|
|
|
|
[{AKey, NewValue} | Acc]
|
|
|
|
end,
|
|
|
|
[], Vars).
|
2010-02-16 14:05:29 +00:00
|
|
|
|
2011-05-12 21:14:24 +00:00
|
|
|
%%
|
|
|
|
%% Given a string, determine if it is expandable
|
|
|
|
%%
|
|
|
|
is_expandable(InStr) ->
|
|
|
|
case re:run(InStr,"\\\$",[{capture,none}]) of
|
|
|
|
match -> true;
|
|
|
|
nomatch -> false
|
|
|
|
end.
|
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
%%
|
|
|
|
%% Given env. variable FOO we want to expand all references to
|
|
|
|
%% it in InStr. References can have two forms: $FOO and ${FOO}
|
|
|
|
%%
|
2009-11-30 23:03:45 +00:00
|
|
|
expand_env_variable(InStr, VarName, VarValue) ->
|
|
|
|
R1 = re:replace(InStr, "\\\$" ++ VarName, VarValue),
|
2009-12-01 17:38:30 +00:00
|
|
|
re:replace(R1, "\\\${" ++ VarName ++ "}", VarValue, [{return, list}]).
|
|
|
|
|
|
|
|
|
|
|
|
%%
|
|
|
|
%% Filter a list of env vars such that only those which match the provided
|
|
|
|
%% architecture regex (or do not have a regex) are returned.
|
|
|
|
%%
|
|
|
|
filter_envs([], Acc) ->
|
|
|
|
lists:reverse(Acc);
|
|
|
|
filter_envs([{ArchRegex, Key, Value} | Rest], Acc) ->
|
|
|
|
case rebar_utils:is_arch(ArchRegex) of
|
|
|
|
true ->
|
|
|
|
filter_envs(Rest, [{Key, Value} | Acc]);
|
|
|
|
false ->
|
|
|
|
filter_envs(Rest, Acc)
|
|
|
|
end;
|
|
|
|
filter_envs([{Key, Value} | Rest], Acc) ->
|
|
|
|
filter_envs(Rest, [{Key, Value} | Acc]).
|
2009-11-30 23:03:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
erts_dir() ->
|
|
|
|
lists:concat([code:root_dir(), "/erts-", erlang:system_info(version)]).
|
|
|
|
|
2010-02-16 14:05:29 +00:00
|
|
|
os_env() ->
|
2011-01-28 15:08:27 +00:00
|
|
|
Os = [list_to_tuple(re:split(S, "=", [{return, list}, {parts, 2}])) ||
|
|
|
|
S <- os:getenv()],
|
2010-09-18 22:34:19 +00:00
|
|
|
lists:keydelete([],1,Os). %% Remove Windows current disk and path
|
2010-02-16 14:05:29 +00:00
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
default_env() ->
|
2010-04-28 15:31:38 +00:00
|
|
|
[
|
2010-07-12 14:36:11 +00:00
|
|
|
{"CC", "cc"},
|
|
|
|
{"CXX", "c++"},
|
2010-02-16 14:05:29 +00:00
|
|
|
{"ERL_CFLAGS", lists:concat([" -I", code:lib_dir(erl_interface, include),
|
2010-09-29 19:28:20 +00:00
|
|
|
" -I", filename:join(erts_dir(), "include"),
|
2010-02-16 14:05:29 +00:00
|
|
|
" "])},
|
|
|
|
{"ERL_LDFLAGS", lists:concat([" -L", code:lib_dir(erl_interface, lib),
|
|
|
|
" -lerl_interface -lei"])},
|
|
|
|
{"DRV_CFLAGS", "-g -Wall -fPIC $ERL_CFLAGS"},
|
|
|
|
{"DRV_LDFLAGS", "-shared $ERL_LDFLAGS"},
|
2011-01-28 15:08:27 +00:00
|
|
|
{"darwin", "DRV_LDFLAGS",
|
|
|
|
"-bundle -flat_namespace -undefined suppress $ERL_LDFLAGS"},
|
2011-05-31 08:52:23 +00:00
|
|
|
{"ERLANG_ARCH", rebar_utils:wordsize()},
|
2010-04-28 15:31:38 +00:00
|
|
|
{"ERLANG_TARGET", rebar_utils:get_arch()},
|
|
|
|
|
2011-05-12 21:14:24 +00:00
|
|
|
%% Solaris specific flags
|
|
|
|
{"solaris.*-64$", "CFLAGS", "-D_REENTRANT -m64 $CFLAGS"},
|
|
|
|
{"solaris.*-64$", "CXXFLAGS", "-D_REENTRANT -m64 $CXXFLAGS"},
|
|
|
|
{"solaris.*-64$", "LDFLAGS", "-m64 $LDFLAGS"},
|
2010-04-28 15:31:38 +00:00
|
|
|
|
2011-05-12 21:14:24 +00:00
|
|
|
%% OS X Leopard flags for 64-bit
|
|
|
|
{"darwin9.*-64$", "CFLAGS", "-m64 $CFLAGS"},
|
|
|
|
{"darwin9.*-64$", "CXXFLAGS", "-m64 $CXXFLAGS"},
|
|
|
|
{"darwin9.*-64$", "LDFLAGS", "-arch x86_64 $LDFLAGS"},
|
2010-04-28 15:31:38 +00:00
|
|
|
|
2011-05-12 21:14:24 +00:00
|
|
|
%% OS X Snow Leopard flags for 32-bit
|
|
|
|
{"darwin10.*-32", "CFLAGS", "-m32 $CFLAGS"},
|
|
|
|
{"darwin10.*-32", "CXXFLAGS", "-m32 $CXXFLAGS"},
|
|
|
|
{"darwin10.*-32", "LDFLAGS", "-arch i386 $LDFLAGS"}
|
2010-04-28 15:31:38 +00:00
|
|
|
].
|
2009-11-30 23:03:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2009-12-01 17:38:30 +00:00
|
|
|
source_to_bin(Source) ->
|
|
|
|
Ext = filename:extension(Source),
|
|
|
|
filename:rootname(Source, Ext) ++ ".o".
|
|
|
|
|
2010-04-28 23:27:54 +00:00
|
|
|
so_specs(Config, AppFile, Bins) ->
|
2010-09-18 22:34:19 +00:00
|
|
|
Specs = make_so_specs(Config, AppFile, Bins),
|
|
|
|
case os:type() of
|
|
|
|
{win32, nt} ->
|
|
|
|
[switch_so_to_dll(SoSpec) || SoSpec <- Specs];
|
|
|
|
_ ->
|
|
|
|
Specs
|
|
|
|
end.
|
|
|
|
|
|
|
|
switch_so_to_dll(Orig = {Name, Spec}) ->
|
|
|
|
case filename:extension(Name) of
|
|
|
|
".so" ->
|
|
|
|
{filename:rootname(Name, ".so") ++ ".dll", Spec};
|
|
|
|
_ ->
|
|
|
|
%% Not a .so; leave it
|
|
|
|
Orig
|
|
|
|
end.
|
|
|
|
|
|
|
|
make_so_specs(Config, AppFile, Bins) ->
|
2010-04-28 23:27:54 +00:00
|
|
|
case rebar_config:get(Config, so_specs, undefined) of
|
2010-05-03 16:27:00 +00:00
|
|
|
undefined ->
|
2011-01-28 15:08:27 +00:00
|
|
|
%% New form of so_specs is not provided. See if the old form
|
|
|
|
%% of {so_name} is available instead
|
2011-01-28 19:02:51 +00:00
|
|
|
Dir = "priv",
|
2010-05-03 16:27:00 +00:00
|
|
|
SoName = case rebar_config:get(Config, so_name, undefined) of
|
|
|
|
undefined ->
|
2011-01-28 15:08:27 +00:00
|
|
|
%% Ok, neither old nor new form is available. Use
|
|
|
|
%% the app name and generate a sensible default.
|
2010-05-07 18:01:48 +00:00
|
|
|
AppName = rebar_app_utils:app_name(AppFile),
|
2011-01-28 19:02:51 +00:00
|
|
|
filename:join(Dir,
|
|
|
|
lists:concat([AppName, "_drv.so"]));
|
2010-05-03 16:27:00 +00:00
|
|
|
|
|
|
|
AName ->
|
|
|
|
%% Old form is available -- use it
|
2011-01-28 19:02:51 +00:00
|
|
|
filename:join(Dir, AName)
|
2010-05-03 16:27:00 +00:00
|
|
|
end,
|
|
|
|
[{SoName, Bins}];
|
|
|
|
|
|
|
|
SoSpecs ->
|
|
|
|
SoSpecs
|
|
|
|
end.
|