mix.exs

defmodule Mix.Tasks.Compile.NetcdfNif do
  def run(_args) do
    {result, _errcode} = System.cmd("gcc",
      [ "-O3",
        "-fpic",
        "-shared",
        "-lnetcdf",
        "-DELIXIR_MODULE",
        "-I#{System.get_env("ERL_INCLUDE")}",
        "-o", "priv/netcdf_nif_ex.so",
        "c_src/netcdf_nif.c"
      ], stderr_to_stdout: true)
    IO.puts(result)
  end
end

defmodule NetcdfNif.Mixfile do
  use Mix.Project

  def project do
    [
      app: :netcdf_nif,
      version: "0.1.0",
      elixir: "~> 1.5",
      start_permanent: Mix.env == :prod,
      deps: deps(),
      package: package(),
      compilers: [:netcdf_nif] ++ Mix.compilers,
      description: description(),
    ]
  end

  defp description do
    """
    A simple Erlang/Elixir NIF wrapper for the NetCDF C library
    """
  end

  defp package do
    [
      name: :netcdf_nif,
      files: ["c_src", "lib", "mix.exs", "rebar.config", "src"],
      maintainers: ["Przemysław Kamiński"],
      licenses: ["MIT"],
      links: %{"Sourcehut" => "https://git.sr.ht/~cgenie/netcdf_nif"},
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      {:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
    ]
  end
end