From dab172c9769e161037e59bc34f9a665d33b89736 Mon Sep 17 00:00:00 2001 From: Kazunobu Kuriyama Date: Fri, 2 Oct 2015 22:21:45 +0900 Subject: [PATCH] Tweaks for the build on Mac OS X On Mac OS X, the `file_name` parameter of `g_module_open()` must be an abosolute path to open the module successfully. To fulfil the requirement, the following changes were done: * `lgi/Makefile` - Add a new variable called `GOBJECT_INTROSPECTION_LIBDIR` whose value is set by `pkgconfig` automatically. - Pass the value of the variable to the compiler as a CPP constant macro via `CFLAGS`. * `lgi/core.c` - Construct the absolute path of a module using the value of `GOBJECT_INTROSPECTION_LIBDIR`. --- lgi/Makefile | 4 ++++ lgi/core.c | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lgi/Makefile b/lgi/Makefile index 72a43be3..d638cba8 100644 --- a/lgi/Makefile +++ b/lgi/Makefile @@ -25,6 +25,7 @@ ifeq ($(HOST_OS),darwin) CORE = corelgilua51.so LIBFLAG = -bundle -undefined dynamic_lookup CCSHARED = -fno-common +GOBJECT_INTROSPECTION_LIBDIR = $(shell pkg-config --variable=libdir $(GINAME)) else CORE = corelgilua51.so LIBFLAG = -shared @@ -39,6 +40,9 @@ ifndef COPTFLAGS CFLAGS = -Wall -Wextra -O2 -g endif endif +ifeq ($(HOST_OS),darwin) +CFLAGS += -DGOBJECT_INTROSPECTION_LIBDIR=\"$(GOBJECT_INTROSPECTION_LIBDIR)\" +endif ALL_CFLAGS = $(CCSHARED) $(COPTFLAGS) $(LUA_CFLAGS) $(shell $(PKG_CONFIG) --cflags $(PKGS)) $(CFLAGS) LIBS += $(shell $(PKG_CONFIG) --libs $(PKGS)) ALL_LDFLAGS = $(LIBFLAG) $(LDFLAGS) diff --git a/lgi/core.c b/lgi/core.c index 429e8773..b616a2b8 100644 --- a/lgi/core.c +++ b/lgi/core.c @@ -536,6 +536,13 @@ core_module (lua_State *L) name = g_strdup_printf (MODULE_NAME_FORMAT_PLAIN, luaL_checkstring (L, 1)); +#if defined(__APPLE__) + char *path = g_module_build_path (GOBJECT_INTROSPECTION_LIBDIR, + name); + g_free(name); + name = path; +#endif + /* Try to load the module. */ GModule *module = g_module_open (name, 0); if (module == NULL)