-
Notifications
You must be signed in to change notification settings - Fork 12
/
mix.exs
140 lines (122 loc) · 3.75 KB
/
mix.exs
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
defmodule Circuits.I2C.MixProject do
use Mix.Project
@version "2.0.6"
@description "Use I2C in Elixir"
@source_url "https://github.com/elixir-circuits/circuits_i2c"
def project do
[
app: :circuits_i2c,
version: @version,
elixir: "~> 1.13",
description: @description,
package: package(),
source_url: @source_url,
compilers: [:elixir_make | Mix.compilers()],
elixirc_paths: elixirc_paths(Mix.env()),
make_targets: ["all"],
make_clean: ["clean"],
docs: docs(),
aliases: [compile: [&set_make_env/1, "compile"], format: [&format_c/1, "format"]],
start_permanent: Mix.env() == :prod,
dialyzer: [
flags: [:missing_return, :extra_return, :unmatched_returns, :error_handling, :underspecs]
],
deps: deps(),
preferred_cli_env: %{
docs: :docs,
"hex.publish": :docs,
"hex.build": :docs
}
]
end
defp elixirc_paths(env) when env in [:test, :dev], do: ["lib", "examples"]
defp elixirc_paths(_env), do: ["lib"]
def application do
# IMPORTANT: This provides a default at runtime and at compile-time when
# circuits_i2c is pulled in as a dependency.
[env: [default_backend: default_backend()]]
end
defp package do
%{
files: [
"lib",
"c_src/*.[ch]",
"c_src/linux/*.h",
"c_src/compat/linux/*.h",
"mix.exs",
"README.md",
"PORTING.md",
"LICENSE",
"CHANGELOG.md",
"Makefile"
],
licenses: ["Apache-2.0"],
links: %{"GitHub" => @source_url}
}
end
defp deps() do
[
{:ex_doc, "~> 0.22", only: :docs, runtime: false},
{:credo, "~> 1.6", only: :dev, runtime: false},
{:credo_binary_patterns, "~> 0.2.2", only: :dev, runtime: false},
{:dialyxir, "~> 1.2", only: :dev, runtime: false},
{:elixir_make, "~> 0.6", runtime: false}
]
end
defp docs do
[
assets: %{"assets" => "assets"},
extras: ["README.md", "PORTING.md", "CHANGELOG.md"],
main: "readme",
source_ref: "v#{@version}",
source_url: @source_url
]
end
defp default_backend(), do: default_backend(Mix.env(), Mix.target())
defp default_backend(:test, _target), do: {Circuits.I2C.I2CDev, test: true}
defp default_backend(_env, :host) do
case :os.type() do
{:unix, :linux} -> Circuits.I2C.I2CDev
_ -> {Circuits.I2C.I2CDev, test: true}
end
end
# MIX_TARGET set to something besides host
defp default_backend(env, _not_host) do
# If CROSSCOMPILE is set, then the Makefile will use the crosscompiler and
# assume a Linux/Nerves build If not, then the NIF will be build for the
# host, so use the default host backend
case System.fetch_env("CROSSCOMPILE") do
{:ok, _} -> Circuits.I2C.I2CDev
:error -> default_backend(env, :host)
end
end
defp set_make_env(_args) do
# Since user configuration hasn't been loaded into the application
# environment when `project/1` is called, load it here for building
# the NIF.
backend = Application.get_env(:circuits_i2c, :default_backend, default_backend())
System.put_env("CIRCUITS_I2C_I2CDEV", i2c_dev_compile_mode(backend))
end
defp i2c_dev_compile_mode({Circuits.I2C.I2CDev, options}) do
if Keyword.get(options, :test) do
"test"
else
"normal"
end
end
defp i2c_dev_compile_mode(Circuits.I2C.I2CDev) do
"normal"
end
defp i2c_dev_compile_mode(_other) do
"disabled"
end
defp format_c([]) do
case System.find_executable("astyle") do
nil ->
Mix.Shell.IO.info("Install astyle to format C code.")
astyle ->
System.cmd(astyle, ["-n", "c_src/*.c"], into: IO.stream(:stdio, :line))
end
end
defp format_c(_args), do: true
end