Commit 925ce89b authored by Ondřej Surý's avatar Ondřej Surý

Dynamically resolve SONAME for libknot and libzscanner from Makefile

and set libknot_SONAME and libzscanner_SONAME as lua literals.

Remove now obsolete libpath lua function - use find_soname from
platform.mk to define <arg>_SONAME, add lua_pushliteral to
daemon/engine.c and add -D to daemon/daemon.mk for any new library
loaded from Lua.
parent 4464b5f7
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
*.out *.out
*.6 *.6
*.log *.log
*.inc /daemon/lua/*.inc
*.mdb *.mdb
*.gcno *.gcno
*.gcda *.gcda
...@@ -54,3 +54,4 @@ kresd.amalg.c ...@@ -54,3 +54,4 @@ kresd.amalg.c
libkres.amalg.c libkres.amalg.c
/doc/kresd.8 /doc/kresd.8
/libkres.pc /libkres.pc
/daemon/lua/sandbox.lua
...@@ -31,6 +31,17 @@ $(eval $(call find_lib,socket_wrapper)) ...@@ -31,6 +31,17 @@ $(eval $(call find_lib,socket_wrapper))
$(eval $(call find_lib,libsystemd,227)) $(eval $(call find_lib,libsystemd,227))
$(eval $(call find_lib,gnutls)) $(eval $(call find_lib,gnutls))
# Lookup SONAME
$(eval $(call find_soname,libknot))
$(eval $(call find_soname,libzscanner))
ifeq ($(libknot_SONAME),)
$(error "Unable to resolve libknot_SONAME, update find_soname in platform.mk")
endif
ifeq ($(libzscanner_SONAME),)
$(error "Unable to resolve libzscanner_SONAME, update find_some in platform.mk")
endif
# Find Go version and platform # Find Go version and platform
GO_VERSION := $(shell $(GO) version 2>/dev/null) GO_VERSION := $(shell $(GO) version 2>/dev/null)
ifeq ($(GO_VERSION),) ifeq ($(GO_VERSION),)
......
...@@ -23,7 +23,9 @@ endif ...@@ -23,7 +23,9 @@ endif
bindings-install: $(kresd_DIST) $(DESTDIR)$(MODULEDIR) bindings-install: $(kresd_DIST) $(DESTDIR)$(MODULEDIR)
$(INSTALL) -m 0644 $(kresd_DIST) $(DESTDIR)$(MODULEDIR) $(INSTALL) -m 0644 $(kresd_DIST) $(DESTDIR)$(MODULEDIR)
kresd_CFLAGS := -fPIE kresd_CFLAGS := -fPIE \
-Dlibknot_SONAME=\"$(libknot_SONAME)\" \
-Dlibzscanner_SONAME=\"$(libzscanner_SONAME)\"
kresd_DEPEND := $(libkres) $(contrib) kresd_DEPEND := $(libkres) $(contrib)
kresd_LIBS := $(libkres_TARGET) $(contrib_TARGET) $(libknot_LIBS) \ kresd_LIBS := $(libkres_TARGET) $(contrib_TARGET) $(libknot_LIBS) \
$(libzscanner_LIBS) $(libdnssec_LIBS) $(libuv_LIBS) $(lua_LIBS) \ $(libzscanner_LIBS) $(libdnssec_LIBS) $(libuv_LIBS) $(lua_LIBS) \
......
...@@ -129,26 +129,6 @@ static int l_setuser(lua_State *L) ...@@ -129,26 +129,6 @@ static int l_setuser(lua_State *L)
return 1; return 1;
} }
/** Return platform-specific versioned library name. */
static int l_libpath(lua_State *L)
{
int n = lua_gettop(L);
if (n < 2)
return 0;
auto_free char *lib_path = NULL;
const char *lib_name = lua_tostring(L, 1);
const char *lib_version = lua_tostring(L, 2);
#if defined(__APPLE__)
lib_path = afmt("%s.%s.dylib", lib_name, lib_version);
#elif _WIN32
lib_path = afmt("%s.dll", lib_name); /* Versioned in RC files */
#else
lib_path = afmt("%s.so.%s", lib_name, lib_version);
#endif
lua_pushstring(L, lib_path);
return 1;
}
/** Quit current executable. */ /** Quit current executable. */
static int l_quit(lua_State *L) static int l_quit(lua_State *L)
{ {
...@@ -508,8 +488,10 @@ static int init_state(struct engine *engine) ...@@ -508,8 +488,10 @@ static int init_state(struct engine *engine)
lua_setglobal(engine->L, "user"); lua_setglobal(engine->L, "user");
lua_pushcfunction(engine->L, l_trustanchor); lua_pushcfunction(engine->L, l_trustanchor);
lua_setglobal(engine->L, "trustanchor"); lua_setglobal(engine->L, "trustanchor");
lua_pushcfunction(engine->L, l_libpath); lua_pushliteral(engine->L, libknot_SONAME);
lua_setglobal(engine->L, "libpath"); lua_setglobal(engine->L, "libknot_SONAME");
lua_pushliteral(engine->L, libzscanner_SONAME);
lua_setglobal(engine->L, "libzscanner_SONAME");
lua_pushcfunction(engine->L, l_tojson); lua_pushcfunction(engine->L, l_tojson);
lua_setglobal(engine->L, "tojson"); lua_setglobal(engine->L, "tojson");
lua_pushcfunction(engine->L, l_map); lua_pushcfunction(engine->L, l_map);
......
...@@ -11,17 +11,7 @@ local bit = require('bit') ...@@ -11,17 +11,7 @@ local bit = require('bit')
local bor = bit.bor local bor = bit.bor
local band = bit.band local band = bit.band
local C = ffi.C local C = ffi.C
local knot = ffi.load(libknot_SONAME)
-- Load any of supported libknot SO versions
local knot
for ver = 2, 3 do
local ok, lib = pcall(ffi.load, libpath('libknot', tostring(ver)))
if ok then
knot = lib
break
end
end
assert(knot, 'support libknot not found')
ffi.cdef[[ ffi.cdef[[
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
-- --
local ffi = require('ffi') local ffi = require('ffi')
local libzscanner = ffi.load(libpath('libzscanner', '1')) local libzscanner = ffi.load(libzscanner_SONAME)
ffi.cdef[[ ffi.cdef[[
void free(void *ptr); void free(void *ptr);
void *realloc(void *ptr, size_t size); void *realloc(void *ptr, size_t size);
......
...@@ -177,3 +177,29 @@ endef ...@@ -177,3 +177,29 @@ endef
define find_gopkg define find_gopkg
HAS_$(1) := $(shell go list $(2) > /dev/null 2>&1 && echo yes || echo no) HAS_$(1) := $(shell go list $(2) > /dev/null 2>&1 && echo yes || echo no)
endef endef
define find_soname
# N/A on Windows
ifeq ($(PLATFORM),Windows)
$(1)_SONAME = $(1).dll
endif
# Use otool -D on OS X
ifeq ($(PLATFORM),Darwin)
$(1)_SONAME = $$(shell otool -D $$$$(pkg-config --variable=libdir $(1))/$(1)$(LIBEXT) | sed -ne 's,.*/\($(1)\.[0-9]*.$(LIBEXT)\),\1,p')
endif
# Use objdump -p on Linux and BSDs
ifeq ($(PLATFORM),POSIX)
ifeq ($(UNAME),OpenBSD)
$(1)_SONAME = $$(shell basename $$$$(readlink -f $$$$(pkg-config --variable=libdir $(1))/$(1)$(LIBEXT)) | cut -f 1-3 -d .)
else
$(1)_SONAME = $$(shell objdump -p $$$$(pkg-config --variable=libdir $(1))/$(1)$(LIBEXT) | sed -ne 's/[[:space:]]*SONAME[[:space:]]*\($(1)\.so\.[0-4]*\)/\1/p')
endif
endif
endef # find_soname
# Use this on OpenBSD
#
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment