Support OTP<21.3

This commit is contained in:
Jordan Bracco 2020-07-09 16:21:08 +02:00
parent 4983596ab2
commit 51ecea6458
3 changed files with 26 additions and 3 deletions

View file

@ -1,15 +1,20 @@
CFLAGS = -std=c99 -g -Wall -Werror
CPPFLAGS = -I$(ERL_EI_INCLUDE_DIR)
LDFLAGS = -L$(ERL_EI_LIBDIR)
CPPFLAGS = -I$(ERL_EI_INCLUDE_DIR) -I/usr/local/include
LDFLAGS = -L$(ERL_EI_LIBDIR) -L/usr/local/lib
LDLIBS = -lpthread -lei -lm -lmagic
PRIV = priv/
RM = rm -Rf
ifeq ($(EI_INCOMPLETE),YES)
LDLIBS += -lerl_interface
CFLAGS += -DEI_INCOMPLETE
endif
all: priv/libmagic_port
priv/libmagic_port: src/libmagic_port.c
mkdir -p priv
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ $(LDLIBS) -o $@
$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $< $(LDLIBS) -o $@
clean:
$(RM) $(PRIV)

11
mix.exs
View file

@ -14,6 +14,7 @@ defmodule Majic.MixProject do
elixirc_options: [warnings_as_errors: warnings_as_errors(Mix.env())],
start_permanent: Mix.env() == :prod,
compilers: [:elixir_make] ++ Mix.compilers(),
make_env: make_env(),
package: package(),
deps: deps(),
dialyzer: dialyzer(),
@ -70,4 +71,14 @@ defmodule Majic.MixProject do
defp warnings_as_errors(:dev), do: false
defp warnings_as_errors(_), do: true
defp make_env() do
otp = :erlang.system_info(:otp_release)
|> to_string()
|> String.to_integer()
ei_incomplete = if(otp < 21.3, do: "YES", else: "NO")
%{"EI_INCOMPLETE" => ei_incomplete}
end
end

View file

@ -43,6 +43,9 @@
#include <arpa/inet.h>
#include <ei.h>
#ifdef EI_INCOMPLETE
#include <erl_interface.h>
#endif
#include <errno.h>
#include <getopt.h>
#include <libgen.h>
@ -104,7 +107,11 @@ static magic_t magic_type_name; // MAGIC_NONE
bool magic_loaded = false;
int main(int argc, char **argv) {
#ifdef EI_INCOMPLETE
erl_init(NULL, -1);
#else
EI_ENSURE(ei_init());
#endif
setup_environment();
magic_open_all();