You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2021/06/08 21:34:00 UTC

[couchdb-erlfdb] 01/01: rebar3

This is an automated email from the ASF dual-hosted git repository.

rnewson pushed a commit to branch rebar3
in repository https://gitbox.apache.org/repos/asf/couchdb-erlfdb.git

commit 6ee3caa640efd45a39d28c8de925ae602f92ec2e
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Jun 8 22:12:34 2021 +0100

    rebar3
---
 .gitignore                   |  11 +++----
 Makefile                     |   7 +++--
 c_src/Makefile               |  73 +++++++++++++++++++++++++++++++++++++++++++
 enc                          | Bin 23313 -> 0 bytes
 plugins/rebar_gdb_plugin.erl |  13 --------
 rebar.config                 |  25 +++++----------
 6 files changed, 89 insertions(+), 40 deletions(-)

diff --git a/.gitignore b/.gitignore
index 6782584..aa7b660 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,12 +1,11 @@
 
 .eunit/
-.rebar/
+_build/
+rebar.lock
 
-compile_commands.json
-erln8.config
-
-c_src/*.d
 c_src/*.o
-ebin/
 
 priv/erlfdb_nif.*
+
+compile_commands.json
+erln8.config
diff --git a/Makefile b/Makefile
index b6752bc..5f9396e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,10 +1,11 @@
 all: check
 
 build:
-	rebar compile
+	@rebar3 compile
 
 check: build
-	rebar eunit
+	@rebar3 eunit
 
 clean:
-	rebar clean
+	@rebar3 clean
+	@rm -rf _build
diff --git a/c_src/Makefile b/c_src/Makefile
new file mode 100644
index 0000000..131c02d
--- /dev/null
+++ b/c_src/Makefile
@@ -0,0 +1,73 @@
+# Based on c_src.mk from erlang.mk by Loic Hoguin <es...@ninenines.eu>
+
+CURDIR := $(shell pwd)
+BASEDIR := $(abspath $(CURDIR)/..)
+
+PROJECT := erlfdb_nif
+
+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 -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) -lei -lfdb_c
+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 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/enc b/enc
deleted file mode 100755
index 3626e16..0000000
Binary files a/enc and /dev/null differ
diff --git a/plugins/rebar_gdb_plugin.erl b/plugins/rebar_gdb_plugin.erl
deleted file mode 100644
index f27645d..0000000
--- a/plugins/rebar_gdb_plugin.erl
+++ /dev/null
@@ -1,13 +0,0 @@
--module(rebar_gdb_plugin).
--compile(export_all).
-
-pre_eunit(_Config, _AppFile) ->
-    case os:getenv("USE_GDB") of
-        false ->
-            ok;
-        _ ->
-            Prompt = io_lib:format("GDB Attach to: ~s~n", [os:getpid()]),
-            io:get_line(Prompt)
-    end,
-    ok.
-
diff --git a/rebar.config b/rebar.config
index d72bc82..dea0af8 100644
--- a/rebar.config
+++ b/rebar.config
@@ -1,22 +1,11 @@
-{port_specs, [
-    {"priv/erlfdb_nif.so", ["c_src/*.c"]}
-]}.
-
-{plugins, [rebar_gdb_plugin]}.
-
-{port_env, [
-    {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
-        "CFLAGS", "$CFLAGS -Ic_src/ -g -Wall -Werror"},
-    {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
-        "CXXFLAGS", "$CXXFLAGS -Ic_src/ -g -Wall -Werror"},
-
-    {"(linux|solaris|freebsd|netbsd|openbsd|dragonfly|darwin|gnu)",
-        "LDFLAGS", "$LDFLAGS -lfdb_c"}
-]}.
+{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"}]}.
 
 {eunit_opts, [
+    debug_info,
     verbose
 ]}.
-
-{pre_hooks, [{"", compile, "escript enc compile"}]}.
-{post_hooks, [{"", clean, "escript enc clean"}]}.