diff --git a/.gitignore b/.gitignore index 560aff8b..c9527a91 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,8 @@ auth_secret.exs # Farmbot argifacts tmp/ test_tmp/ +priv/build_calendar.so +*.o # Generated on crash by the VM erl_crash.dump @@ -29,7 +31,6 @@ erl_crash.dump # From other branches /cache *.js -Makefile /release-* node_modules diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..867827ab --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +ifeq ($(ERTS_DIR),) +ERTS_DIR = $(shell erl -eval "io:format(\"~s/erts-~s~n\", [code:root_dir(), erlang:system_info(version)])" -s init stop -noshell) +ifeq ($(ERTS_DIR),) + $(error Could not find the Erlang installation. Check to see that 'erl' is in your PATH) +endif +endif + +CFLAGS = -fPIC -Wl,-undefined -Wl,dynamic_lookup -shared +ERL_FLAGS = -I$(ERTS_DIR)/include +CC ?= $(CROSSCOMPILER)cc + +all: + $(CC) $(ERL_FLAGS) $(CFLAGS) -o priv/build_calendar.so c_src/build_calendar.c + +clean: + $(RM) build_calendar.* priv/build_calendar.* diff --git a/c_src/build_calendar.c b/c_src/build_calendar.c index df8b9f45..222f82ba 100644 --- a/c_src/build_calendar.c +++ b/c_src/build_calendar.c @@ -5,7 +5,7 @@ #include -#define MAX_GENERATED 1000 +#define MAX_GENERATED 60 static ERL_NIF_TERM do_build_calendar(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[]) { @@ -40,17 +40,17 @@ static ERL_NIF_TERM do_build_calendar(ErlNifEnv* env, int argc, const ERL_NIF_TE // if this event (i) is after the grace period, add it to the array. if(i > gracePeriodSeconds) { events[j] = i; - events[j] -= (events[j] % MAX_GENERATED); + events[j] -= (events[j] % 60); j++; } } // Count up our total generated events - for(i = 0, j=0; j 0) { i++; } } + for(i=0, j=0; j 0) { i++; } } // Build the array to be returned. ERL_NIF_TERM retArr [i]; - for(j=0; j :ok + {:error, {:reload, _}} -> :ok + {:error, reason} -> Logger.warn "Failed to load nif: #{inspect reason}" + end end alias Farmbot.Repo.JSONType diff --git a/mix.exs b/mix.exs index 82c2e009..100b0181 100644 --- a/mix.exs +++ b/mix.exs @@ -23,6 +23,8 @@ defmodule Farmbot.Mixfile do app: :farmbot, description: "The Brains of the Farmbot Project", package: package(), + compilers: [:elixir_make] ++ Mix.compilers, + make_clean: ["clean"], test_coverage: [tool: ExCoveralls], version: @version, target: @target, @@ -76,6 +78,7 @@ defmodule Farmbot.Mixfile do defp deps do [ {:nerves, "~> 0.8.3", runtime: false}, + {:elixir_make, "~> 0.4", runtime: false}, {:gen_stage, "~> 0.12"}, {:poison, "~> 3.0"}, {:ex_json_schema, "~> 0.5.3"},