From 2c6ab6b092985fc26b96cbdc17204384e7f37bf9 Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Tue, 30 May 2017 23:10:06 +0200 Subject: [PATCH] Use glib-compile-resource instead of sed magic Signed-off-by: Sebastian Ramacher --- .gitignore | 2 +- Makefile | 15 ++++++++------- config.mk | 3 +++ data/zathura-css.gresource.xml | 6 ++++++ zathura/css-definitions.h | 8 -------- zathura/zathura.c | 15 +++++++++++---- 6 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 data/zathura-css.gresource.xml delete mode 100644 zathura/css-definitions.h diff --git a/.gitignore b/.gitignore index 360e877..4f07153 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ # generated files dbus-interface-definitions.c -css-definitions.c +css-definitions.* zathura.1 zathurarc.5 diff --git a/Makefile b/Makefile index af5d2a9..906ccdd 100644 --- a/Makefile +++ b/Makefile @@ -85,16 +85,17 @@ ${PROJECT}/version.h: ${PROJECT}/version.h.in config.mk -e 's/ZVABI/${ZATHURA_ABI_VERSION}/' ${PROJECT}/version.h.in > ${PROJECT}/version.h.tmp $(QUIET)mv ${PROJECT}/version.h.tmp ${PROJECT}/version.h -${PROJECT}/css-definitions.c: data/zathura.css_t - $(QUIET)echo '#include "css-definitions.h"' > $@.tmp - $(QUIET)echo 'const char* CSS_TEMPLATE_INDEX =' >> $@.tmp - $(QUIET)sed 's/^\(.*\)$$/"\1\\n"/' $< >> $@.tmp - $(QUIET)echo ';' >> $@.tmp - $(QUIET)mv $@.tmp $@ +${PROJECT}/css-definitions.%: data/zathura-css.gresource.xml config.mk + $(call colorecho,GEN,$@) + @mkdir -p ${DEPENDDIR}/$(dir $@) + $(QUIET)$(GLIB_COMPILE_RESOURCES) --generate --c-name=zathura_css --internal \ + --dependency-file=$(DEPENDDIR)/$@.dep \ + --sourcedir=data --target=$@ data/zathura-css.gresource.xml # common dependencies -${OBJECTS} ${OBJECTS_DEBUG} ${OBJECTS_GCOV}: config.mk ${PROJECT}/version.h \ +${OBJECTS} ${OBJECTS_DEBUG} ${OBJECTS_GCOV}: config.mk \ + ${PROJECT}/version.h ${PROJECT}/css-definitions.h \ .version-checks/GIRARA .version-checks/GLIB .version-checks/GTK # rlease build diff --git a/config.mk b/config.mk index e07e903..6c78b7e 100644 --- a/config.mk +++ b/config.mk @@ -32,6 +32,9 @@ GTK_PKG_CONFIG_NAME = gtk+-3.0 # pkg-config binary PKG_CONFIG ?= pkg-config +# glib-compile-resources +GLIB_COMPILE_RESOURCES ?= glib-compile-resources + # database # To disable support for the sqlite backend set WITH_SQLITE to 0. WITH_SQLITE ?= $(shell (${PKG_CONFIG} --atleast-version=3.5.9 sqlite3 && echo 1) || echo 0) diff --git a/data/zathura-css.gresource.xml b/data/zathura-css.gresource.xml new file mode 100644 index 0000000..a74b211 --- /dev/null +++ b/data/zathura-css.gresource.xml @@ -0,0 +1,6 @@ + + + + zathura.css_t + + diff --git a/zathura/css-definitions.h b/zathura/css-definitions.h deleted file mode 100644 index 5e31db3..0000000 --- a/zathura/css-definitions.h +++ /dev/null @@ -1,8 +0,0 @@ -/* See LICENSE file for license and copyright information */ - -#ifndef GIRARA_CSS_DEFINITIONS_H -#define GIRARA_CSS_DEFINITIONS_H - -extern const char* CSS_TEMPLATE_INDEX; - -#endif diff --git a/zathura/zathura.c b/zathura/zathura.c index 09fda45..0197c51 100644 --- a/zathura/zathura.c +++ b/zathura/zathura.c @@ -251,10 +251,17 @@ init_css(zathura_t* zathura) g_free(color); } - char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate), - CSS_TEMPLATE_INDEX); - girara_template_set_base(csstemplate, css); - g_free(css); + GResource* css_resource = zathura_css_get_resource(); + GBytes* css_data = g_resource_lookup_data(css_resource, + "/org/pwmt/zathura/CSS/zathura.css_t", + G_RESOURCE_LOOKUP_FLAGS_NONE, NULL); + if (css_data != NULL) { + char* css = g_strdup_printf("%s\n%s", girara_template_get_base(csstemplate), + g_bytes_get_data(css_data, NULL)); + girara_template_set_base(csstemplate, css); + g_free(css); + g_bytes_unref(css_data); + } } static void