diff --git a/README.md b/README.md index 3678cad..337a650 100644 --- a/README.md +++ b/README.md @@ -77,8 +77,8 @@ make check-stress # randomized, capacity, collision, failure, and restart test tests. `make docker-check` force-rebuilds and runs all three tiers in the container; run `make docker-image` first after changing `Dockerfile`. -Native Linux builds require a C toolchain, Make, pkg-config, Python 3, and -cmp/diff, plus: +Native Linux source builds require a C toolchain, Make, pkg-config, Python 3, +and cmp/diff, plus development files for: - Plan 9 port (`9c`, `9l`, `libthread`, and `libbio`); - D-Bus development files; @@ -133,10 +133,17 @@ export GTK_IM_MODULE=strans GLFW_IM_MODULE=ibus kitty ``` -The GTK module directory is derived from GTK's pkg-config `libdir` and binary -version. It can be overridden with `GTK_MODULE_DIR`; `DESTDIR` staging is -supported and deliberately skips the host module-cache update. Remove a -native installation with: +Building `gtk/im-strans.so` requires GTK development files. Installing an +already-built, up-to-date module from this build tree does not: the install +target first uses an explicit `GTK_MODULE_DIR`, then GTK's pkg-config +variables, and finally the module directory reported by the GTK runtime's +`gtk-query-immodules-3.0`. Packagers and cross builds should set +`GTK_MODULE_DIR` explicitly. A prebuilt module must still match the target +architecture and library ABI. + +`DESTDIR` staging is supported and deliberately skips the host module-cache +update. A native install needs the GTK runtime query utility so it can refresh +that cache. Remove a native installation with: ```sh doas make -C gtk uninstall diff --git a/gtk/Makefile b/gtk/Makefile index b1283bc..98f4a6a 100644 --- a/gtk/Makefile +++ b/gtk/Makefile @@ -3,10 +3,17 @@ PKG_CONFIG ?= pkg-config CFLAGS ?= -O2 GTK_CFLAGS = $(shell $(PKG_CONFIG) --cflags gtk+-3.0) GTK_LIBS = $(shell $(PKG_CONFIG) --libs gtk+-3.0) -GTK_LIBDIR ?= $(shell $(PKG_CONFIG) --variable=libdir gtk+-3.0) -GTK_BINARY_VERSION ?= $(shell $(PKG_CONFIG) --variable=gtk_binary_version gtk+-3.0) -GTK_MODULE_DIR ?= $(GTK_LIBDIR)/gtk-3.0/$(GTK_BINARY_VERSION)/immodules GTK_QUERY_IMMODULES ?= gtk-query-immodules-3.0 +GTK_LIBDIR ?= $(shell $(PKG_CONFIG) --variable=libdir gtk+-3.0 2>/dev/null) +GTK_BINARY_VERSION ?= $(shell $(PKG_CONFIG) \ + --variable=gtk_binary_version gtk+-3.0 2>/dev/null) +GTK_RUNTIME_MODULE_DIR = $(shell GTK_PATH= GTK_IM_MODULE_FILE= \ + $(GTK_QUERY_IMMODULES) 2>/dev/null | \ + awk -F '"' '/^"\// { sub("/[^/]*$$", "", $$2); print $$2; exit }') +GTK_MODULE_DIR ?= $(strip $(if \ + $(and $(strip $(GTK_LIBDIR)),$(strip $(GTK_BINARY_VERSION))),\ + $(GTK_LIBDIR)/gtk-3.0/$(GTK_BINARY_VERSION)/immodules,\ + $(GTK_RUNTIME_MODULE_DIR))) all: $(PROG) @@ -15,19 +22,29 @@ $(PROG): main.c ../ipc.c ../ipc.h -shared -fPIC -o $@ main.c ../ipc.c $(GTK_LIBS) $(LDLIBS) install: $(PROG) - test -n "$(GTK_LIBDIR)" - test -n "$(GTK_BINARY_VERSION)" - test -n "$(GTK_MODULE_DIR)" - mkdir -p "$(DESTDIR)$(GTK_MODULE_DIR)" - cp $(PROG) "$(DESTDIR)$(GTK_MODULE_DIR)/" - if test -z "$(DESTDIR)"; then $(GTK_QUERY_IMMODULES) --update-cache; fi + module_dir="$(GTK_MODULE_DIR)"; \ + test -n "$$module_dir" || { \ + echo "cannot find GTK 3 module directory; set GTK_MODULE_DIR" >&2; \ + exit 1; \ + }; \ + mkdir -p "$(DESTDIR)$$module_dir" && \ + cp "$(PROG)" "$(DESTDIR)$$module_dir/" && \ + if test -z "$(DESTDIR)"; then \ + GTK_PATH= GTK_IM_MODULE_FILE= \ + $(GTK_QUERY_IMMODULES) --update-cache; \ + fi uninstall: - test -n "$(GTK_LIBDIR)" - test -n "$(GTK_BINARY_VERSION)" - test -n "$(GTK_MODULE_DIR)" - rm -f "$(DESTDIR)$(GTK_MODULE_DIR)/$(PROG)" - if test -z "$(DESTDIR)"; then $(GTK_QUERY_IMMODULES) --update-cache; fi + module_dir="$(GTK_MODULE_DIR)"; \ + test -n "$$module_dir" || { \ + echo "cannot find GTK 3 module directory; set GTK_MODULE_DIR" >&2; \ + exit 1; \ + }; \ + rm -f "$(DESTDIR)$$module_dir/$(PROG)" && \ + if test -z "$(DESTDIR)"; then \ + GTK_PATH= GTK_IM_MODULE_FILE= \ + $(GTK_QUERY_IMMODULES) --update-cache; \ + fi clean: rm -f $(PROG)