floof/mix.exs
2022-11-23 23:06:28 +01:00

71 lines
1.8 KiB
Elixir

defmodule Floof.MixProject do
use Mix.Project
def project do
[
app: :floof,
version: "0.1.0",
elixir: "~> 1.13",
start_permanent: Mix.env() == :prod,
compilers: [:asn1] ++ Mix.compilers(),
asn1_options: [:per],
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:asn1, :asn1ct, :logger],
mod: {Floof.Application, []}
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:enacl, "~> 1.0.0"}
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
]
end
end
# source: https://github.com/processone/ejabberd/blob/441eca75b23ecc3fd2ae35655d23061fb28cdefa/mix.exs
defmodule Mix.Tasks.Compile.Asn1 do
use Mix.Task
alias Mix.Compilers.Erlang
@recursive true
@manifest ".compile.asn1"
def run(args) do
{opts, _, _} = OptionParser.parse(args, switches: [force: :boolean])
project = Mix.Project.config
source_paths = project[:asn1_paths] || ["asn1"]
dest_paths = project[:asn1_target] || ["src"]
mappings = Enum.zip(source_paths, dest_paths)
options = project[:asn1_options] || []
force = case opts[:force] do
:true -> [force: true]
_ -> [force: false]
end
Erlang.compile(manifest(), mappings, :asn1, :erl, force, fn
input, output ->
options = options ++ [:noobj, outdir: Erlang.to_erl_file(Path.dirname(output))]
case :asn1ct.compile(Erlang.to_erl_file(input), options) do
:ok -> {:ok, :done}
error -> error
end
end)
end
def manifests, do: [manifest()]
defp manifest, do: Path.join(Mix.Project.manifest_path, @manifest)
def clean, do: Erlang.clean(manifest())
end