summaryrefslogtreecommitdiff
path: root/gtk/Makefile.target
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2015-06-13 11:31:23 +0100
committerVincent Sanders <vince@kyllikki.org>2015-06-17 21:35:40 +0100
commit8ef292b9caf5cae2197493a87480723138f10344 (patch)
treefa39583104ab806b81f382eb85bc9f5a05331dfd /gtk/Makefile.target
parent16fbb97dbb1688fd9b6f19546792b4173bc30bf1 (diff)
downloadnetsurf-8ef292b9caf5cae2197493a87480723138f10344.tar.gz
netsurf-8ef292b9caf5cae2197493a87480723138f10344.tar.bz2
Change GTK UI builder handling to use resource API
GTK UI builder resources have till now been exclusively stored on disc requiring netsurf to ship numerous additional resource files. This requires going to disc every time a UI action is performed which can become a lot of unwanted file handling. GLib/GTK has moved towards GResource handling for such resources instead. It now seems that migrating to this style of usage is expected and indeed the only portable way to include pixbufs. This introduces an API to hide the various implementation details of how resources are handled from the rest of the codebase.
Diffstat (limited to 'gtk/Makefile.target')
-rw-r--r--gtk/Makefile.target41
1 files changed, 36 insertions, 5 deletions
diff --git a/gtk/Makefile.target b/gtk/Makefile.target
index 01c00c2fb..c31cca459 100644
--- a/gtk/Makefile.target
+++ b/gtk/Makefile.target
@@ -65,6 +65,7 @@ $(eval $(call pkg_config_find_and_add,gtk+-$(NETSURF_GTK_MAJOR).0,GTK-$(NETSURF_
$(eval $(call pkg_config_find_and_add,gthread-2.0,GThread2))
$(eval $(call pkg_config_find_and_add,gmodule-2.0,GModule2))
+
CFLAGS += $(GTKCFLAGS)
LDFLAGS += -lm
@@ -76,9 +77,40 @@ ifeq ($(HOST),Windows_NT)
CFLAGS += -U__STRICT_ANSI__
endif
+# ----------------------------------------------------------------------------
+# Builtin resource handling
+# ----------------------------------------------------------------------------
+
+# builtin resource sources
+S_RESOURCE :=
+
+# Glib prior to 2.32 does not have GResource handling.
+#
+# This uses pkg-config to check for the minimum required version for
+# this feature. Note we check for gmodule-2.0 which is a specific
+# part of glib we require.
+# It would be nice if we could check for this functionality rather
+# than "knowing" the version but there does not appear to be a simple
+# way to implement that.
+NETSURF_GRESOURCE_AVAILABLE := $(shell $(PKG_CONFIG) --atleast-version=2.32 gmodule-2.0 && echo yes)
+ifeq ($(NETSURF_GRESOURCE_AVAILABLE),yes)
+
+GLIB_COMPILE_RESOURCES := glib-compile-resources
+CFLAGS += -DWITH_GRESOURCE
+
+S_RESOURCE += $(OBJROOT)/netsurf_gresource.c
+
+NSGTK_RESOURCES_DIR := gtk/res
+GRESOURCE_XML := $(NSGTK_RESOURCES_DIR)/netsurf.gresource.xml
+
+# generate the gresource source file
+$(OBJROOT)/netsurf_gresource.c: $(GRESOURCE_XML) $(shell $(GLIB_COMPILE_RESOURCES) --sourcedir $(NSGTK_RESOURCES_DIR) --generate-dependencies $(GRESOURCE_XML))
+ $(GLIB_COMPILE_RESOURCES) --generate-source --sourcedir $(NSGTK_RESOURCES_DIR) --target=$@ $<
+
+endif
# ----------------------------------------------------------------------------
-# Pixbuf
+# Builtin Pixbuf resources
# ----------------------------------------------------------------------------
GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
@@ -88,7 +120,8 @@ GTK_IMAGE_menu_cursor := gtk/res/menu_cursor.png
# 3: bitmap name
define convert_image
-S_PIXBUF += $(2)
+# add converted pixbuf to builtin resource sources
+S_RESOURCE += $(2)
$(2): $(1)
$(Q)echo "#include <gdk-pixbuf/gdk-pixdata.h>" > $(2)
@@ -101,8 +134,6 @@ endef
# Source file setup
# ----------------------------------------------------------------------------
-#converted pixbuf sources
-S_PIXBUF :=
$(eval $(foreach V,$(filter GTK_IMAGE_%,$(.VARIABLES)),$(call convert_image,$($(V)),$(OBJROOT)/$(patsubst GTK_IMAGE_%,%,$(V)).c,$(patsubst GTK_IMAGE_%,%,$(V))_pixdata)))
@@ -120,7 +151,7 @@ S_GTK := $(addprefix gtk/,$(S_GTK)) $(addprefix utils/,container.c)
# This is the final source build list
# Note this is deliberately *not* expanded here as common and image
# are not yet available
-SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_PIXBUF) $(S_GTK)
+SOURCES = $(S_COMMON) $(S_IMAGE) $(S_BROWSER) $(S_RESOURCE) $(S_GTK)
# The gtk binary target
EXETARGET := nsgtk