Add ESQLITE_USE_SYSTEM

This allows the nif to link against the system's SQLite database.
Useful when you need to share the database with other
applications
This commit is contained in:
Michael Schmidt
2019-03-14 15:20:25 +00:00
parent f236290168
commit db73ab8ce2
5 changed files with 51 additions and 25 deletions

2
.gitignore vendored
View File

@@ -7,4 +7,4 @@ priv
*.o *.o
*~ *~
_build _build
c_src/*.d c_src/**/*.d

View File

@@ -1,24 +0,0 @@
{require_min_otp_vsn, "R15"}.
{port_env, [
%% Default darwin ldflags causes loading of system sqlite. Removed -bundle flag.
{"darwin", "DRV_LDFLAGS",
"-flat_namespace -undefined suppress $ERL_LDFLAGS"},
{"solaris", "CFLAGS",
"-std=c99"},
{"linux", "CFLAGS",
"-std=c11"},
{"CFLAGS", "$CFLAGS -DSQLITE_THREADSAFE=1 -DSQLITE_USE_URI -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS"}
]}.
{port_specs, [
{"priv/esqlite3_nif.so", ["c_src/esqlite3_nif.c", "c_src/queue.c", "c_src/sqlite3.c"]}
]}.
{plugins, [pc]}.
{provider_hooks,
[{post,
[{compile, {pc, compile}},
{clean, {pc, clean}}]}]}.

50
rebar.config.script Normal file
View File

@@ -0,0 +1,50 @@
NifSharedSources = ["c_src/esqlite3_nif.c", "c_src/queue.c"].
NifStaticSources = NifSharedSources ++ ["c_src/sqlite3/sqlite3.c"].
CFlagsDefault = "$CFLAGS -DSQLITE_THREADSAFE=1 -DSQLITE_USE_URI -DSQLITE_ENABLE_FTS3 -DSQLITE_ENABLE_FTS3_PARENTHESIS".
DrvLdFlagsDefault = "-shared -lsqlite3".
DrvLdFlags =
case os:getenv("ESQLITE_CFLAGS") of
NotDefined when NotDefined == false; NotDefined == [] -> DrvLdFlagsDefault;
DrvLdFlagsOverride -> DrvLdFlagsOverride
end.
{NifSources, LdEnv, CFlagsExt} =
case os:getenv("ESQLITE_USE_SYSTEM") of
NotDefined when NotDefined == false; NotDefined == [] -> {NifStaticSources, [], []};
_Defined -> {NifSharedSources, [{"DRV_LDFLAGS", DrvLdFlags}], " -Ic_src/sqlite3"}
end.
CFlags =
case os:getenv("ESQLITE_CFLAGS") of
NotDefined when NotDefined == false; NotDefined == [] -> CFlagsDefault ++ CFlagsExt;
CFlagsOverride -> CFlagsOverride
end.
[
{require_min_otp_vsn, "R15"},
{port_env, [
%% Default darwin ldflags causes loading of system sqlite. Removed -bundle flag.
{"darwin", "DRV_LDFLAGS",
"-flat_namespace -undefined suppress $ERL_LDFLAGS"},
{"solaris", "CFLAGS",
"-std=c99"},
{"linux", "CFLAGS",
"-std=c11"},
{"CFLAGS", CFlags}
] ++ LdEnv},
{port_specs, [
{"priv/esqlite3_nif.so", NifSources}
]},
{plugins, [pc]},
{provider_hooks,
[{post,
[{compile, {pc, compile}},
{clean, {pc, clean}}]}]}
].