Skip to content
This repository was archived by the owner on Dec 17, 2018. It is now read-only.

Commit c0a7799

Browse files
michaelkschmidtConnorRigby
authored andcommitted
First pass at ESQLITE_USE_SYSTEM
This allows the system SQLite to be used instead of the included file
1 parent 988ae1a commit c0a7799

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

Makefile

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,39 @@ ifeq ($(ERL_EI_INCLUDE_DIR),)
22
$(error ERL_EI_INCLUDE_DIR not set. Invoke via mix)
33
endif
44

5+
ifeq ($(ERL_EI_LIBDIR),)
6+
$(error ERL_EI_LIBDIR not set. Invoke via mix)
7+
endif
8+
9+
510
# Set Erlang-specific compile and linker flags
611
ERL_CFLAGS ?= -I$(ERL_EI_INCLUDE_DIR)
7-
ERL_LDFLAGS ?= -L$(ERL_EI_LIBDIR)
12+
ERL_LDFLAGS ?= -L$(ERL_EI_LIBDIR) -lei
813

9-
SRC=$(wildcard c_src/*.c)
10-
OBJ=$(SRC:.c=.o)
14+
SRC = $(wildcard c_src/*.c)
1115

1216
LDFLAGS ?= -fPIC -shared -pedantic
17+
1318
CFLAGS ?= -fPIC -O2
1419
SQLITE_CFLAGS = -DSQLITE_THREADSAFE=1 -DSQLITE_USE_URI -DSQLITE_ENABLE_FTS3 \
1520
-DSQLITE_ENABLE_FTS3_PARENTHESIS -DSQLITE_ENABLE_FTS5 -DSQLITE_ENABLE_JSON1 \
1621
-DSQLITE_ENABLE_RTREE
1722

23+
# ESQLITE_USE_SYSTEM - Use the system sqlite3 library
24+
# Set this ENV var to compile/link against the system sqlite3 library.
25+
# This is necessary if other applications are accessing the same sqlite db
26+
# as the versions must match exactly
27+
28+
ifdef ESQLITE_USE_SYSTEM
29+
CFLAGS += -fPIC
30+
LDFLAGS += -fPIC -shared -pedantic -lsqlite3
31+
else
32+
SRC += $(wildcard c_src/sqlite3/*.c)
33+
CFLAGS += $(SQLITE_CFLAGS) -fPIC -Ic_src/sqlite3
34+
endif
35+
36+
OBJ = $(SRC:.c=.o)
37+
1838
NIF=priv/esqlite3_nif.so
1939

2040
all: priv $(NIF)
@@ -23,7 +43,7 @@ priv:
2343
mkdir -p priv
2444

2545
%.o: %.c
26-
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) $(SQLITE_CFLAGS) -o $@ $<
46+
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) -o $@ $<
2747

2848
$(NIF): $(OBJ)
2949
$(CC) $^ $(ERL_LDFLAGS) $(LDFLAGS) -o $@
File renamed without changes.
File renamed without changes.

lib/esqlite3/esqlite3_nif.ex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ defmodule Esqlite3Nif do
8888
def enable_load_extension(_db, _ref, _dest), do: :erlang.nif_error(:nif_library_not_loaded)
8989

9090
@on_load :load_nif
91+
# Don't load the file automatically during compile
92+
# If we are cross compiled this will cause an error
93+
@compile {:autoload, false}
94+
9195
@doc false
9296
def load_nif do
9397
require Logger

0 commit comments

Comments
 (0)