Skip to content

Commit

Permalink
Update to OTP24/25/26 and rebar3
Browse files Browse the repository at this point in the history
  $ ./rebar3 version
  rebar 3.24.0+build.5424.ref7da4837b on Erlang/OTP 26 Erts 14.2.5
  • Loading branch information
andriytk committed Sep 3, 2024
1 parent 84ddeeb commit 4e253c0
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 23 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
*~
*.swp

# Rebar / Erlang Folders
deps/
ebin/
# Rebar / Erlang folders and files
priv/
blocks/
_build/
rebar.lock

# Testing
*.dec
Expand All @@ -51,7 +51,6 @@ blocks/
erl_crash.dump
rel/example_project
.concrete/DEV_MODE
.rebar

c_src/gf-complete
c_src/jerasure
Expand Down
11 changes: 4 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
.PHONY: deps test

REBAR := ./rebar
REBAR := ./rebar3

all:
@$(REBAR) update-deps
@$(REBAR) get-deps
@$(REBAR) compile
@$(REBAR) xref skip_deps=true
@$(REBAR) eunit skip_deps=true
Expand All @@ -20,9 +18,8 @@ doc: compile
@$(REBAR) doc
clean:
@$(REBAR) clean skip_deps=true
rm -rf c_src/isa-l
rm -rf c_src/gf-complete
rm -rf c_src/jerasure
@rm -rf c_src/*.o
distclean:
@$(REBAR) delete-deps
@$(REBAR) clean
@rm -rf c_src/*.o
@rm -rf _build/ priv/ blocks/ .eunit/ rebar.lock
78 changes: 78 additions & 0 deletions c_src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Based on c_src.mk from erlang.mk by Loic Hoguin <[email protected]>

CURDIR := $(shell pwd)
BASEDIR := $(abspath $(CURDIR)/..)

PROJECT ?= $(notdir $(BASEDIR))
PROJECT := $(strip $(PROJECT))

ERTS_INCLUDE_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts/erts-~ts/include/\", [code:root_dir(), erlang:system_info(version)])." -s init stop)
ERL_INTERFACE_INCLUDE_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, include)])." -s init stop)
ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, lib)])." -s init stop)

C_SRC_DIR = $(CURDIR)
C_SRC_OUTPUT ?= $(CURDIR)/../priv/$(PROJECT).so

# System type and C compiler/flags.

UNAME_SYS := $(shell uname -s)
ifeq ($(UNAME_SYS), Darwin)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
LDFLAGS ?= -flat_namespace -undefined suppress
else ifeq ($(UNAME_SYS), FreeBSD)
CC ?= cc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
LDFLAGS ?= -lstdc++
else ifeq ($(UNAME_SYS), Linux)
CC ?= gcc
CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes
CXXFLAGS ?= -O3 -finline-functions -Wall
LDFLAGS ?= -lstdc++
endif

CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
CXXFLAGS += -I isa-l/include -I jerasure/include -I gf-complete/include

LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei
LDFLAGS += gf-complete/src/.libs/*.o jerasure/src/.libs/*.o -Wl,-load_hidden,isa-l/.libs/libisal.a
LDFLAGS += -shared

# Verbosity.

c_verbose_0 = @echo " C " $(?F);
c_verbose = $(c_verbose_$(V))

cpp_verbose_0 = @echo " CPP " $(?F);
cpp_verbose = $(cpp_verbose_$(V))

link_verbose_0 = @echo " LD " $(@F);
link_verbose = $(link_verbose_$(V))

SOURCES := $(shell echo *.cpp)
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))

COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c

$(C_SRC_OUTPUT): $(OBJECTS)
@mkdir -p $(BASEDIR)/priv/
$(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)

%.o: %.c
$(COMPILE_C) $(OUTPUT_OPTION) $<

%.o: %.cc
$(COMPILE_CPP) $(OUTPUT_OPTION) $<

%.o: %.C
$(COMPILE_CPP) $(OUTPUT_OPTION) $<

%.o: %.cpp
$(COMPILE_CPP) $(OUTPUT_OPTION) $<

clean:
@rm -f $(C_SRC_OUTPUT) $(OBJECTS)
Binary file removed rebar
Binary file not shown.
20 changes: 8 additions & 12 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,18 @@
%% under the License.
%%
%%======================================================================
{require_otp_vsn, "R16B*|17|18|19|22"}.
{require_otp_vsn, "22|24|25|26"}.
{xref_checks, [undefined_function_calls]}.

{port_specs, [{"priv/leo_erasure.so", ["c_src/*.cpp"]}]}.

{port_env, [{"CXXFLAGS", "$CXXFLAGS -Wall -I c_src/jerasure/include -I c_src/gf-complete/include -I c_src/isa-l/include -DNIF -fPIC"},
{"CFLAGS", "$CFLAGS -Wall -I c_src/jerasure/include -I c_src/gf-complete/include -I c_src/isa-l/incode -DNIF -fPIC"},
{"DRV_LDFLAGS", "$DRV_LDFLAGS c_src/gf-complete/src/.libs/*.o c_src/jerasure/src/.libs/*.o -Wl,-load_hidden,c_src/isa-l/.libs/libisal.a"},
{pre_hooks, [{compile, "c_src/build_deps.sh"},
{"(linux|darwin|solaris)", compile, "make -C c_src"},
{"(freebsd)", compile, "gmake -C c_src"}]}.

%% Make sure to link -lstdc++ on Linux, FreeBSD, or Solaris
{"(linux|freebsd|solaris)", "LDFLAGS", "$LDFLAGS -lstdc++"}
]}.

{pre_hooks, [{'get-deps', "c_src/build_deps.sh get-deps"},
{compile, "c_src/build_deps.sh"}]}.

{post_hooks, [{clean, "c_src/build_deps.sh clean"}]}.
{post_hooks, [{clean, "c_src/build_deps.sh clean"},
{"(linux|darwin|solaris)", clean, "make -C c_src clean"},
{"(freebsd)", clean, "gmake -C c_src clean"}]}.

{erl_opts, [{d, 'NOTEST'},
warn_obsolete_guard,
Expand All @@ -45,4 +40,5 @@
warn_shadow_vars,
warn_export_vars,
warn_export_all]}.

{xref_checks, [undefined_function_calls]}.
Binary file added rebar3
Binary file not shown.

0 comments on commit 4e253c0

Please sign in to comment.