Skip to content

Commit 6d23870

Browse files
authored
Merge pull request #35 from mmzeeman/use-makefile-instead-of-pc
Move to a makefile based nif compilation
2 parents 1827c7e + 59c7015 commit 6d23870

File tree

7 files changed

+124
-96
lines changed

7 files changed

+124
-96
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
uses: actions/checkout@v3
2525

2626
- name: Compile
27-
run: make
27+
run: make NO_OPT=1
2828

2929
- name: Test
30-
run: make test
30+
run: make test NO_OPT=1

c_src/Makefile

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Based on c_src.mk from erlang.mk by Loic Hoguin <[email protected]>
2+
3+
CURDIR := $(shell pwd)
4+
BASEDIR := $(abspath $(CURDIR)/..)
5+
6+
PROJECT ?= $(notdir $(BASEDIR))
7+
PROJECT := $(strip $(PROJECT))
8+
9+
ERTS_INCLUDE_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts/erts-~ts/include/\", [code:root_dir(), erlang:system_info(version)])." -s init stop)
10+
ERL_INTERFACE_INCLUDE_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, include)])." -s init stop)
11+
ERL_INTERFACE_LIB_DIR ?= $(shell erl -noshell -eval "io:format(\"~ts\", [code:lib_dir(erl_interface, lib)])." -s init stop)
12+
13+
DUCKDB_INCLUDE_DIR ?= $(CURDIR)/duckdb
14+
15+
C_SRC_DIR = $(CURDIR)
16+
C_SRC_OUTPUT ?= $(CURDIR)/../priv/$(PROJECT).so
17+
18+
ifeq ($(NO_OPT), 1)
19+
O_LEVEL = 0
20+
else
21+
O_LEVEL ?= 3
22+
endif
23+
24+
# System type and C compiler/flags.
25+
26+
UNAME_SYS := $(shell uname -s)
27+
ifeq ($(UNAME_SYS), Darwin)
28+
CC ?= cc
29+
CFLAGS ?= -O$(O_LEVEL) -std=c99 -finline-functions -Wall -Wmissing-prototypes
30+
CXXFLAGS ?= -O$(O_LEVEL) -finline-functions -Wall
31+
LDFLAGS ?= -flat_namespace -undefined suppress
32+
else ifeq ($(UNAME_SYS), FreeBSD)
33+
CC ?= cc
34+
CFLAGS ?= -O$(O_LEVEL) -std=c99 -finline-functions -Wall -Wmissing-prototypes
35+
CXXFLAGS ?= -O$(O_LEVEL) -finline-functions -Wall
36+
else ifeq ($(UNAME_SYS), Linux)
37+
CC ?= gcc
38+
CFLAGS ?= -O$(O_LEVEL) -std=c99 -finline-functions -Wall -Wmissing-prototypes
39+
CXXFLAGS ?= -O$(O_LEVEL) -finline-functions -Wall
40+
endif
41+
42+
CFLAGS += -fPIC -I $(DUCKDB_INCLUDE_DIR) -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
43+
CXXFLAGS += -std=c++11 -fPIC -I $(ERTS_INCLUDE_DIR) -I $(ERL_INTERFACE_INCLUDE_DIR)
44+
45+
LDLIBS += -L $(ERL_INTERFACE_LIB_DIR) -lei
46+
LDFLAGS += -shared
47+
48+
# Verbosity.
49+
50+
c_verbose_0 = @echo " C " $(?F);
51+
c_verbose = $(c_verbose_$(V))
52+
53+
cpp_verbose_0 = @echo " CPP " $(?F);
54+
cpp_verbose = $(cpp_verbose_$(V))
55+
56+
link_verbose_0 = @echo " LD " $(@F);
57+
link_verbose = $(link_verbose_$(V))
58+
59+
SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
60+
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
61+
62+
COMPILE_C = $(c_verbose) $(CC) $(CFLAGS) $(CPPFLAGS) -c
63+
COMPILE_CPP = $(cpp_verbose) $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
64+
65+
$(C_SRC_OUTPUT): $(OBJECTS)
66+
@mkdir -p $(BASEDIR)/priv/
67+
$(link_verbose) $(CC) $(OBJECTS) $(LDFLAGS) $(LDLIBS) -o $(C_SRC_OUTPUT)
68+
69+
%.o: %.c
70+
$(COMPILE_C) $(OUTPUT_OPTION) $<
71+
72+
%.o: %.cc
73+
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
74+
75+
%.o: %.C
76+
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
77+
78+
%.o: %.cpp
79+
$(COMPILE_CPP) $(OUTPUT_OPTION) $<
80+
81+
clean:
82+
@rm -f $(C_SRC_OUTPUT) $(OBJECTS)

c_src/educkdb_nif.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1491,7 +1491,6 @@ educkdb_parameter_name(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
14911491
static ERL_NIF_TERM
14921492
educkdb_parameter_index(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) {
14931493
char name[MAX_ATOM_LENGTH];
1494-
int len;
14951494
educkdb_prepared_statement *stmt;
14961495
ErlNifBinary bin;
14971496
idx_t index;

rebar.config

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{minimum_otp_vsn, "25.0"}.
2+
3+
{erl_opts, [debug_info]}.
4+
5+
{xref_checks, [undefined_function_calls,
6+
undefined_functions,
7+
locals_not_used,
8+
deprecated_function_calls,
9+
deprecated_functions]}.
10+
11+
{artifacts, ["priv/educkdb.so"]}.
12+
13+
{pre_hooks,
14+
[{"(linux|darwin|solaris)", compile, "make -C c_src"},
15+
{"(freebsd)", compile, "gmake -C c_src"}]}.
16+
{post_hooks,
17+
[{"(linux|darwin|solaris)", clean, "make -C c_src clean"},
18+
{"(freebsd)", clean, "gmake -C c_src clean"}]}.
19+
20+
{dialyzer, [
21+
{warnings, [
22+
unmatched_returns,
23+
error_handling,
24+
race_conditions,
25+
underspecs,
26+
unknown
27+
]}
28+
]}.
29+
30+
{project_plugins, [rebar3_ex_doc]}.
31+
32+
{hex, [{doc, ex_doc}]}.
33+
34+
{ex_doc, [
35+
{source_url, <<"https://github.com/mmzeeman/educkdb">>},
36+
{extras, [<<"README.md">>, <<"LICENSE">>]},
37+
{main, <<"readme">>}
38+
]}.

rebar.config.script

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/educkdb.app.src

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{application, educkdb,
22
[
33
{description, "DuckDB NIF Interface"},
4-
{vsn, "0.9.10"},
4+
{vsn, "0.10.0"},
55
{modules, [educkdb]},
66
{registered, []},
77
{licenses, ["Apache-2.0"]},

src/educkdb.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
-on_load(init/0).
196196

197197
init() ->
198-
NifName = "educkdb_nif",
198+
NifName = "educkdb",
199199
NifFileName = case code:priv_dir(educkdb) of
200200
{error, bad_name} -> filename:join("priv", NifName);
201201
Dir -> filename:join(Dir, NifName)

0 commit comments

Comments
 (0)