Search through a list of compilers to compile the NIF
This commit is contained in:
24
mix.exs
24
mix.exs
@@ -8,6 +8,9 @@ defmodule Mix.Tasks.Compile.Nif do
|
|||||||
paths = Keyword.fetch!(config, :paths)
|
paths = Keyword.fetch!(config, :paths)
|
||||||
flags = Keyword.fetch!(config, :flags)
|
flags = Keyword.fetch!(config, :flags)
|
||||||
exts = Keyword.fetch!(config, :exts)
|
exts = Keyword.fetch!(config, :exts)
|
||||||
|
compiler =
|
||||||
|
Keyword.get(config, :compilers, ["cc", "gcc", "clang"])
|
||||||
|
|> find_compiler
|
||||||
|
|
||||||
# Create the directory (e.g. "priv/")
|
# Create the directory (e.g. "priv/")
|
||||||
file |> Path.dirname |> File.mkdir_p!
|
file |> Path.dirname |> File.mkdir_p!
|
||||||
@@ -15,16 +18,29 @@ defmodule Mix.Tasks.Compile.Nif do
|
|||||||
# Figure out whether we should compile the NIF. Compare the source
|
# Figure out whether we should compile the NIF. Compare the source
|
||||||
# files with the target binary. If the target is newer, recompile.
|
# files with the target binary. If the target is newer, recompile.
|
||||||
to_compile = Mix.Utils.extract_files(paths, exts)
|
to_compile = Mix.Utils.extract_files(paths, exts)
|
||||||
stale = Mix.Utils.extract_stale(to_compile, [file])
|
|
||||||
case stale do
|
case Mix.Utils.extract_stale(to_compile, [file]) do
|
||||||
[] ->
|
[] ->
|
||||||
:noop
|
:noop
|
||||||
_ ->
|
_ ->
|
||||||
filesarg = Enum.join(to_compile, " ")
|
cmd =
|
||||||
cmd = "gcc -shared -fpic -o #{file} #{filesarg} #{flags}"
|
[compiler, "-shared", "-fpic", "-o #{file}", to_compile, flags]
|
||||||
|
|> List.flatten
|
||||||
|
|> Enum.join(" ")
|
||||||
|
|
||||||
IO.puts System.cmd(cmd)
|
IO.puts System.cmd(cmd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp find_compiler([compiler | tail]) do
|
||||||
|
case System.find_executable(compiler) do
|
||||||
|
nil ->
|
||||||
|
find_compiler(tail)
|
||||||
|
path ->
|
||||||
|
path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defmodule Geef.Mixfile do
|
defmodule Geef.Mixfile do
|
||||||
|
|||||||
Reference in New Issue
Block a user