This is an automated email from the ASF dual-hosted git repository. ronny pushed a commit to branch update-snappy in repository https://gitbox.apache.org/repos/asf/couchdb-snappy.git
commit 7bc779d4b63cba74b36c05d78ddc4f1e26f59cf7 Author: Louis-Philippe Gauthier <[email protected]> AuthorDate: Wed Jul 6 19:03:25 2016 -0400 Add rebar3 support (#15) --- c_src/Makefile | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ rebar.config | 15 ++++++------ 2 files changed, 81 insertions(+), 7 deletions(-) diff --git a/c_src/Makefile b/c_src/Makefile new file mode 100644 index 0000000..68bca8f --- /dev/null +++ b/c_src/Makefile @@ -0,0 +1,73 @@ +# Based on c_src.mk from erlang.mk by Loic Hoguin <[email protected]> + +CURDIR := $(shell pwd) +BASEDIR := $(abspath $(CURDIR)/..) + +PROJECT := snappy_nif + +ERTS_INCLUDE_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~s/erts-~s/include/\", [code:root_dir(), erlang:system_info(version)]).") +ERL_INTERFACE_INCLUDE_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~s\", [code:lib_dir(erl_interface, include)]).") +ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -s init stop -eval "io:format(\"~s\", [code:lib_dir(erl_interface, lib)]).") + +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 -arch x86_64 -finline-functions -Wall -Wmissing-prototypes + CXXFLAGS ?= -O3 -arch x86_64 -finline-functions -Wall + LDFLAGS ?= -arch x86_64 -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 +else ifeq ($(UNAME_SYS), Linux) + CC ?= gcc + CFLAGS ?= -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes + CXXFLAGS ?= -O3 -finline-functions -Wall +endif + +CFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR) +CXXFLAGS += -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR) + +LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lerl_interface -lei +LDFLAGS += -shared -lstdc++ + +# 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 find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.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) diff --git a/rebar.config b/rebar.config index 86fdef1..86804a7 100644 --- a/rebar.config +++ b/rebar.config @@ -1,10 +1,11 @@ {require_otp_vsn, "R13B04|R14|R15|R16|17|18"}. - {erl_opts, [debug_info, warn_unused_vars, warn_shadow_vars, warn_unused_import]}. -{port_env, [ - {"(linux|solaris)", "LDFLAGS", "$LDFLAGS -lstdc++"}, - {"(freebsd)", "LDFLAGS", "$LDFLAGS -lstdc++"} -]}. -{port_specs, [{"priv/snappy_nif.so", ["c_src/*.cc", - "c_src/snappy/*.cc"]}]}. {eunit_opts, [verbose]}. +{pre_hooks, [ + {"(linux|darwin|solaris)", compile, "make -C c_src"}, + {"(freebsd)", compile, "gmake -C c_src"} +]}. +{post_hooks, [ + {"(linux|darwin|solaris)", clean, "make -C c_src clean"}, + {"(freebsd)", clean, "gmake -C c_src clean"} +]}.
